Skip to content

fix(gateway): classify opening timeouts and repair lifetime checks - #146508

Merged
steipete merged 3 commits into
mainfrom
codex/gateway-handshake-timeout-20260912
Sep 13, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/gateway-handshake-timeout-20260912

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway queries lose their transport classification when a TCP peer stalls during the WebSocket upgrade. Validation also exposed two reproducible lifetime failures: Vitest could reuse a removed mock, and a media-policy fixture leaked file handles while producing a misleading successful assertion.

User Impact

Gateway queries now return actionable transport errors that existing recovery code recognizes. The regression checks exercise the intended authorization and media-ownership paths, including under the original CI test ordering.

Timeout budgets and automatic retry policy are unchanged. The Vitest version remains pinned at 5.0.0; its existing temporary patch owns the framework correction.

Why This Change Was Made

  • Gateway transport: classify the dependency's uncoded opening timeout as ETIMEDOUT in the Node WebSocket adapter. Existing RPC diagnostics and recovery classification then work without consumer message matching. The contract is ws 8.21.3's timeout callback and its fresh Error(message) in abortHandshake.
  • Mock resolution: Vitest 5 empties its pending-id queue before awaited resolution completes. A concurrent fetch could see an empty queue and read the old registry. The native mocker now owns ordered resolution and a completion tail, and every fetch joins that owner before lookup. Shared-worker cleanup follows the latest tail. Remove the obsolete local serializer and its fake queue model; real imports cover unmocking, nested factories, failure recovery, queued work, and cleanup.
  • Media fixture: use dispatch admission, which already withdraws Gateway-local media access. The old fixture attempted activation without an attached environment, throwing before its newly opened file reached the closure owner. The test now verifies the intended placement state and closed descriptor, with cleanup on assertion failure.

Production OpenClaw delta is +5 lines. The dependency implementation grows by 9 lines while the duplicated local test tooling shrinks by 75; patch context and indentation account for the larger generated diff. Overall the PR is net negative, with no new runtime config, protocol, or database surface.

Evidence

  • Real loopback TCP timeout regression fails before normalization and passes after it. A separate real callGateway probe returns gateway_transport_error and recovery eligibility in 484 ms.
  • A real Vitest dynamic-import regression fails in under one second before the framework repair: an import completes during a held unmock and returns the old export. All three real-import cases pass afterward in normal and fresh isolated projects, including importActual/nested-factory reentrancy and resolution failure recovery.
  • The shared-worker child proof validates 47 assertions plus its existing intentional skip/collection failure. It covers queued work during a resolution and a later pass arriving during cleanup. Reducing cleanup to a single await makes the negative control fail; restoring the completion-tail loop passes.
  • The original cold CI selector passes 119 files / 2415 tests on macOS Node 26.8.2 and Linux Node 24.19.0. The previously 120-second profile-authorization timeout completes in 209 ms and 294 ms respectively. The Node 26 FileHandle-GC errors are gone. Blacksmith Testbox workflow; the accepted Crabbox command exit is 0, independent of later lease cleanup status.
  • All eight installed Vitest target hashes match the generated pnpm patch and documented manifest. Independent review found no actionable P0–P2 findings. Broad selected changed gates passed, including full typechecks, lint, dependency locks, guards, and import cycles. The final targeted lint lane passed on rerun after documenting two pinned Vitest API contracts.

The original CI failure is retained as evidence: run 34720664470, large-9. Commit history shows #122100 began forwarding raw connection errors, while #124581 normalized errno failures but missed this uncoded timeout. The Vitest 5 migration in #138264 retained the local serializer's older queue assumptions. This PR preserves the original opening-handshake deadline from #108348.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 docs Improvements or additions to documentation size: S maintainer Maintainer-authored PR labels Sep 12, 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 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 7:48 PM ET / 23:48 UTC (Revision 2).

ClawSweeper review

What this changes

The PR classifies Gateway opening timeouts as transport errors, repairs Vitest mock-resolution ordering, and corrects a media-access test’s file-handle cleanup.

Merge readiness

