Skip to content

fix(cloud-workers): first turn after a Gateway update fails with a missing worker bundle - #160820

Merged
steipete merged 4 commits into
mainfrom
fix/cloud-workers-refresh-bundle-retain
Sep 30, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/cloud-workers-refresh-bundle-retain

Conversation

@steipete

@steipete steipete commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Related: #160730

What Problem This Solves

Fixes: after a Gateway update, a cloud worker's first turn could fail with ENOENT ... realpath '<node-host>/gateway-<ns>/bundles/<bundleHash>' because node cleanup deleted the worker bundle the in-place runtime refresh had just installed.

User Impact

User impact: cloud machines that are refreshed in place after a Gateway update, and cold-provisioned machines, keep the newly installed worker bundle until the environment records it, so the next turn launches instead of failing with a missing bundle.

Why This Change Was Made

#160730 fixed this failure for cold provisioning and explicitly left runtime refresh open. Refresh has the same window: provider-runtime-refresh.ts installs the new bundle, then records the new receipt afterwards (store.refreshBootstrapReceipt). Throughout that window the environment stays ready/idle/attached with its old receipt.

The node marks each finished install with a new generation. It protects that bundle only until the Gateway acknowledges the generation, and the Gateway acknowledges whatever generation the previous retain pass returned. A retain pass that the node queues behind the install (its per-namespace queue serializes them) returns the new generation, even though the Gateway built its keep set from the old receipt. The next pass then prunes the refreshed bundle.

This is reachable after every Gateway update. The node reconnects, and its first retain pass lands behind the refresh install. The first bundle-status acceptance on a new connection (undefined -> installed) reschedules the same node, so a second pass races the receipt write. The 60 s placement reconcile and node inventory changes can also supply that pass during long installs.

Persistent hosts were already safe because the coordinator always pins the Gateway's current build there. Environment-owned cloud nodes were deliberately excluded from that pin (#140449), so they were exposed.

Provisioning and refresh share one cause: both install the Gateway's current build (the same memoized prepareInstallation("bundle") artifact that bundleRetention.currentBuild() returns) before recording it. The retain coordinator now applies one rule: keep the current build on a node until every live environment there has recorded it. This completes the reachability snapshot instead of suspending retention, and it replaces the provisioning-only bundleRetentionReady special case from #160730. Pruning of other bundles continues during provisioning and refresh.

If preparing the current build fails, the coordinator now sends a workspace-only retain request (no bundle keep set, generation acknowledgement or status query) and warns. Workspace retention on cloud nodes therefore still does not depend on bundle preparation; this addresses ClawSweeper's P2 on the first head.

Other behavior is unchanged:

  • Persistent hosts keep their existing always-on pin and status target.
  • Cloud nodes still report their environment receipt as bundle status.
  • The status pin appears only while an environment is converging.
  • Cloud nodes now resolve currentBuild() when bundle retention is supported. The provider reconcile loop already prepares that artifact for every ready, idle or attached environment.
  • No protocol, schema, store or lifecycle changes.

Evidence

  • The regression in src/node-host/node-worker-bundle-installer.test.ts extends the fix(cloud-workers): retain bundles through provisioning #160730 pattern to two phases: cold provisioning and runtime refresh. It uses the real node installer, the real retain coordinator, a queued retain pass during the install, receipt recording and the real launch-path resolver.
    • On the previous coordinator, the runtime-refresh phase fails with the live error: ENOENT: no such file or directory, realpath '.../gateway-test/bundles/8450792f...'. The provisioning phase passes, as expected with fix(cloud-workers): retain bundles through provisioning #160730 in place.
    • With the fix, both phases pass. The refresh phase also proves that the previous bundle is pruned once the new receipt is recorded, so retention still works rather than being suspended.
  • A coordinator unit test covers the rule on a cloud node:
    • a stale receipt pins the current build, and the status target stays the receipt;
    • once the receipt records the current build, only that hash is kept;
    • once the environment is terminal, nothing is pinned.
  • Test results:
    • node-worker-bundle-installer.test.ts: 27/27 pass.
    • node-workspace-retain-coordinator.test.ts: 20/20 pass.
    • server-worker-placement-startup-maintenance.test.ts: 7/7 pass.
  • Measured cost (--maxWorkers=1, verbose reporter):
    • new runtime-refresh case: 686 ms (the existing provisioning case is 614 ms);
    • new coordinator test: 3 ms;
    • no timers, sleeps or new fixtures.
  • node scripts/check-changed.mjs on the touched files passed conflict markers, line-cap/max-lines/assertion ratchets, format, plugin boundaries, wrapper shadowing, core tsgo graph boundary and core typecheck.
    • typecheck core tests failed only in untouched ui/src/components/* files, because this worktree has a gateway-only install without UI packages (@panzoom/panzoom, @modelcontextprotocol/client) and resolves @types/markdown-it from a parent checkout.
    • The test graphs for the touched files passed in a separate run.
    • oxlint and oxfmt on the touched files are clean.
  • Codex autoreview (P2 threshold, with the refresh, provisioning, installer and retention sources as evidence) is scoped-clean on the first head. After merging main and adding the preparation-failure fallback, the full-candidate review reported only the committed-state gap that the fallback commit closes.
  • Merged main (merge commit, no rebase). Only the coordinator conflicted: main's async manifest-ref preparation, terminal-state helper and per-dispatch recheck are kept, and the bundle snapshot is taken after the last preparation await.
  • Post-merge results: coordinator 26/26 and installer 27/27 pass; maintenance 7/7 passes; pnpm tsgo:core, targeted oxlint, oxfmt, git diff --check and the touched test-graph typecheck shards pass. The new preparation-failure regression takes 40 ms and failed before the fallback.
  • The first head's CI failure (checks-node-changed-compact-large-15-2) is unrelated to this change. src/gateway/server.agent.rpc-contracts.test.ts failed in beforeAll Gateway startup (Startup failed: required secrets are unavailable ... Shared-state worker opening path changed, STATE_DATABASE_READ_ADMISSION_INVALIDATED). The preceding file in the same Vitest worker had just retired the shared-state worker owner. This PR touches no state-database, secrets or startup code.
  • The second head's CI failures were main-side test defects that test(ci): await heartbeat completion and match candidate authority checks #161455 has since fixed. checks-node-changed-compact-small-7-3 failed in src/cron/service.failure-alert-notifications.test.ts and src/cron/service.heartbeat-busy-poll.test.ts. checks-node-changed-compact-small-3-1 failed in src/infra/update-candidate-canary.test.ts (streamed candidate progress). Locally the cron suites passed and the canary failure reproduced on the merged main content, which this PR does not touch. I merged current main (clean merge, PR diff unchanged) to pick up that fix.
  • The earlier server.agent.rpc-contracts.test.ts startup failure did not recur on the second head. A local two-file replay in the CI order failed both Gateway suites in this gateway-only worktree install. I did not capture enough output to tell that apart from the environment, so the cause is unconfirmed and I claim no fix here.
  • Not run: a live cold-Hetzner or in-place-update cell. The regression reproduces the exact live ENOENT at the installer–coordinator boundary.

Runtime refresh installs the Gateway's current worker bundle before it
records the new bootstrap receipt. A retain pass processed by the node after
that install acknowledged the new install generation while the Gateway's keep
set still held only the old receipt, so the next pass pruned the refreshed
bundle and the next worker launch failed with ENOENT, the same failure #160730
fixed for cold provisioning.

Provisioning and refresh share one cause: both install the current build
before recording it. The retain coordinator now keeps the current build on a
node until every live environment there has recorded it, which completes the
reachability snapshot instead of suspending retention. This replaces the
provisioning-only special case from #160730. Persistent hosts keep their
existing current-build pin and status target; cloud nodes keep reporting
their environment receipt.

The installer regression now covers both phases with the real node installer
and coordinator. The runtime-refresh phase reproduces ENOENT on the previous
code and also proves the previous bundle is pruned once the new receipt is
recorded.
@clawsweeper

clawsweeper Bot commented Sep 29, 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 docs Improvements or additions to documentation gateway Gateway runtime size: M labels Sep 29, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 9:30 PM ET / September 30, 2026, 01:30 UTC (Revision 3).

ClawSweeper review

What this changes

The branch changes Gateway retention so cloud nodes keep the current worker bundle until live environments record it, and adds regression coverage and lifecycle documentation.

Merge readiness

✅ Ready for maintainer review

Current main protects cold provisioning but still leaves the runtime-refresh retention window open. The current head addresses that window and the earlier review finding; I found no new blocking defect.

Priority: P1
Reviewed head: 593b4aaa8ef6042993ffd4a2675f0cb1e0a8b243

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused repair has strong boundary regression coverage and no identified patch defect, with live cloud-update behavior still unobserved.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The provided MEMBER association exempts this PR from the external-contributor proof gate. Its reported before/after regression exercises the production coordinator and installer through an in-process transport and checks launch-path resolution; a live cloud update was not run. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The provided MEMBER association exempts this PR from the external-contributor proof gate. Its reported before/after regression exercises the production coordinator and installer through an in-process transport and checks launch-path resolution; a live cloud update was not run. No stored-data contract changes.
Evidence reviewed 8 items Current main still has the refresh window: Current main excludes environment-owned nodes from the current-build pin and suspends bundle retention only during provisioning.
Refresh installs before recording the receipt: The refresh path installs the node bundle before publishing its replacement bootstrap receipt.
Introduced retention rule: The proposed snapshot includes the current build while a live environment has an older or absent receipt, while keeping the cloud node's receipt as its status target.
Findings None None.
Security None None.

How this fits together

The Gateway sends connected nodes a snapshot of workspaces and worker bundles to retain. Node cleanup uses that snapshot before a later worker turn launches from the bundle named in its environment receipt.

flowchart LR
  A[Gateway worker build] --> C[Retention coordinator]
  B[Environment receipts] --> C
  C --> D[Node retain request]
  D --> E[Bundle cleanup]
  E --> F[Next worker turn]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +10, Tests +75, Docs 0. Total +85 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 32 22 +10
Tests 2 200 125 +75
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 233 148 +85

Review metrics

None.

Root-cause cluster

Relationship: canonical
Canonical: #160820
Summary: This PR addresses the refresh window explicitly left open by the merged cold-provisioning repair; persistent-host retention is adjacent work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep bundle retention tied to live environment receipts, preserve workspace-only cleanup when build preparation fails, and retain the installer-to-launch regression.

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

Yes, from source and the reported baseline regression: current main can acknowledge retention before the refreshed bundle has a recorded receipt. This read-only review did not run the test or a live Gateway update.

Is this the best way to solve the issue?

Yes. The change extends the existing retention owner across both receipt-publication windows and preserves workspace retention if build preparation fails.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 06e816331cc6.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported race can prevent the first cloud-worker turn after a Gateway update.
  • merge-risk: 🚨 availability: The changed retention snapshot controls whether the bundle needed by a later worker turn survives node cleanup.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The provided MEMBER association exempts this PR from the external-contributor proof gate. Its reported before/after regression exercises the production coordinator and installer through an in-process transport and checks launch-path resolution; a live cloud update was not run. No stored-data contract changes.

Evidence

What I checked:

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 (2 earlier review cycles)
  • reviewed 2026-09-29T00:12:16.538Z sha 1314e98 :: blocked before merge. :: [P2] Keep cloud retention running when build preparation fails
  • reviewed 2026-09-30T00:59:33.114Z sha 6e204bf :: needs maintainer review before merge. :: none

@steipete
steipete enabled auto-merge (squash) September 30, 2026 00:08
…d-workers-refresh-bundle-retain

# Conflicts:
#	src/gateway/worker-environments/node-workspace-retain-coordinator.ts
…ails

Cloud nodes now resolve the Gateway's current build for bundle retention.
If that preparation rejects, send workspace-only retention without a bundle
keep set, generation acknowledgement, or status query, and warn instead of
failing the whole pass. Workspace retention previously did not depend on
bundle preparation for cloud nodes.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 30, 2026
@steipete
steipete merged commit 477250c into main Sep 30, 2026
241 checks passed
@steipete
steipete deleted the fix/cloud-workers-refresh-bundle-retain branch September 30, 2026 01:41
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…ssing worker bundle (openclaw#160820)

* fix(cloud-workers): retain refreshed bundles until receipts record them

Runtime refresh installs the Gateway's current worker bundle before it
records the new bootstrap receipt. A retain pass processed by the node after
that install acknowledged the new install generation while the Gateway's keep
set still held only the old receipt, so the next pass pruned the refreshed
bundle and the next worker launch failed with ENOENT, the same failure openclaw#160730
fixed for cold provisioning.

Provisioning and refresh share one cause: both install the current build
before recording it. The retain coordinator now keeps the current build on a
node until every live environment there has recorded it, which completes the
reachability snapshot instead of suspending retention. This replaces the
provisioning-only special case from openclaw#160730. Persistent hosts keep their
existing current-build pin and status target; cloud nodes keep reporting
their environment receipt.

The installer regression now covers both phases with the real node installer
and coordinator. The runtime-refresh phase reproduces ENOENT on the previous
code and also proves the previous bundle is pruned once the new receipt is
recorded.

* fix(cloud-workers): keep workspace retention when build preparation fails

Cloud nodes now resolve the Gateway's current build for bundle retention.
If that preparation rejects, send workspace-only retention without a bundle
keep set, generation acknowledgement, or status query, and warn instead of
failing the whole pass. Workspace retention previously did not depend on
bundle preparation for cloud nodes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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