Skip to content

fix(test): stop leaking sockets after failed Gateway setup - #137982

Merged
steipete merged 1 commit into
mainfrom
steipete/gateway-server-acquisition
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/gateway-server-acquisition

Conversation

@steipete

@steipete steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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.

  • Before: AWS run run_cde1160ec248 reproduced exactly two new failures, with all twelve existing controls passing. The stalled socket was still CONNECTING when acquisition rejected; the malformed frame produced WS_ERR_INVALID_OPCODE but acquisition returned the missing-nonce error instead.
  • After: AWS run run_a7265731adb3 verified 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.
  • Fresh Codex autoreview found no accepted/actionable P0 findings in the two-file patch. The shared helper and installed ws 8.21.3 error/termination/close contracts were inspected directly; native fault tests exercise the dependency behavior.
  • Local node scripts/check-changed.mjs -- src/gateway/test-helpers.acquisition.test.ts src/gateway/test-helpers.server.ts passed, 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:

node scripts/run-vitest.mjs src/gateway/test-helpers.acquisition.test.ts --reporter=verbose --reporter=json --outputFile=.artifacts/raw-opening-proof/red.json
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.json

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.

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.
@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 06:31
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 2:41 AM ET / 06:41 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 0039126a29004d4b59086f70db72953e972bd090

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused canonical-owner consolidation with behavior-level native socket coverage and no supported correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER PR is exempt from the external-contributor proof gate; its supplied body nevertheless describes before/after native WebSocket fault runs for the changed helper path. The linked artifacts could not be independently opened because upstream DNS was unavailable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER PR is exempt from the external-contributor proof gate; its supplied body nevertheless describes before/after native WebSocket fault runs for the changed helper path. The linked artifacts could not be independently opened because upstream DNS was unavailable.
Evidence reviewed 6 items Introduced owner delegation: The PR creates a socket, installs nonce observation, then delegates acquisition to the shared owner with the unchanged 10-second budget.
Boundary regression coverage: The existing native peer matrix adds webchat stalled-upgrade and malformed-frame cases, then asserts first-error identity, closed state, close observation, and listener cleanup.
Canonical owner provenance: The merged cleanup introduced the shared acquisition helper; its parent was inspected and the helper file is added by that commit, while the earlier merge did not modify the server helper.
Findings None None.
Security None None.

How this fits together

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

Before merge

  • Resolve merge risk (P1) - The reviewer could not independently inspect the installed ws source because this read-only worktree lacks dependencies and upstream DNS was unavailable; normal exact-head CI remains the appropriate dependency-contract check before merge.
Agent review details

Security

None.

PR surface

Source -45, Tests +5. Total -40 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 48 -45
Tests 1 11 6 +5
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 14 54 -40

Review metrics

Metric Value Why it matters
Production versus test delta production +0/-0; test support +3/-48; regression tests +11/-6 The change removes duplicated test-support opening logic while adding two cases to the existing native socket boundary matrix.

Root-cause cluster

Relationship: canonical
Canonical: #137982
Summary: This PR is the focused remaining server/webchat acquisition cleanup after the merged shared-helper change.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

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

Labels

Label changes:

  • add P3: This is a bounded Gateway test-fixture reliability repair with no production-runtime, configuration, protocol, or user-flow change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER PR is exempt from the external-contributor proof gate; its supplied body nevertheless describes before/after native WebSocket fault runs for the changed helper path. The linked artifacts could not be independently opened because upstream DNS was unavailable.

Label justifications:

  • P3: This is a bounded Gateway test-fixture reliability repair with no production-runtime, configuration, protocol, or user-flow change.
  • 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: This MEMBER PR is exempt from the external-contributor proof gate; its supplied body nevertheless describes before/after native WebSocket fault runs for the changed helper path. The linked artifacts could not be independently opened because upstream DNS was unavailable.

Evidence

What I checked:

  • Introduced owner delegation: The PR creates a socket, installs nonce observation, then delegates acquisition to the shared owner with the unchanged 10-second budget. (src/gateway/test-helpers.server.ts:796, 0039126a2900)
  • Boundary regression coverage: The existing native peer matrix adds webchat stalled-upgrade and malformed-frame cases, then asserts first-error identity, closed state, close observation, and listener cleanup. (src/gateway/test-helpers.acquisition.test.ts:170, 0039126a2900)
  • Canonical owner provenance: The merged cleanup introduced the shared acquisition helper; its parent was inspected and the helper file is added by that commit, while the earlier merge did not modify the server helper. (test/helpers/gateway-websocket.ts:34, de14dd375040)
  • Current-main necessity: Current main has no changes on the affected server helper, acquisition test, or shared helper relative to the PR base, so it still retains the pre-PR local waiter behavior. (src/gateway/test-helpers.server.ts:787, 13f017b67c9e)
  • Failure cleanup contract: On acquisition failure the canonical helper preserves the original error, awaits termination through close, then removes its listeners; the fixture runner retains the body error while still running cleanup. (test/helpers/gateway-websocket.ts:65, de14dd375040)
  • Dependency inspection limitation: The target manifest and lockfile pin ws 8.21.3, but this read-only checkout has no node_modules and DNS prevented fetching upstream source; no ws event-ordering claim is inferred beyond the native boundary evidence in the PR. (pnpm-lock.yaml:9600, 0039126a2900)

Likely related people:

  • Peter Steinberger: Raw commit de14dd3 adds test/helpers/gateway-websocket.ts:34 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: de14dd375040; files: test/helpers/gateway-websocket.ts)

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.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 0039126a29004d4b59086f70db72953e972bd090 is complete.

The completed ClawSweeper review has no code finding. Its sole before-merge item was the review worker's inability to inspect installed ws or open the proof links because of DNS failure. That gap is addressed here: the maintainer directly inspected ws 8.21.3 lib/websocket.js termination/handshake-abort/error/close paths (302–307, 492–503, 1053–1125) and lib/receiver.js synchronous frame parsing (172–199, 333–343, 632–640). Those files were byte-compared with the final candidate's installed dependency. Native fault injection then proved both error identity and close-joined rejection. No dependency-proof waiver is being taken.

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

Local static command, passed:

node scripts/check-changed.mjs -- src/gateway/test-helpers.acquisition.test.ts src/gateway/test-helpers.server.ts

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

@steipete
steipete merged commit a550b3f into main Sep 4, 2026
311 of 313 checks passed
@steipete
steipete deleted the steipete/gateway-server-acquisition branch September 4, 2026 06:49
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 4, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…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.
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

1 participant