✅ Ready for maintainer review

The updated PR remains useful and has no actionable introduced findings. Current main still lacks the timeout classification, and the additional lifetime repairs address concrete failures without changing production authorization or timeout budgets.

Priority: P2
Reviewed head: 5d1a8b91e17fdaaf498c01fd6783ead035c098f9

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A sound owner-level repair with relevant recorded behavior proof, meaningful negative controls, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded real-socket GatewayClient and callGateway observations exercise the changed timeout boundary and show transport classification and recovery eligibility; real Vitest imports and shared-worker runs cover the tooling repair. Raw workflow logs were unavailable to this reviewer, without contradicting the supplied observations.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded real-socket GatewayClient and callGateway observations exercise the changed timeout boundary and show transport classification and recovery eligibility; real Vitest imports and shared-worker runs cover the tooling repair. Raw workflow logs were unavailable to this reviewer, without contradicting the supplied observations.
Evidence reviewed 10 items Introduced scope and review continuity: Reviewed the pinned merge-base-to-head changes, including the complete replacement tests and removed serializer. The production timeout hunk is unchanged from the previous reviewed head; the previous review retained no findings. Base-only changes and the stale test merge were not treated as PR introductions.
Direct dependency contract: The production adapter imports the WebSocket implementation, and the PR explicitly relies on ws opening-timeout semantics. The cited dependency source creates a fresh Error without an errno in abortHandshake, supporting normalization at the adapter boundary.
Existing recovery owner: callGateway already recognizes ETIMEDOUT and wraps connection errors as Gateway transport errors. The patch supplies the missing code without adding consumer-side message matching or changing request dispatch.
Findings None None.
Security None None.

How this fits together

Gateway clients translate WebSocket connection failures into diagnostics and recovery decisions for CLI callers. The accompanying test infrastructure changes ensure asynchronous mock resolution finishes before imports and shared-worker cleanup proceed.

flowchart TD
  A[Gateway query] --> B[WebSocket connection]
  B --> C[Opening timeout classification]
  C --> D[Transport diagnostics and recovery]
  E[Test imports and mock changes] --> F[Serialized mock resolution]
  F --> G[Registry lookup]
  F --> H[Shared-worker cleanup]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests -135, Docs +13, Other +77. Total -40 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 0 +5
Tests 7 207 342 -135
Docs 2 15 2 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 2 87 10 +77
Total 12 314 354 -40

Review metrics

Metric Value Why it matters
Ownership consolidation Production +5 lines; tests/fixtures −60; shared runner −75 The small runtime addition restores existing error classification while dependency-owned resolution removes duplicated test tooling.

Technical review

Best possible solution:

Keep timeout normalization in the WebSocket adapter and mock ordering in Vitest’s native owner, with the documented upstream-removal gate.

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

Yes: a TCP peer that accepts but never upgrades produces an uncoded ws timeout that current main cannot classify through its errno-based recovery path; the held-unmock regression also targets the actual dependency fetch boundary. These paths were source-verified, not executed by this reviewer.

Is this the best way to solve the issue?

Yes: both repairs sit with the existing owners, and the media fixture now proves policy withdrawal and descriptor closure instead of passing through an unrelated activation failure.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs bounded Gateway diagnostics and test-lifetime failures without evidence of an urgent production outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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): Recorded real-socket GatewayClient and callGateway observations exercise the changed timeout boundary and show transport classification and recovery eligibility; real Vitest imports and shared-worker runs cover the tooling repair. Raw workflow logs were unavailable to this reviewer, without contradicting the supplied observations.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded real-socket GatewayClient and callGateway observations exercise the changed timeout boundary and show transport classification and recovery eligibility; real Vitest imports and shared-worker runs cover the tooling repair. Raw workflow logs were unavailable to this reviewer, without contradicting the supplied observations.

Evidence

What I checked:

  • Introduced scope and review continuity: Reviewed the pinned merge-base-to-head changes, including the complete replacement tests and removed serializer. The production timeout hunk is unchanged from the previous reviewed head; the previous review retained no findings. Base-only changes and the stale test merge were not treated as PR introductions. (packages/gateway-client/src/client.ts:631, 5d1a8b91e17f)
  • Direct dependency contract: The production adapter imports the WebSocket implementation, and the PR explicitly relies on ws opening-timeout semantics. The cited dependency source creates a fresh Error without an errno in abortHandshake, supporting normalization at the adapter boundary. (lib/websocket.js:888, c791e707eab3)
  • Existing recovery owner: callGateway already recognizes ETIMEDOUT and wraps connection errors as Gateway transport errors. The patch supplies the missing code without adding consumer-side message matching or changing request dispatch. (src/gateway/call.ts:1034, 5d1a8b91e17f)
  • Main and release necessity: Fetched main still forwards the uncoded opening timeout, and the v2026.9.4 source obtained through GitHub likewise lacks normalization. Main also retains the local mock serializer. The related merged timeout and Vitest migration PRs establish earlier behavior, not completion of these repairs. (packages/gateway-client/src/client.ts:627, 1ccb3e114fe3)
  • Published Vitest implementation inspected: Read the published [email protected] package in memory, including its repository metadata, mocker, importActual path, registry lookup, and module-fetch boundary. The original chunk SHA-256 matches the documented preimage, 9868c71ba3a06ca6f9890c60a9e6b298762b0fca74b09595a8f76340d3f92fe9. Resolution clears pendingIds before awaiting RPCs; mock factories execute later, supporting the proposed serialization without a factory reentrancy cycle. Published artifact: https://registry.npmjs.org/vitest/-/vitest-5.0.0.tgz.
  • Single mock-resolution owner and regression coverage: The dependency patch serializes resolution, drains newly queued IDs, and makes fetches join resolution before registry lookup. Shared-worker cleanup follows the latest completion tail. Real-import tests cover held unmocking, nested factories/importActual, and recovery after failure; paired child fixtures cover later work arriving during cleanup. Searches found no retained local serializer. (test/non-isolated-runner.ts:377, 5d1a8b91e17f)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: 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 (1 earlier review cycle)
  • reviewed 2026-09-12T21:51:43.865Z sha 51c6602 :: needs maintainer review before merge. :: none

@steipete
steipete requested a review from a team as a code owner September 12, 2026 23:42
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: L and removed size: S labels Sep 12, 2026
@steipete steipete changed the title fix(gateway): classify websocket opening timeouts for recovery fix(gateway): classify opening timeouts and repair lifetime checks Sep 12, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The updated head includes the verified Vitest mock-resolution owner repair and media-fixture lifetime correction alongside the transport classification fix. The final body records the real import regression, cleanup proof, original cold CI group passing on macOS/Linux, installed patch hashes, and complete validation results.

@github-actions github-actions Bot added the dependencies-changed PR changes dependency-related files label Sep 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Guard

This PR changes dependency-related files. Maintainers should confirm these changes are intentional.

Changed files:

Maintainer follow-up:

  • Review whether the dependency changes are intentional.
  • Inspect resolved package deltas when lockfiles or workspace dependency policy changes are present.
  • Treat pnpm-lock.yaml and package-lock.json diffs as dependency security-review surfaces.
  • Run pnpm deps:changes:report -- --base-ref origin/main --markdown /tmp/dependency-changes.md --json /tmp/dependency-changes.json locally for detailed release-style evidence.

@github-actions

Copy link
Copy Markdown
Contributor

Dependency graph changes noted

This PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin, a member of @openclaw/openclaw-secops, or an OpenClaw organization member with Maintain or Admin repository access.

  • Current SHA: 5d1a8b91e17fdaaf498c01fd6783ead035c098f9
  • Trusted actor: @steipete
  • Trusted role: pull request author; openclaw-secops

Security review is still recommended before merge when the dependency graph change is intentional.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 292e161 into main Sep 13, 2026
191 checks passed
@steipete
steipete deleted the codex/gateway-handshake-timeout-20260912 branch September 13, 2026 00:13
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies-changed PR changes dependency-related files docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR 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: L 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.

1 participant