Repository navigation
fix(gateway): handle settled HTTP request authority failures - #157501
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 10:21 PM ET / September 26, 2026, 02:21 UTC (Revision 3). ClawSweeper reviewWhat this changesGateway HTTP handlers classify expired or revoked request authority so core and plugin routes can send a denial or close the response without logging an expected failure. Merge readiness✅ Ready for maintainer review Keep open. Current main still sends settled authority failures through generic error handling, and the proposed fix remains useful. The introduced patch has no supported blocking correctness finding. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway receives HTTP requests from the Control UI and plugin routes, checks their authority, and passes them to route handlers. The response owner decides whether a request can return data, needs a denial, or must close a partial connection. flowchart LR
A[HTTP client] --> B[Gateway router]
B --> C[Live authority check]
C --> D[Core or plugin handler]
C --> E[Response finisher]
D --> E
E --> F[Response or closed connection]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +30, Tests +207. Total +237 across 8 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use one Gateway-owned authority outcome contract across core and plugin HTTP requests, with live checks before data is returned and unexpected failures retaining diagnostics. Do we have a high-confidence way to reproduce the issue? Yes. The reported live failure and current-main generic catch establish a clear path, though this read-only review did not rerun it. Is this the best way to solve the issue? Yes. A typed settled-authority outcome handled by the two HTTP request owners is a narrow repair that retains unexpected-error logging. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a410b4d0fb53. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Keep normal disconnects and HTTP authority expiry out of unhandled-error logs. Use one error class for requests whose response is already answered or closed. Reuse operator denial and its existing 403 response helper; close partial responses while preserving diagnostics for unexpected errors. Share response-authority checks across cookie and plugin routes. Preserve absence of client authority on plugin-auth routes: downstream consumers use callback presence as source evidence. Both HTTP request owners consume the same two-class error contract. The failure finisher keeps its interface. Production: +73/-43 (net +30). Tests: +229/-22 (net +207). The remaining production growth supplies the typed terminal outcome, shared request-owner handling, and safe closed/partial-response settlement. The real TCP cases share one server and took 316ms in the final run. Validation: 239 tests passed across 10 Gateway HTTP suites: node scripts/run-vitest.mjs \ src/gateway/server-http.authority-outcomes.test.ts \ src/gateway/server/plugins-http.runtime-scopes.test.ts \ src/gateway/http-auth-utils.paired-device.test.ts \ src/gateway/http-auth-utils.test.ts \ src/gateway/plugin-icon-http.test.ts \ src/gateway/server/plugins-http.test.ts \ src/gateway/user-profiles-http.gravatar.test.ts \ src/gateway/server-http.control-ui-lazy.test.ts \ src/gateway/control-ui-plugin-auth-cookie.test.ts \ src/gateway/http-common.test.ts The first CI-mode attempt exhausted the 900s no-output watchdog before any test verdict, after 822s of worker preparation. Removed the launcher's unnecessary CI flag, prepared and verified artifacts through createVitestWorkerRun, then reran with the normal local cache policy and unchanged test limits. Final wrapper: 1108.93s. All execution used isolated test state and free ports. Typed lint reported only the test file's line limit; removing duplicated logger assertions fixed it. The repository focused lint path passed with 0 warnings/errors, as did formatting and git diff --check. Independent review was clean at the configured P0 threshold. An unscoped lint attempt timed out preparing SDK declarations at 300s; that broad check remains inconclusive. Repo-wide Knip/storage scans were intentionally not rerun. Follow-up: audit the broad completed-response catch in src/gateway/http-endpoint-helpers.ts separately.
e76b201 to
f12f7df
Compare
|
Merged via squash.
|
…w#157501) Keep normal disconnects and HTTP authority expiry out of unhandled-error logs. Use one error class for requests whose response is already answered or closed. Reuse operator denial and its existing 403 response helper; close partial responses while preserving diagnostics for unexpected errors. Share response-authority checks across cookie and plugin routes. Preserve absence of client authority on plugin-auth routes: downstream consumers use callback presence as source evidence. Both HTTP request owners consume the same two-class error contract. The failure finisher keeps its interface. Production: +73/-43 (net +30). Tests: +229/-22 (net +207). The remaining production growth supplies the typed terminal outcome, shared request-owner handling, and safe closed/partial-response settlement. The real TCP cases share one server and took 316ms in the final run. Validation: 239 tests passed across 10 Gateway HTTP suites: node scripts/run-vitest.mjs \ src/gateway/server-http.authority-outcomes.test.ts \ src/gateway/server/plugins-http.runtime-scopes.test.ts \ src/gateway/http-auth-utils.paired-device.test.ts \ src/gateway/http-auth-utils.test.ts \ src/gateway/plugin-icon-http.test.ts \ src/gateway/server/plugins-http.test.ts \ src/gateway/user-profiles-http.gravatar.test.ts \ src/gateway/server-http.control-ui-lazy.test.ts \ src/gateway/control-ui-plugin-auth-cookie.test.ts \ src/gateway/http-common.test.ts The first CI-mode attempt exhausted the 900s no-output watchdog before any test verdict, after 822s of worker preparation. Removed the launcher's unnecessary CI flag, prepared and verified artifacts through createVitestWorkerRun, then reran with the normal local cache policy and unchanged test limits. Final wrapper: 1108.93s. All execution used isolated test state and free ports. Typed lint reported only the test file's line limit; removing duplicated logger assertions fixed it. The repository focused lint path passed with 0 warnings/errors, as did formatting and git diff --check. Independent review was clean at the configured P0 threshold. An unscoped lint attempt timed out preparing SDK declarations at 300s; that broad check remains inconclusive. Repo-wide Knip/storage scans were intentionally not rerun. Follow-up: audit the broad completed-response catch in src/gateway/http-endpoint-helpers.ts separately. Co-authored-by: Peter Steinberger <[email protected]>
Discard abandoned representation headers before sending a complete 401 or operator-denial 403 response. Share the existing 500 preparation and terminal response handling, preserving security/CORS headers and cookie policy. Extend the existing core/plugin TCP cases with staged response metadata and retain the admitted runtime-scope cancellation signal assertion. Related: #157501
Discard abandoned representation headers before sending a complete 401 or operator-denial 403 response. Share the existing 500 preparation and terminal response handling, preserving security/CORS headers and cookie policy. Extend the existing core/plugin TCP cases with staged response metadata and retain the admitted runtime-scope cancellation signal assertion. Related: openclaw#157501
What Problem This Solves
Closing a Control UI tab while plugin icon requests were still in flight made the Gateway log, once per request, with a stack trace:
Observed live on
main(d36ba5479c3) with an isolated dev Gateway: five such entries at the moment the browser disconnected. These are expected lifecycle outcomes, not failures, and the generic catch also tried to finish the already-closed response. The same path mishandled two siblings:assertCurrentalready sent a 401 for lapsed client authority, it threw a plainError("Unauthorized")that was again logged as unhandled;GatewayOperatorAccessDeniedErrorraised mid-request reached the generic catch and became a 500 instead of an operator-access denial.Why This Change Was Made
bindHttpResponseAuthoritythrew plain errors for outcomes whose response was already settled, and the request owners (server-http.tsand the plugin route handler) could only treat them as unexpected. This change:GatewayHttpRequestAuthorityError("authority ended; the response is already answered or closed") and uses it at every such throw site, replacing the duplicate string-message errors inhttp-auth-utils,http-auth-plugin-cookie, and plugin route scope checks;GatewayOperatorAccessDeniedErrorthrough onefinishGatewayHttpAuthorityError: nothing is written to a closed response, operator denial gets the existing auth-failure response when headers are unsent, and a partial response is closed;sendUnauthorizeditself own "headers already sent" and cookie removal;bindHttpResponseAuthoritycheck instead of a parallel inline check.Genuine exceptions still log
unhandled error in request handlerand get the normal failure response.User Impact
No more alarming stack traces in Gateway logs when a browser tab closes, one clean 401 when client authority lapses mid-request, and a proper denial instead of a 500 when operator access is revoked mid-request.
Evidence
src/gateway/server-http.authority-outcomes.test.ts(TCP requests against the real handler): client disconnect (no unhandled log, no write), lapsed authority (exactly one 401), operator denial (denial response when unsent, closed partial response), and a genuine thrown error (still logged with 500). The regression cases fail on currentmain.node scripts/run-vitest.mjsacross 10 Gateway HTTP suites (authority outcomes, plugin routes and runtime scopes, auth utils, plugin icon, user-profile avatars, lazy Control UI, plugin auth cookie, http-common): 239 passed.oxfmt --check, andgit diff --checkpass. The repo-wide Knip/storage scans could not finish locally under extreme host load; CI covers them.Production LOC: +73 / −43 (net +30): one error class and the shared finisher replace three plain-error throw sites and the plugin route's parallel authority check. Tests: +229 / −22.