Skip to content

fix(runners): preserve node workspaces across restarts - #123889

Merged
steipete merged 2 commits into
mainfrom
steipete/node-workspace-retain
Aug 14, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/node-workspace-retain

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a restarted node host could delete an older workspace generation that the Gateway still durably owned, while the final generation of a retired session and its transfer artifacts could remain forever. The previous cleanup inferred ownership from the numerically latest local directory plus active launch receipts, which did not represent idle durable placements.

Why This Change Was Made

The Gateway now publishes a full reconnect-scoped retain snapshot through the existing private node-worker command dialect. The node accepts bounded replacement snapshots, unions them with nonterminal launch receipts and every in-flight workspace operation, and only then removes unretained generations, transfer staging and rollback siblings, unreachable manifests, and empty workspace parents in bounded passes. The old startup/latest-generation heuristic is deleted. This AI-assisted change adds no public Gateway method, public protocol-version bump, configuration, durable sidecar, or SQLite schema-version change.

Production delta is +966/-306 (net +660); tests are +579/-78 (net +501), with a net +3 docs update. The production growth is the missing ownership capability: deterministic Gateway publication, a closed private contract, node-local race fencing, and authoritative filesystem collection. The old 53-line heuristic owner is removed rather than retained as a fallback.

User Impact

Paired devices can keep idle session workspaces safely across node and Gateway restarts, while sessions and environments that are no longer owned stop leaking disk. A missing or failed snapshot only over-retains; it never authorizes fallback deletion.

Evidence

  • Pre-fix reproduction: does not delete workspaces before the first Gateway snapshot failed against the previous production implementation because supervisor startup removed the older durable workspace.
  • Focused owner-boundary proof: 6 files, 49 tests passed after the final rebase, covering full replacement, authoritative empty snapshots, final-generation deletion, bounded replay, launch and command races, namespace isolation, reconnect publication, private dispatch, and closed protocol parsing.
  • Transfer sibling proof: node transfer and Gateway transfer suites passed after moving all workspace operations under the shared session owner.
  • Full changed gate passed locally after every configured remote backend was unavailable; it covered formatting, dead exports, core and core-test type checks, full core lint, schema-version guard, import cycles, and architecture guards.
  • pnpm build passed locally after the selected Testbox backend was unavailable because its client executable was missing.
  • Fresh structured autoreview on the final rebased branch reported no accepted/actionable findings.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 14, 2026
@steipete
steipete marked this pull request as ready for review August 14, 2026 23:49
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 14, 2026, 7:56 PM ET / 23:56 UTC.

ClawSweeper review

What this changes

This PR replaces node-local workspace cleanup heuristics with Gateway-published retention snapshots so durable node workspaces survive restarts and obsolete artifacts are removed.

Merge readiness

⛔ Blocked by patch quality or review findings - 8 items remain

Keep open: the Gateway-authoritative ownership model is the right repair boundary, but two P1 upgrade and freshness gaps can still delete a durable node workspace.

Priority: P1
Reviewed head: 24060663e3de92b6a3ccdbf69626bb6c44dd0140
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The owner-boundary direction is strong, but two concrete P1 deletion paths must be repaired before this lifecycle change is quality-ready.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its reported local tests remain supplemental and do not cover the two identified ordering and upgrade cases.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its reported local tests remain supplemental and do not cover the two identified ordering and upgrade cases.
Evidence reviewed 5 items Stale continuation can delete a newly durable workspace: The coordinator constructs one full snapshot before its continuation loop, then reuses it for every hasMore response; pending newer work is not drained until that loop returns. A newer durable placement can therefore be absent from a later cleanup pass after its local operation finishes.
Existing advertised dialect does not prove retain-command support: Current main advertises only node-worker-supervisor-v1; an older node with that feature qualifies for the new command even though its dispatcher cannot recognize it and its startup retention heuristic still runs.
Current coordinator tests omit the freshness race: The branch tests identical snapshot replay for a bounded backlog, but do not introduce a newly durable placement or a queued refresh between hasMore passes.
Findings 2 actionable findings [P1] Refresh retention before each bounded cleanup continuation
[P1] Advertise support for the new retain command
Security None None.

How this fits together

The Gateway owns durable worker placements, while paired node hosts store the resulting session workspaces. The new coordinator sends ownership snapshots over the private node-worker command channel, and the node uses them with live local operations to decide what may be deleted.

