Skip to content

bin(proxies): response-side per-chunk decode corrupts multibyte UTF-8 split across chunks — stdout line buffers and design-code response accumulators stringify each chunk separately (response-side twin of #3186) #4336

Closed

Description

@dezren39

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 _onStdout
  • bin/claude-code-proxy.mjs:369 — this.lineBuffer += chunk.toString('utf-8'); in _onStdout
  • bin/codex-proxy.mjs:947 — lineBuffer += chunk.toString('utf-8');
  • bin/commandcode-proxy.mjs:592 and bin/commandcode-proxy.mjs:1145 — two stdout handlers
  • bin/muse-proxy.mjs:464 and bin/muse-proxy.mjs:1774 — two stdout handlers

Upstream response accumulation (design-code-proxy):

  • bin/design-code-proxy.mjs:412 — SSE streaming buffer += chunk.toString('utf-8'); (lines are JSON-parsed, model-rewritten, and re-serialized to the client)
  • bin/design-code-proxy.mjs:437 — non-streaming fullBody += chunk.toString('utf-8'); before JSON.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 in bin/*.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

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    effort/sSmall: expected under 2 hours of work
    app/codex-proxybin/codex-proxy.mjs fleet proxy
    app/agy-proxybin/agy-proxy.mjs warm-session proxy
    app/muse-proxybin/muse-proxy.mjs OpenAI-compatible Muse bridge
    on Nov 2, 2026
  2. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. 36 remaining items

  4. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed on Nov 2, 2026
  5. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  6. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 2, 2026
  7. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  8. added a commit that references this issue on Nov 2, 2026
  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/agy-proxybin/agy-proxy.mjs warm-session proxyapp/claude-code-proxybin/claude-code-proxy.mjsapp/codex-proxybin/codex-proxy.mjs fleet proxyapp/commandcode-proxybin/commandcode-proxy.mjs fleet proxyapp/design-code-proxybin/design-code-proxy.mjs fleet proxyapp/muse-proxybin/muse-proxy.mjs OpenAI-compatible Muse bridgeeffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions