Skip to content

fix(cloud-workers): Stop can lose workspace edits across a Gateway restart or update - #159484

Merged
steipete merged 7 commits into
mainfrom
codex/reclaim-obligation-restart
Sep 28, 2026
Merged

steipete merged 7 commits into
mainfrom
codex/reclaim-obligation-restart

Conversation

@steipete

@steipete steipete commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: stopping or idle-suspending a cloud session can lose unsaved workspace edits if the Gateway restarts before the Stop is retried, and updating the Gateway while such a Stop is pending can leave the Stop stuck forever while the machine keeps running.

User Impact

User impact: a requested Stop (manual or suspendAfter) now keeps its "save the workspace, then release the machine" obligation across Gateway restarts and updates. Unsynced worker edits are reconciled instead of silently discarded, and an update no longer deadlocks the pending Stop or keeps paying for its machine. Genuine machine loss still ends with the last accepted workspace and a visible diagnostic; there is no automatic turn replay.

Why This Change Was Made

Two defects in the same invariant, found by a restart/update audit during cloud-session stress testing:

  1. Data loss: Stop commits draining; if final synchronization fails before a result is staged, the retryable Stop releases its claim and fence while the placement stays draining. On the next startup, generic recovery treated that unprotected draining placement as a failed dispatch and destroyed the environment without reconciling. Startup recovery now restores the Stop's pending-result obligation (reusing the existing reclaim claim/handoff APIs) before environment recovery, so recovery reconciles first and keeps the fence if cleanup fails.
  2. Update deadlock: runtime refresh was allowed only for active placements and receipt publication only for active placements, while unstaged result recovery needs a current-bundle tunnel. After an update, a draining Stop could neither refresh nor recover. Refresh now admits exactly one case beyond active — a draining placement whose pending result is the recovery-owned Stop result — prepares its facts in the database worker, revalidates authority at receipt publication, and fences the old process without reviving a turn claim.

Update behavior: an older Gateway can leave a bare draining placement or an unstaged Stop result bound to an old bundle. The new code consumes those existing records, restores recovery custody, refreshes the exact retained machine, reconciles, then releases it. No schema migration, protocol, config, or SDK change.

Evidence

  • Baseline regressions fail on main (restart after failed pre-staging Stop destroys before reconcile; draining + unstaged result + changed build cannot refresh): 3 failed.
  • node scripts/run-vitest.mjs over 18 placement dispatch/reclaim/recovery/move/shutdown/authority test files: 330 passed; plus 97 passing tests in the five other touched files (runtime refresh, worker gate, store refresh, launcher build recovery, service lifetime), including version-change and same-version-rebuild recovery.
  • pnpm tsgo:core, all 25 core test typecheck graphs, targeted lint, store/schema/import-cycle/auth guards, formatting passed.
  • Independent Codex autoreview (P2): scoped-clean.

Follow-up (ClawSweeper + CI)

  • Recovery-claim fencing (security P1): the Stop claim that startup recovery synthesizes for a claimless draining placement is now registered as recovery-only with the existing worker gate owner before the transaction publishes and before commit observers run, so on a same-build restart operational worker-turn validation, credential reconciliation, and worker RPC reject it before any credential or worker I/O. Runtime refresh uses the same owner and set.
  • Import cycle (CI check:architecture): WorkerWorkspacePendingResult moved to a leaf placement-workspace-result.types.ts; consumers import the leaf directly; Madge reports 0 cycles.
  • Released-state upgrade proof: tests construct the exact SQLite shapes a v2026.9.6 Gateway leaves (claimless draining placement; unstaged Stop result bound to an older bundle) with the real store APIs, close and reopen the database, then run startup recovery: the former gets a fenced recovery claim and reconciles before release; the latter uses the scoped runtime refresh, saves the workspace, then releases the machine.
  • 478 tests across 26 files pass (21-file placement/recovery/authority suite 369/369 including the in-process Gateway recovery-binding test). Test cost (pnpm test <file> --maxWorkers=1): provider-runtime-refresh 14 / 65 s; placement-dispatch-reclaim 32 / 60 s; worker-turn-rpc 19 / 43 s; service-lifetime 24 / 87 s; worker-turn-launcher-build-recovery 29 / 98 s; workspace-result-repository 23 / 307 s (existing real-SQLite suite).
  • pnpm check:madge-import-cycles, pnpm check:import-cycles, pnpm tsgo:core, and the gateway core-test graphs passed.

Live update cell (published 2026.9.6 → this branch)

Isolated state, real paired session host (openclaw connect --session-host), OpenAI worker-turn session, Gateway reached through a public HTTPS tunnel:

  1. On [email protected]: dispatched a session to the node (placement active, generation 5), completed a turn, then wrote stop-proof.txt directly into the node's retained workspace. No turn ever synced it.
  2. Took the node offline and pressed Stop (sessions.reclaim). 2026.9.6 answered UNAVAILABLE device worker node is not connected with the supervisor dialect and left the placement draining (generation 6) with no staged result, the exact released-state shape this PR targets. Its own shutdown then exited 1 (shutdown step failed (connection-dependent sidecars)).
  3. Started this branch (edabc80) on the same state and brought the node back with its saved pairing. The candidate refreshed the retained machine onto the new build: the node downloaded the ~104 MB worker bundle in 5 min 23 s through the tunnel. It then reconciled and released: the placement went draining → reclaimed 14 s after the bundle landed. The Gateway workspace now contains stop-proof.txt byte-identical to what was written on the node, and the node's retained workspace is removed.

No manual Stop, force-destroy, or Doctor step was needed.

Follow-up: forced abandonment survives the crash window

A forced environments.destroy committed draining before it recorded the forced-abandonment failure. If the Gateway exited between those two writes, the new startup recovery found no claim, result, or move and synthesized an ordinary Stop. That Stop could save edits and keep a machine the operator chose to abandon. The force path now persists its intent first, before invoking placement abandonment, and does so even when destruction was already requested. It reuses the existing worker_environments.destroy_requested_at_ms and forced-abandonment diagnostic, so there is no schema change. Startup recovery matches that exact environment owner and resumes the abandonment before any Stop claim is synthesized; move recovery keeps its ownership. The regression runs a real forced destroy, interrupts it between draining and placement failure, closes and reopens SQLite, and runs startup recovery, for both fresh and previously requested destruction. It shows zero Stop claims, zero workspace tunnels or saves, an unchanged accepted manifest, and exactly one provider release, and it fails on the previous head. Production +52 lines. placement-force-destroy.test.ts has 6 tests / 100 s (pnpm test <file> --maxWorkers=1). The 32-file placement/recovery/force suite passed 561 tests; the 4 that failed were git init fixture setup exceeding its 10 s deadline at host load around 68, and they passed unchanged on replay (no flake fix claimed). Madge and import cycles are 0; tsgo:core and the Gateway core-test graphs pass; P2 review is clean.

Follow-up: dedicated node teardown diagnostics

fb2b0b6eac85 preserves the forced-abandonment marker together with the latest bounded provider cleanup error in the existing teardown fields. Pending cleanup errors remain visible in environment status after restart; startup and explicit retries recognize the marker with or without a diagnostic. No schema change. The dedicated-node regression proves SQLite reopen, bounded diagnosis replacement, no Stop claim or workspace save, and eventual release.

Validation: 690 tests passed across 42 placement/recovery/provider/environment RPC files (2,642.58 s wall). The changed force-destroy file passed 7 tests (187.01 s via pnpm test <file> --maxWorkers=1). Madge and runtime import cycles: 0; core and all four Gateway type graphs, changed-file lint/format, diff check, and Codex P2 review passed.

Follow-up: recovery-only result handoff

