Title: design-code-proxy: quota error in a 200 JSON body hangs the request forever — writeHead precedes the in-body check, so fallback can never fire · Issue #681 · developing-today/code · GitHub
Open Graph Title: design-code-proxy: quota error in a 200 JSON body hangs the request forever — writeHead precedes the in-body check, so fallback can never fire · Issue #681 · developing-today/code
X Title: design-code-proxy: quota error in a 200 JSON body hangs the request forever — writeHead precedes the in-body check, so fallback can never fire · Issue #681 · developing-today/code
Description: Finding bin/design-code-proxy.mjs's local-dispatch fallback can never fire for a quota error reported in the JSON body of an HTTP 200 response, and the client request hangs forever instead. In tryTarget (bin/design-code-proxy.mjs:213-266...
Open Graph Description: Finding bin/design-code-proxy.mjs's local-dispatch fallback can never fire for a quota error reported in the JSON body of an HTTP 200 response, and the client request hangs forever instead. In tryT...
X Description: Finding bin/design-code-proxy.mjs's local-dispatch fallback can never fire for a quota error reported in the JSON body of an HTTP 200 response, and the client request hangs forever instead. In ...
Opengraph URL: https://github.com/developing-today/code/issues/681
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"design-code-proxy: quota error in a 200 JSON body hangs the request forever — writeHead precedes the in-body check, so fallback can never fire","articleBody":"## Finding\n\n`bin/design-code-proxy.mjs`'s local-dispatch fallback can never fire for a quota error reported **in the JSON body of an HTTP 200 response**, and the client request **hangs forever** instead.\n\nIn `tryTarget` (`bin/design-code-proxy.mjs:213-266` on main `4b85ef69`):\n\n1. The response callback calls `clientRes.writeHead(localRes.statusCode || 200, ...)` at **line 219** — before the body has been read. From that moment `clientRes.headersSent` is `true`.\n2. The non-stream body handler (line 254-258) parses the body and, for a quota error, calls `return onFail(new Error('Quota exceeded in JSON body'))`.\n3. The primary target's `onFail` wrapper (line 279-280) begins with `if (clientRes.headersSent) return;` — so it silently returns without trying the fallback target and **without ever ending `clientRes`**. The fallback target's own `onFail` (line 284) is guarded the same way, so the hang happens whichever target returns the quota body.\n\nThe status-based path works fine because the `429`/`>=500` check (line 213) runs *before* `writeHead` — only the in-body check, which the code explicitly added to catch quota exhaustion, is defeated by the ordering.\n\n## Evidence (reproduced on current main `4b85ef6906a25c1a59694c64986cb17828b6c2b6`)\n\nRan the real `bin/design-code-proxy.mjs` locally with stub HTTP backends on the Antigravity/Codex ports (`DESIGN_CODE_PROXY_PORT`/`ANTIGRAVITY_LS_PROXY_PORT`/`CODEX_PROXY_PORT` pointed at the stubs), model `design-code-flash`, non-stream:\n\n- Stub primary returns **HTTP 200** with `{\"error\":{\"code\":429,\"message\":\"quota stub\",\"type\":\"insufficient_quota\"}}`:\n - `curl --max-time 5` → **timed out after 5002 ms with 0 bytes received** (curl exit 28); the proxy logged only the primary attempt — no \"Falling back\" line, the fallback stub was never contacted, and the response was never ended. Without a client-side timeout this hangs indefinitely.\n- Control — stub primary returns **HTTP 429 status** with an error body:\n - Proxy logged `returned 429`, tried the fallback target, and answered **502 `All design code backends failed: HTTP 429` in under a second** — the intended behaviour the in-body path was written to provide.\n\n## Why it matters\n\nThe in-body quota shape is exactly what this branch exists for (backends that report quota exhaustion in a 200 JSON error body). Today, instead of failing over to the fallback model/backend, every such request wedges an open client connection forever — the worst failure mode for a dispatch proxy whose whole job is fallback — and leaks the socket on both sides until the client gives up.\n\n## Suggested fix\n\nFor the non-stream path, buffer the body and run the quota check **before** `clientRes.writeHead(...)`; only write the head once the response is known not to be a quota failure (the stream path must keep writing its head up front). Equivalently, restructure so the head is written at the point the body is ended for non-stream responses.\n\n## Acceptance criteria\n\n- [ ] A non-stream request whose primary backend returns HTTP 200 with `{\"error\":{\"code\":429,...}}` or `{\"error\":{\"type\":\"insufficient_quota\",...}}` tries the fallback target instead of hanging; if the fallback succeeds, its (model-rewritten) response is returned; if it also fails, the client gets the existing 502 `All design code backends failed` response promptly.\n- [ ] The same holds when the *fallback* target returns the in-body quota error: prompt 502, no hang.\n- [ ] Unchanged behaviour: HTTP-status 429/5xx fallback, connection-error fallback, successful non-stream responses (status, headers, `model` rewritten to the design model id), and streaming responses.\n- [ ] Regression tests cover the in-body quota case (primary and fallback) with stub backends — `bin/design-code-proxy.mjs` currently has no test file; `bin/codex-proxy.test.mjs` / `bin/muse-proxy.test.mjs` show the stub-backend pattern to follow.\n\nCross-repo check: `design-code-proxy` exists only in this repo (git grep across developing-today/opencode, developing-today/openchamber, dezren39/nix: no copies) — no cross-repo set.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-23T19:18:18Z","url":"https://github.com/developing-today/code/issues/681"}
| 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:c08e1d4b-9600-5c3f-53b6-375b9182989c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 94DE:130DD7:AC9D8A:E5D054:6B063EDA |
| html-safe-nonce | 3916252ecbb461dee8d56f41f5a050ef22d1a36fd264be6d196664efffeda2ce |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NERFOjEzMERENzpBQzlEOEE6RTVEMDU0OjZCMDYzRURBIiwidmlzaXRvcl9pZCI6IjI5MzM3ODIwMTcyNTY4NjU0OTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c256fa96a30a5de18ca53a3436c01cdf5967e5e43bd4e07347f4d1838f6aa79d |
| hovercard-subject-tag | issue:6004033630 |
| 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/681/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4eb5e8d060b877f03967649c1d76234eb02e5256d2994393441126c79b17c76b/developing-today/code/issues/681 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4eb5e8d060b877f03967649c1d76234eb02e5256d2994393441126c79b17c76b/developing-today/code/issues/681 |
| og:image:alt | Finding bin/design-code-proxy.mjs's local-dispatch fallback can never fire for a quota error reported in the JSON body of an HTTP 200 response, and the client request hangs forever instead. In tryT... |
| 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 | 1bff4f6bfaa96dc9c42cacf315424c24ebb548b06142ced5e3aaccb2a42dd652 |
| 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 | ac613d3698d3d8565651455086e1f74da07bf277 |
| ui-target | canary-2 |
| 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