Title: design-code-proxy: forwarded Content-Length truncates the re-serialized success body (PR #682) · Issue #684 · developing-today/code · GitHub
Open Graph Title: design-code-proxy: forwarded Content-Length truncates the re-serialized success body (PR #682) · Issue #684 · developing-today/code
X Title: design-code-proxy: forwarded Content-Length truncates the re-serialized success body (PR #682) · Issue #684 · developing-today/code
Description: 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-serial...
Open Graph Description: 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 ...
X Description: 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 di...
Opengraph URL: https://github.com/developing-today/code/issues/684
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"design-code-proxy: forwarded Content-Length truncates the re-serialized success body (PR #682)","articleBody":"## Finding\n\n`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**.\n\nEvidence (PR + current main):\n\n- PR: https://github.com/developing-today/code/pull/682 (1 commit `be7244972df90becc95b70b018ab23489c6f8163`, merge `c6ec7bd623df42909fdfa2225d249b593ad2e44c` = current main)\n- `bin/design-code-proxy.mjs:224-231` on main `c6ec7bd6`:\n\n ```js\n const writeHead = () => {\n if (!clientRes.headersSent) {\n clientRes.writeHead(localRes.statusCode || 200, {\n ...localRes.headers,\n 'Access-Control-Allow-Origin': '*'\n });\n }\n };\n ```\n\n `...localRes.headers` includes the backend's `content-length`.\n- `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).\n\n## Reproduced on current main (`c6ec7bd6`)\n\nRan 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:\n\n- Request: non-stream `design-code-flash` chat completion, primary returns 200 with `Content-Length: 191` and a 191-byte compact JSON body.\n- 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.\n- `JSON.parse` of the received body fails: `Expected ',' or '}' after property value in JSON at position 191`.\n- 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.\n\nThe 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.\n\n## Why it matters\n\nThis 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.\n\n## Acceptance criteria\n\n- [ ] 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).\n- [ ] 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.\n- [ ] 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.\n- [ ] Streaming success behaviour unchanged.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-23T19:41:19Z","url":"https://github.com/developing-today/code/issues/684"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:149fc97a-c5ad-3d05-abf3-b91b2ee76896 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9FB2:249987:6FFA03:96067B:6B062F2D |
| html-safe-nonce | 49f6c5770908aa94099befb63a9ff8e0473326bf53a306f563acddbefd7451e7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkIyOjI0OTk4Nzo2RkZBMDM6OTYwNjdCOjZCMDYyRjJEIiwidmlzaXRvcl9pZCI6IjcyODI2MDE2NDA0Mzg2NzMxOTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2bd520e35250ed69c4f5e3511eb4d7b2cbf98e3f9bc0db876ace4a3c0b45ca80 |
| hovercard-subject-tag | issue:6004342557 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/684/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7c4d275da32f23478c6b77b861b7aa8e9e1df9e30992a98327c8c0661d366bcc/developing-today/code/issues/684 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7c4d275da32f23478c6b77b861b7aa8e9e1df9e30992a98327c8c0661d366bcc/developing-today/code/issues/684 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7f961de5dd5c5d4aca24d33f8b3ffb3fb8b2ef53d0a4f32f01f0a790e512f6d3 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 494ea0bb1e0feef734a83e2628697647755e8864 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width