Skip to content

fix(streaming): preserve Unicode across reply envelope boundaries - #574

Draft
dovvnloading wants to merge 3 commits into
mainfrom
fix/573-unicode-stream-envelopes
Draft

dovvnloading wants to merge 3 commits into
mainfrom
fix/573-unicode-stream-envelopes

Conversation

@dovvnloading

@dovvnloading dovvnloading commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Problem

Live replies can display stray internal markup or lose visible Unicode characters around reply envelopes. This breaks parity between the streamed answer and the completed answer.

Closes #573.

Root cause

Unicode lowercasing can expand characters, shifting offsets when a lowercased string is searched and the original string sliced. Lowercase equality also disagrees with Python's Unicode case-insensitive regular expressions. After main introduced JSON-aware closing-tag detection (#612), the scanner and malformed-JSON fallback still had these mismatches.

Change

  • Match complete opening and closing tags against original characters using escaped literal regular expressions with the cleaner's case-insensitive semantics.
  • Match incomplete opening tags against a bounded suffix of the original text; preserve normal prose and leading-only reasoning.
  • Preserve JSON string/escape tracking, including ignoring literal closing tags inside valid JSON strings. Match actual closers and malformed-payload fallback on original text in both the stream and final parser.
  • Add 17 stream fixtures, three JSON closer offset/case regression checks, and nine cleaner/agent parity fixtures. Exercise whole replies, per-character streams, every two-chunk split and intermediate output.
  • Record the change in the Unreleased changelog.

Branch integration and verification

Updated to main c9c3e9bba34842987b9bbc46aab3e7aa4ca7378e (29 incoming commits) in 709f5c0766647b1d63121549e1d9fb89e6d3511b using a non-force merge commit. Compared the resulting tree against main: only five intended files differ; mergeability is restored. Main's Quality and Python compatibility runs passed before integration.

Check Result
Isolated baseline reproduction on relevant main code 13/19 stream fixtures failed; 3/3 closer checks failed
Isolated patched reproduction 19/19 stream fixtures passed (1,094 chunk scenarios, including two existing JSON behavior fixtures); 3/3 closer checks passed
Previous PR head Quality Passed (historical)
Previous PR head Python compatibility 3.13 passed; 3.14 failed on Windows PowerShell smoke-test timeout (2,602 passed, 1 failed, 6 skipped)
Updated head Quality Fresh run requested automatically by branch update; pending
Updated head Python compatibility Fresh run requested automatically by branch update; pending

The new local reproduction used Python 3.13.5 and an isolated harness transcribing the relevant stream and JSON-closer implementation from the pinned source, with equivalent patch changes. This is not an exact full checkout or the actual repository pytest suite: DNS prevents cloning, and the pinned dependencies/Windows runtime are unavailable locally. The fresh CI runs are required to verify the actual committed code and integration tests. The historical Windows failure may be unrelated but has not been conclusively diagnosed; no timeout assertions, skips, or CI settings have been altered.

Scope and risk

No API schema, dependencies, execution permissions, proposal validation, persistence, generated artifacts, or sandbox tests are changed. Regex patterns are escaped literals; the suffix search is bounded and the JSON scan remains incremental. Coverage floors and required Quality checks are unchanged. Keep this PR draft until fresh verification and maintainer review are complete.

Rollback

Revert the eventual squash commit if a regression is observed. No data migration is necessary.

Historical verification (original PR head)

The original PR description reported 10 failing and 3 passing baseline tests, 13 passing fixed tests, three killed targeted mutants (opening, closing, partial matching), byte-compilation passing and exact-source blob identity. These results apply only to the previous version; they are not claims about the updated head.

Use case-insensitive matches on original text to preserve character offsets.
Cover chunk boundaries, Unicode tag variants, and parser/stream parity.

Refs #573
Merge main and preserve its JSON-aware closer scanner. Match literal tags
on original text with re.IGNORECASE, including malformed JSON fallback.
Extend stream and parser regression coverage for Unicode offsets, quoted
closers, malformed payloads and escaped quotes. No changes to CI, execution
permissions or sandbox timeout assertions.

Refs #573

This branch has not been deployed

No deployments
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.

Streamed answers can lose Unicode text or display internal reply tags

1 participant