Skip to content

fix(gateway): flush failed websocket upgrade rejections - #141303

Merged
obviyus merged 2 commits into
openclaw:mainfrom
hugenshen:fix/gateway-ws-upgrade-reject-flush
Sep 9, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
hugenshen:fix/gateway-ws-upgrade-reject-flush

Conversation

@hugenshen

@hugenshen hugenshen commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

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 9bf06f7cc0f34a9f69c26de1326b4901d3b55b5b 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.

  • AI-assisted

@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 9:49 AM ET / 13:49 UTC (Revision 4).

ClawSweeper review

What this changes

The 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
Reviewed head: 44f4c8e8060303b1acb0647d5578811b8c991313

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused helper reuse with meaningful TCP regression coverage and convincing, explicitly bounded production-path proof.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured body reports real TCP requests through baseline and candidate built Gateways with the real WebSocket implementation: an injected pre-write exception changes an empty disconnect into a complete 503 followed by server-led closure, with admission and authenticated-connection controls preserved.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports real TCP requests through baseline and candidate built Gateways with the real WebSocket implementation: an injected pre-write exception changes an empty disconnect into a complete 503 followed by server-led closure, with admission and authenticated-connection controls preserved.
Evidence reviewed 9 items Verified introduced production change: The pinned merge-base-to-head comparison changes only the exception handler's immediate destruction into the existing HTTP rejection helper; unrelated endpoint drift is excluded.
Current main still needs the repair: The fetched main revision retains socket.destroy() in the final upgrade exception handler.
Latest release comparison: The supplied latest release, v2026.9.3, also retains immediate destruction on the same exception path.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source 0, Tests +75. Total +75 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 1 75 0 +75
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 76 1 +75

Review metrics

None.

Technical review

Best 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.

Labels

Label justifications:

  • P2: This improves a bounded Gateway handshake failure path without evidence of a widespread outage or urgent regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports real TCP requests through baseline and candidate built Gateways with the real WebSocket implementation: an injected pre-write exception changes an empty disconnect into a complete 503 followed by server-led closure, with admission and authenticated-connection controls preserved.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports real TCP requests through baseline and candidate built Gateways with the real WebSocket implementation: an injected pre-write exception changes an empty disconnect into a complete 503 followed by server-led closure, with admission and authenticated-connection controls preserved.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-07T15:29:56.989Z sha 71d44bb70f01a15a677892e32b0d622960acaba9 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-07T16:10:34.927Z sha 7061a0d6c9ce40e1980a98c7ada5017d157a52d6 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-07T17:18:18.810Z sha 3d02b12 :: needs maintainer review before merge. :: none

@hugenshen
hugenshen force-pushed the fix/gateway-ws-upgrade-reject-flush branch from 7061a0d to 3d02b12 Compare September 7, 2026 17:11
@obviyus obviyus self-assigned this Sep 9, 2026
@obviyus
obviyus requested review from a team as code owners September 9, 2026 13:42
@openclaw-barnacle openclaw-barnacle Bot removed the gateway Gateway runtime label Sep 9, 2026
@obviyus obviyus changed the title fix(gateway): flush websocket upgrade rejects before destroy fix(gateway): flush failed websocket upgrade rejections Sep 9, 2026
@obviyus
obviyus merged commit b827d20 into openclaw:main Sep 9, 2026
217 checks passed
@obviyus

obviyus commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

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.

  • Bug: Failed pre-transfer upgrades silently disconnected clients.
  • Fix: The existing shared rejection helper writes HTTP 503 before closing.
  • Preserved: Exact-once admission release, authenticated health requests, normal closes, payload limits, and the tested route/authentication controls.
  • Validation: 161 focused checks passed. Fresh exact-head review had no findings. Hosted CI passed with 141 successful jobs and 17 skips.

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.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 10, 2026
)

## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants