Repository navigation
fix(test): stop leaking sockets after failed Gateway setup - #137982
Conversation
Reuse the shared WebSocket acquisition owner in server-suite and webchat helpers. Preserve the ten-second opening budget and native transport errors, and join failed sockets before rejecting. Extend the existing native peer regressions rather than adding another fixture. Related to #137924; authenticated and composite rollback remain separate follow-ups.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 2:41 AM ET / 06:41 UTC. ClawSweeper reviewWhat this changesThe PR replaces duplicated Gateway server-suite and webchat WebSocket opening waiters with the shared cleanup-owning helper and adds native failed-opening regressions for webchat. Merge readiness⛔ Blocked before merge - 1 item remains Keep open. The focused test-helper repair is correct and still necessary: current main retains the two local opening waiters, while this branch delegates them to the merged canonical acquisition owner. This is a maintainer-authored/protected-label PR, so it should remain for normal maintainer handling rather than automated cleanup. Priority: P3 Review scores
Verification
How this fits togetherGateway tests create local WebSocket clients for server and webchat flows. The shared acquisition helper owns opening failures, preserves native transport errors, and terminates a failed socket before the test helper returns. flowchart LR
A[Gateway test] --> B[Server or webchat helper]
B --> C[WebSocket client]
C --> D[Shared acquisition owner]
D --> E{Socket opens cleanly}
E -->|Yes| F[Connect and run test]
E -->|No| G[Close socket and return first error]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -45, Tests +5. Total -40 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the single canonical acquisition path for the server-suite and webchat callers, retaining the focused native socket regressions; leave distinct LAN and auth-helper acquisition paths to separately scoped follow-up work. Do we have a high-confidence way to reproduce the issue? No independent high-confidence current-main execution was possible in this read-only checkout because dependencies are absent. Source shows the pre-PR waiters settle without owning failed-socket termination, and the supplied PR body records matching native before/after runs. Is this the best way to solve the issue? Yes. Reusing the already-merged acquisition owner is the narrowest maintainable repair: it preserves nonce-observation ordering and budgets while eliminating two duplicate opening paths. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 13f017b67c9e. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready proof for The completed ClawSweeper review has no code finding. Its sole before-merge item was the review worker's inability to inspect installed Before: run_cde1160ec248 produced the two expected webchat failures and twelve passing controls. After: run_a7265731adb3 passed all 48 selected acquisition and real Gateway tests, with no skips. The PR body records the proof-script quotation-matching correction; candidate source did not change. Runtime command, executed only in the fresh credential-free AWS VM: node scripts/run-vitest.mjs src/gateway/test-helpers.acquisition.test.ts src/gateway/server.shared-auth-rotation.test.ts src/gateway/server.node-pairing-authz.test.ts src/gateway/server.sessions.permissions-hooks.test.ts --reporter=verbose --reporter=json --outputFile=.artifacts/raw-opening-proof/green.jsonLocal static command, passed: node scripts/check-changed.mjs -- src/gateway/test-helpers.acquisition.test.ts src/gateway/test-helpers.server.tsFresh Codex P0 autoreview is scoped-clean. Native review artifacts have validated. Exact-head CI run 33844746629, attempt 2 is green. Attempt 1 had one cancelled Blacksmith job with runner ID 0 and zero executed steps; rerunning that exact job passed. No source workaround or CI bypass was used. This is the canonical raw-opening repair: reuse the shared acquisition owner, delete both duplicate waiters, preserve nonce observation and original ten-second budgets. Production runtime LOC is 0; support is −45 net and tests +5 net. Authenticated/composite rollback remains a separate focused change. The active lifetime work and all operator state/services remain untouched. The completed review is fresh and its item is satisfied; no re-review request is needed under the repository policy. |
|
Merged via squash.
|
Keep the complete awaited authentication callback inside the shared WebSocket acquisition owner. Roll back newly acquired servers before restoring selectors, preserve setup and cleanup errors independently, and capture the E2E helper config-path mutation. Extend native failure-boundary coverage without changing production runtime or timeout budgets. Builds on #137982 and #137924; fixture lifetime accounting remains with #136146.
…7982) Reuse the shared WebSocket acquisition owner in server-suite and webchat helpers. Preserve the ten-second opening budget and native transport errors, and join failed sockets before rejecting. Extend the existing native peer regressions rather than adding another fixture. Related to openclaw#137924; authenticated and composite rollback remain separate follow-ups.
…aw#138037) Keep the complete awaited authentication callback inside the shared WebSocket acquisition owner. Roll back newly acquired servers before restoring selectors, preserve setup and cleanup errors independently, and capture the E2E helper config-path mutation. Extend native failure-boundary coverage without changing production runtime or timeout budgets. Builds on openclaw#137982 and openclaw#137924; fixture lifetime accounting remains with openclaw#136146.
Related: #137924 (shared test-client acquisition cleanup). Separate from #136146 (Gateway work/state lifetime); this change does not modify that active work or its WebSocket harness.
Additional instructions
Keep Allow edits from maintainers enabled so maintainers can update this branch.
What Problem This Solves
Resolves a problem where failed Gateway test setup returned while its WebSocket was still connecting. A native protocol error arriving with the HTTP upgrade could also be replaced by a misleading missing-nonce error. The server-suite and webchat helpers still had their own opening waiters after the sibling acquisition repair landed.
Why This Change Was Made
Use the existing shared WebSocket acquisition owner for both server-suite and webchat opening. It retains the native error, terminates failed acquisition, joins the close event, and removes its listeners before returning the failure. Nonce observation stays installed before opening, and both original ten-second opening budgets remain unchanged.
This deletes two duplicate waiting paths rather than introducing another helper or test scaffold. Authenticated acquisition and composite server/client rollback are separate follow-ups; this PR does not claim to fix those boundaries.
User Impact
No production-runtime, configuration, protocol, or operator-facing behavior changes. Developers get deterministic failed setup without an abandoned connecting socket or a masked opening error. Existing successful Gateway flows remain covered.
Evidence
The existing native HTTP/WebSocket peer table gains two webchat cases; no new test file or production seam.
run_cde1160ec248reproduced exactly two new failures, with all twelve existing controls passing. The stalled socket was stillCONNECTINGwhen acquisition rejected; the malformed frame producedWS_ERR_INVALID_OPCODEbut acquisition returned the missing-nonce error instead.run_a7265731adb3verified the retained baseline and passed all 48 tests across four files, including real Gateway pairing, shared-token rotation, and session-permission/RPC flows. No selected cases were skipped.ws8.21.3 error/termination/close contracts were inspected directly; native fault tests exercise the dependency behavior.node scripts/check-changed.mjs -- src/gateway/test-helpers.acquisition.test.ts src/gateway/test-helpers.server.tspassed, including core/test typechecks, formatting, lint, dead-export scans, import-cycle checks, and the selected guards.Exact runtime commands, executed only in the owned VM:
The VM was newly leased with no instance role, auth hydration, Tailnet, or shared cache volumes. The canonical bootstrap verified the native IAM-credentials endpoint returned 404 and the base was
f113b70b285b223eb3346715d7167f37aa2d4c62; all application state was synthetic and VM-owned. The initial proof script stopped after the expected red run because its test-name classifier missed Vitest's quotation marks. The continuation corrected that bookkeeping, verified the retained report and restored candidate hash, and ran the full green proof; no candidate source change was needed.LOC: production runtime 0; test support +3/-48 (net −45); regressions +11/-6 (net +5). Total +14/-54 (net −40), two files. No changelog, dependencies, lockfiles, schemas, or protocol versions changed.