Skip to content

fix(anthropic_stream_events): fail closed on malformed upstream UTF-8 (#553) - #873

Open
leseb wants to merge 1 commit into
praxis-proxy:mainfrom
leseb:leseb/fix-issue-553
Open

fix(anthropic_stream_events): fail closed on malformed upstream UTF-8 (#553)#873
leseb wants to merge 1 commit into
praxis-proxy:mainfrom
leseb:leseb/fix-issue-553

Conversation

@leseb

@leseb leseb commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Once the anthropic_stream_events filter has begun emitting Anthropic Messages events, malformed or truncated UTF-8 in the upstream OpenAI SSE was passed through raw and transformation then resumed, producing a single response that mixed two incompatible wire formats and leaked raw Chat Completions bytes (including buffered partial event text) to the client. This fails the transformed stream closed with a FilterError on malformed UTF-8 and discards buffered SSE line data, which is the smallest change that restores protocol consistency.

Related issue

Closes #553

Validation

  • Unit tests — reworked invalid_utf8_rejected, invalid_utf8_after_stream_start_rejected, truncated_utf8_at_end_of_stream_rejected, pending_utf8_rejected_by_none_end_of_stream_body, and malformed_utf8_discards_partial_sse_buffer
  • Integration or functional tests — make test (full workspace, 0 failures)
  • make lint (clippy -D warnings, deps, docs/README syncs, check-inference all green)

Checklist

  • I reviewed every changed line and can explain the change.
  • New capabilities include an example config and functional example test. — N/A: bug fix, no new capability.
  • User-facing behavior and generated documentation are updated. — no doc changes required; sync-* and check-inference pass.
  • Performance-sensitive changes include appropriate benchmark or load-test evidence. — N/A: removes an allocation/passthrough path, no perf regression.
  • Commits are signed and include a Signed-off-by trailer.

Breaking changes

None. Malformed UTF-8 was already an invalid upstream SSE response; the stream now fails closed instead of emitting a mixed-format response.

…praxis-proxy#553)

Once the filter has emitted Anthropic Messages events, passing malformed OpenAI SSE bytes through unchanged and then resuming transformation produced a single response mixing two incompatible wire formats, leaking raw Chat Completions SSE (including buffered partial event text) to the client.

Return a FilterError when the combined buffer contains malformed UTF-8 and discard any buffered SSE line data instead of flushing it, so the transformed stream fails closed. Remove the now-unused passthrough_with_line_buffer helper and CombinedUtf8Chunk::into_bytes.

Signed-off-by: Sébastien Han <seb@redhat.com>
@leseb
leseb requested review from a team and crstrn13 September 2, 2026 10:42
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.

Malformed Anthropic stream UTF-8 passes raw OpenAI bytes inside a transformed response

1 participant