9aac18cdcc1a fixes the runtime-refresh exemption introduced by b56ac75f6b2b: it skipped the existing handoff for active recovery-only pending results, leaving recoveryRequestedAtMs null when the old process was fenced. The placement gate now commits the handoff through the existing SQLite worker, then captures fresh placement facts while retaining the exact claim incarnation. Release and readmission of identical claim fields cannot revive the old refresh authority. No schema or external protocol change.

The original owner-revocation regression is unchanged (3/3 pass; main-only baseline 19254bf236ea 3/3, pre-fix PR 1 failure/2 passes). The store-refresh test spans preparation and receipt publication, so it now requires the exact handoff timestamp while preserving every other pending-result field. The new claim-replacement regression passes. Net change: +122 production / +30 test lines.

Validation: placement gate 22/22, runtime refresh 14/14, forced destroy 7/7, store refresh 10/10, and all 117 environment RPC tests across nine files pass. Changed-file single-worker walls: placement gate 187.65 s; store refresh 402.26 s. The infra-owned transcript-footprint file was run explicitly: 2/2, 598.78 s. Madge and runtime import cycles are zero; core and all four Gateway type graphs, changed-file lint/format, diff check, and fresh Codex P2 review pass.

The requested full local selection was not green. At severe host I/O contention, the initial run was stopped after 1,985 passing, 52 failing, and 3 skipped results (5,461.66 s); local-workspace-projection and workspace-result-repository fixtures were repeatedly timing out and remained incomplete. The continuation finished 118 files with 1,396 passing, 5 failing, and 1 skipped tests (4,018.73 s): one failure was the store expectation corrected above; four were fixture Git initialization timeouts. With the explicit infra run, all 248 requested files have recorded outcomes. A bounded single-worker reproduction of three failing files passed 28/31 (564.46 s); the three remaining failures are Git initialization exceeding the existing 10-second fixture budget at placement-dispatch-staged-results.test.ts:76, before recovery assertions. No timeout was increased, no retry policy was added, and passing replays are not claimed as flake fixes. These local failures and incomplete cases remain proof limits for CI to adjudicate.

Rebase and failure classification

Rebased onto main 8b549de1e0c7, preserving admitted-execution drain accounting, main's interrupted-turn result recovery, and the PR's exact-claim runtime-refresh handoff. The owner-revocation fix commits recoveryRequestedAtMs through the shared-state worker before refreshing placement authority, retaining the exact claim incarnation and rejecting replacement/re-admission; its original regression remains unchanged. The 52 failures from the interrupted run span 16 files: all 16 now pass with two workers (274 passed, two existing filesystem skips, zero failures; 755.84 s wall). An earlier rebased replay had three failures; the same-file main comparison reproduced the large-upload deadline and fixture Git-add failure, while a candidate-only initial clone timeout remained unattributed. All three pass in this final replay; this is not a claimed flake fix, and no timeout, retry, or assertion was relaxed. The final type-only integration extraction changes +49/-45 lines. Additional handoff/claim tests pass 35/35 (255.95 s), and the changed shutdown test passes 1/1 with one worker (51.76 s). Core and all four Gateway graphs, both cycle checks, changed-file lint/format, diff check, and fresh Codex P2 review pass. Published head: e8e5ca0513de.

@clawsweeper

clawsweeper Bot commented Sep 27, 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: L labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 4:39 AM ET / 08:39 UTC (Revision 12).

ClawSweeper review

What this changes

The branch makes cloud-worker Stop and idle suspension retain their final workspace-save obligation across Gateway restarts and updates, with recovery, authority-fencing, diagnostics, tests, and lifecycle documentation.

Merge readiness

✅ Ready for maintainer review

Current main still has the reported Stop recovery gap, so this PR remains necessary. The current test merge is clean, the previously raised forced-abandonment concern has regression coverage, and this review found no discrete introduced defect.

Priority: P0
Reviewed head: e8e5ca0513defbfee33857f4d5d269d86e3a8c05

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A real published-state update trace, current-head stored-state and authority regressions, and a coherent owner-level repair provide strong review evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed Gateway recovery owner is exercised by a reported published-v2026.9.6-to-candidate run on a paired session host: an unstaged Stop recovered the retained file byte-identically before machine release. The live run used an earlier head; current-head SQLite-reopen and worker-authority tests cover subsequent recovery and fencing changes. Existing stored Stop shapes are covered without a schema migration.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed Gateway recovery owner is exercised by a reported published-v2026.9.6-to-candidate run on a paired session host: an unstaged Stop recovered the retained file byte-identically before machine release. The live run used an earlier head; current-head SQLite-reopen and worker-authority tests cover subsequent recovery and fencing changes. Existing stored Stop shapes are covered without a schema migration.
Evidence reviewed 9 items Current-main Stop recovery gap: Current main routes a draining placement without a pending result to failed-draining teardown; its startup environment pass precedes placement-result recovery.
Current-main refresh limit: The current placement gate admits runtime refresh only for an active placement, leaving a draining Stop unable to refresh an older worker bundle.
Introduced startup custody: Before environment recovery, the branch gives an unclaimed draining Stop a pending-result claim and fences that claim from operational worker use.
Findings None None.
Security None None.

How this fits together

The Gateway tracks which cloud worker owns a session and its workspace. Stop and recovery consume that placement state, save worker edits into the Gateway workspace, then release the machine.

flowchart LR
  A[Stop or idle suspension] --> B[Draining placement]
  B --> C[Pending workspace result]
  C --> D[Gateway restart recovery]
  D --> E{Current worker bundle?}
  E -->|No| F[Refresh retained worker]
  E -->|Yes| G[Reconcile workspace]
  F --> G
  G --> H[Release machine]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +397, Tests +601, Docs +2. Total +1000 across 43 files.

View PR surface stats
Area Files Added Removed Net
Source 27 610 213 +397
Tests 15 764 163 +601
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 43 1376 376 +1000

Review metrics

Metric Value Why it matters
Production and test lines production +610/-213; tests and test support +764/-163 The production growth supports restart custody, exact authority checks, and upgrade handling; the larger test change exercises those boundaries.

Technical review

Best possible solution:

Keep one durable Stop result owner through restart and update, reject its claim for worker execution, and release the machine only after workspace reconciliation settles.

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

Yes. Current-main source shows the unclaimed draining Stop falling into failed teardown and its placement gate rejecting draining refresh; the PR also records a published-version failure and recovery trace. I did not execute the path in this read-only review.

Is this the best way to solve the issue?

Yes. The patch uses the existing placement, pending-result, and provider lifecycle owners, with exact-result checks before receipt publication and no new config or protocol surface.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P0: The existing Stop path can discard unsaved workspace edits across a Gateway restart.
  • merge-risk: 🚨 session-state: Recovery changes when a session's pending workspace result is saved and when its worker is released.
  • merge-risk: 🚨 security-boundary: Startup creates a recovery-only worker claim whose operational use must remain fenced; current-head tests exercise credential and worker-RPC denial.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed Gateway recovery owner is exercised by a reported published-v2026.9.6-to-candidate run on a paired session host: an unstaged Stop recovered the retained file byte-identically before machine release. The live run used an earlier head; current-head SQLite-reopen and worker-authority tests cover subsequent recovery and fencing changes. Existing stored Stop shapes are covered without a schema migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed Gateway recovery owner is exercised by a reported published-v2026.9.6-to-candidate run on a paired session host: an unstaged Stop recovered the retained file byte-identically before machine release. The live run used an earlier head; current-head SQLite-reopen and worker-authority tests cover subsequent recovery and fencing changes. Existing stored Stop shapes are covered without a schema migration.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Agustin Rivera: 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 (11 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-27T12:09:01.994Z sha edabc80 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-27T13:28:38.147Z sha c947a60 :: needs real behavior proof before merge. :: [P2] Keep forced abandonment out of synthesized Stop recovery
  • reviewed 2026-09-27T13:37:29.163Z sha c947a60 :: blocked before merge. :: [P2] Preserve forced abandonment before synthesizing a Stop claim
  • reviewed 2026-09-27T16:18:39.107Z sha b67f440 :: blocked before merge. :: [P2] Preserve the provider failure alongside forced-discard intent
  • reviewed 2026-09-27T18:30:58.128Z sha fb2b0b6eac8513a8fc903c11b6a5edb04fdf8a29 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-27T20:19:54.276Z sha 03ceee4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T04:49:03.360Z sha 9aac18c :: blocked before merge. :: none
  • reviewed 2026-09-28T07:55:41.015Z sha 186b58efc77f71129cf05d59a5911ae1f555077f :: blocked before merge. :: none

@steipete
steipete marked this pull request as ready for review September 27, 2026 08:01
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: e8e5ca0513defbfee33857f4d5d269d86e3a8c05
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/worker-environments/placement-turn-authority.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Sep 27, 2026
steipete added a commit that referenced this pull request Sep 27, 2026
Extract the pending workspace result into a type-only leaf so the worker store
contract does not introduce a Madge cycle through executable placement code.

Fence startup-synthesized Stop claims through the existing worker gate inside
the claim transaction, before commit observers or credential/worker I/O can
use them. Reuse that same gate operation for runtime-refresh classification.
Keep the durable result authority intact and leave normal turn claims alone.

Reopen the claimless-draining and unstaged old-bundle state shapes emitted by
v2026.9.6 through real stores. Prove same-build denial before I/O, final save
before release, and inherited/revoked worker RPC rejection. Packaged wire proof
remains unavailable without a dist build on the constrained host.

Validation: 478 unique tests across 26 targeted files; measured changed-file
pnpm test walls; scoped core/Gateway typechecks; zero Madge/runtime import
cycles; targeted lint; independent Codex review.

Refs: #159484
@steipete
steipete force-pushed the codex/reclaim-obligation-restart branch from d0fcc14 to 72cb63a Compare September 27, 2026 11:43
steipete added a commit that referenced this pull request Sep 27, 2026
Extract the pending workspace result into a type-only leaf so the worker store
contract does not introduce a Madge cycle through executable placement code.

Fence startup-synthesized Stop claims through the existing worker gate inside
the claim transaction, before commit observers or credential/worker I/O can
use them. Reuse that same gate operation for runtime-refresh classification.
Keep the durable result authority intact and leave normal turn claims alone.

Reopen the claimless-draining and unstaged old-bundle state shapes emitted by
v2026.9.6 through real stores. Prove same-build denial before I/O, final save
before release, and inherited/revoked worker RPC rejection. Packaged wire proof
remains unavailable without a dist build on the constrained host.

Validation: 478 unique tests across 26 targeted files; measured changed-file
pnpm test walls; scoped core/Gateway typechecks; zero Madge/runtime import
cycles; targeted lint; independent Codex review.

Refs: #159484
@steipete
steipete force-pushed the codex/reclaim-obligation-restart branch 2 times, most recently from edabc80 to c947a60 Compare September 27, 2026 13:20
steipete added a commit that referenced this pull request Sep 27, 2026
Extract the pending workspace result into a type-only leaf so the worker store
contract does not introduce a Madge cycle through executable placement code.

Fence startup-synthesized Stop claims through the existing worker gate inside
the claim transaction, before commit observers or credential/worker I/O can
use them. Reuse that same gate operation for runtime-refresh classification.
Keep the durable result authority intact and leave normal turn claims alone.

Reopen the claimless-draining and unstaged old-bundle state shapes emitted by
v2026.9.6 through real stores. Prove same-build denial before I/O, final save
before release, and inherited/revoked worker RPC rejection. Packaged wire proof
remains unavailable without a dist build on the constrained host.

Validation: 478 unique tests across 26 targeted files; measured changed-file
pnpm test walls; scoped core/Gateway typechecks; zero Madge/runtime import
cycles; targeted lint; independent Codex review.

Refs: #159484
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@steipete
steipete force-pushed the codex/reclaim-obligation-restart branch from 9aac18c to 186b58e Compare September 28, 2026 07:47
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 28, 2026
Treat a claimless draining placement left by Stop as a retained final-save
obligation during startup, including older Gateway state and the crash window
before result claiming. Resume the existing result owner and release the machine
only after reconciliation or proven loss.

Permit runtime refresh for the exact recovery-owned draining Stop result.
Prepare placement facts in the read worker, retain live authority through the
existing placement owner, and revalidate the result in receipt publication.
Fence the old process without reviving a turn or discarding its pending result.

Preserve manual retry, idle suspension, explicit abandonment, and dead-machine
semantics without changing the database schema or remote protocol. Document the
update behavior. Verify with 427 passing tests across 23 targeted files, scoped
typechecks, lint and repository guards, and independent Codex review.
Extract the pending workspace result into a type-only leaf so the worker store
contract does not introduce a Madge cycle through executable placement code.

Fence startup-synthesized Stop claims through the existing worker gate inside
the claim transaction, before commit observers or credential/worker I/O can
use them. Reuse that same gate operation for runtime-refresh classification.
Keep the durable result authority intact and leave normal turn claims alone.

Reopen the claimless-draining and unstaged old-bundle state shapes emitted by
v2026.9.6 through real stores. Prove same-build denial before I/O, final save
before release, and inherited/revoked worker RPC rejection. Packaged wire proof
remains unavailable without a dist build on the constrained host.

Validation: 478 unique tests across 26 targeted files; measured changed-file
pnpm test walls; scoped core/Gateway typechecks; zero Madge/runtime import
cycles; targeted lint; independent Codex review.

Refs: #159484
Record forced-discard intent in the existing environment teardown fields before placement cleanup, including already-requested destruction. Startup resumes that abandonment before restoring ordinary Stop obligations, and transient cleanup errors retain the marker. No schema change is required.

Prove the crash window through forced destruction, SQLite close/reopen, and real startup recovery. Fresh and previously requested destruction both release the machine without a Stop claim or workspace save. Released Gateway Stop-state coverage remains intact.
Keep the forced-abandonment marker alongside the latest bounded provider cleanup error, and use the same marker reader during startup and explicit retries. Expose persisted errors while destruction is pending so a dedicated node that remains attached after provider failure has an actionable status after restart.

Reuse existing teardown fields without a schema change. Add real-store dedicated-worker restart coverage for bounded diagnostics, retry replacement, no Stop claim or workspace save, and eventual provider release.
The runtime-refresh exemption added in b56ac75 skipped the existing
owner-revocation handoff for active recovery-only results, leaving their
recoveryRequestedAtMs unset when the old process was fenced.

Commit that handoff through the shared-state worker before capturing fresh
placement facts. Retain the exact claim incarnation across the handoff and
reject release/readmission even when the replacement reuses every claim field.
Preserve ordinary live-turn rejection and retained draining Stop authority.
No schema or external protocol change is needed.

Keep the original provider-owner-revocation regression unchanged. The store
refresh test spans preparation and receipt publication, so it now expects the
handoff timestamp while comparing every other pending-result field exactly.
The receipt still preserves the result and recovery-only claim.
The combined main and PR reclaim coverage exceeds the 1,000-line lint limit.
Move the two existing restart-recovery cases into the existing result-recovery
suite and retain their managed command fixture, database reopen, and assertions.
The resulting suite covers both unstaged and staged result recovery.

No production behavior, test deadline, or retry policy changes. The reorganized
result-recovery file passes all 20 tests, including both save-before-release
restart cases.
Preserve the narrowed recovery interface after rebasing onto interrupted-turn workspace recovery. Declare the startup claim-fencing dependency and migrate all type consumers to its leaf contract, keeping the pending-result implementation within the existing line budget. The interrupted active-turn fixture rejects unexpected Stop synthesis.
@steipete
steipete force-pushed the codex/reclaim-obligation-restart branch from 186b58e to e8e5ca0 Compare September 28, 2026 08:30
@steipete
steipete merged commit a08f2aa into main Sep 28, 2026
354 of 367 checks passed
@steipete
steipete deleted the codex/reclaim-obligation-restart branch September 28, 2026 09:09
steipete added a commit that referenced this pull request Sep 28, 2026
Resolves the provider-runtime-refresh.ts conflict with #159484, which replaced
assertWorkerRuntimeRefresh with the async prepareWorkerRuntimeRefresh placement
authority. Main's refresher is kept verbatim; the in-flight refresh fact is
published before the prepareWorkerRuntimeRefresh call so the launcher's claim
fence still observes it before the refresh's first placement read, and bundle
transfer progress is forwarded to ensureNodeWorkerBundle.
steipete added a commit that referenced this pull request Sep 28, 2026
…sions (#160299)

- fix(gateway): keep slow worker operations from blocking unrelated sessions
- fix(gateway): keep forced destroy ahead of later same-session work
- fix(gateway): order overlapping forced-destroy admissions
- fix(gateway): avoid forced-destroy discovery deadlocks
- refactor(gateway): keep recovery admission in the recovery contract leaf
- test(gateway): install placement spies before harness construction

Periodic worker-placement reconciliation no longer installs a global placement fence. Each coordinator operation is admitted per session: dispatch and Move enter after same-session Stop predecessors, Stop preparation stays outside the queue and only entered cleanup joins it, provisioning recovery holds its session until the provider settles, and forced destroy reserves attached/live owners at call time and try-reserves durable-only owners without waiting. Sweep recovery units read fresh facts after admission (full/startup sweeps skip busy sessions; targeted sweeps wait), and environment reconciliation always runs outside session admission. The #159484 startup Stop final-save pass runs as admitted units. Slow provider inspection or teardown for one environment no longer delays dispatch or Stop of unrelated sessions (live: paired-device dispatch had taken 818 s and 554 s behind stuck Crabbox teardown).

Known pre-existing limitation: Move and dispatch local barriers wait for turn-claim release inside admission; previously global, now same-session only.

Landed with an operator-authorized admin merge: the remaining CI failure was unrelated (src/gateway/server.config-patch.test.ts ConfigWritePostCommitError), with all static checks green.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
…start or update (openclaw#159484)

* fix(cloud-workers): retain stop recovery across restarts and updates

Treat a claimless draining placement left by Stop as a retained final-save
obligation during startup, including older Gateway state and the crash window
before result claiming. Resume the existing result owner and release the machine
only after reconciliation or proven loss.

Permit runtime refresh for the exact recovery-owned draining Stop result.
Prepare placement facts in the read worker, retain live authority through the
existing placement owner, and revalidate the result in receipt publication.
Fence the old process without reviving a turn or discarding its pending result.

Preserve manual retry, idle suspension, explicit abandonment, and dead-machine
semantics without changing the database schema or remote protocol. Document the
update behavior. Verify with 427 passing tests across 23 targeted files, scoped
typechecks, lint and repository guards, and independent Codex review.

* fix(cloud-workers): fence recovery claims before publication

Extract the pending workspace result into a type-only leaf so the worker store
contract does not introduce a Madge cycle through executable placement code.

Fence startup-synthesized Stop claims through the existing worker gate inside
the claim transaction, before commit observers or credential/worker I/O can
use them. Reuse that same gate operation for runtime-refresh classification.
Keep the durable result authority intact and leave normal turn claims alone.

Reopen the claimless-draining and unstaged old-bundle state shapes emitted by
v2026.9.6 through real stores. Prove same-build denial before I/O, final save
before release, and inherited/revoked worker RPC rejection. Packaged wire proof
remains unavailable without a dist build on the constrained host.

Validation: 478 unique tests across 26 targeted files; measured changed-file
pnpm test walls; scoped core/Gateway typechecks; zero Madge/runtime import
cycles; targeted lint; independent Codex review.

Refs: openclaw#159484

* fix(cloud-workers): persist forced abandonment before draining

Record forced-discard intent in the existing environment teardown fields before placement cleanup, including already-requested destruction. Startup resumes that abandonment before restoring ordinary Stop obligations, and transient cleanup errors retain the marker. No schema change is required.

Prove the crash window through forced destruction, SQLite close/reopen, and real startup recovery. Fresh and previously requested destruction both release the machine without a Stop claim or workspace save. Released Gateway Stop-state coverage remains intact.

* fix(cloud-workers): retain forced teardown failure diagnostics

Keep the forced-abandonment marker alongside the latest bounded provider cleanup error, and use the same marker reader during startup and explicit retries. Expose persisted errors while destruction is pending so a dedicated node that remains attached after provider failure has an actionable status after restart.

Reuse existing teardown fields without a schema change. Add real-store dedicated-worker restart coverage for bounded diagnostics, retry replacement, no Stop claim or workspace save, and eventual provider release.

* fix(cloud-workers): hand off recovery results before runtime refresh

The runtime-refresh exemption added in b56ac75 skipped the existing
owner-revocation handoff for active recovery-only results, leaving their
recoveryRequestedAtMs unset when the old process was fenced.

Commit that handoff through the shared-state worker before capturing fresh
placement facts. Retain the exact claim incarnation across the handoff and
reject release/readmission even when the replacement reuses every claim field.
Preserve ordinary live-turn rejection and retained draining Stop authority.
No schema or external protocol change is needed.

Keep the original provider-owner-revocation regression unchanged. The store
refresh test spans preparation and receipt publication, so it now expects the
handoff timestamp while comparing every other pending-result field exactly.
The receipt still preserves the result and recovery-only claim.

* test(cloud-workers): regroup Stop restart recovery cases

The combined main and PR reclaim coverage exceeds the 1,000-line lint limit.
Move the two existing restart-recovery cases into the existing result-recovery
suite and retain their managed command fixture, database reopen, and assertions.
The resulting suite covers both unstaged and staged result recovery.

No production behavior, test deadline, or retry policy changes. The reorganized
result-recovery file passes all 20 tests, including both save-before-release
restart cases.

* refactor(cloud-workers): isolate the recovery dependency contract

Preserve the narrowed recovery interface after rebasing onto interrupted-turn workspace recovery. Declare the startup claim-fencing dependency and migrate all type consumers to its leaf contract, keeping the pending-result implementation within the existing line budget. The interrupted active-turn fixture rejects unexpected Stop synthesis.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
…sions (openclaw#160299)

- fix(gateway): keep slow worker operations from blocking unrelated sessions
- fix(gateway): keep forced destroy ahead of later same-session work
- fix(gateway): order overlapping forced-destroy admissions
- fix(gateway): avoid forced-destroy discovery deadlocks
- refactor(gateway): keep recovery admission in the recovery contract leaf
- test(gateway): install placement spies before harness construction

Periodic worker-placement reconciliation no longer installs a global placement fence. Each coordinator operation is admitted per session: dispatch and Move enter after same-session Stop predecessors, Stop preparation stays outside the queue and only entered cleanup joins it, provisioning recovery holds its session until the provider settles, and forced destroy reserves attached/live owners at call time and try-reserves durable-only owners without waiting. Sweep recovery units read fresh facts after admission (full/startup sweeps skip busy sessions; targeted sweeps wait), and environment reconciliation always runs outside session admission. The openclaw#159484 startup Stop final-save pass runs as admitted units. Slow provider inspection or teardown for one environment no longer delays dispatch or Stop of unrelated sessions (live: paired-device dispatch had taken 818 s and 554 s behind stuck Crabbox teardown).

Known pre-existing limitation: Move and dispatch local barriers wait for turn-claim release inside admission; previously global, now same-session only.

Landed with an operator-authorized admin merge: the remaining CI failure was unrelated (src/gateway/server.config-patch.test.ts ConfigWritePostCommitError), with all static checks green.
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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. security-sensitive-changed size: XL 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