Skip to content

fix(qa): prevent reserved gateway port startup deadlock - #126370

Merged
steipete merged 2 commits into
mainfrom
steipete/qa-port-reservation-release-20260819
Aug 19, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/qa-port-reservation-release-20260819

Conversation

@steipete

@steipete steipete commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted: Yes. The implementation and validation used AI coding tools, with a clean final autoreview.

What Problem This Solves

Fixes an issue where QA flows that stage packaged authentication before launching an isolated Gateway could hang until their outer test timeout. The reserved Gateway port accepted an internal probe connection, and release then waited indefinitely before the real Gateway process was spawned. This surfaced in the real Gateway/node MCP stress suite as a 180-second timeout and an orphaned fixture process.

Why This Change Was Made

The port-reservation owner now immediately closes any probe connection while continuing to hold the bind address through staging. Socket creation remains at the existing Gateway-child network boundary, while release stays idempotent and occurs immediately before the real Gateway bind.

User Impact

There is no production runtime or user-visible behavior change. QA Gateway launches no longer deadlock when staged CLI work probes the reserved port, so real-process integration tests fail or proceed at their actual product boundary instead of timing out before Gateway startup.

Evidence

  • Pre-fix real-process reproduction: gateway-node-mcp.stress.e2e.test.ts exhausted its 180-second test budget; the preserved QA root had completed both auth writes but had empty Gateway logs, proving no Gateway child was spawned.
  • The focused regression failed before the fix with Expected: "released" / Received: "probe remained open and release stayed pending".
  • node scripts/run-vitest.mjs extensions/qa-lab/src/gateway-port-reservation.test.ts — 2/2 passed on final head.
  • node scripts/run-vitest.mjs extensions/qa-lab/src/gateway-child.test.ts — 87/87 passed on final head.
  • node scripts/check-changed.mjs -- extensions/qa-lab/src/gateway-port-reservation.ts extensions/qa-lab/src/gateway-port-reservation.test.ts extensions/qa-lab/src/gateway-child.ts — passed on final head.
  • node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-node-mcp.stress.e2e.test.ts — passed on final head in 26.80 seconds; transport recovery, stateful expiry, and descendant cleanup assertions all completed.
  • Final Codex autoreview — clean, no accepted/actionable findings.
  • The first PR head moved the existing node:net import into the helper and correctly triggered the network-runtime boundary scanner. The final head keeps socket construction in the already-classified Gateway owner while the helper owns connection rejection; focused proof and autoreview were rerun after that refinement.

Production LOC: +5/-3 (net +2), justified by the lifecycle invariant that accepted probes cannot block reservation release. Tests: +26/-1.

@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 19, 2026 17:03
@steipete steipete self-assigned this Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 1:28 PM ET / 17:28 UTC.

ClawSweeper review

What this changes

The PR closes probe connections accepted by a reserved QA Gateway port, preventing port release from waiting before the real Gateway can start.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

No blocking defect was found in the focused QA repair. This maintainer-labeled PR should remain open for explicit maintainer handling until its required exact-head checks finish.

Priority: P2
Reviewed head: 31c2a3707e6432f1137c6e34882f872258a200fb
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with a credible regression test and reported real-process validation; only maintainer review and exact-head CI remain.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer-authored QA-infrastructure PR is exempt from the external-contributor proof gate; its body nevertheless reports focused native-socket and real-process Gateway validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored QA-infrastructure PR is exempt from the external-contributor proof gate; its body nevertheless reports focused native-socket and real-process Gateway validation.
Evidence reviewed 5 items Current-main failure path: Current main creates a bare reservation server; its release resolves only through the server close callback, while no handler closes an accepted probe socket.
Caller and owner-boundary repair: The PR passes the concrete server to the reservation owner, which destroys accepted probe sockets; the Gateway child still releases the reservation directly before spawning the real Gateway.
Focused regression coverage: The new native TCP regression opens a probe, releases the reservation, and requires both the probe close and release completion before its timeout.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-node-mcp.stress.e2e.test.ts

Result: FAIL (partial) — step 2 expect_output serializes catalogs, recovers terminal streams, fences expiry, and reaps crash generations: expected terminal output was not visible within 30 seconds: "serializes catalogs, recovers terminal streams, fences expiry, and reaps crash generations"

node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-node-mcp.stress.e2e.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126370-GRJqtp/target$ node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-node-mcp.stress.e2e.test.ts
[test] starting test/vitest/vitest.e2e.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126370-GRJqtp/target

