Repository navigation
fix(#541): hoist TextDecoder out of SSE read loops in all three adapters - #542
Merged
Merged
Conversation
Contributor
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-542Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr542.tgz
npm install -g packageThis comment is automatically updated on each push. |
Owner
Author
[bot] 🏷 PR 审核完成:通过,可合并。以下结论均为本沙箱独立复验(未仅采信 PR 描述)。 查重: #542 是既有 bug 报告 #541 的修复 PR(标题即 独立验证:
Pre-flight 复跑结果(本分支):
结论: 变更最小(三处各净 +1 行)、打在根因(decoder 实例生命周期)而非症状、回归测试经 A/B 证实有效、pre-flight 干净。分支直接基于最新 master,version 未动,commit message 合规。可以合并——按仓库规则 merge 仅限人工,请自行合并: #542 |
This was referenced Sep 5, 2026
Merged
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.
What
iterSseChunks(openai),iterSseEvents(anthropic) anditerSseEvents(responses) each created a newTextDecoderinside their read loop. With{ stream: true }, an incomplete multi-byte UTF-8 sequence is held in the decoder instance's internal buffer — which was discarded every iteration. The next chunk's orphan continuation bytes (0x80–0xBF) then decoded as U+FFFD, corrupting exactly one CJK character per boundary split (issue #541: random 1–2 U+FFFD mid-character in compressed long sessions).Fix: hoist
const decoder = new TextDecoder()out of the loop in all three adapters — same pattern already used byobserveSseTerminalState(src/stream-terminal.ts:40) and both SSE loops insrc/plugin.ts. One line net effect per site.Sites
src/loop/adapter-openai.ts—iterSseChunkssrc/loop/adapter-anthropic.ts—iterSseEventssrc/loop/adapter-responses.ts—iterSseEventsA repo-wide scan confirmed these are the only in-loop decoders (
stream-terminal.tsandplugin.tswere already correct).Regression tests
New F8 tests in
tests/loop-adapters.test.ts: for each adapter, build a real SSE payload containing CJK text (残留), encode to bytes, split the stream into two chunks right after the lead byte of the second character (worst case: two orphan continuation bytes), run throughparseStream, and assert the text round-trips exactly with no U+FFFD.Verified the guard bites: with the fix stashed, all three F8 tests fail (
残留→残\uFFFD\uFFFD); with the fix, they pass.Pre-flight
npm run typecheck— passnpm test— 1034/1035 pass; the single failure (launcher.test.ts"resolveClientCommand: codex/claude resolve to themselves") is pre-existing in this environment (sandbox has/usr/bin/codex, test expects barecodex) — reproduced identically on pristine master without this changenpm run build— passtests/e2e/e2e-codex.test.ts): preflight (E2E_CHECK=1) passes; full run blocked here because the default local sglang upstream (127.0.0.1:8199) is not running in this sandbox —ECONNREFUSEDon forward, reproduced identically on pristine master (A/B verified). Needs the manual-dispatch CI or a machine with the local upstream up.