Finding
bin/design-code-proxy.mjs's writeHead() helper (added by PR #682, fixing #681) forwards the backend's Content-Length header verbatim, but the non-stream success path then sends a different body than the backend sent: it re-serializes the parsed JSON with the model field rewritten and pretty-printing (JSON.stringify(json, null, 2)). Whenever the backend sets Content-Length — the normal behaviour of a buffered JSON HTTP server — the forwarded length is the length of the backend's original (usually compact) body, so the client reads exactly that many bytes and gets truncated, unparseable JSON.
Evidence (PR + current main):
-
PR: fix(design-code-proxy): fall back on quota errors in a 200 JSON body instead of hanging (#681) #682 (1 commit be7244972df90becc95b70b018ab23489c6f8163, merge c6ec7bd623df42909fdfa2225d249b593ad2e44c = current main)
-
bin/design-code-proxy.mjs:224-231 on main c6ec7bd6:
const writeHead = () => {
if (!clientRes.headersSent) {
clientRes.writeHead(localRes.statusCode || 200, {
...localRes.headers,
'Access-Control-Allow-Origin': '*'
});
}
};
...localRes.headers includes the backend's content-length.
-
bin/design-code-proxy.mjs:270-272: json.model = modelId; writeHead(); clientRes.end(JSON.stringify(json, null, 2)); — the body actually sent is longer than the backend's body in essentially every case (pretty-printing alone guarantees it; the model rewrite usually changes the length too).
Reproduced on current main (c6ec7bd6)
Ran the real bin/design-code-proxy.mjs with stub backends (same stub pattern as bin/design-code-proxy.test.mjs), except the primary stub sets an explicit Content-Length on its compact JSON success body, as a standard HTTP server does:
- Request: non-stream
design-code-flash chat completion, primary returns 200 with Content-Length: 191 and a 191-byte compact JSON body.
- Proxy response: status 200,
content-length: 191 forwarded — but the re-serialized pretty body is longer, so the client receives exactly 191 bytes, ending mid-JSON.
JSON.parse of the received body fails: Expected ',' or '}' after property value in JSON at position 191.
- Control: the PR's own test suite passes 5/5 on the same main — its stubs never set
Content-Length (Node then answers chunked), which is why the suite cannot see this. The sibling in-repo proxies (muse/codex/agy) also happen to answer chunked (they set only Content-Type), so the default local chain may not trigger it today; any backend that sets Content-Length — e.g. the real Antigravity LS backend this proxy fronts, or any Go/Rust/framework server — truncates every successful non-stream response through this proxy.
The streaming path uses the same writeHead() spread, so the same mismatch applies in principle there too (each SSE chunk's model is rewritten, changing lengths); SSE backends normally answer chunked, so the verified harm is the non-stream path.
Why it matters
This turns the proxy's success path into corrupted output for a whole class of standards-compliant backends: the client gets a 200 with a syntactically invalid JSON body instead of the completion. It sits in the exact helper PR #682 introduced, and the new test file's stubs mask it by never sending the one header that triggers it.
Acceptance criteria
- A non-stream success response from a backend that sets
Content-Length arrives at the client complete and parseable, with model rewritten to the design model id (no truncation).
- The proxy does not forward a stale
Content-Length for any body it re-serializes (drop the header and let Node frame the response, or set it to the actual sent length); headers for bodies forwarded byte-for-byte (the non-JSON catch branch) stay correct.
- Regression test: a stub backend that sets an explicit
Content-Length on its JSON success body, asserting the client receives the full model-rewritten body; the existing 5 tests in bin/design-code-proxy.test.mjs still pass.
- Streaming success behaviour unchanged.