flowchart LR
  A[Durable placements] --> B[Gateway retention coordinator]
  C[Node inventory or reconnect] --> B
  B --> D[Private retain command]
  D --> E[Node-host workspace runtime]
  F[Active launches and transfers] --> E
  E --> G[Retained session workspaces]
  E --> H[Bounded artifact cleanup]
Loading

Decision needed

Question Recommendation
Should this private node-worker dialect gain an explicit retention capability/version gate before merge, with old-node behavior treated as incompatible until the node host is upgraded? Version and gate retention support: Add a distinct retention capability or owner-approved dialect version, then stop stale continuation replay and cover mixed-version and between-pass placement updates.

Why: The repository policy requires owner confirmation for protocol-version changes, and the current v1 declaration cannot distinguish a node that implements the new destructive-cleanup authority from one that does not.

Before merge

  • Refresh retention before each bounded cleanup continuation (P1) - The hasMore loop reuses the snapshot built before the first pass, while schedule() queues newer placement state until this loop finishes. A generation that becomes durable after that snapshot can finish its local operation and then be removed by the stale replay; rebuild or yield to a new full snapshot between passes and cover that ordering.
  • Advertise support for the new retain command (P1) - This command is sent to every peer with the unchanged node-worker-supervisor-v1 capability. An older node can advertise that v1 feature, reject this new command, and still execute its startup pruning heuristic, leaving the original deletion path active during a mixed-version upgrade; add an owner-approved capability/version gate and a compatibility test.
  • Resolve merge risk (P1) - A new Gateway can send the retain command to an older node that advertises the unchanged v1 supervisor dialect; that node continues its startup heuristic, so the reported deletion remains possible during a normal mixed-version update.
  • Resolve merge risk (P1) - A bounded cleanup continuation reuses an obsolete retain set, so a workspace that becomes durably owned between passes can be deleted after its local operation ends.
  • Resolve merge risk (P1) - The PR reports production +660 net lines; that capability growth needs to remain a single owner-boundary flow after the two blockers are repaired, because the deleted local heuristic cannot supply Gateway-authoritative ownership.
  • Improve patch quality - Rebuild or supersede the retain snapshot between bounded cleanup passes and add the intervening-placement regression.
  • Improve patch quality - Add an owner-approved node-host capability/version gate with old-node/new-Gateway coverage.

Findings

  • [P1] Refresh retention before each bounded cleanup continuation — src/gateway/worker-environments/node-workspace-retain-coordinator.ts:108-135
  • [P1] Advertise support for the new retain command — src/infra/node-commands.ts:26-33
Agent review details

Security

None.

PR surface

Source +660, Tests +501, Docs +3. Total +1164 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 16 966 306 +660
Tests 6 579 78 +501
Docs 1 23 20 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 1568 404 +1164

Review metrics

Metric Value Why it matters
Production versus test delta production +660 net, tests +501 net (reported in PR body) The new lifecycle ownership capability is substantial and should remain one canonical Gateway-to-node cleanup path after the blockers are fixed.
Retention capability advertisement 1 new private command, 0 new advertised node capabilities The unchanged closed v1 inventory declaration cannot distinguish a node that implements workspace retention from an older compatible-looking peer.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/node-worker-gateway-namespace.ts, durable storage schema: src/gateway/worker-environments/node-worker-tunnel.ts, durable storage schema: src/gateway/worker-environments/node-workspace-retain-coordinator.test.ts, durable storage schema: src/gateway/worker-environments/node-workspace-retain-coordinator.ts, durable storage schema: src/worker/node-workspace-retain-protocol.test.ts, durable storage schema: src/worker/node-workspace-retain-protocol.ts, and 6 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Gate compatible node hosts and refresh snapshots (recommended)
    Before merge, introduce an owner-approved retention capability/version and rebuild a full retain snapshot whenever bounded cleanup continues or newer placement work is queued.
  2. Pause until the node-host upgrade contract is set
    Do not land destructive retention cleanup until maintainers decide how older paired node hosts are identified and upgraded.

Technical review

Best possible solution:

Version or otherwise explicitly gate node retention support, rebuild retention state before every bounded continuation, and prove an older node plus an intervening durable-placement update cannot delete an owned workspace.

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

Yes, source-reproducible: seed more than one cleanup pass, make a placement durable after the first hasMore response, finish its local operation, and observe the stale replay retain set delete it; a new-Gateway/old-node-host pair independently reproduces the compatibility path.

Is this the best way to solve the issue?

No: Gateway-owned retention is the right boundary, but this implementation must distinguish old node hosts and must not replay an obsolete full snapshot after retention state changes.

