Skip to content

fix(test): retain Gateway listeners through initial port allocation - #155209

Merged
steipete merged 2 commits into
mainfrom
codex/fix-initial-listener-reservation-20260921
Sep 22, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-initial-listener-reservation-20260921

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Related: #122757 and #148262.

What Problem This Solves

Automatic Gateway test-fixture creation can fail when another loopback listener takes the selected port after the allocator's probe closes and before the fixture binds it.

User Impact

Test fixtures recover from an initial automatic bind collision after successfully cleaning up the abandoned attempt. Explicit ports and later reacquisition remain pinned. This is test infrastructure only; it changes no production Gateway behavior or operator configuration.

Why This Change Was Made

Compose the existing port-claim allocator with a retained TCP or HTTP listener, preserving the canonical claim owner and claim-aware probes introduced by #155228. Only an initial automatic EADDRINUSE can select another distinct candidate, and only after awaited rollback succeeds. Cancellation, other acquisition errors, and cleanup failures still stop acquisition. Each adapter keeps its existing listener-adoption and claim lifetime.

Evidence

On the tested main base, both deterministic controls fail with a real initial listen EADDRINUSE: a real competing listener binds after the allocator's probe, before fixture acquisition. The candidate passes 123 cases across seven files, including both adapters, replacement-socket exclusivity, abandoned-claim release, explicit-port refusal, and the existing cooperative port-collision regression. The two new regression rows add no Gateway boot, sleep, or polling.

All 34 selected checks passed, including production and root-test types, all 25 core-test type graphs, lint, three dead-code scans, import-cycle checks, formatting, and the remaining selected guards. Fresh independent review found no actionable findings. Proof binds tree 7027d728d0b09cfd34c7698933af82be84bf00ba on base 09e06495a3980cd74623951442d6e8ce4b777779; merge commit 5bf4b896756af32f5b80a051a297881fdcb0378b preserves that exact tree and the previously published PR ancestry.

The earlier agents-support failure received separate owner-level repairs on main. One qualification of the original 84 input paths through current routing passed 1,431 cases with 14 skips, including all 79 previously failing reported case labels. That result qualifies current source and routing; it does not establish a common cause for every historical failure. Current-head PR CI passed at 5bf4b896, testing merge be4d76b7 against base eab403af. All four tested source blobs match this candidate. The standard watcher returned green with no pending checks and no reruns.

Measured test cost and proof identity

The candidate Testbox run used Node 24.19.0 on isolated Linux with four available CPUs and 16.56 GB RAM.

Scope Result Command wall time
pnpm test test/helpers/openclaw-test-instance.acquisition.test.ts --maxWorkers=1 16 passed 21.414 s
Six allocator, instance-lifecycle, listener, and claim siblings 107 passed 64.320 s
Selected changed checks 34 passed, including 25 core-test type graphs 1,624.408 s

The acquisition file's summed case time was 0.148 s; the new TCP and HTTP rows took 43 ms and 17 ms. These are measurements, not a performance comparison. All 20 recorded source hashes matched before controls, after controls, and after candidate proof; all 15 downloaded artifact hashes verified. Native and wrapper exits were zero, and the lease was independently confirmed completed. An optional runner-portal synchronization warning occurred after the successful workload and did not trigger a rerun.

Current published-head hosted acquisition proof on 5bf4b896 passed all 16 cases with zero skips. Reported case durations total 0.171s, including 0.062s for the two reservation-conflict regressions (0.033s child-process and 0.029s in-process). These are summed case durations; standalone file wall time is unavailable. CI tested merge be4d76b7 against base eab403af.

For hosted cost already available, PR CI run 35657958292 exercised the previous published head 78feaa27 through merge 546fe9fc. Its acquisition file passed all 16 cases with 0.239 s summed case time, including 49 ms TCP and 25 ms HTTP. The reporter did not expose a separate file wall time. This is retained proof for that earlier source, not hosted CI success for the new head; the same run's agents-support group failed.

Disposition of the earlier agents-support failure

Main now includes #155304 (e32fe542), which runs agents-support in forked processes so real retired-lease cleanup can use the host-thread broker; #155312 (0f68ab0a), which attributes teardown failures to their file and phase while preserving failed SQLite custody and continuing independent cleanup; and #155120 (19fae013), which removes maintenance test overrides and routes the remaining database-backed suites through their process-isolated broker owner. Teardown attribution itself does not repair a retained broker refusal or dependent database-read failure.

One unchanged-source qualification on merged main 19fae013 passed the original 84 inputs to the native explicit-target router. Every input was assigned exactly once: three broker-owned paths under infra and 81 under agents-support, with sequential projects and two workers per project. Infra passed 152 cases in 29.79 s; agents-support passed 1,279 cases with 14 skips in 66.53 s. Overall, 82 files executed and two were skipped; router wall time was 98.71 s. All 79 previously failing reported case labels passed across the six original failure files. The case inventory has changed on main, so the current total is not a reconstruction of the historical inventory.

