Skip to content

fix(gateway): stop portal proof timeouts from cascading through Gateway test shards - #164522

Merged
steipete merged 2 commits into
mainfrom
steipete/portal-proof-bundle-cascade
Oct 3, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/portal-proof-bundle-cascade

Conversation

@steipete

@steipete steipete commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: a gateway-server test shard fails 28 of its 48 files whenever the checkout has a built dist/worker. This was seen in the w103 full-suite Node 24.19 baseline on Linux (AWS c7a.48xlarge, commit 9d2ebf6) and reproduces locally on current main.

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-server shards 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 real prepareInstallation("bundle"), and Gateway reconcile calls it again. With a built dist/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 stayed retained and 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.ts already uses. It still derives the bootstrap receipt from the Gateway-owned prepareInstallation, and the build-dependent fallback branch is gone.

The close failure also exposed the product leak. createNodeWorkerTunnelManager().stopAll() evaluated listEnvironments() while building its id set. A revoked inventory therefore threw before any live tunnel was stopped and before workspaceTransfer.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-0569 locally: the same 48 files, vitest.gateway-server.config.ts, --maxWorkers=4, shared worker (isolate: false), macOS, with a built dist/worker.

  • Before (current main): 28 failed / 20 passed, the same split as the AWS baseline, with the same Worker environment inventory has closed retained-close cause.
  • After, three replays:
    • Run 1: 48/48 passed.
    • Run 2: 46/48, with no fixture-lifetime errors. The two failures are in other files and unrelated to this change:
      • server.private-completion.test.ts "preserves executing private timeout facts (abandoned)": an existing ordering flake that also failed on unmodified main in the baseline replay. It is tracked as a follow-up.
      • server.roles-allowlist-update.test.ts: an update.run RPC 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.
    • Run 3: 48/48 passed.

Portal proof on its own (pnpm test src/gateway/server.portals.session.test.ts --maxWorkers=1, with the real dist/worker present):

  • Before: 60.5 s (43.0 s of that was bundle preparation) against a 30 s limit, so it timed out.
  • After: 15.6 s.
  • 20 standalone runs on a shared Mac with load average 24–67: 19 passed, with test bodies of 8–26 s. One run timed out at load average 48.
  • A startup trace of the remaining time shows an ordinary full worker-runtime Gateway boot (ready at about 4.8 s at load 24) with no single stall.

Owner tests. node-worker-tunnel.test.ts adds a revoked-inventory shutdown regression. Before the fix it failed with expected '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:core and pnpm tsgo:core:test (27 shards) pass.
  • oxlint --type-aware and oxfmt pass on the touched files.
  • Codex autoreview (P0–P2) was scoped-clean.

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 only checks-ui-e2e board-mcp-app.e2e.test.ts > retains one board runtime…, and fail-fast cancelled the rest. That failure was a red main from #164493: a bisect on main showed reverting only its UI files made the test pass. main was then fixed by 11515ce5, and head 77c17c21 merges main with the product diff unchanged. On the merged tree, pnpm tsgo:core passes and both changed test files pass.

Gaps. A Linux Node 24.19 Testbox replay was attempted but blocked: lease tbx_01m41nms7syfne9fz9aeq7j7af stayed queued for 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.

  • Worker bundle preparation from a source build still costs 27–37 s per Gateway process, even with a warm cache.
  • The private-completion abandoned-timeout ordering flake.

…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.
@clawsweeper

clawsweeper Bot commented Oct 3, 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 labels Oct 3, 2026
@steipete
steipete marked this pull request as ready for review October 3, 2026 20:30
@steipete steipete self-assigned this Oct 3, 2026
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 7:20 PM ET / 23:20 UTC (Revision 2).

ClawSweeper review

What this changes

The 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
Reviewed head: 77c17c21f1cc505d4e849d6f09af44794f78f576

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regressions, recorded boundary validation, and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies MEMBER authorship, so ordinary external-contributor proof is exempt. Recorded real-Gateway portal replays support the test repair; revoked-inventory cleanup is covered by a mocked-transport owner regression. No material authority contract or stored-data model changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies MEMBER authorship, so ordinary external-contributor proof is exempt. Recorded real-Gateway portal replays support the test repair; revoked-inventory cleanup is covered by a mocked-transport owner regression. No material authority contract or stored-data model changes.
Evidence reviewed 10 items Pinned introduced change: The merge-base-to-head diff contains the portal test adjustment, shutdown regression, stale-epoch characterization cases, and tunnel cleanup repair. No dependency, workflow, public API, configuration, or persisted-format change is introduced.
Still necessary on main: Fetched main still evaluates listEnvironments while constructing the shutdown ID set, before starting tunnel cleanup. A revoked inventory can therefore prevent both live cleanup and shared transfer closure.
Cleanup authority preserved: Live cleanup retains its exact environment, session, namespace, and owner epoch. Retirement still fences local work, drains outstanding operations, and authorizes only cleanup of the retired scope. The start refactor preserves stale-epoch rejection and authorization rechecks.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -1, Tests +43. Total +42 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 26 27 -1
Tests 2 64 21 +43
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 90 48 +42

Review metrics

None.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This is a bounded Gateway shutdown leak and build-dependent test reliability repair, with no demonstrated urgent user-facing outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies MEMBER authorship, so ordinary external-contributor proof is exempt. Recorded real-Gateway portal replays support the test repair; revoked-inventory cleanup is covered by a mocked-transport owner regression. No material authority contract or stored-data model changes.

Label justifications:

  • P2: This is a bounded Gateway shutdown leak and build-dependent test reliability repair, with no demonstrated urgent user-facing outage.
  • 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 supplied repository state identifies MEMBER authorship, so ordinary external-contributor proof is exempt. Recorded real-Gateway portal replays support the test repair; revoked-inventory cleanup is covered by a mocked-transport owner regression. No material authority contract or stored-data model changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head diff contains the portal test adjustment, shutdown regression, stale-epoch characterization cases, and tunnel cleanup repair. No dependency, workflow, public API, configuration, or persisted-format change is introduced. (src/gateway/worker-environments/node-worker-tunnel.ts:712, 77c17c21f1cc)
  • Still necessary on main: Fetched main still evaluates listEnvironments while constructing the shutdown ID set, before starting tunnel cleanup. A revoked inventory can therefore prevent both live cleanup and shared transfer closure. (src/gateway/worker-environments/node-worker-tunnel.ts:717, af10ddf84e64)
  • Cleanup authority preserved: Live cleanup retains its exact environment, session, namespace, and owner epoch. Retirement still fences local work, drains outstanding operations, and authorizes only cleanup of the retired scope. The start refactor preserves stale-epoch rejection and authorization rechecks. (src/gateway/worker-environments/node-worker-tunnel.ts:477, 77c17c21f1cc)
  • Portal boundary coverage retained: The changed test replaces only bundle production. It continues through the Gateway-owned installation preparation and real HTTP/WebSocket transport, checking allowed access, outsider rejection, stream closure, and revocation before delayed persistence. The existing startup test uses the same bundle-producer seam. (src/gateway/server.portals.session.test.ts:128, 77c17c21f1cc)
  • Focused regression coverage: The new inventory-revocation test verifies stopped tunnel status, per-environment transfer closure, shared closure, and propagation of the original inventory error. Two deferred-promise cases independently protect current and retiring stale-owner rejection. (src/gateway/worker-environments/node-worker-tunnel.test.ts:295, 77c17c21f1cc)
  • Re-review continuity: All three reviewed files are unchanged from the earlier reviewed head. The supplied completed-review projection contains no previous findings or published rank-up moves. (77c17c21f1cc)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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-10-03T20:35:56.896Z sha bf70de1 :: needs maintainer review before merge. :: none

@steipete
steipete enabled auto-merge (squash) October 3, 2026 23:17
@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 Oct 3, 2026
@steipete
steipete merged commit f42f774 into main Oct 3, 2026
130 checks passed
@steipete
steipete deleted the steipete/portal-proof-bundle-cascade branch October 3, 2026 23:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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