Strip lone surrogates from chat-surface replies at the gateway delivery boundary - #55310
Open
MaxFreedomPollard wants to merge 1 commit into
Open
Conversation
tonydwb
reviewed
Jun 30, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
Small fix for lone surrogates crashing Telegram utf16_len encoding.
Looks Good
- Reuses existing _sanitize_surrogates from message_sanitization module
- Only affects chat surfaces (raw text passthrough preserved)
- Test verifies both chat and raw surfaces
- Complements existing surrogate handling in build_assistant_message
This was referenced Jun 30, 2026
Contributor
|
Thanks for tracing the raw final-response path; the non-streaming premise is verified on current main. Problems
Suggested changes
Automated hermes-sweeper review. |
MaxFreedomPollard
force-pushed
the
fix/gateway-delivery-surrogate-sanitize
branch
3 times, most recently
from
July 25, 2026 05:28
47f78fd to
512b562
Compare
…eam deltas Two delivery paths could hand Telegram text that is not UTF-16 encodable (a truncated emoji half from some local-model backends), aborting delivery with UnicodeEncodeError: 1. Final-response boundary: _sanitize_gateway_final_response now surrogate-sanitizes the delivered copy (the stored history copy was already sanitized in build_assistant_message). The interrupt-sentinel fast path added on main (NousResearch#7921) is preserved ahead of it. 2. Streaming: raw deltas reached GatewayStreamConsumer unchanged, so the strict UTF-16 length/edit paths could crash mid-stream before the boundary sanitizer ever ran. Sanitize at the consumer's on_delta entry point - the single chokepoint every delta source (gateway callback, proxy SSE) funnels through. Regressions: boundary tests (chat surface sanitized, raw programmatic surface untouched) and a streaming test asserting the queued delta is UTF-16 encodable.
MaxFreedomPollard
force-pushed
the
fix/gateway-delivery-surrogate-sanitize
branch
from
July 31, 2026 03:52
512b562 to
c068898
Compare
Contributor
|
📌 Overlap note: opened #77395 (fix(agent): close unclosed JSON tool-call args in LIFO order). Touches agent/message_sanitization.py — unrelated concern (repair-correctness vs surrogate stripping), but same file; flagging for coordination. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased onto current main and extended per the sweeper review:
_sanitize_gateway_final_responsesurrogate-sanitizes the delivered copy; the stored history copy was already sanitized inbuild_assistant_message. The interrupt-sentinel fast path added on main (Bug: Telegram users can receive internal system messages like home-channel setup and interrupt status text #7921) is preserved ahead of the sanitize, as requested.GatewayStreamConsumerunchanged, so Telegram's strict UTF-16 length/edit paths could raiseUnicodeEncodeErrormid-stream before the boundary sanitizer ran. Deltas are now sanitized at the consumer'son_deltaentry — the single chokepoint every delta source (gateway stream callback and the proxy SSE path) funnels through, which also makes the behavior directly unit-testable.Regressions: chat-surface sanitize + raw-programmatic-surface passthrough at the boundary, and a streaming test asserting the queued delta content is UTF-16 encodable.
Repro/report: #55309.