Skip to content

fix(gateway): deliver upgrade rejection responses under Bun - #139516

Merged
steipete merged 2 commits into
mainfrom
codex/bun-gateway-rejections
Sep 6, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/bun-gateway-rejections

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Gateway clients could receive a connection reset instead of the HTTP rejection response when attempting a WebSocket upgrade on a reused connection under Bun.

Why This Change Was Made

Upgrade rejection helpers now own shutdown: they end the response and destroy the socket only after its buffered bytes finish writing. Existing admission decisions, status codes, headers, and response bodies stay intact. The background completion timeout assertion also checks the standard TimeoutError identity instead of runtime-specific wording.

User Impact

Clients receive the intended rejection and explanation when WebSocket admission is unavailable or authentication fails.

Evidence

  • Node: 72 focused tests passed.
  • Bun: 23 timeout tests, 7 Tailscale tests, and the new ordinary keep-alive upgrade rejection regression passed.
  • Full changed-file gate passed; independent P0–P2 review found no actionable findings.
  • The added regression protects delivery of a 503 response after an ordinary request reuses the same connection.
  • Hosted checks exposed two fixture omissions: the new server now uses the existing payload limit, and the sibling suspension-admission mock records end(response) before its completion callback. Both targeted benign 503 cases pass under Node and true Bun; final changed checks and independent review pass.
  • This is a bounded compatibility fix. Twelve existing Bun transport cases remain failing outside the repaired path; the full Bun suite is not green.

@clawsweeper

clawsweeper Bot commented Sep 5, 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 maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 23:40
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 9:27 PM ET / September 6, 2026, 01:27 UTC.

ClawSweeper review

What this changes

The PR flushes Gateway WebSocket rejection responses before closing connections, adds reused-connection coverage, and makes timeout assertions portable across runtimes.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on the supplied main and latest release. No actionable introduced defect remains, and the earlier payload-limit warning is addressed.

Priority: P2
Reviewed head: d86c67d78e329e02e4db66bd8090f3cf86f3872c

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused transport repair with meaningful regression coverage and no remaining actionable finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied MEMBER association exempts this PR from the external-contributor proof gate. Its regression exercises the production Gateway upgrade handler through a real HTTP client, and the body reports Node/Bun success; no independent runtime execution occurred here.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied MEMBER association exempts this PR from the external-contributor proof gate. Its regression exercises the production Gateway upgrade handler through a real HTTP client, and the body reports Node/Bun success; no independent runtime execution occurred here.
Evidence reviewed 8 items Current main still needs the repair: The supplied main implementation writes the 503 response and immediately destroys the socket; it does not wait for buffered output.
Latest release comparison: Inspected v2026.9.2:src/gateway/server/http-work-admission.ts; the latest supplied release also retains write followed by immediate destruction.
Shutdown ownership and routing: The rejection helper owns end(response) and callback destruction. Updated callers return after rejection; authentication conditions, admission checks, response framing, and accepted upgrade dispatch remain intact.
Findings None None.
Security None None.

How this fits together

The Gateway checks incoming WebSocket upgrades for authentication and admission before handing accepted connections to their handlers. Rejected connections receive an HTTP explanation before closing.

flowchart TD
  A[Client upgrade request] --> B[Gateway routing]
  B --> C{Authentication and admission}
  C -->|Accepted| D[WebSocket handler]
  C -->|Rejected| E[HTTP rejection response]
  E --> F[Finish writing]
  F --> G[Close socket]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -16, Tests +75. Total +59 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 31 47 -16
Tests 3 77 2 +75
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 108 49 +59

Review metrics

None.

Technical review

Best possible solution:

Keep rejection shutdown in the transport owner, preserving existing admission decisions and complete HTTP responses across Node and Bun.

Do we have a high-confidence way to reproduce the issue?

Yes: the focused regression sends an ordinary request followed by an upgrade on a reused connection under Bun. Main's immediate destruction establishes the source-level failure mechanism; this review did not execute it.

Is this the best way to solve the issue?

Yes: moving closure into the response-completion callback repairs the owning transport boundary without adding configuration, changing authorization, or duplicating routing.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against abd18df28d85.

Labels

Label justifications:

  • P2: This is a bounded transport compatibility repair for rejection responses under the optional Bun runtime.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied MEMBER association exempts this PR from the external-contributor proof gate. Its regression exercises the production Gateway upgrade handler through a real HTTP client, and the body reports Node/Bun success; no independent runtime execution occurred here.

Evidence

What I checked:

  • Current main still needs the repair: The supplied main implementation writes the 503 response and immediately destroys the socket; it does not wait for buffered output. (src/gateway/server/http-work-admission.ts:58, abd18df28d85)
  • Latest release comparison: Inspected v2026.9.2:src/gateway/server/http-work-admission.ts; the latest supplied release also retains write followed by immediate destruction. (src/gateway/server/http-work-admission.ts:58, 3928bad9badf)
  • Shutdown ownership and routing: The rejection helper owns end(response) and callback destruction. Updated callers return after rejection; authentication conditions, admission checks, response framing, and accepted upgrade dispatch remain intact. (src/gateway/server-http-upgrades.ts:68, d86c67d78e32)
  • Regression and previous feedback: The new test exercises the production HTTP server and upgrade handler with a real keep-alive HTTP client, checking 200 followed by the complete 503 response. Its WebSocket server now uses MAX_PREAUTH_PAYLOAD_BYTES, addressing the supplied scanner comment. The suspension fixture records end(response) before invoking its callback. (src/gateway/server-http.rejection-transport.test.ts:16, d86c67d78e32)
  • Validation scope: The captured PR body reports focused Node and Bun passes, including the reused-connection regression and corrected fixtures, while explicitly reporting twelve existing Bun transport failures outside this repair. Tests were not executed during this read-only review. (d86c67d78e32)
  • Introduction and merge boundaries: The host supplies a complete merge-base-to-head patch. Raw test-merge parent records match the pinned main followed by the exact PR head, and its main-parent comparison contains only the five introduced paths. (f0b7b0181dd4)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vito Cappello: 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 (2 earlier review cycles)
  • reviewed 2026-09-05T23:46:04.685Z sha 7382128 :: blocked before merge. :: none
  • reviewed 2026-09-06T01:04:45.664Z sha 06ce84770f4bab66c5b8a18fb2edcc7a224fbac0 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/bun-gateway-rejections branch from 7382128 to 06ce847 Compare September 6, 2026 00:58
@steipete
steipete force-pushed the codex/bun-gateway-rejections branch from 06ce847 to d86c67d Compare September 6, 2026 01:22
@steipete
steipete merged commit 425c694 into main Sep 6, 2026
173 checks passed
@steipete
steipete deleted the codex/bun-gateway-rejections branch September 6, 2026 01:40
vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit '047587a542ce205ee78354fbd88ba8ec05c07844': (45 commits)
  chore(ui): refresh control ui locales (#139481)
  fix(slack): keep prototype-named emoji shortcodes intact (#136374)
  fix(gateway): deliver upgrade rejection responses under Bun (#139516)
  refactor(test): simplify catalog guards and fix native report fixture (#139496)
  fix(macos): prevent dashboard fixture loopback timeouts (#139556)
  fix(matrix): preserve selected reply targets inside threads (#139479)
  test(gateway): preserve held-work close failures (#139593)
  refactor(exec): share package argument scanning (#139560)
  fix(audit): preserve sequence range validation before numeric decoding (#139587)
  fix(transcripts): retain capture ownership through failed cleanup (#139572)
  refactor(models): share selector reference traversal (#139571)
  perf(agents): classify allowlists without intermediate sets (#138392)
  chore(release): update appcast for 2026.9.2 (#139575)
  fix(ci): synchronize cloud retries and board widget input (#139506)
  fix(plugins): explain SDK incompatibilities after core updates (#139458)
  fix(voice-call): retain installed WebSocket behavior under Bun (#139567)
  test(text): consolidate literal sanitizer cases (#139579)
  test(gateway): observe native drain without a lint exception (#139576)
  test(memory): consolidate visibility fixtures without policy defaults (#139569)
  fix(ui): show shimmer skeletons while loading Control UI (#139525)
  ...
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 6, 2026
* origin/main:
  fix(cli): keep note text with Windows and Unicode line endings (#139512)
  fix(agents): keep isolated completion context on its admitted generation (#139607)
  fix: avoid declaration builds during source-server updates (#139392)
  fix(models): keep discovered models after catalog refresh failures (#139357)
  fix(gateway): record a transcript notice when a run fails before replying (#139439)
  refactor(ios): reuse shared integer conversion (#139581)
  fix(sessions): prevent database lock failures during reclamation (#139469)
  perf(test): reuse transforms within owned scheduler slots (#139553)
  test(agents): share sparse transcript input fixtures (#139589)
  chore(ui): refresh control ui locales (#139481)
  fix(slack): keep prototype-named emoji shortcodes intact (#136374)
  fix(gateway): deliver upgrade rejection responses under Bun (#139516)
  refactor(test): simplify catalog guards and fix native report fixture (#139496)
  fix(macos): prevent dashboard fixture loopback timeouts (#139556)
  fix(matrix): preserve selected reply targets inside threads (#139479)
vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit 'refs/openclaw/tasks/pr-135167-main': (2467 commits)
  refactor(ios): reuse shared integer conversion (#139581)
  fix(sessions): prevent database lock failures during reclamation (#139469)
  perf(test): reuse transforms within owned scheduler slots (#139553)
  test(agents): share sparse transcript input fixtures (#139589)
  chore(ui): refresh control ui locales (#139481)
  fix(slack): keep prototype-named emoji shortcodes intact (#136374)
  fix(gateway): deliver upgrade rejection responses under Bun (#139516)
  refactor(test): simplify catalog guards and fix native report fixture (#139496)
  fix(macos): prevent dashboard fixture loopback timeouts (#139556)
  fix(matrix): preserve selected reply targets inside threads (#139479)
  test(gateway): preserve held-work close failures (#139593)
  refactor(exec): share package argument scanning (#139560)
  fix(audit): preserve sequence range validation before numeric decoding (#139587)
  fix(transcripts): retain capture ownership through failed cleanup (#139572)
  refactor(models): share selector reference traversal (#139571)
  perf(agents): classify allowlists without intermediate sets (#138392)
  chore(release): update appcast for 2026.9.2 (#139575)
  fix(ci): synchronize cloud retries and board widget input (#139506)
  fix(plugins): explain SDK incompatibilities after core updates (#139458)
  fix(voice-call): retain installed WebSocket behavior under Bun (#139567)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
…#139516)

* fix(gateway): flush upgrade rejections before closing sockets

* test(gateway): model rejection flush and bound upgrade fixtures
necromman pushed a commit to necromman/openclaw that referenced this pull request Sep 20, 2026
…#139516)

* fix(gateway): flush upgrade rejections before closing sockets

* test(gateway): model rejection flush and bound upgrade fixtures

(cherry picked from commit 425c694)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

2 participants