node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-node-mcp.stress.e2e.test.ts
[openclaw] Building TypeScript (dist is stale: missing_private_qa_dist - private QA dist entry missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
  - tsdown:deps (48%)
  - rolldown-plugin-dts:fake-js (22%)
  - rolldown-plugin-dts:generate (19%)
See https://rolldown.rs/reference/InputOptions.checks#plugintimings for more details.

[tsdown-build] invocation 1/11 finished in 4.8s
[tsdown-build] invocation 2/11 finished in 20.7s































Assertions:

  • FAIL expect_output: serializes catalogs, recovers terminal streams, fences expiry, and reaps crash generations

How this fits together

QA Lab reserves a local Gateway port while staging configuration and authentication, then releases it immediately before starting an isolated Gateway process. This change ensures incidental probe connections cannot block that handoff.

flowchart LR
  A[QA scenario] --> B[Reserve local Gateway port]
  B --> C[Stage configuration and auth]
  C --> D[Release reservation]
  D --> E[Start isolated Gateway]
  E --> F[Run real-process QA checks]
Loading

Decision needed

Question Recommendation
Should this maintainer-labeled QA deadlock fix land once required checks are green on its exact head? Land after CI: Merge the focused owner-boundary repair once required checks complete successfully.

Why: The protected maintainer label requires a human landing decision even though no code-level blocker was found.

Before merge

  • Resolve merge risk (P1) - Required exact-head CI is still running.
  • Resolve merge risk (P1) - Production code is net +2 lines; the added socket cleanup belongs at the reservation owner, while replacing the factory caller removes the avoidable wrapper.
  • Resolve merge risk (P1) - A direct local loopback confirmation was blocked by the review sandbox's EPERM bind restriction; the PR body reports the focused and real-process runs instead.
Agent review details

Security

None.

PR surface

Source +2, Tests +25. Total +27 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 5 3 +2
Tests 1 26 1 +25
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 31 4 +27

Review metrics

Metric Value Why it matters
Production versus tests production +5/-3 (net +2); tests +26/-1 The net production growth is limited to owner-boundary socket cleanup and its narrow structural type; the prior server factory is removed.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep accepted-socket cleanup at the port-reservation owner and land after maintainer review and green exact-head CI.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep accepted-socket cleanup at the port-reservation owner and land after maintainer review and green exact-head CI.

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

Yes. Opening a TCP probe to the reserved loopback port before release exercises the source-proven wait condition; the focused regression directly covers that sequence.

Is this the best way to solve the issue?

Yes. Closing probes at the reservation owner removes the blocking connection without altering the real Gateway or adding a downstream timeout.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 957f013454d4.

Labels

Label changes:

  • add P2: This repairs a bounded QA Gateway-startup deadlock without changing the shipped user-facing runtime.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.

Label justifications:

  • P2: This repairs a bounded QA Gateway-startup deadlock without changing the shipped user-facing runtime.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

Likely related people:

  • steipete: Authored the reviewed reservation-owner repair; the partial checkout could not provide complete earlier file history. (role: current QA repair author; confidence: medium; commits: 31c2a3707e64; files: extensions/qa-lab/src/gateway-port-reservation.ts, extensions/qa-lab/src/gateway-child.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for required exact-head CI before landing.

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

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 31c2a3707e6432f1137c6e34882f872258a200fb:

  • Focused proof passed: gateway-port-reservation.test.ts 2/2, gateway-child.test.ts 87/87, and node scripts/check-changed.mjs -- extensions/qa-lab/src/gateway-port-reservation.ts extensions/qa-lab/src/gateway-port-reservation.test.ts extensions/qa-lab/src/gateway-child.ts.
  • Exact-head real-process proof passed: node scripts/run-vitest.mjs test/e2e/qa-lab/runtime/gateway-node-mcp.stress.e2e.test.ts (1/1, 26.80s).
  • Required exact-head CI is green: run 32281201639.
  • ClawSweeper's exact-head review found no code defect and rated patch quality platinum. Its only rank-up move was to wait for CI, now resolved; the sandbox EPERM bind limitation is superseded by the local real-process proof above.
  • Fresh exact-head autoreview is clean with no accepted or actionable findings.
  • Production LOC: +5/-3 (net +2), justified by the reservation-owner accepted-socket lifecycle/type contract. Tests: +26/-1.

Maintainer decision: land. Destroying accepted probes at the QA Gateway reservation owner fixes the release deadlock while keeping socket creation at the existing Gateway-child network boundary; retries, timeout increases, a new CodeQL classification, or downstream cleanup would be the wrong layer.

@steipete
steipete merged commit 7e353d7 into main Aug 19, 2026
117 checks passed
@steipete
steipete deleted the steipete/qa-port-reservation-release-20260819 branch August 19, 2026 17:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

* fix(qa): close probes on reserved gateway ports

* fix(qa): keep port sockets at the gateway boundary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant