Repository navigation
fix(test): Gateway e2e connect fails with 1006 when another fixture takes the instance port - #163003
Conversation
…ness A post-start `gateway closed during connect (1006)` carried no evidence of which process answered readiness or what the owned child was doing. The test instance now records the responder's reported uptime per readiness probe and exposes a bounded `diagnose()` snapshot (child pid/exit state and age, last readiness probe, Linux LISTEN-socket owners of the port under a 1s scan budget, and the child log tail). The shared acquisition close error names the handshake stage (socket opened, connect request sent). gateway-cold-agent-abort attaches the snapshot to a connect failure before cleanup retires the child. Assertions are unchanged.
gateway-cold-agent-abort intermittently failed with
`gateway closed during connect (1006)` about 260 ms into the test: far too
early for its own cold Gateway child to have answered readiness.
Root cause: OpenClawTestInstance claims its port block and releases its
reservation listener right before spawning the child. In-process Gateway
fixtures picked ports with getGatewayE2ePortBlock(), a probe that released its
claim before returning, and then called startGatewayServer(). The production
listener retries EADDRINUSE every 500 ms, so a fixture that probed the same
candidate just before the instance claimed it kept retrying against the
reservation and took the port at the handoff. The instance's /readyz probe was
then answered by that foreign in-process Gateway, and the client hit it while
it was closing (1006) or got a token mismatch while it was alive.
getGatewayE2ePortBlock is removed. acquireGatewayE2ePortBlock (next to
startClaimedGateway) returns a held claim, and every caller keeps it until the
Gateway or server bound to that port has closed: startClaimedGateway for
in-process servers, startGatewayWithClient({ portClaim }), or an explicit
release after close, including same-port restarts and a guard for claims not
yet handed to a starting Gateway. The documented contract that shared port
claims cover in-process listener lifetimes now holds. Kernel-assigned (port 0)
allocations stay out of scope; on Linux they come from the ephemeral range the
claimed pool excludes.
Regression: an instance whose first candidate is an in-process Gateway E2E
port must allocate a different port; it fails on the probe-only helper.
|
🦞👀 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 October 2, 2026, 1:35 AM ET / 05:35 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR retains shared test-port claims until their listeners close and adds diagnostics when a Gateway test connection fails after readiness. Merge readiness✅ Ready for maintainer review This PR remains useful: current main and the latest release retain the probe-only allocation path. The latest head resolves the previous cleanup finding, and no additional blocking defect was found. Priority: P2 Review scores
Verification
How this fits togetherGateway test fixtures launch isolated servers and connect clients over local HTTP and WebSocket transports. Shared port ownership prevents concurrent fixtures from connecting to the wrong server during startup. flowchart TD
A[Concurrent test fixtures] --> B[Shared port claims]
B --> C[Gateway listener startup]
C --> D[Readiness and client connection]
D --> E[Test results and diagnostics]
C --> F[Listener cleanup]
F --> G{Cleanup succeeded?}
G -->|Yes| B
G -->|No| H[Retain port claim]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -1, Tests +263. Total +262 across 32 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Use the shared claim owner throughout fixture startup, restarts, and verified listener teardown, with bounded diagnostics for any recurrence. Do we have a high-confidence way to reproduce the issue? Yes, the source establishes the collision path: probe-only allocation releases ownership before a listener that retries EADDRINUSE starts. The PR supplies deterministic reproduction evidence; this read-only review did not execute it. Is this the best way to solve the issue? Yes, repairing fixture ownership through the existing shared claim owner addresses the cause without adding a product readiness protocol or weakening assertions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b21e522e2ad1. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
The MCP App conformance fixture released all three of its port claims after cleanup steps that record and swallow failures. A failed Gateway close, MCP runtime disposal, or asset-server close could therefore free a port whose listener was still bound, reopening the handoff collision this branch closes. Each claim is now released only after its own listener's teardown succeeded: the Gateway claim after Gateway close, the sandbox claim after Gateway close and MCP startup/disposal, and the asset claim after the asset server closed or when it never started. Incomplete cleanup keeps the port claimed, matching startClaimedGateway.
|
Landed as 8095d77 with a pinned-head squash merge (head Inherited failure:
Also before merge: ClawSweeper revision 4 on this exact head reports Ready with no remaining items. The cleanup finding from revision 3 was fixed in 19116d4, and the delta autoreview is scoped-clean. All other checks passed. The export-collision and eager-import/wrapper closure guards pass locally. The earlier |
…akes the instance port (openclaw#163003) gateway-cold-agent-abort intermittently failed with `gateway closed during connect (1006)` about 260 ms into the test, too early for its own cold Gateway child to have answered readiness. OpenClawTestInstance claims its port block and releases its reservation listener right before spawning the child. In-process Gateway fixtures picked ports with getGatewayE2ePortBlock(), a probe that released its claim before returning, and then started a Gateway whose listener retries EADDRINUSE every 500 ms. A fixture that probed the same candidate just before the instance claimed it won the port at the handoff, and the instance's /readyz was answered by that foreign Gateway (1006 while it closed, token mismatch while alive). getGatewayE2ePortBlock is removed. acquireGatewayE2ePortBlock (beside startClaimedGateway) returns a held claim, and every caller keeps it until the Gateway or server bound to that port has closed, including same-port restarts, unstarted-claim guards, and listener-specific release in the MCP App conformance fixture. Kernel-assigned port-0 binders stay out of scope (the Linux pool excludes the ephemeral range). The test instance gains bounded post-start diagnostics (diagnose(), responder uptime vs child age, Linux listener owners, handshake stage in the close error). Regression: an instance whose first candidate is an in-process Gateway E2E port must allocate a different port (fails on the probe-only helper).
* ci(release): install Chromium for A-K live tests (#163178) (cherry picked from commit 9ce1498) * ci(release): pin reachable live provider models (#163177) (cherry picked from commit 0fa2ddd) * test(opencode): refresh free live tool model (#163470) Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit cd7c2d2) * test: synchronize Telegram recorder failure admission Gate the synthetic control timeline on the recorder's durable failure receipt so slow filesystem publication cannot overtake the intended failure precondition. Preserve every assertion and align the touched fixture with the existing lint rules. (cherry picked from commit 0dfb96f) * fix(ui): reconcile end after layout correction (#166261) (cherry picked from commit 51f772a) * fix(ci): forward live video provider credentials (#164317) Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit d0ce76b) * fix(security): backport MCP dependency advisory fix (cherry picked from commit c39d9b0) * fix(test): make live qualification waits event driven * fix(test): Gateway e2e connect fails with 1006 when another fixture takes the instance port (#163003) gateway-cold-agent-abort intermittently failed with `gateway closed during connect (1006)` about 260 ms into the test, too early for its own cold Gateway child to have answered readiness. OpenClawTestInstance claims its port block and releases its reservation listener right before spawning the child. In-process Gateway fixtures picked ports with getGatewayE2ePortBlock(), a probe that released its claim before returning, and then started a Gateway whose listener retries EADDRINUSE every 500 ms. A fixture that probed the same candidate just before the instance claimed it won the port at the handoff, and the instance's /readyz was answered by that foreign Gateway (1006 while it closed, token mismatch while alive). getGatewayE2ePortBlock is removed. acquireGatewayE2ePortBlock (beside startClaimedGateway) returns a held claim, and every caller keeps it until the Gateway or server bound to that port has closed, including same-port restarts, unstarted-claim guards, and listener-specific release in the MCP App conformance fixture. Kernel-assigned port-0 binders stay out of scope (the Linux pool excludes the ephemeral range). The test instance gains bounded post-start diagnostics (diagnose(), responder uptime vs child age, Linux listener owners, handshake stage in the close error). Regression: an instance whose first candidate is an in-process Gateway E2E port must allocate a different port (fails on the probe-only helper). (cherry picked from commit 8095d77) --------- Co-authored-by: RoboClaw <[email protected]> Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Patrick Erichsen <[email protected]>
* ci(release): install Chromium for A-K live tests (#163178) (cherry picked from commit 9ce1498) * ci(release): pin reachable live provider models (#163177) (cherry picked from commit 0fa2ddd) * test(opencode): refresh free live tool model (#163470) Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit cd7c2d2) * test: synchronize Telegram recorder failure admission Gate the synthetic control timeline on the recorder's durable failure receipt so slow filesystem publication cannot overtake the intended failure precondition. Preserve every assertion and align the touched fixture with the existing lint rules. (cherry picked from commit 0dfb96f) * fix(ui): reconcile end after layout correction (#166261) (cherry picked from commit 51f772a) * fix(ci): forward live video provider credentials (#164317) Co-authored-by: Peter Steinberger <[email protected]> (cherry picked from commit d0ce76b) * fix(security): backport MCP dependency advisory fix (cherry picked from commit c39d9b0) * fix(test): make live qualification waits event driven * fix(test): Gateway e2e connect fails with 1006 when another fixture takes the instance port (#163003) gateway-cold-agent-abort intermittently failed with `gateway closed during connect (1006)` about 260 ms into the test, too early for its own cold Gateway child to have answered readiness. OpenClawTestInstance claims its port block and releases its reservation listener right before spawning the child. In-process Gateway fixtures picked ports with getGatewayE2ePortBlock(), a probe that released its claim before returning, and then started a Gateway whose listener retries EADDRINUSE every 500 ms. A fixture that probed the same candidate just before the instance claimed it won the port at the handoff, and the instance's /readyz was answered by that foreign Gateway (1006 while it closed, token mismatch while alive). getGatewayE2ePortBlock is removed. acquireGatewayE2ePortBlock (beside startClaimedGateway) returns a held claim, and every caller keeps it until the Gateway or server bound to that port has closed, including same-port restarts, unstarted-claim guards, and listener-specific release in the MCP App conformance fixture. Kernel-assigned port-0 binders stay out of scope (the Linux pool excludes the ephemeral range). The test instance gains bounded post-start diagnostics (diagnose(), responder uptime vs child age, Linux listener owners, handshake stage in the close error). Regression: an instance whose first candidate is an in-process Gateway E2E port must allocate a different port (fails on the probe-only helper). (cherry picked from commit 8095d77) --------- Co-authored-by: RoboClaw <[email protected]> Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: vincentkoc <[email protected]> Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Patrick Erichsen <[email protected]> (cherry picked from commit 8aa6d7c) Release adaptation: Select only live-shard evidence handling for disabled llama.cpp, Meta, and Mistral URL/key prerequisites. Re-home regression cases in the stable evidence helper; no workflow credentials, dependencies, or fixture ownership changes. Companion audit: Historical release bundle is not on pinned main and #166341 has no pinned-main PR mentions. Recorded backports for Chromium, provider routes, workflow secrets, MCP versions, UI and Gateway fixtures are unrelated to the evidence slice; no additional commit. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes: Gateway e2e tests intermittently fail with
gateway closed during connect (1006):right afterstartGateway()reports ready, because another test's in-process Gateway took the instance's claimed port during its spawn handoff. Observed intest/gateway-cold-agent-abort.e2e.test.tson a Gateway e2e shard 1/4 Testbox replay, where the whole test failed in 264 ms. Passing runs take about 7–8 s.User Impact
No product or user-visible change. Gateway e2e shards stop losing
OpenClawTestInstancetests to cross-fixture port theft, and a post-start connect failure now reports which process answered readiness.Why This Change Was Made
A test that fails in 264 ms cannot have been answered by its own cold Gateway child.
OpenClawTestInstanceclaims its port block and releases its reservation listener right before spawning the child. In-process Gateway fixtures picked ports withgetGatewayE2ePortBlock(), which probes a port and then releases its claim, and then calledstartGatewayServer(). The production listener retriesEADDRINUSEevery 500 ms (src/gateway/server/http-listen.ts). A fixture that probed the same candidate just before the instance claimed it therefore kept retrying against the reservation and won the port at the handoff. Two forks that hash to the same port shard both try offset 0 first, so the collision is realistic. The instance's/readyzprobe was then answered by the foreign Gateway. A closing contender terminates the upgrade (1006, the observed signature); a live one rejects the token.The fix:
getGatewayE2ePortBlockis removed.acquireGatewayE2ePortBlock()(next tostartClaimedGatewayinsrc/gateway/test-helpers.listener.ts) returns a held claim.startClaimedGateway, client fixtures throughstartGatewayWithClient({ portClaim }), and the rest release explicitly after close. Same-port restarts keep one claim, and claims not yet handed to a starting Gateway are released by their owner.docs/ci/capacity.mdalready promised that shared port claims cover in-process listener lifetimes; that now holds.docs/reference/test/runner-internals.mdrecords the rule.getFreePort) are intentionally unchanged. On Linux the claimed pool excludes the ephemeral range, so they cannot collide with instance claims.Diagnostics, with no assertion changes:
uptimeMsper readiness probe.diagnose()returns bounded facts: child pid/exit state/age, the last probe with the child's age at that probe, Linux LISTEN-socket owners of the port with pgid under a 1 s scan budget, and a 64 KB log tail.gateway-cold-agent-abortattaches this snapshot when connect fails after readiness.Why not a readiness identity check in the product?
/readyzhas no cheap token-bound identity field. Binding the responder strongly would need a product readiness change for a test-only concern. The defect lives in fixture port ownership, so the fix is there. The recordeduptimeMsvs child age makes any recurrence self-explaining (a responder older than the child is foreign).Evidence
Mechanism reproduced locally, deterministically (scratch tests, not committed). The instance's first candidate was forced onto a port that an in-process contender had probed:
listenGatewayHttpServerretry:startGateway()resolved after 1 probe in 16 ms. The instance child was alive and never listening. Connect failed withgateway closed during connect (1006): [pre-hello socketOpened=true connectRequestSent=false].startGatewayServercontender: a closing contender reproduces the exact 1006 signature; a live one givesunauthorized: gateway token mismatch.Regression (
test/helpers/openclaw-test-instance.port-collision.test.ts): an instance whose first candidate is an in-process Gateway E2E port must allocate a different port.expected 64008 not to be 64008.pnpm test test/helpers/openclaw-test-instance.port-collision.test.ts --maxWorkers=1. The new test takes 11–17 ms; file import share is unchanged at about 6%, because the helper lives in the light listener module.Testbox baseline (unfixed tree plus diagnostics only):
tbx_01m3wbawxk4dgyzq7e5sbdvs13(https://github.com/openclaw/openclaw/actions/runs/36906528400): focused loop ofgateway-cold-agent-abort, 3 concurrent lanes × 12, 36/36 passed. Shard 1/4 ×3 did not include the file on that tree; see the sharding note below. One replay failed on unrelatedgateway-repeated-request-recovery(72 s timeout).tbx_01m3wevazx2w9bsynvcv71sm5t(https://github.com/openclaw/openclaw/actions/runs/36914161773): shard 2/4 ×4, the shard that owns the file on currentmain.gateway-cold-agent-abortpassed 4/4 (7.3–9.0 s). These failures are pre-existing onmainand unrelated:test/e2e/qa-lab/media/vision-channel-offload.e2e.test.tsandtest/e2e/qa-lab/runtime/conversation-route-ownership.e2e.test.tsfailed in 4/4 replays;openclaw-sandbox-workspace-isolationfailed in 1/4 (Docker sandbox image not built in that payload; CI runsscripts/sandbox-setup.sh).Sharding note: shard membership is not stable across trees.
RepoE2eSequencerweights untimed files by bytes and assigns greedily. Recomputed offline (it matched the observed 66/67-file shards), the file is in shard 2/4 onmainand in shard 1/4 with this PR applied. Post-fix replays therefore target shard 1/4.Review: Codex autoreview took three passes. Accepted and fixed: claim retention on
GatewayStartupCleanupError, a bounded/procscan, and pre-transfer claim release. Rejected: an explicit-port double-claim (createOpenClawTestInstance({ port })never claims). Final pass scoped-clean. ClawSweeper then found that the MCP App conformance fixture released its claims even when listener cleanup failed. Fixed in 19116d4: each claim is released only after its own listener closed, and the delta autoreview is scoped-clean. Verified withtsgo:test:ui, oxlint, and the MCP conformance e2e (2/2). The export-collision and eager-import/wrapper closure guards also pass (20/20).Post-fix proof (local, at the maintainer's request). Three Testbox leases timed out after 15 minutes queued (
tbx_01m3whz5jqe6jcpgbvpt4db5ct,tbx_01m3wk190dry6gfvpxj2yp60y3,tbx_01m3wm85emj57xgbst8gnw3wvz), so the proof ran on a 32-core macOS host at load ~20–28, at headb8314c249832:check:changedlanes pass, run explicitly:tsgo:core,tsgo:core:test,tsgo:test:root,tsgo:test:ui, oxlint core and test-root, import cycles, deadcode exports, and the line-cap, assertion-safety, and timeout-race ratchets. Two lanes fail only on inheritedmainstate this branch predates, both already fixed onmain: the stalemax-linesbaseline entry forchat.abort-persistence.test.ts(fixed in ccbd3b5) and theagents-othertsgo root budget at 726/720 (fixed in chore(ci): finish grouping session-lifecycle agent tests in the agents-sessions type graph #162930). This PR adds no test files.plugin-cron-registry-owner). All 4 changed UI e2e files pass (19/19).gateway-cold-agent-abortpassed 24/24 (3 concurrent lanes × 8).pnpm test:e2e:gateway --shard=1/4ran ×3 withOPENCLAW_E2E_WORKERS=2andscripts/sandbox-setup.sh.gateway-cold-agent-abortpassed in all 3 replays (11.2 s, 13.1 s, 8.8 s). The replays were not fully clean; every failing file is unrelated and reproduces without this PR:src/agents/model-fallback.reply-entry.e2e.test.ts(6 tests,expected +0 to be 1provider attempts) fails identically when run alone on the unfixed base and on this head. It imports nothing this PR touches.test/gateway.multi.e2e.test.tswall-clock test fails alone on the unfixed base (1 failed / 2 passed) and passes alone on this head (3/3). It is a pre-existing load-sensitive flake.cli-json-stdout.hooks(aslow SQLite transactionwarning on stderr under load) andgateway-repeated-request-recovery(gateway request deadline exceeded, which also failed on the unfixed Testbox baseline).Separately,
vision-channel-offloadandconversation-route-ownershipin shard 2/4 fail onmainbecause the qa-channel plugin cannot loadpackages/normalization-core/src/record-coerce.jsfromsrc/plugin-sdk/qa-channel-protocol.ts(ERR_MODULE_NOT_FOUND). That needs its own fix.