Skip to content

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

Closed

Description

@dezren39

Bug: bin proxies corrupt multibyte UTF-8 split across request-body chunks

Eight proxies in bin/ accumulate the request body with bodyText += chunk, where chunk is a Buffer and no handler calls req.setEncoding. Each chunk is therefore stringified on its own: a multibyte UTF-8 sequence straddling a chunk boundary decodes to U+FFFD replacement characters on both sides, and the corrupted text is parsed and forwarded upstream as if the client had sent it. JSON still parses (the damage lands inside string values), so prompts containing emoji/CJK/accented text are silently garbled — no error anywhere.

Evidence (verified this run, main fe62dc7)

Handlers with the pattern (no setEncoding in any of these files):

  • bin/clef-proxy.mjs:194-196
  • bin/agy-proxy.mjs:844-846
  • bin/antigravity-ls-proxy.mjs:751-753
  • bin/claude-code-proxy.mjs:721-723
  • bin/codex-proxy.mjs:1069-1071
  • bin/commandcode-proxy.mjs:897-899
  • bin/design-code-proxy.mjs:180-182
  • bin/muse-proxy.mjs:1484-1486 and bin/muse-proxy.mjs:1582-1584 (two handlers)

The correct house pattern already exists in the same directory: bin/antigravity-direct.mjs:700-701 collects Buffer chunks and decodes once with Buffer.concat(chunks).toString('utf8'); bin/opencode-route-proxy.mjs uses a streaming TextDecoder.

Laptop probe (~/git/fleet/probe-2026-10-31-laneB-chunksplit/, real bin/clef-proxy.mjs from the laptop clone, sha256 7eac5569… identical to sandbox main, stub upstream via CLEF_PROXY_GATEWAY_BASE): POST /v1/systemone with {"questions":{"q":"before-😀-after"}}:

  • Control (single write): stub upstream receives q = "before-😀-after" — intact.
  • Split (first write ends 2 bytes into the emoji's 4-byte sequence, rest 150 ms later): stub upstream receives q = "before-���-after" — 3× U+FFFD, emoji destroyed.

Chunk boundaries are not exotic: Node's HTTP parser emits data per socket read (64 KiB high-water mark), so any non-ASCII character landing on a read boundary of a large body — or simply split by client/network segmentation, as in the probe — is corrupted.

Why it matters

These proxies front the fleet's model traffic (Muse, Codex, Muse, CommandCode, design, agy, antigravity-ls, clef). A user prompt, file content, or tool result with non-ASCII text near a chunk boundary reaches the model with replacement characters substituted in, silently — the request succeeds, the answer is just computed over garbled input. The larger and more international the payload, the more likely a hit.

Acceptance criteria

  • Every handler listed above decodes the body exactly once over the complete byte stream (Buffer.concat + single toString('utf8'), a streaming TextDecoder with {stream: true}, or req.setEncoding('utf8')), matching the antigravity-direct.mjs pattern; the byte-based size caps keep working (count bytes, not decoded characters, if the accumulation changes form).
  • A regression test per affected proxy (or one shared test driving the pattern): a body with a multibyte character split across two writes arrives/parses byte-identical; the existing per-proxy test files (bin/*.test.mjs) still pass.
  • No behavior change for ASCII bodies, oversize bodies (413 path), or malformed JSON (400 path).

Dedup

Searched open + closed issues for bodyText, chunk-boundary / U+FFFD / replacement-character / split-UTF-8 proxy terms on 2026-10-31: no existing issue covers this. Related but distinct: #1844 (proxy-relay RELAY_TARGET_PORTS parsing), #483/#494 (strict port parsing in bin/proxy-port.mjs), #690 closed (clef-proxy JSON parse error shape).

— filed by new-issue-creator-code-b (Lane B), 2026-10-31 run

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/antigravity-ls-proxyPackage/app: antigravity-ls-proxy (bin/ in this repo)
    app/muse-proxybin/muse-proxy.mjs OpenAI-compatible Muse bridge
    on Oct 31, 2026
  2. 12 remaining items

  3. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed
    status/readyTriaged and ready for queued implementation work
    on Nov 2, 2026
  5. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: queue worker (repo-worker-code)
    • Session / ID: task 5657
    • Found via: queue claim
    • Task: Fix split-chunk UTF-8 request-body decoding across the affected bin proxies and add regression coverage.
    • Expectation: effort s — all affected handlers decode complete byte streams correctly, preserve limits/error behavior, and targeted proxy tests pass.
    • Links: branch queue/5657-3186-split-utf8; worktree /home/user/git/fleet/5657 (planned)
  6. removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 2, 2026
  7. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    • Agent: queue worker (repo-worker-code)
    • Session / ID: task 5657
    • Found via: queue claim
    • Task: Fixed split-chunk UTF-8 decoding across the affected proxy request-body handlers.
    • Expectation: effort s — merged implementation, regression coverage, and targeted proxy checks.
    • Links: PR fix: preserve UTF-8 across proxy request chunks #4322 (merged); merge 3af111d928d8a5f0f6fb4a45af00ff5a3b8d95e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/agy-proxybin/agy-proxy.mjs warm-session proxyapp/antigravity-ls-proxyPackage/app: antigravity-ls-proxy (bin/ in this repo)app/claude-code-proxybin/claude-code-proxy.mjsapp/clef-proxybin/clef-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 job

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions