Skip to content

fix(workers): protect in-flight workspace manifests from concurrent retention - #130449

Merged
steipete merged 1 commit into
mainfrom
steipete/fu-reconcile
Aug 26, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fu-reconcile

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

In the 50-session cross-machine farm run (#129979), 12/50 turns ended with "Cloud worker finished, but its workspace result could not be reconciled" — the worker did its job and the result was silently lost, the worst failure class in this repo.

Why This Change Was Made

Root cause is a manifest-retention race. Between a worker's manifest upload and its verification, a sibling completion can trigger workspace retention with a snapshot that only knows the old base manifest. The just-finished worker no longer protects the workspace, so cleanup deletes the newly uploaded manifest, and verification fails with ENOENT at src/gateway/worker-environments/workspace-sync-scripts.ts:301.

The repair closes the race at both owners:

  • The node workspace runtime pins the latest transferred manifest per generation (src/node-host/node-worker-workspace.ts) and includes it in every cleanup's reachable set; the pin is cleared with its generation.
  • Gateway retention snapshots treat unsettled results — an active turn claim or a pending-result fence matching the environment + owner epoch — as protection (src/gateway/worker-environments/node-workspace-retain-coordinator.ts), which also covers restarts where node-local pins are gone.
  • Manifest-capture errors now retain bounded, redacted stderr (src/gateway/worker-environments/node-worker-workspace-fallback.ts) so this failure class can never be faceless again.

No deadlines, protocol, schema, or completion semantics changed. Production delta +11 lines.

User Impact

Operators running many parallel worker sessions on one node no longer lose completed work to concurrent cleanup; capture failures that do occur carry actionable stderr.

Evidence

  • Deterministic 1-turn and 50-turn reproductions fail pre-fix with the exact missing-manifest ENOENT, pass post-fix with result bytes preserved and claims released.
  • 110 focused tests across seven files (including real HTTP transfers and cleanup), pnpm check:changed green.
  • Broad suites: 1,584 passed; remaining failures are unchanged pre-existing timing-sensitive tests (node-config startup import 18.6s vs 15s probe deadline; large-inventory recovery; large SSH workspace), reproduced in isolation without this change.
  • Automated review (branch vs origin/main): no actionable findings.

Part of the #129979 worker-mortality follow-up campaign. A combined live rig run with the lifecycle lane (#130446) follows before the campaign closes.

…etention

At high completion concurrency, 12/50 turns failed with 'Cloud worker
finished, but its workspace result could not be reconciled' (#129979):
between a worker's manifest upload and its verification, a sibling
completion could trigger retention with a snapshot holding only the old
base manifest — the terminal worker no longer protected the workspace, so
cleanup deleted the just-uploaded manifest and verification died on ENOENT.
The node workspace runtime now pins the latest transferred manifest per
generation and includes it in every cleanup's reachable set (cleared with
its generation), and gateway retention snapshots treat unsettled results —
an active claim or a pending-result fence — as protection, which also
preserves it across restarts when node-local pins are gone. Capture errors
retain bounded redacted stderr so this failure class can never be
faceless again. No deadlines, protocol, or completion-semantics changes;
deterministic 1-turn and 50-turn reproductions fail pre-fix.
@clawsweeper

clawsweeper Bot commented Aug 26, 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: L maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 22:10
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 6:26 PM ET / 22:26 UTC.

ClawSweeper review

What this changes

This PR preserves in-flight worker workspace manifests through concurrent cleanup, adds restart-safe pending-result retention, and reports bounded redacted manifest-capture failures.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: current main still has the unprotected retention behavior, while this branch adds a coherent two-owner repair for the manifest-loss race. No concrete patch defect was found; exact-head CI and normal maintainer review remain before landing.

Priority: P1
Reviewed head: d2e6a2188daa2ab6d03b7f5852c5eef0f3274c95

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with substantial regression coverage; exact-head CI and an integrated restart proof would further reduce residual risk.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR is maintainer-authored, so the external-contributor proof gate does not apply; the PR body nevertheless describes its concurrent-run evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR is maintainer-authored, so the external-contributor proof gate does not apply; the PR body nevertheless describes its concurrent-run evidence.
Evidence reviewed 5 items Node-side race protection: The workspace runtime holds the latest successfully transferred manifest per generation, includes it in cleanup reachability, and drops the pin only with the retired generation.
Restart-safe owner boundary: The Gateway sends a full manifest-retention sentinel while an exact durable pending result matches the environment and owner epoch; pending rows are bound to one session and exact claim data.
Boundary regression coverage: The added regression drives one and fifty concurrent reconciliations through claims, journals, node retention, verification, and managed-worktree application.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/gateway/worker-environments/workspace-result-finalize.test.ts

Result: FAIL (failed) — step 1 run pnpm test src/gateway/worker-environments/workspace-result-finalize.test.ts: previous terminal command was still running after 30 seconds: "pnpm test src/gateway/worker-environments/workspace-result-finalize.test.ts"

$ node --import tsx scripts/test-projects.mts src/gateway/worker-environments/workspace-result-finalize.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130449-CFmK85/target

Assertions:

  • FAIL expect_output: concurrent worker workspace results

How this fits together

A cloud worker uploads its workspace result to the Gateway, then the Gateway verifies and reconciles it into the managed worktree. Node-side retention must not delete either the transfer result or its manifest before that reconciliation has safely settled.

flowchart LR
  A[Completed worker turn] --> B[Workspace manifest upload]
  B --> C[Node transfer pin]
  B --> D[Gateway pending-result fence]
  C --> E[Retention reachability]
  D --> E
  E --> F[Manifest verification]
  F --> G[Workspace reconciliation]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main and exact-head checks are still running; landing should use the actual merge head after CI completes.
  • Resolve merge risk (P1) - The repair adds net +11 production lines of transient reachability state; existing tests cover the two halves, but not a fresh node-runtime restart combined with a durable pending-result retention snapshot.
Agent review details

Security

None.

PR surface

Source +25, Tests +373, Docs +2, Other 0. Total +400 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 5 83 58 +25
Tests 4 401 28 +373
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 11 487 87 +400

Review metrics

Metric Value Why it matters
Production versus regression coverage production +69/-58 (net +11); tests/support +415/-28; docs +2 The small production increase records two necessary ownership facts—post-transfer reachability and durable unsettled state—while most of the change is concurrency regression coverage.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/node-worker-tunnel.test-support.ts, durable storage schema: src/gateway/worker-environments/node-worker-tunnel.test.ts, durable storage schema: src/gateway/worker-environments/node-worker-tunnel.ts, durable storage schema: src/gateway/worker-environments/node-worker-workspace-fallback.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, and 9 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the node transfer pin and Gateway durable-fence repair, then validate it on the rebased merge head with exact-head CI and the planned concurrent lifecycle run.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the node transfer pin and Gateway durable-fence repair, then validate it on the rebased merge head with exact-head CI and the planned concurrent lifecycle run.

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

Yes—source provides a deterministic one- and fifty-turn ordering harness that reproduces cleanup after upload but before verification; this review did not execute it because the checkout is read-only.

Is this the best way to solve the issue?

Yes—the node-local pin covers the command gap, while the durable Gateway fence covers restart after node-local state is lost; neither owner alone covers both cases.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The PR addresses silently lost completed worker workspace results during concurrent operation.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is maintainer-authored, so the external-contributor proof gate does not apply; the PR body nevertheless describes its concurrent-run evidence.

Label justifications:

  • P1: The PR addresses silently lost completed worker workspace results during concurrent operation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is maintainer-authored, so the external-contributor proof gate does not apply; the PR body nevertheless describes its concurrent-run evidence.

Evidence

What I checked:

Likely related people:

  • steipete: History attributes the original node workspace transfer, retention preservation, and this repair to the same contributor. (role: feature owner and recent area contributor; confidence: high; commits: 860aeed8f672, d9137961120f, d2e6a2188daa; files: src/node-host/node-worker-workspace.ts, src/gateway/worker-environments/node-workspace-retain-coordinator.ts, src/gateway/worker-environments/placement-workspace-result.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Verify green CI on the exact merge head after the required review refresh.
  • Attach or link a redacted concurrent lifecycle trace that includes a restart while a durable pending workspace result is retained.

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

Rank-up moves before landing:

  1. Exact-head CI: satisfied — the cancelled CI workflow run was re-fired and attempt 2 completed green on head d2e6a2188daa2ab6d03b7f5852c5eef0f3274c95.
  2. Restart + durable pending-result trace: the combination is covered by the protects unsettled manifests for pending ownership case in src/gateway/worker-environments/node-workspace-retain-coordinator.test.ts, which models a durable pending workspace result recorded by a previous gateway instance (gatewayInstanceId: "previous-gateway", no live turn claim, node-local pins gone after a node-runtime restart) and asserts the retain snapshot keeps all manifests (manifestRefs: null). A live restart trace was not additionally captured; the deterministic reproduction plus this boundary test cover the changed path.

@steipete
steipete merged commit 95161c2 into main Aug 26, 2026
271 of 310 checks passed
@steipete
steipete deleted the steipete/fu-reconcile branch August 26, 2026 23:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 26, 2026
* origin/main: (26 commits)
  fix(plugins): preserve registry epoch on activation rollback (#129232)
  refactor(plugins): make discovery invocation-owned (#130486)
  feat(ui): save appearance preferences per user profile (#130340)
  fix: Buzz bots recover relay stalls and reject revoked senders (#130467)
  fix(code-mode): serialize catalog handles nested in final values (#130276)
  fix(webchat): CLI skill and harness-injected turns render as operator-sent messages (#130427)
  fix(agents): read the published model catalog owner from session_status (#130277)
  fix(channels): preserve long presentation text (#130368)
  fix(agents): route CLI bootstrap truncation notice into the system prompt (#130325)
  refactor(plugins): unify setup registration and artifact selection (#130474)
  fix(memory): prevent forgotten session content from returning (#130451)
  refactor(outbound): consolidate transport completion (#130460)
  fix(workers): protect in-flight workspace manifests from concurrent retention (#130449)
  fix(portals): keep worker previews reachable and owned by the active environment (#130434)
  fix(config): keep core channels keys in the generated config schema (#120736)
  chore(deps): refresh dependencies after seven-day cooldown (#130296)
  fix(agents): remind exec models to quote shell metacharacters (#125485)
  fix(auth): honor shared-store ownership in temp-state exec and agent deletion (#130437)
  fix(openshell): preserve file writes during concurrent mirror commands (#130447)
  fix(workers): report full nodes as at capacity, not offline (#130445)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…etention (openclaw#130449)

At high completion concurrency, 12/50 turns failed with 'Cloud worker
finished, but its workspace result could not be reconciled' (openclaw#129979):
between a worker's manifest upload and its verification, a sibling
completion could trigger retention with a snapshot holding only the old
base manifest — the terminal worker no longer protected the workspace, so
cleanup deleted the just-uploaded manifest and verification died on ENOENT.
The node workspace runtime now pins the latest transferred manifest per
generation and includes it in every cleanup's reachable set (cleared with
its generation), and gateway retention snapshots treat unsettled results —
an active claim or a pending-result fence — as protection, which also
preserves it across restarts when node-local pins are gone. Capture errors
retain bounded redacted stderr so this failure class can never be
faceless again. No deadlines, protocol, or completion-semantics changes;
deterministic 1-turn and 50-turn reproductions fail pre-fix.
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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