Repository navigation
fix(gateway): stop portal proof timeouts from cascading through Gateway test shards - #164522
Conversation
…way failures
A full-suite Node 24.19 run failed 28 of 48 files in one gateway-server
shard. The first failure was server.portals.session.test.ts: it called the
Gateway's real prepareInstallation("bundle"), and Gateway reconcile calls it
again. With a built dist/worker present (113 MB, 5,041 files), the bundle
producer stages, hashes and gzips the whole bundle into the test's fresh
state-dir cache. That costs 43 s on its own, so the 30 s test timed out.
Without a build, the producer took the fast ENOENT branch, so ordinary lanes
never saw it.
Vitest abandoned the timed-out body without cancelling it. File teardown then
retired the SQLite singletons under the still-live Gateway. The late close
failed with "Worker environment inventory has closed", so the fixture lifetime
stayed retained and every later file in that fork refused admission.
The portal proof now binds the Gateway's own bundle producer to a fixed
artifact, using the same seam as the lazy worker-startup test. It still
derives the receipt from the Gateway-owned prepareInstallation and no longer
branches on ambient build output. The test now takes 15.6 s instead of 60.5 s
with a real worker build present.
The cascade also exposed a shutdown leak. Node worker tunnel stopAll()
evaluated listEnvironments() while building its id set. When a runtime state
database terminal failure (or a closed store) has revoked the inventory, it
threw before stopping any live tunnel and before closing shared workspace
transfer state. It now snapshots live and retired owners first and lists
durable-only node environments in their own settled branch. Live cleanup and
transfer closure then finish before the inventory failure is reported.
The production change stays line-negative and under the file's max-lines cap.
It merges start()'s two identical "owner epoch is stale" checks. New owner
tests cover the revoked-inventory shutdown and both stale-epoch paths.
|
🦞👀 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 3, 2026, 7:20 PM ET / 23:20 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR removes build-dependent packaging from the portal transport test and ensures Gateway shutdown drains live node-worker tunnels and transfer state before reporting an unavailable inventory. Merge readiness✅ Ready for maintainer review The PR remains useful: current main still has the shutdown ordering defect, and the reviewed patch has no actionable correctness findings. Its MEMBER authorship also excludes automatic closure. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway manages connections to node-hosted workers and their workspace transfers. Shutdown must retire those connections and drain their work even when the durable worker inventory has become unavailable. flowchart TD
A[Gateway shutdown] --> B[Node-worker tunnel manager]
B --> C[Live and retired owners]
B --> D[Durable worker inventory]
C --> E[Drain exact worker scopes]
D --> E
E --> F[Close shared transfers]
F --> G[Report cleanup or inventory failure]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -1, Tests +43. Total +42 across 3 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep tunnel cleanup independent of inventory availability while retaining exact-owner fencing, observable failures, and focused portal transport coverage. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the failure path: revoke the inventory before shutdown and its synchronous list call throws before cleanup starts. The supplied body reports matching before-fix failures; this review did not execute a reproduction. Is this the best way to solve the issue? Yes, the patch repairs the existing cleanup owner and removes unrelated packaging cost from the portal test without duplicating lifecycle policy or weakening its transport assertions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against af10ddf84e64. LabelsLabel changes:
Label 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)
|
…way failures (openclaw#164522) A full-suite Node 24.19 run failed 28 of 48 files in one gateway-server shard. The first failure was server.portals.session.test.ts: it called the Gateway's real prepareInstallation("bundle"), and Gateway reconcile calls it again. With a built dist/worker present (113 MB, 5,041 files), the bundle producer stages, hashes and gzips the whole bundle into the test's fresh state-dir cache. That costs 43 s on its own, so the 30 s test timed out. Without a build, the producer took the fast ENOENT branch, so ordinary lanes never saw it. Vitest abandoned the timed-out body without cancelling it. File teardown then retired the SQLite singletons under the still-live Gateway. The late close failed with "Worker environment inventory has closed", so the fixture lifetime stayed retained and every later file in that fork refused admission. The portal proof now binds the Gateway's own bundle producer to a fixed artifact, using the same seam as the lazy worker-startup test. It still derives the receipt from the Gateway-owned prepareInstallation and no longer branches on ambient build output. The test now takes 15.6 s instead of 60.5 s with a real worker build present. The cascade also exposed a shutdown leak. Node worker tunnel stopAll() evaluated listEnvironments() while building its id set. When a runtime state database terminal failure (or a closed store) has revoked the inventory, it threw before stopping any live tunnel and before closing shared workspace transfer state. It now snapshots live and retired owners first and lists durable-only node environments in their own settled branch. Live cleanup and transfer closure then finish before the inventory failure is reported. The production change stays line-negative and under the file's max-lines cap. It merges start()'s two identical "owner epoch is stale" checks. New owner tests cover the revoked-inventory shutdown and both stale-epoch paths.
What Problem This Solves
Fixes: a
gateway-servertest shard fails 28 of its 48 files whenever the checkout has a builtdist/worker. This was seen in the w103 full-suite Node 24.19 baseline on Linux (AWS c7a.48xlarge, commit 9d2ebf6) and reproduces locally on currentmain.It also fixes a shutdown leak: Gateway shutdown left live node-worker tunnels and shared workspace-transfer state running when the worker environment inventory had already been revoked, for example after a state-database terminal failure.
User Impact
Operators: when a Gateway's worker environment inventory has been revoked before shutdown, the Gateway still releases its live node-worker tunnels and workspace-transfer state, and it still reports the inventory failure. Developers:
gateway-servershards no longer fail depending on whether a worker build is present. There is no other user-visible change.Why This Change Was Made
The first failing file was
server.portals.session.test.ts. It called the Gateway's realprepareInstallation("bundle"), and Gateway reconcile calls it again. With a builtdist/worker(113 MB, 5,041 files), the bundle producer stages, hashes and gzips the whole bundle into the test's fresh state-dir cache. That took 43 s on its own, so the 30 s test timed out. Without a build, the producer took a fast ENOENT branch, so ordinary lanes never saw this.Vitest abandoned the timed-out body without cancelling it. File teardown then retired the SQLite singletons under the still-live Gateway. The late close failed with
shutdown step failed (connection-dependent sidecars): Worker environment inventory has closed, so the fixture lifetime stayedretainedand every later file in that fork refused admission. That fail-closed fixture behavior is intended and unchanged.The portal proof now binds the Gateway's own bundle producer to a fixed artifact, using the seam
server-worker-environment-startup.lazy.test.tsalready uses. It still derives the bootstrap receipt from the Gateway-ownedprepareInstallation, and the build-dependent fallback branch is gone.The close failure also exposed the product leak.
createNodeWorkerTunnelManager().stopAll()evaluatedlistEnvironments()while building its id set. A revoked inventory therefore threw before any live tunnel was stopped and beforeworkspaceTransfer.closeAll()ran.stopAll()now snapshots live and retired owners first and lists durable-only node environments in their own settled branch, so live cleanup and transfer closure finish before the inventory failure is reported.The production diff is line-negative (26 added, 27 removed) and keeps the file under its 700-line cap. To fund it,
start()'s two identical "owner epoch is stale" checks are merged into one.Evidence
Original shard replay. I replayed
w1-0569locally: the same 48 files,vitest.gateway-server.config.ts,--maxWorkers=4, shared worker (isolate: false), macOS, with a builtdist/worker.main): 28 failed / 20 passed, the same split as the AWS baseline, with the sameWorker environment inventory has closedretained-close cause.server.private-completion.test.ts"preserves executing private timeout facts (abandoned)": an existing ordering flake that also failed on unmodifiedmainin the baseline replay. It is tracked as a follow-up.server.roles-allowlist-update.test.ts: anupdate.runRPC timed out at 10 s while the host load average was about 42. That suite uses the minimal Gateway, which never creates the node-worker tunnel manager, and the RPC failed before any restart.Portal proof on its own (
pnpm test src/gateway/server.portals.session.test.ts --maxWorkers=1, with the realdist/workerpresent):Owner tests.
node-worker-tunnel.test.tsadds a revoked-inventory shutdown regression. Before the fix it failed withexpected 'connected' to be 'stopped'; now it passes. A characterization test covers both stale-epoch paths, and a mutation check showed it fails fast when the retiring-owner check is dropped. All four node-worker-tunnel suites pass (39 tests).Checks.
pnpm tsgo:coreandpnpm tsgo:core:test(27 shards) pass.oxlint --type-awareandoxfmtpass on the touched files.Test cost. The three new tunnel tests add 69 ms in total. The portal test body is now dominated by its necessary non-minimal Gateway boot.
CI history. The first head (
bf70de1a) failed onlychecks-ui-e2eboard-mcp-app.e2e.test.ts > retains one board runtime…, and fail-fast cancelled the rest. That failure was a redmainfrom #164493: a bisect onmainshowed reverting only its UI files made the test pass.mainwas then fixed by11515ce5, and head77c17c21mergesmainwith the product diff unchanged. On the merged tree,pnpm tsgo:corepasses and both changed test files pass.Gaps. A Linux Node 24.19 Testbox replay was attempted but blocked: lease
tbx_01m41nms7syfne9fz9aeq7j7afstayedqueuedfor about 28 minutes under shared capacity contention, then was stopped. Linux evidence is therefore the original AWS failure only. The root cause, bundle-pack cost inside the test deadline, is not platform-specific.Follow-ups, not in this PR.
private-completionabandoned-timeout ordering flake.