Repository navigation
fix(test): retain Gateway listeners through initial port allocation - #155209
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 21, 2026, 10:31 PM ET / September 22, 2026, 02:31 UTC (Revision 2). ClawSweeper reviewWhat this changesGateway 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 Review scores
Verification
How this fits togetherGateway 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -3, Tests +158. Total +155 across 4 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
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.
Dependency graph guard clearedThis PR no longer has dependency changes awaiting review. A future dependency graph change from an external contributor requires a maintainer's
|
|
Merged via squash.
|
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
EADDRINUSEcan 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
7027d728d0b09cfd34c7698933af82be84bf00baon base09e06495a3980cd74623951442d6e8ce4b777779; merge commit5bf4b896756af32f5b80a051a297881fdcb0378bpreserves 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 mergebe4d76b7against baseeab403af. 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.
pnpm test test/helpers/openclaw-test-instance.acquisition.test.ts --maxWorkers=1The 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
5bf4b896passed 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 mergebe4d76b7against baseeab403af.For hosted cost already available, PR CI run 35657958292 exercised the previous published head
78feaa27through merge546fe9fc. 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
19fae013passed 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
EADDRINUSEobservation 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.