Full review comments:

  • [P1] Refresh retention before each bounded cleanup continuation — src/gateway/worker-environments/node-workspace-retain-coordinator.ts:108-135
    The hasMore loop reuses the snapshot built before the first pass, while schedule() queues newer placement state until this loop finishes. A generation that becomes durable after that snapshot can finish its local operation and then be removed by the stale replay; rebuild or yield to a new full snapshot between passes and cover that ordering.
    Confidence: 0.96
  • [P1] Advertise support for the new retain command — src/infra/node-commands.ts:26-33
    This command is sent to every peer with the unchanged node-worker-supervisor-v1 capability. An older node can advertise that v1 feature, reject this new command, and still execute its startup pruning heuristic, leaving the original deletion path active during a mixed-version upgrade; add an owner-approved capability/version gate and a compatibility test.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: Both blockers can delete a workspace that the Gateway durably owns, interrupting an active or resumable runner session.
  • add merge-risk: 🚨 compatibility: The new private command is dispatched through the existing v1 node-worker capability, which older node hosts can advertise without implementing it.
  • add merge-risk: 🚨 session-state: A stale full-retain replay can remove a generation that became durable between bounded cleanup passes.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its reported local tests remain supplemental and do not cover the two identified ordering and upgrade cases.

Label justifications:

  • P1: Both blockers can delete a workspace that the Gateway durably owns, interrupting an active or resumable runner session.
  • merge-risk: 🚨 compatibility: The new private command is dispatched through the existing v1 node-worker capability, which older node hosts can advertise without implementing it.
  • merge-risk: 🚨 session-state: A stale full-retain replay can remove a generation that became durable between bounded cleanup passes.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its reported local tests remain supplemental and do not cover the two identified ordering and upgrade cases.

Evidence

What I checked:

  • Stale continuation can delete a newly durable workspace: The coordinator constructs one full snapshot before its continuation loop, then reuses it for every hasMore response; pending newer work is not drained until that loop returns. A newer durable placement can therefore be absent from a later cleanup pass after its local operation finishes. (src/gateway/worker-environments/node-workspace-retain-coordinator.ts:108, 24060663e3de)
  • Existing advertised dialect does not prove retain-command support: Current main advertises only node-worker-supervisor-v1; an older node with that feature qualifies for the new command even though its dispatcher cannot recognize it and its startup retention heuristic still runs. (src/infra/node-runner-inventory.ts:8, b5f62303867c)
  • Current coordinator tests omit the freshness race: The branch tests identical snapshot replay for a bounded backlog, but do not introduce a newly durable placement or a queued refresh between hasMore passes. (src/gateway/worker-environments/node-workspace-retain-coordinator.test.ts:151, 24060663e3de)
  • Feature-history provenance: The current worker-placement surface dates to the cloud-worker implementation and has recent follow-up work on node-worker outcomes and transfer lifecycle. (src/gateway/server-worker-placement-startup.ts:413, 0a6b95a3df9f)
  • Current-main comparison limitation: The checkout is on current main, but a full base-to-branch diff could not be materialized because this partial clone needed a promisor object and network DNS was unavailable; branch-source and current-main files were inspected directly.

Likely related people:

  • steipete: Available history attributes the cloud-worker placement base and its immediate node-worker/transfer follow-ups to this contributor. (role: feature owner and recent area contributor; confidence: high; commits: 0a6b95a3df9f, 47e683ad27a3, 4fadf4674012; files: src/gateway/server-worker-placement-startup.ts, src/node-host/node-worker-workspace.ts, src/gateway/worker-environments/node-worker-tunnel.ts)

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready on exact head 24060663e3de92b6a3ccdbf69626bb6c44dd0140.

Maintainer decision: node workspace deletion must require a full reconnect-scoped Gateway snapshot. Missing, stale, malformed, or failed publication retains bytes; it never authorizes the old latest-generation fallback. The existing private supervisor dialect is still unreleased, so adding the bounded retain command does not require a public protocol-version change.

Proof completed:

Production is +966/-306 (net +660); tests +579/-78 (net +501); docs net +3. This is justified capability growth for deterministic Gateway authority, a closed private contract, node-local race fencing, and authoritative generation/artifact/manifest collection. The prior 53-line heuristic owner is deleted, and there is no configuration, durable sidecar, public Gateway method, or SQLite schema-version change.

@steipete
steipete merged commit d913796 into main Aug 14, 2026
250 checks passed
@steipete
steipete deleted the steipete/node-workspace-retain branch August 14, 2026 23:59
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant