Repository navigation
Description
Bug: bin proxies decode subprocess/response streams per chunk — multibyte UTF-8 split across chunks is corrupted to U+FFFD on the response side (the response-side twin of #3186)
#3186 fixed the request-body side: eight proxies collected request bodies with per-chunk stringification, and the fix introduced the shared bin/request-body.mjs collector (Buffer-concat, decode once). The response side was never given the same treatment. Across bin/, subprocess stdout line buffers and upstream response accumulators still do buffer += chunk.toString('utf-8') per chunk, with no StringDecoder anywhere in bin/ (grep-verified). A multibyte UTF-8 sequence straddling a chunk boundary decodes to U+FFFD on both sides. Because the damage lands inside JSON string values, the line still parses — assistant/response text containing emoji, CJK, or accented characters is silently garbled before it reaches the client, with no error anywhere. (Flagged as an unverified lead by lane A earlier today; verified this run.)
Sites (main f576a6c)
JSON-line stdout buffers (parsed events / content deltas flow through these):
bin/agy-proxy.mjs:574—this.lineBuffer += chunk.toString();in_onStdoutbin/claude-code-proxy.mjs:369—this.lineBuffer += chunk.toString('utf-8');in_onStdoutbin/codex-proxy.mjs:947—lineBuffer += chunk.toString('utf-8');bin/commandcode-proxy.mjs:592andbin/commandcode-proxy.mjs:1145— two stdout handlersbin/muse-proxy.mjs:464andbin/muse-proxy.mjs:1774— two stdout handlers
Upstream response accumulation (design-code-proxy):
bin/design-code-proxy.mjs:412— SSE streamingbuffer += chunk.toString('utf-8');(lines are JSON-parsed, model-rewritten, and re-serialized to the client)bin/design-code-proxy.mjs:437— non-streamingfullBody += chunk.toString('utf-8');beforeJSON.parse(fullBody)
Same pattern, lower impact (ASCII-shaped output today, still in scope for the audit): bin/agy-proxy.mjs:271 (stdout += d feeding parseAgyModelsOutput) and bin/muse-proxy.mjs:243 (out += c.toString('utf-8') feeding a --flag scan). The per-chunk stderr tails in the same files share the flaw for diagnostic text.
The correct house patterns already exist in the same directory: bin/request-body.mjs (Buffer-concat / decode-once for request bodies) and node:string_decoder's StringDecoder for streaming line buffers.
Evidence (verified this run, main f576a6c)
Laptop probe (~/git/fleet/probe-2026-11-02-laneB-stdoututf8/, laptop clone at the same HEAD f576a6c; bin/claude-code-proxy.mjs md5 5bc03524c6d6874a5c14156d939de4e2 and bin/agy-proxy.mjs md5 d63469ac6958f95bdee8403d78a6f259, identical to sandbox main): the verbatim _onStdout method bodies extracted by line range from both files were fed a JSON line {"type":"assistant","text":"before-☃é😀-after"} as two chunks split 1 byte into the ☃ (3-byte) sequence:
- claude-code-proxy
_onStdout: parsed message text ="before-���é😀-after"— ☃ destroyed (3× U+FFFD) - agy-proxy
_onStdout: parsed message text ="before-���é😀-after"— same corruption - StringDecoder control (same chunks):
"before-☃é😀-after"— intact
Chunk boundaries on a pipe/socket are not exotic: a busy CLI emitting large JSON lines will routinely split output at 64 KiB (or smaller) boundaries, and any non-ASCII character near one is garbled.
Why it matters
These proxies are the fleet's front door to the model CLIs. Response text is the product: garbled characters in streamed assistant output, code comments, and non-English text are silent data corruption in exactly the place #3186 already established is unacceptable on the request side. It is also a latent trap for any future structured field that must round-trip exactly (ids, hashes, signatures) if one ever lands in a split string value.
Acceptance criteria
- Every stdout line buffer and response accumulator listed above decodes via a streaming
StringDecoder(or Buffer-concat/decode-once where the consumer is whole-body), including the end-of-stream flush (decoder.end()tail is processed through the same line path). - A regression test in the house style (cf.
bin/antigravity-ls-proxy.test.mjs"preserves UTF-8 split across HTTP request-body chunks (bin(proxies): bodyText += chunk corrupts multibyte UTF-8 split across chunks — 8 proxies stringify each Buffer chunk separately, non-ASCII text straddling a boundary reaches upstream as U+FFFD #3186)") feeds a multibyte character split across two chunks through at least the claude-code-proxy and agy-proxy stdout paths and one design-code-proxy response path, and asserts the parsed/forwarded text is byte-identical. - No per-chunk
chunk.toString()accumulation remains on stdout/response paths inbin/*.mjs(grep-auditable), except demonstrably ASCII-only uses that are commented as such. - Existing per-proxy test suites pass on the laptop or CI.
Related: #3186 (request-body twin, closed), #4335 (opencode-route-proxy request body, open — same class, different file/side).
Activity
dezren39 commentedon Nov 2, 2026
🤖 Agent note · filed
_onStdoutextractions on the laptop.36 remaining items
dezren39 commentedon Nov 2, 2026
🤖 Agent note · parked
dezren39 commentedon Nov 2, 2026
🤖 Agent note · picked up
queue/6213-4336-stringdecoderMerge pull request #4341 from developing-today/queue/6213-4336-string…
dezren39 commentedon Nov 2, 2026
🤖 Agent note · done
~/git/fleet/6213-4336at PR head 50ba5cf):bin/stream-decode.test.mjs3/3 pass; per-proxy suites: agy-proxy 13/13, claude-code-proxy 7/7, commandcode-proxy 4/4, design-code-proxy 16/16, muse-proxy 28/28 — all pass. codex-proxy: 12 of 13 pass, 0 fail; the 13th test was cancelled by a 900s timeout (each codex test burns ~60s under laptop load 126–190; the earlier combined run's apparent hang was the same load/timeout artifact, proven by the solo rerun's steady passes). No Codex review round was posted on PR fix(bin): decode proxy response streams with StringDecoder (#4336) #4341 despite a review request, so no findings were outstanding.bin/muse-proxy.mjson main; PR Fix request-scoped direct tool aliases #3102 (task 4371) will need a rebase by its owner — task 5434's park resume condition (PR Fix request-scoped direct tool aliases #3102 merges/closes) is unchanged.queue/6213-4336-stringdecoder