Skip to content

fix(sanitizer): strip zero-width chars from Anthropic-native streaming text_delta (#8271) - #8287

Merged
diegosouzapw merged 1 commit into
cheaper-inference:release/v3.8.49from
Dingding-leo:fix/anthropic-streaming-zero-width
Jul 23, 2026
Merged

diegosouzapw merged 1 commit into
cheaper-inference:release/v3.8.49from
Dingding-leo:fix/anthropic-streaming-zero-width

Conversation

@Dingding-leo

Copy link
Copy Markdown
Contributor

Summary

Fixes #8271. sanitizeStreamingChunk() only stripped zero-width characters (U+200B, U+200C, U+200D, U+FEFF) from OpenAI-format choices[].delta.content. Anthropic-native content_block_delta events with text_delta or thinking_delta payloads bypassed that path entirely, leaking zero-width characters to clients on the Messages API streaming route.

Root Cause

The sanitizer had two code paths:

  1. response.* events → sanitizeResponsesStreamingEvent()
  2. OpenAI choices[].delta.content → zero-width strip

Anthropic content_block_delta events fell through as unrecognized and were returned with only id/object/created/model stripped — text payloads (delta.text, delta.thinking) passed through unmodified.

Changes

Verification

  • npx tsc --pretty false -p tsconfig.typecheck-core.json — zero errors
  • tests/unit/response-sanitizer.test.ts — 50/50 pass

1 file changed, +17

…g text_delta (#8271)

sanitizeStreamingChunk() only stripped zero-width characters (U+200B,
U+200C, U+200D, U+FEFF) from OpenAI-format choices[].delta.content.
Anthropic-native content_block_delta events with text_delta or
thinking_delta payloads bypassed that path entirely, leaking U+200D
to clients on the Messages API streaming route.

Add a content_block_delta branch that strips zero-width characters
from delta.text and delta.thinking before returning the event,
matching the existing OpenAI path behavior from #5857.
Copilot AI review requested due to automatic review settings July 23, 2026 13:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks, @Dingding-leo! 🙏 Merged — strips zero-width chars from Anthropic-native sanitizer input. Nice hardening.

@diegosouzapw
diegosouzapw merged commit acd3d46 into cheaper-inference:release/v3.8.49 Jul 23, 2026
5 checks passed
@diegosouzapw diegosouzapw mentioned this pull request Jul 28, 2026
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
…g text_delta (cheaper-inference#8271) (cheaper-inference#8287)

sanitizeStreamingChunk() only stripped zero-width characters (U+200B,
U+200C, U+200D, U+FEFF) from OpenAI-format choices[].delta.content.
Anthropic-native content_block_delta events with text_delta or
thinking_delta payloads bypassed that path entirely, leaking U+200D
to clients on the Messages API streaming route.

Add a content_block_delta branch that strips zero-width characters
from delta.text and delta.thinking before returning the event,
matching the existing OpenAI path behavior from cheaper-inference#5857.

Co-authored-by: Austin Liu <austinliu@Austins-MacBook-Air-3.local>
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…g text_delta (cheaper-inference#8271) (cheaper-inference#8287)

sanitizeStreamingChunk() only stripped zero-width characters (U+200B,
U+200C, U+200D, U+FEFF) from OpenAI-format choices[].delta.content.
Anthropic-native content_block_delta events with text_delta or
thinking_delta payloads bypassed that path entirely, leaking U+200D
to clients on the Messages API streaming route.

Add a content_block_delta branch that strips zero-width characters
from delta.text and delta.thinking before returning the event,
matching the existing OpenAI path behavior from cheaper-inference#5857.

Co-authored-by: Austin Liu <austinliu@Austins-MacBook-Air-3.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Native Anthropic streaming text leaks U+200D despite #5857

3 participants