Skip to content

opencode-route-proxy: request body decoded per chunk — multibyte UTF-8 split across chunks reaches the leaf as U+FFFD (the #3186 fix missed this proxy; also no body size cap) #4335

Closed

Description

@dezren39

Problem

bin/opencode-route-proxy.mjs is the one proxy the #3186 fix missed. Its chat-completions handler still assembles the request body by string-concatenating each network chunk:

// bin/opencode-route-proxy.mjs:988-990 (main 3d5023d0)
if (req.method === "POST" && url.pathname === "/v1/chat/completions") {
  let raw = "";
  for await (const part of req) raw += part;

raw += part coerces each Buffer chunk to a UTF-8 string separately. A multibyte character whose bytes straddle a chunk boundary is decoded as U+FFFD replacement characters on both sides of the split — exactly the bug #3186 fixed in the other eight proxies (bin/request-body.mjs's createRequestBodyCollector, PR #4322 / commit 7733c68), whose fix commit touched agy, antigravity-ls, claude-code, clef, codex, commandcode, design-code and muse proxies but not this one. #3186's own title scopes it to those 8 proxies, and this file is not among them.

The corrupted body is still valid JSON, so the request succeeds (HTTP 200) and the leaf provider receives silently mangled user content — no error anywhere.

Verified (this run, laptop probe)

Probe: ~/git/fleet/probe-2026-11-02-laneA-routeutf8/probe.mjs — runs the real proxy (laptop clone at main 3d5023d, bin/opencode-route-proxy.mjs md5 c7ad0712, matching the sandbox clone) against a stub leaf that decodes its received body correctly (Buffer concat), with a raw-socket chunked-encoding client:

  • Control (whole body in one chunk): leaf receives "café ☃ fin" — intact.
  • Test (chunk split inside the é bytes 0xC3|0xA9 and inside the ☃ bytes 0xE2|0x98 0x83): leaf receives "caf�� ��� fin" — every split character replaced by U+FFFD, response still HTTP/1.1 200 OK.

Secondary facet: no body size bound

The same loop accumulates raw with no cap (no 413 / length check anywhere in the file — grep for 413|content-length|maxBytes is empty). The sibling proxies bound bodies at 20–50 MB via the collector and answer 413. A client (or a stuck sender) can grow this proxy's memory unboundedly with one request.

Why it matters

This proxy is the fleet's routing door for OpenAI-compatible clients (#2518); chat traffic routinely carries non-ASCII content (accented text, CJK, emoji, math symbols), and TCP chunk boundaries are not under the sender's control — any sufficiently large or unluckily segmented request can be silently corrupted in transit while every health signal stays green.

Acceptance criteria

  • The /v1/chat/completions body is collected as bytes and decoded once after the full body arrives — e.g. via the shared createRequestBodyCollector from bin/request-body.mjs, as in the other eight proxies.
  • Regression test in bin/opencode-route-proxy.test.mjs: a chunked request whose chunk boundary falls inside a multibyte UTF-8 character reaches the leaf byte-for-byte intact (the probe above is a ready-made repro).
  • The body is size-bounded with a 413 response past the cap, consistent with the sibling proxies (20–50 MB range; pick and document one).
  • No other per-chunk string coercion of request bodies remains in this file.

Related: #3186 (closed — the same bug in the other eight proxies), #4259 (this proxy's window-time validation).

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
    on Nov 2, 2026
  2. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 2, 2026
  4. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked_up

  5. 31 remaining items

  6. developing-today commented on Nov 3, 2026

    @developing-today
    Contributor

    agent-note:v1
    state: triaged (coverage pass)
    Coverage pass 2026-11-03: reviewed in the fleet-wide per-issue pass (drift / overlap / already-handled / stale / blockers / ordering). Verdict: still live; queued in repo-health-code-pilot as triage at priority 40 (priority/normal). If this is already handled at current main, the triage closes it with evidence; if it needs splitting, the triage files the split.
    Found via: coverage pass 2026-11-03

  7. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 3, 2026
  8. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    Agent note — picked up (OpenChamber scheduled lane)

  9. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    Agent note — triage findings (OpenChamber scheduled lane)

  10. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triage verdict — SUPERSEDED: the route proxy was retired; closing

  11. added 2 commits that reference this issue on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/opencode-route-proxybin/opencode-route-proxy.mjs fleet proxyeffort/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