This run used four available CPUs and 16.56 GB RAM, compared with the historical eight CPUs and 33.23 GB, fresh task-owned caches, and no outer infra/runtime-config contention. Historical worker order and cache state were not reproduced. Normal admission and deadlines remained enabled, with one attempt and no automatic retry. All 112 recorded source hashes matched before and after; native and wrapper exits were zero, downloaded evidence hashes verified, and the lease was independently confirmed completed.

The historical initial HTTP EADDRINUSE observation in #155098 did not retain the competing socket owner's identity. A single replay of its 98-input Gateway core/client group passed on the available four-CPU Testbox with the normal two-worker fallback; it did not reproduce the original eight-worker topology. The earlier zero-close acquisition-cleanup failures in the related PRs also remain unattributed. This PR fixes the independently reproduced initial allocation race without claiming those historical causes.

Compose the cooperative port claim and real loopback listener for initial
TCP fixture and HTTP Gateway reservations. Select another automatic port
only after a real bind collision and fully joined rollback; preserve
explicit ports, pinned reacquisition, cancellation, and cleanup failures.

Reproduce both adapters with real competing listeners. All 122 focused
cases and the complete selected changed gate pass; independent P2 review
is clean. The historical acquisition CI failures remain unattributed.
@clawsweeper

clawsweeper Bot commented Sep 21, 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 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 21:34
@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 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 10:31 PM ET / September 22, 2026, 02:31 UTC (Revision 2).

ClawSweeper review

What this changes

Gateway test fixtures retain their initial TCP or HTTP listener and select another port after a bind collision only when cleanup succeeds.

Merge readiness

✅ Ready for maintainer review

The repair remains useful on current main. The introduced patch preserves shared claims and limits recovery to initial automatic bind collisions; no actionable correctness or security findings were identified.

Priority: P2
Reviewed head: 5bf4b896756af32f5b80a051a297881fdcb0378b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful socket-boundary regressions, recorded validation, and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this maintainer-authored fixture repair. Supplied Linux evidence exercises both actual fixture entrypoints with real competing sockets and reports recovery; no production Gateway execution is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this maintainer-authored fixture repair. Supplied Linux evidence exercises both actual fixture entrypoints with real competing sockets and reports recovery; no production Gateway execution is claimed.
Evidence reviewed 7 items Pinned introduced patch: Reviewed the merge-base-to-head patch independently of endpoint drift. The raw head records tree 7027d728d0b09cfd34c7698933af82be84bf00ba and parents 09e0649 and 78feaa2, matching the supplied proof identity. The supplied test merge is stale and was not used to infer removal of main-branch work.
Recovery preserves failure boundaries: The shared reservation helper acquires the existing claim, binds a real listener, checks cancellation, and awaits rollback. Another candidate is allowed only for the original bind EADDRINUSE on automatic allocation with no cleanup error; repeated candidates stop acquisition.
Both adapters preserve their lifecycle: Initial automatic child-process fixture allocation uses the shared reservation helper. Explicit ports still bypass automatic allocation, later idle reservation remains pinned, and the HTTP adapter retains its existing transport-adoption and claim-release behavior.
Findings None None.
Security None None.

How this fits together

Gateway test fixtures allocate loopback ports before starting isolated test servers. Shared claims coordinate cooperating tests, while retained sockets prevent other listeners from taking the selected port before handoff.

flowchart TD
  A[Test fixture request] --> B[Allocate and claim port block]
  B --> C[Bind retained loopback listener]
  C -->|Success| D[Fixture startup and handoff]
  C -->|Bind collision| E[Await rollback]
  E -->|Automatic initial allocation| B
  E -->|Explicit port or cleanup failure| F[Report acquisition failure]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -3, Tests +158. Total +155 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 14 -3
Tests 3 164 6 +158
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 175 20 +155

Review metrics

Metric Value Why it matters
Runtime versus test growth Production +0; test support net +70; regression tests +85 Growth is confined to shared fixture recovery and its two adapter regressions.
Recorded regression cost New rows: 43 ms TCP, 17 ms HTTP; acquisition file: 21.414 s command wall The captured Linux run measures real socket collisions without adding Gateway boots, sleeps, or polling.

Technical review

Best possible solution:

Keep initial collision recovery in the shared reservation owner while preserving explicit ports, published fixture identities, and awaited cleanup.

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

Yes: bind a competing loopback listener after the allocator closes its probe, then acquire either fixture adapter. Source and the recorded baseline controls establish the failure path; this review did not execute it.

Is this the best way to solve the issue?

Yes: composing retained listeners with the existing claim owner addresses the remaining race without replacing the cooperative-probe fix or changing later fixture identity.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes a bounded test-fixture acquisition race without changing product runtime behavior.
  • 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 external-contributor proof gate does not apply to this maintainer-authored fixture repair. Supplied Linux evidence exercises both actual fixture entrypoints with real competing sockets and reports recovery; no production Gateway execution is claimed.

Evidence

What I checked:

  • Pinned introduced patch: Reviewed the merge-base-to-head patch independently of endpoint drift. The raw head records tree 7027d728d0b09cfd34c7698933af82be84bf00ba and parents 09e0649 and 78feaa2, matching the supplied proof identity. The supplied test merge is stale and was not used to infer removal of main-branch work. (5bf4b896756a)
  • Recovery preserves failure boundaries: The shared reservation helper acquires the existing claim, binds a real listener, checks cancellation, and awaits rollback. Another candidate is allowed only for the original bind EADDRINUSE on automatic allocation with no cleanup error; repeated candidates stop acquisition. (src/test-utils/port-claims.ts:63, 5bf4b896756a)
  • Both adapters preserve their lifecycle: Initial automatic child-process fixture allocation uses the shared reservation helper. Explicit ports still bypass automatic allocation, later idle reservation remains pinned, and the HTTP adapter retains its existing transport-adoption and claim-release behavior. (test/helpers/openclaw-test-instance.ts:757, 5bf4b896756a)
  • Current main still lacks this recovery: Fetched main contains the cooperative claim allocator but no retained-listener acquisition operation. Its adapter differences match the introduced repair. The merged prerequisite fix(test): prevent port probes from colliding with fixture reservations #155228 protects against cooperating probes; it does not handle an unrelated listener winning after the probe closes. (src/test-utils/port-claims.ts:9, 2a4527f00917)
  • Regression and recorded validation: The two added rows call the actual fixture adapters, insert a real competing socket after allocation, verify replacement-socket exclusivity, reacquire the abandoned claim, and reject an occupied explicit port. The captured body reports both baseline controls failing and 123 candidate cases passing on isolated Linux, plus 34 selected checks, bound to the verified head tree. These are supplied results, not tests executed during this read-only review. Historical zero-close failures remain explicitly unattributed. (test/helpers/openclaw-test-instance.acquisition.test.ts:20, 5bf4b896756a)
  • Main-history routing: Current-main history identifies Peter Steinberger across the shared claim repair, listener parallelization, and fixture-lifecycle maintenance. Earlier source blobs were unavailable for exact introduction verification, so no source-line introduction attribution is asserted. (src/gateway/test-helpers.listener.ts, c3ae72c09c80)

Likely related people:

  • steipete: 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-21T21:42:42.436Z sha 78feaa2 :: needs maintainer review before merge. :: none

Compose initial TCP and HTTP reservations over the canonical claim owner
extracted in #155228, retaining its claim-aware allocation probes. Retry only
an automatic initial bind that reports EADDRINUSE after joined rollback;
keep explicit and published ports, later reacquisition, cancellation and
cleanup failures pinned to their existing contracts.

Integrate #155209 without replacing its published ancestry. Current-main
controls reproduce both real initial-bind failures. The composed candidate
passes all 123 cases across seven files and all 34 selected checks, including
25 core-test type graphs. Fresh P2 review has no actionable findings.

The recorded #155098 group passed once on the available 4-CPU Testbox with
its normal two-worker fallback. That result does not reproduce the original
eight-worker topology or establish the historical competing socket owner;
earlier zero-close acquisition failures also remain unattributed.
@steipete
steipete requested review from a team as code owners September 22, 2026 02:24
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo labels Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has dependency changes awaiting review. A future dependency graph change from an external contributor requires a maintainer's /allow-dependencies-change comment after the guard notice identifies that revision.

  • Current SHA: 5bf4b896756af32f5b80a051a297881fdcb0378b

@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

agents Agent runtime and tooling app: android App: android app: ios App: ios app: linux app: macos App: macos app: web-ui App: web-ui channel: a2a channel: buzz channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: irc channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: qa-channel Channel integration: qa-channel channel: raft Channel integration: Raft channel: reef Channel integration: reef channel: signal Channel integration: signal channel: slack Channel integration: slack channel: sms Channel integration: sms channel: synology-chat channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: twitch Channel integration: twitch channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser cli CLI command changes commands Command implementations deploy: cloudflare Cloudflare deployment template and docs docs Improvements or additions to documentation extensions: acpx extensions: amazon-bedrock extensions: amazon-bedrock-mantle extensions: anthropic extensions: anthropic-vertex extensions: apple-fm extensions: browser extensions: clickclack extensions: codex extensions: crabbox extensions: diffs extensions: firecrawl extensions: lobster Extension: lobster extensions: memory-core Extension: memory-core extensions: memory-wiki extensions: openai extensions: openshell extensions: qa-lab extensions: webhooks extensions: xai gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. plugin: code-mode-quickjs plugin: cua-computer plugin: imap plugin: linux-node plugin: mxc plugin: team-reports plugin: visitor-access plugin: workboard rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security Security documentation size: XL 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