Skip to content

fix(workers): preserve disappeared-worker failures across restarts - #121122

Merged
steipete merged 7 commits into
mainfrom
steipete/cloud-reconcile-loss
Aug 10, 2026
Merged

steipete merged 7 commits into
mainfrom
steipete/cloud-reconcile-loss

Conversation

@steipete

@steipete steipete commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a cloud worker could disappear while a session result was being reconciled, leaving the session looking clean or losing the diagnostic across a Gateway restart. In the worst ordering, a pending workspace result and its failure record were updated separately, and sessions sharing one worker environment could surface the wrong session's recovery error.

Why This Change Was Made

The placement row is now the durable owner of per-session terminal facts. terminal_reason and terminal_at_ms are additive final columns on worker_session_placements; terminal transitions, pending-result removal, claim release, and recovery diagnostics commit in one synchronous state transaction. Unexpected destroyed, unknown, missing, failed, or orphaned worker evidence records a bounded cloud worker disappeared: ... failure, while clean operator reclaim keeps a null reason.

The worker still sends a non-terminal finishing fence before workspace reconciliation. The normal outer fallback cycle remains the sole owner of run-level terminal normalization; this removes the prior in-memory finalization path and environment-scoped session diagnostics. No table or schema-version bump is introduced.

Production LOC: +435/-134 (net +301) | Tests/QA: +1120/-78 | Docs/generated: +50/-50. The production growth establishes the durable owner boundary, atomic failure transaction, and generated Swift protocol follow-through.

User Impact

Operators now see an accurate cloud-worker failure in the affected session and selected Control UI chat, including after Gateway replacement. A disappeared worker is never presented as a clean reclaim, retained workspace results stay fenced for recovery, and one session's terminal reason cannot leak to another session that references the same environment.

Evidence

  • Placement store and redispatch: 25/25 tests passed, including additive column order, clean reclaim time/null reason, bounded disappearance reason, restart persistence, same-environment session isolation, failed-retry preservation, redispatch clearing, and transaction rollback.
  • Gateway dispatch/lifecycle/projector: 200/200 focused tests passed; post-rebase sanity passed 91/91.
  • Workspace reconciliation: 82/82 focused tests passed.
  • Shared-state schema: 113 passed, 1 skipped; post-rebase additive-schema checks passed 2/2.
  • Worker runtime/result fence: 39/39 focused tests passed after rebase.
  • Control UI Playwright on Blacksmith Testbox: 2/2 passed for durable conflict guidance and selected-chat failure alert.
  • pnpm check:changed on Blacksmith Testbox: all-project types, core/extensions/scripts lint, schema, DB, metadata, and import-cycle guards passed. Run: https://github.com/openclaw/openclaw/actions/runs/31320267085
  • Autoreview: clean on cycle 1, no accepted/actionable findings, correctness confidence 0.98.
  • Real behavior: isolated qa-channel + mock-openai + static-ssh mock-provider child Gateway, three Gateway replacements, distinct reasons for two sessions sharing one environment. Testbox verdict:
{
  "status": "pass",
  "providerMode": "mock-openai",
  "channel": "qa-channel",
  "workerProvider": "static-ssh",
  "gatewayReplacementCount": 3,
  "disappearance": {
    "sessionId": "ephemeral-session-a",
    "terminalReason": "cloud worker disappeared: Worker provider no longer recognizes lease",
    "durableAcrossRestarts": true
  },
  "isolation": {
    "sharedEnvironmentId": "qa-static-worker-loss",
    "otherSessionId": "ephemeral-session-b",
    "otherTerminalReason": "independent session failure",
    "reasonsDistinct": true
  },
  "environment": {
    "state": "orphaned",
    "error": "Worker provider no longer recognizes lease"
  }
}

@clawsweeper

clawsweeper Bot commented Aug 9, 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 app: web-ui App: web-ui gateway Gateway runtime extensions: qa-lab size: XL maintainer Maintainer-authored PR labels Aug 9, 2026
@steipete
steipete marked this pull request as ready for review August 9, 2026 16:33
@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch 5 times, most recently from 220d428 to 67f6287 Compare August 9, 2026 19:19
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. 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. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 10, 2026, 2:57 AM ET / 06:57 UTC.

ClawSweeper review

What this changes

The PR makes cloud-worker terminal diagnostics durable per session across Gateway restarts, projects them through session APIs, and shows the selected session’s failure in the Control UI.

Merge readiness

⚠️ Needs maintainer review before merge - 5 items remain

Keep open: two prior lifecycle blockers remain. An already accepted workspace result is still converted into a durable worker failure for failed/orphaned/missing environments, and an oversized finishing error can prevent the fence that the new recovery flow relies on.

Priority: P2
Reviewed head: 11d1fb005df46905d2d14297d088e47a315fdd7d

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong restart and UI proof supports the intended path, but two concrete lifecycle defects still block merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies an after-fix isolated Gateway run with qa-channel, a mock provider, three replacements, and durable per-session results; the remaining blockers are uncovered sibling terminal-loss cases.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies an after-fix isolated Gateway run with qa-channel, a mock provider, three replacements, and durable per-session results; the remaining blockers are uncovered sibling terminal-loss cases.
Evidence reviewed 5 items Accepted-result loss path: The branch only completes an accepted pending result when the environment is destroyed; failed, orphaned, or missing environments fall into the new durable-failure path instead.
Existing coverage gap: The restart regression covers an accepted result after a destroyed environment, while failed/orphaned accepted-result cases are absent.
Finishing-fence payload contract: The changed worker code sends errors as lifecycle phase finishing, but the bounding helper only handles oversized lifecycle phase error; an oversized finishing payload throws before the direct fence emit.
Findings 2 actionable findings [P2] Reclaim accepted results for every terminal-loss state
[P2] Bound finishing errors before emitting the durable fence
Security None None.

How this fits together

Cloud workers send lifecycle and workspace-result fences to the Gateway. The Gateway persists a session placement, reconciles it after restart, then projects the resulting state to session APIs and the selected Control UI chat.

flowchart LR
  A[Cloud worker] --> B[Lifecycle finishing fence]
  B --> C[Gateway placement store]
  C --> D[Restart reconciliation]
  D --> E[Session API projection]
  E --> F[Control UI selected chat]
Loading

Before merge

  • Reclaim accepted results for every terminal-loss state (P2) - workspaceAcceptedAtMs means the local workspace result is already final, but only destroyed is reclaimed. For failed, orphaned, or a missing environment, this new branch calls failWorkspaceResultAndReleaseTurn, so the completed result is presented as a cloud-worker failure instead. Complete the accepted result for all proven terminal-loss states and add restart coverage for them.
  • Bound finishing errors before emitting the durable fence (P2) - This change sends terminal errors as finishing, while the live-event bounding path only truncates lifecycle error payloads. A large provider error therefore makes the direct finishing emit throw before it is acknowledged, defeating the fence required by the new reconciliation flow. Bound the finishing error and cover the oversized-error path.
  • Resolve merge risk (P1) - This bug-fix branch adds net production code around durable state and lifecycle recovery; landing without the two remaining terminal-state repairs would preserve incorrect operator-visible outcomes.
  • Resolve merge risk (P1) - Two new persisted placement columns and projected session fields are upgrade-sensitive, so the repaired exact head still needs its schema and generated-client checks green.
  • Complete next step (P2) - The protected maintainer-authored PR should have its two concrete blockers resolved through normal owner review rather than an automated repair lane.

Findings

  • [P2] Reclaim accepted results for every terminal-loss state — src/gateway/worker-environments/placement-dispatch-pending-results.ts:354-357
  • [P2] Bound finishing errors before emitting the durable fence — src/worker/embedded-agent-live.runtime.ts:321-325
Agent review details

Security

None.

PR surface

Source +301, Tests +990, Docs 0, Generated +2, Other +51. Total +1344 across 46 files.

View PR surface stats
Area Files Added Removed Net
Source 26 428 127 +301
Tests 15 1068 78 +990
Docs 1 1 1 0
Config 0 0 0 0
Generated 2 46 44 +2
Other 2 52 1 +51
Total 46 1595 251 +1344

Review metrics

Metric Value Why it matters
Production versus test delta production +435/-134 (net +301); tests/QA +1120/-78; docs/generated +50/-50 The durable-state repair materially grows production lifecycle code, so the remaining correctness gaps should be resolved before accepting that growth.
Persisted and projected fields 2 additive SQLite columns and 2 session-placement protocol fields added Existing databases and generated clients must continue to handle the new per-session terminal metadata safely.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-state-db.test.ts, durable storage schema: src/gateway/worker-environments/placement-dispatch-failure.ts, durable storage schema: src/gateway/worker-environments/placement-dispatch-pending-results.ts, durable storage schema: src/gateway/worker-environments/placement-dispatch-recovery.ts, durable storage schema: src/gateway/worker-environments/placement-dispatch-test-harness.ts, durable storage schema: src/gateway/worker-environments/placement-dispatch.test.ts, and 42 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair the terminal-loss invariants before merge (recommended)
    Complete accepted workspace results for every proven terminal-loss state and ensure the finishing fence is bounded, then rerun the focused restart and worker-runtime evidence.

Technical review

Best possible solution:

Use one accepted-result completion rule for every proven terminal-loss state, bound finishing-fence errors before RPC emission, and add restart regressions for failed, orphaned, and missing environments.

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

Yes, from source: an accepted pending result with a failed, orphaned, or missing environment reaches the failure transition, and an oversized finishing error is rejected before its required fence is emitted.

Is this the best way to solve the issue?

No. Durable placement ownership is the right boundary, but accepted final results must be reclaimed across every terminal-loss state and the fence must be bounded at its producer.

Full review comments:

  • [P2] Reclaim accepted results for every terminal-loss state — src/gateway/worker-environments/placement-dispatch-pending-results.ts:354-357
    workspaceAcceptedAtMs means the local workspace result is already final, but only destroyed is reclaimed. For failed, orphaned, or a missing environment, this new branch calls failWorkspaceResultAndReleaseTurn, so the completed result is presented as a cloud-worker failure instead. Complete the accepted result for all proven terminal-loss states and add restart coverage for them.
    Confidence: 0.98
  • [P2] Bound finishing errors before emitting the durable fence — src/worker/embedded-agent-live.runtime.ts:321-325
    This change sends terminal errors as finishing, while the live-event bounding path only truncates lifecycle error payloads. A large provider error therefore makes the direct finishing emit throw before it is acknowledged, defeating the fence required by the new reconciliation flow. Bound the finishing error and cover the oversized-error path.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The remaining worker-recovery defects affect a bounded but real session-result and diagnostic path.
  • merge-risk: 🚨 compatibility: The PR adds persisted placement columns and session protocol fields that existing databases and clients must tolerate during upgrade.
  • merge-risk: 🚨 session-state: The patch changes durable ownership and recovery of per-session terminal state across Gateway restarts.
  • merge-risk: 🚨 availability: An oversized finishing error can prevent the required recovery fence, leaving the worker result unable to enter the intended reconciliation flow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body supplies an after-fix isolated Gateway run with qa-channel, a mock provider, three replacements, and durable per-session results; the remaining blockers are uncovered sibling terminal-loss cases.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix isolated Gateway run with qa-channel, a mock provider, three replacements, and durable per-session results; the remaining blockers are uncovered sibling terminal-loss cases.

Evidence

What I checked:

Likely related people:

  • Vyctor H. Brzezowski: Blame attributes the destroyed-only accepted-result branch that the PR now routes into durable failure handling to this current baseline history. (role: recent recovery-path contributor; confidence: high; commits: bb02fc53ea8f; files: src/gateway/worker-environments/placement-dispatch-pending-results.ts)

Rank-up moves

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

  • Add restart regressions proving accepted results reclaim for failed, orphaned, and missing environments.
  • Add an oversized finishing-error proof showing the durable fence is emitted and acknowledged.

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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-09T21:49:08.525Z sha 35147d4b6ebe9d23adb852e3cea75f73e739f093 :: found issues before merge. :: [P2] Reclaim accepted results after provider loss
  • reviewed 2026-08-09T22:50:33.184Z sha 19a0353 :: found issues before merge. :: [P2] Reclaim accepted results after provider loss
  • reviewed 2026-08-09T23:59:52.043Z sha c49abd2e0ebd346d00acc68e37fb8ff4aa94b6c8 :: needs changes before merge. :: [P2] Reclaim accepted results for every unavailable worker state
  • reviewed 2026-08-10T00:56:21.136Z sha 0fabe35b526a537b64c1866b70513de4524c393c :: found issues before merge. :: [P2] Reclaim accepted results for all unavailable worker states
  • reviewed 2026-08-10T02:51:49.313Z sha 15b962c :: found issues before merge. :: [P2] Reclaim accepted results for every terminal loss state | [P2] Keep mismatched pending results fenced before cleanup
  • reviewed 2026-08-10T03:57:39.926Z sha 89c8f2d :: found issues before merge. :: [P2] Reclaim accepted results for failed and orphaned workers
  • reviewed 2026-08-10T04:47:43.089Z sha 5a9d481aec299e1e91ebe2fcc870d4066e204345 :: found issues before merge. :: [P2] Reclaim accepted results for failed and orphaned workers
  • reviewed 2026-08-10T05:46:23.414Z sha 09a5584e1ac90da2db9cb03a979385900f08bf71 :: needs changes before merge. :: [P2] Reclaim accepted results for every terminal-loss state | [P2] Bound finishing lifecycle errors before emitting the fence

@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch 4 times, most recently from 06cde66 to 35147d4 Compare August 9, 2026 21:40
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 9, 2026
@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch 5 times, most recently from c49abd2 to 0fabe35 Compare August 10, 2026 00:50
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 10, 2026
@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch from eec6af4 to 15b962c Compare August 10, 2026 02:10
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 10, 2026
@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch from 15b962c to 89c8f2d Compare August 10, 2026 03:06
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 10, 2026
@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch from 89c8f2d to 5a9d481 Compare August 10, 2026 04:00
@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 10, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Aug 10, 2026
@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch from 5a9d481 to 09a5584 Compare August 10, 2026 05:16
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Aug 10, 2026
@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch 2 times, most recently from 940e4ca to 11d1fb0 Compare August 10, 2026 06:30
@steipete
steipete force-pushed the steipete/cloud-reconcile-loss branch from 11d1fb0 to ce52a7e Compare August 10, 2026 07:16
@steipete
steipete merged commit f6298bf into main Aug 10, 2026
124 checks passed
@steipete
steipete deleted the steipete/cloud-reconcile-loss branch August 10, 2026 07:36
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 10, 2026
Worker live events now share compatible Gateway-owned run contexts so the canonical outer terminal can clear session activity after the worker finishing fence. Follow-up to #121200 and #121122.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 11, 2026
…penclaw#121122)

* fix(workers): persist placement terminal failures

* fix(workers): refresh placement protocol clients

* refactor(workers): isolate error formatting

* fix: integrate cloud terminal state with current main

* chore(plugin-sdk): refresh API baseline

* refactor(ui): inline one-use cloud terminal-reason banner helper

Keeps the Control UI startup JS bundle inside its 317 KiB gzip budget
(the helper + type-only import tipped it by 16 bytes).

* refactor(ui): trim terminal-reason lookup to type-erased optional access

Recovers the last gzip byte of the Control UI startup budget
(324609 B vs the 324608 B limit).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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