Repository navigation
fix(gateway): flush failed websocket upgrade rejections - #141303
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 9, 2026, 9:49 AM ET / 13:49 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR makes failed Gateway WebSocket upgrades send HTTP 503 before closing and adds a regression that checks the complete response over TCP. Merge readiness✅ Ready for maintainer review This remains a useful, narrowly scoped fix: current main still silently disconnects on the exception path. The supplied transport proof supports the repair, and no blocking correctness or security finding remains. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway accepts WebSocket connections from OpenClaw clients and routes them through admission and upgrade handling. Failed upgrades return an HTTP rejection; successful upgrades transfer the connection to the WebSocket owner. flowchart TD
A[Client upgrade request] --> B[Gateway routing and admission]
B --> C[WebSocket handshake]
C --> D[Successful connection]
C --> E[Upgrade exception]
E --> F[Flush HTTP 503]
F --> G[Close socket]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0, Tests +75. Total +75 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Use the shared flush-before-close rejection path while preserving existing admission, authentication, and successful socket ownership. Do we have a high-confidence way to reproduce the issue? Yes: injecting an exception at the real WebSocket headers event reaches the current-main catch that destroys the socket without a response. Source and supplied before/after observations establish the path; this read-only review did not execute it. Is this the best way to solve the issue? Yes: reusing the existing rejection helper is a narrow repair, and the TCP regression verifies the observable response and closure rather than mocking the handshake. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2c191557f381. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
71d44bb to
7061a0d
Compare
Co-authored-by: Cursor <[email protected]>
7061a0d to
3d02b12
Compare
|
Thanks @hugenshen! Merged as b827d20. Proof: The normal built Gateway was tested with a narrow pre-write WebSocket dependency fault. Baseline closed without a response; the candidate and independent acceptance received the complete HTTP 503 response before server EOF and close.
The dependency fault is synthetic; this proof does not claim spontaneous failures or arbitrary post-upgrade exception coverage. Your contribution and human credit are preserved. |
) ## What Problem This Solves When a core Gateway WebSocket upgrade throws before socket ownership transfers, clients receive a silent disconnect instead of an HTTP rejection. ## Why This Change Was Made Use the existing shared rejection helper to send HTTP 503 and close after its write completes. The TCP regression now keeps the real WebSocket handshake, injects a failure at its pre-write headers event, and waits for server-led closure before checking the complete response. ## User Impact Clients receive a readable service-unavailable response when this pre-transfer upgrade failure occurs. Successful connections retain their authentication, payload limits, admission budget, and socket ownership. ## Evidence Built the normal Gateway CLI from baseline `6d50df24645bcf84b608855362547cc5ef531426` and candidate `44f4c8e8060303b1acb0647d5578811b8c991313`. Sent valid raw TCP upgrades through the real core route, with the real WebSocket implementation and production constructor options. | Observed boundary | Baseline | Candidate | | --- | --- | --- | | Pre-write dependency exception | Logged once; zero response bytes; server EOF and close | Complete 55-byte HTTP 503 response, then server EOF and close | | Admission budget after failure | Slot released; overflow still rejected with both ordinary sockets held | Same exact-once release discriminator passed | | Normal connection | Signed device authentication, health RPC, clean close | Passed before and after the failure | | Oversized pre-authentication frame | Existing 65,536-byte limit; WebSocket 1009 | Same limit and rejection | - Ran both the ordinary budget and a separate two-slot budget fixture. TCP clients waited for the server to close; neither a deadline nor client cleanup supplied the observed close. - The new regression failed on baseline specifically because the response was empty, then passed with the repair. - 161 focused checks passed across rejection transport, shared response framing/write failure, upgrade ownership, pre-authentication, desktop/portal streams, plugin authentication, suspension, proxy attribution, and rate limiting. Changed-file formatting/lint and the existing line/assertion checks passed. - Public controls preserved the applicable 401, 403, 404, and admission-owned 503 responses. Focused tests covered 426 framing and the real upgrade 429 body and retry header. - Source review checked the complete catch surface, budget release, write-callback ordering, and successful ownership transfer. - Independent source-blind acceptance reran both public cases and passed the observed response, closure, capacity, authentication, payload-limit, and qualified-route behavior. This proof uses a narrow synthetic dependency failure before HTTP 101. No naturally occurring dependency failure or supported post-upgrade throwing input was established. Desktop/plugin/worker preservation beyond the named public controls uses focused owner tests. - [x] AI-assisted Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
When a core Gateway WebSocket upgrade throws before socket ownership transfers, clients receive a silent disconnect instead of an HTTP rejection.
Why This Change Was Made
Use the existing shared rejection helper to send HTTP 503 and close after its write completes. The TCP regression now keeps the real WebSocket handshake, injects a failure at its pre-write headers event, and waits for server-led closure before checking the complete response.
User Impact
Clients receive a readable service-unavailable response when this pre-transfer upgrade failure occurs. Successful connections retain their authentication, payload limits, admission budget, and socket ownership.
Evidence
Built the normal Gateway CLI from baseline
9bf06f7cc0f34a9f69c26de1326b4901d3b55b5band candidate44f4c8e8060303b1acb0647d5578811b8c991313. Sent valid raw TCP upgrades through the real core route, with the real WebSocket implementation and production constructor options.This proof uses a narrow synthetic dependency failure before HTTP 101. No naturally occurring dependency failure or supported post-upgrade throwing input was established. Desktop/plugin/worker preservation beyond the named public controls uses focused owner tests.