Repository navigation
fix: cloud-worker results are lost when the box dies before reconciliation - #110952
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: af6e467fcd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (probe.termination === "exit" && probe.code === 0) { | ||
| return resolved; | ||
| } | ||
| await requireGit(resolved, ["init", "--quiet", "--object-format=sha1"]); |
There was a problem hiding this comment.
Avoid initializing Git in plain workspaces
When a cloud turn runs against a plain, non-Git workspace, this fallback permanently adds a .git directory. On the next dispatch, syncWorkspaceImpl treats the successful git rev-parse --show-toplevel as Git mode (src/gateway/worker-environments/workspace-sync.ts:257-264) and then requires a valid HEAD (src/gateway/worker-environments/workspace-sync.ts:290-299); this newly initialized repository has no commits, so every subsequent cloud turn fails with “Worker git workspace has no base commit.” Keep the durable result repository outside plain user workspaces or otherwise preserve their plain-mode classification.
Useful? React with 👍 / 👎.
| @@ -3,7 +3,7 @@ | |||
| "version": "2026.7.2", | |||
| "openclaw": { | |||
| "schemaVersions": { | |||
| "state": 4, | |||
| "state": 5, | |||
There was a problem hiding this comment.
Keep the additive state column on schema version 4
When a user starts this version and subsequently rolls back, the database remains at user_version = 5, while the older build supports version 4 and rejects any larger version in src/state/openclaw-state-db-maintenance.ts:64-72, preventing the Gateway from opening its state database. Because staged_result_ref is a nullable additive column that older readers tolerate, this bump creates an unnecessary rollback incompatibility and conflicts with the root AGENTS.md rule that purely additive SQLite surfaces must not bump the schema version.
Useful? React with 👍 / 👎.
1cb2e45 to
4c84633
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c84633ae2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| chunks.push(Buffer.from(`M ${mode} :${blob.mark} ${quoteFastImportPath(blob.entry.path)}\n`)); | ||
| } | ||
| chunks.push(Buffer.from("done\n")); | ||
| const imported = await runCommandBuffered(gitCommand(root, ["fast-import", "--quiet"]), { |
There was a problem hiding this comment.
Replace the prepared ref when rebuilding a retry candidate
If the Gateway crashes after applyPreparedStagedResult() commits the new manifest but before publishStagedResult(), the candidate ref survives while the placement base advances. Recovery then stages a new root commit at the same candidate ref using the advanced base, but this fast-import lacks --force; Git 2.43 rejects that update with Not updating ... new tip ... does not contain <old tip> and exits 1. Every sweep repeats the failure, and after the worker disappears the hasPreparedResult branch preserves the fence indefinitely, blocking the placement until forced abandonment. Delete the prior candidate before rebuilding it or explicitly force this validated ref update.
Useful? React with 👍 / 👎.
49ce95d to
90f77b3
Compare
|
Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 6:17 PM ET / 22:17 UTC. Summary PR surface: Source +1164, Tests +837, Config 0, Generated +2. Total +2003 across 27 files. Reproducibility: yes. The PR provides a concrete current-head live path: complete a cloud-worker result, force the acceptance persistence boundary to fail after staging, stop the AWS lease, restart Gateway, and verify the identical result is applied and the pending state is cleared. Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Land the durable staging design only with an explicit maintainer decision that the v5 rollback behavior is intentional; retain the v4→v5 migration coverage and the proven restart-recovery path. Do we have a high-confidence way to reproduce the issue? Yes. The PR provides a concrete current-head live path: complete a cloud-worker result, force the acceptance persistence boundary to fail after staging, stop the AWS lease, restart Gateway, and verify the identical result is applied and the pending state is cleared. Is this the best way to solve the issue? Yes, conditional on the schema-version decision. Durable local staging before apply directly addresses the failure window and avoids depending on a dead worker tunnel during recovery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 19d887169f78. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +1164, Tests +837, Config 0, Generated +2. Total +2003 across 27 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
Review history (3 earlier review cycles)
|
ba7286d to
2f57a2d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f57a2d7e6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const entries = reconciliationEntries(current.entries).toSorted((left, right) => | ||
| left.path.localeCompare(right.path), | ||
| ); |
There was a problem hiding this comment.
Apply reconciliation limits only to changed entries
When the workspace contains an unchanged file larger than 64 MiB, more than 25,000 total entries, or over 256 MiB of total content, this stages every current entry and applies the reconciliation limits to the entire workspace. Previously, workerWorkspaceTransferPaths filtered to changed paths before enforcing these limits, so even a no-op cloud turn in such a workspace now fails with a size/entry-limit error. Only changed payload blobs need to be stored because applyStagedWorkerWorkspaceResult materializes only paths in changedPaths.
Useful? React with 👍 / 👎.
| ); | ||
| } | ||
| } else { | ||
| const root = await params.resolveWorkspacePath(placement); |
There was a problem hiding this comment.
Allow forced teardown without resolving the worktree
When the session worktree registry or session entry is already missing or inconsistent, resolveWorkspacePath throws here before the pending result is abandoned. Since forceDestroyEnvironment calls environments.destroy only after this helper succeeds (src/gateway/worker-environments/placement-dispatch.ts:327-334), the documented last-resort forced teardown leaves both the environment and claim fenced indefinitely. Treat an unresolvable workspace as having no deletable result ref and continue the explicit abandonment.
Useful? React with 👍 / 👎.
a6ed704 to
a9d37cd
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a9d37cdda8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await requireGit(root, ["update-ref", "-d", stagedResultRef]); | ||
| if (stagedResultRef.startsWith(`${WORKER_RESULT_REF_PREFIX}/`)) { | ||
| await requireGit(root, ["update-ref", "-d", preparedWorkerWorkspaceResultRef(stagedResultRef)]); | ||
| } |
There was a problem hiding this comment.
Prune staged objects after deleting result refs
When cloud turns run repeatedly against a plain workspace, ensureWorkerWorkspaceResultRepository creates an unborn .git at src/gateway/worker-environments/workspace-result-staging.ts:142-152, but this cleanup deletes only the refs. Git 2.43's git gc -h identifies --prune as the operation that removes unreferenced objects; no GC or object cleanup runs here, and an import/delete probe leaves every blob, tree, and commit as loose objects. Because such a workspace has no normal Git maintenance owner, successive changed results can retain deleted content and grow the hidden repository indefinitely, potentially by the reconciliation limits per turn. Use lifecycle-owned result storage or explicitly remove its unreachable objects after the fence is complete.
Useful? React with 👍 / 👎.
|
@clawsweeper re-review The PR body now contains redacted exact-head proof from a real Gateway → bundled Crabbox → AWS worker run. The worker result was durably staged, the AWS lease was stopped, and Gateway restart recovery preserved identical file bytes, cleared the pending row and claim, removed the staging ref, and reclaimed the placement. Maintainer rulings for this PR remain: keep the state schema at |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…ation (openclaw#110952) * fix(cloud-workers): stage worker results durably before reconciliation * fix(cloud-workers): model result staging test seam * fix(cloud-workers): disable staging git hooks safely * chore: defer cloud worker release note * fix(cloud-workers): harden staged result recovery
…ation (openclaw#110952) * fix(cloud-workers): stage worker results durably before reconciliation * fix(cloud-workers): model result staging test seam * fix(cloud-workers): disable staging git hooks safely * chore: defer cloud worker release note * fix(cloud-workers): harden staged result recovery
Related: #110224 (phase 1 of 3)
What Problem This Solves
Resolves the data-loss half of #110224: a cloud-worker turn's file result only existed on the leased box until a clean workspace apply succeeded. If inbound reconciliation failed (real local divergence) and the box then died — or the Gateway restarted and its recovery sweep found the environment gone — the unaccepted result was abandoned and the placement force-failed, permanently losing the turn's work. Observed live during a cloud-workers stress test (full incident log in #110224).
Why This Change Was Made
Stage-first reconciliation: when a worker result is pulled, the complete result tree is committed as a durable Git ref in the session workspace repo (
refs/openclaw/worker-results/<claim>, with a crash-safe candidate ref during construction) before any apply is attempted, and recorded on the pending-result fence row (new nullablestaged_result_refcolumn, state schema v5, additive migration). Apply and every retry then run from the staged tree as a purely local operation; the recovery sweep skips the tunnel entirely when a staged ref exists. Recovery semantics change accordingly: an unaccepted fence with a staged ref must never be destroyed by environment lifecycle — the environment can be reclaimed while the fence and placement stay alive until the local apply is durably accepted. Only legacy fences without a staged ref keep the old abandon path. Staged refs are deleted on acceptance or explicit abandonment; ref construction validates claim ids ([A-Za-z0-9-]+) and fails closed; ordering is candidate apply → quiescence/fence checks → canonical ref publish → SQLite pointer, so a crash at any step leaves a recoverable state. Object retention after ref deletion matches the existing managed-worktree snapshot pattern (refs/openclaw/snapshots/*).Non-goals (later phases per #110224): conflict resolution policy, turn-claim release semantics, chat error copy, UI affordances.
Maintainer rulings for this PR: keep the state schema at
main + 1(v5); the rollback consequence is deliberately accepted. Complete-tree staging and object-store retention parity with managed-worktree snapshots are also accepted design decisions.User Impact
A dead or reclaimed cloud box can no longer lose a finished turn's file changes: the result is already safe on the Gateway and is applied or retried locally. Gateway restarts preserve pending results instead of force-failing their placements.
Evidence
node scripts/run-vitest.mjs src/gateway/worker-environments/ src/state/openclaw-state-db.test.ts— 447 tests green (89 + 358 across shards), including: staging order (ref before apply), crash-gap adoption of canonical refs, dead-environment recovery applying from the staged ref without a tunnel, divergence keeping fence + placement alive, ref cleanup on accept, hostile git-hook neutralization, and the v4→v5 migration.pnpm check:changed(Blacksmith Testbox): exit 0 (typecheck, lint, format, policy guards, import cycles).Real recovery proof
Exact head
a9d37cdda82c3bb1ce5092c9609a609366f31245was built and run through an isolated real Gateway → bundled Crabbox provider → AWS worker path. The model side used the deterministic local QA provider; provisioning, bundle install, SSH/tunnel, worker runtime, workspace transfer, durable staging, lease loss, Gateway restart, and recovery were production paths.The proof injected one persistence-boundary failure with an isolated SQLite trigger: reject the first
workspace_accepted_at_msupdate after the canonical staged Git ref was published. This models the crash window without modifying production code. It then stopped the actual AWS lease before restarting the Gateway.The first harness attempt reached an attached AWS worker but selected an empty side-database path before starting a turn; it failed during trigger installation and cleaned up its lease. The corrected run above used the Gateway's canonical
state/openclaw.sqlitepath and completed end to end.