Skip to content

fix(gateway): recover failed cloud-worker placement to local - #114850

Closed
jokemanfire wants to merge 2 commits into
openclaw:mainfrom
jokemanfire:fix/worker-failed-placement-local-recovery
Closed

jokemanfire wants to merge 2 commits into
openclaw:mainfrom
jokemanfire:fix/worker-failed-placement-local-recovery

Conversation

@jokemanfire

@jokemanfire jokemanfire commented Jul 28, 2026 •

Copy link
Copy Markdown

What Problem This Solves

A cloud-worker session placement that reaches the terminal failed state has no recovery path, so a single dispatch/bootstrap failure permanently bricks the session.

Once a placement is failed:

  • Every turn rejects with Worker turn rejected in placement failed (requireActivePlacement in src/gateway/worker-environments/worker-turn-admission.ts).
  • sessions.dispatch refuses it (session cannot dispatch from placement failed — only local/reclaimed accepted).
  • sessions.reclaim refuses it (session cannot stop cloud worker from placement failed — only active accepted).
  • The reconcile sweep only tears down the environment; it cannot change placement state.
  • The state machine marks failed terminal (failed: [] in src/gateway/worker-environments/placement-state.ts).

So the only recovery today is direct state-store surgery (deleting the placement row). This contradicts the docs, which describe recovery that "can safely retry or reclaim the environment" (docs/gateway/cloud-workers.md).

Observed in the wild: a static-ssh profile whose host lacked npm failed bootstrap (Worker bootstrap failed), after which every dashboard turn for that session threw until the placement row was manually deleted.

Why This Change Was Made

failed should be recoverable for failures that occur before a worker takes ownership, not a permanent dead end. This adds a guarded recovery edge: reclaim a pre-worker failed placement back to local at turn admission, so the session keeps working locally. local is already dispatchable, so cloud dispatch can be requested again from the UI once the underlying cause is fixed.

Safety guard (per review): failed is also reachable from reconciling, i.e. after a worker has run and may have produced unreconciled remote workspace changes. Reclaiming those to local would bypass the worker→local reconciliation boundary and could discard or diverge remote work. The durable signal is activeOwnerEpoch: it is set iff the placement reached active worker ownership. The automatic recovery is therefore restricted to failed placements with activeOwnerEpoch === null (dispatch/bootstrap failures). Post-worker failures keep worker ownership and continue to recover through the existing drain/reconcile path.

  • placement-state.ts: allow failed -> local (the only new outbound edge from failed).
  • placement-store.ts: reclaimFailedToLocal store method — CAS on state+generation, refuses during an active turn, and enforces activeOwnerEpoch === null so a worker-owned failure can never be reset to local through this path. Clears worker metadata and the recovery diagnostic per the local record shape.
  • worker-turn-launcher.ts: in executeTurn, reclaim a failed placement to local only when activeOwnerEpoch === null, then run locally; post-worker failed placements fall through to the existing path.

Degradation to local is safe: sessions without a cloud placement already run locally, so this is a graceful fallback of the same agent work onto the gateway host, not a privilege change. A failed placement may leave an orphaned terminal environment row; that is reaped by the existing environment reconcile and is unchanged by this PR.

User Impact

A session whose cloud worker fails to dispatch/bootstrap (before any worker turn) no longer stops responding to every message. The next turn runs locally and the session returns to local; cloud dispatch can be re-requested. Failures that occur after a worker has run still go through workspace reconciliation so remote changes are not lost.

Evidence

  • node scripts/run-vitest.mjs src/gateway/worker-environments/placement-store-reclaim.test.ts
    • reclaims a pre-worker failed placement to local, clears worker metadata, rejects wrong state/generation;
    • refuses to reclaim a failed placement reached after worker ownership (activeOwnerEpoch set), the post-worker safety case.
  • node scripts/run-vitest.mjs src/gateway/worker-environments/worker-turn-launcher.test.ts
    • a turn against a pre-worker failed placement runs locally and reclaims the placement;
    • does not reclaim a post-worker failed placement — the turn is rejected and the placement stays failed (regression coverage for the reconciliation boundary).
  • placement-dispatch.test.ts and placement-force-abandon.test.ts unchanged.
  • pnpm tsgo:core, oxfmt, oxlint clean for the changed files.

Proof gap: a redacted live failed-bootstrap-to-local run is not yet attached; local CI-equivalent validation is mock/static. Happy to add a live repro on request — it requires building the gateway dist with the patch and a real cloud-worker profile whose bootstrap can be made to fail.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Jul 28, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 3, 2026, 12:45 PM ET / 16:45 UTC.

ClawSweeper review

What this changes

This PR changes pre-worker cloud-placement failures so the next session turn resets the placement to local and runs through the Gateway, while retaining reconciliation handling for placements that reached worker ownership.

Merge readiness

⛔ Blocked until real behavior proof is added - 11 items remain

Keep this PR open, but block merge: its automatic fallback moves a session whose agent tools were selected to run on a cloud worker onto the Gateway host without operator consent. Likely related people: Peter Steinberger is the only source-history routing candidate available from the shallow current-main attribution (low confidence).

Priority: P1
Reviewed head: 18412b326aa973380f461eb44412ff2f133423ad
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The branch has focused regression tests but is not merge-ready because it changes the selected execution security boundary and lacks real after-fix behavior proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body explicitly says the validation is mocked/static and no redacted after-fix failed-bootstrap-to-local runtime trace, terminal output, recording, or logs are attached; add proof only after the execution-boundary decision is resolved, with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🧂 unranked krab (1/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body explicitly says the validation is mocked/static and no redacted after-fix failed-bootstrap-to-local runtime trace, terminal output, recording, or logs are attached; add proof only after the execution-boundary decision is resolved, with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current main leaves failed placements terminal: The current transition table has no outbound edge from failed, and the turn provider routes any non-local/non-reclaimed placement through requireActivePlacement, which rejects a failed placement.
The proposed fallback executes locally: The local helper claims a local turn and invokes runLocal, so the new failed-placement branch would execute the session’s agent/tool loop on the Gateway host rather than merely repair placement metadata.
Documented cloud-worker boundary: Current documentation places the agent loop and tools on the cloud worker box; the design document explicitly calls the worker machine the isolation boundary and describes worker-to-local movement as requiring a stopped session and completed reconciliation.
Findings 1 actionable finding [P1] Keep cloud-worker execution on its selected boundary
Security Needs attention Automatic fallback bypasses the worker isolation boundary: The proposed failed-placement branch calls the local runner after a cloud-worker bootstrap failure. Cloud-worker documentation assigns agent tools to the remote worker, so this can execute the same workload on the Gateway host without an operator choosing that change.

How this fits together

Cloud-worker placement sends a session’s agent loop and tools to a throwaway remote worker while the Gateway retains transcript and durable placement state. The placement state machine decides whether a new turn is admitted remotely, reconciled, or—under this PR—rerouted to the Gateway’s local runner.

flowchart LR
  A[Session turn] --> B[Durable placement record]
  B --> C{Placement state}
  C -->|Active| D[Cloud worker agent and tools]
  C -->|Failed before activation| E[Proposed recovery decision]
  E --> F[Gateway-host local agent and tools]
  D --> G[Gateway transcript and workspace results]
  F --> G
Loading

Decision needed

Question Recommendation
Should a cloud-worker session that fails before activation automatically execute its next agent turn on the Gateway host, or must an operator explicitly choose local recovery? Require explicit local recovery: Add a visible recovery action for pre-worker failures that explains the placement change and only runs locally after operator confirmation.

Why: Current product documentation assigns agent tools to the cloud worker and identifies that machine as the isolation boundary, so code review cannot safely infer consent for silent execution on the Gateway host.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body explicitly says the validation is mocked/static and no redacted after-fix failed-bootstrap-to-local runtime trace, terminal output, recording, or logs are attached; add proof only after the execution-boundary decision is resolved, with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Keep cloud-worker execution on its selected boundary (P1) - Late finding: this unchanged head reclaims a failed cloud placement and immediately calls the Gateway-local runner. Cloud-worker docs put the agent loop and tools on the worker, and the design treats that machine as the isolation boundary, so a bootstrap error can silently move tool execution onto the Gateway host. Preserve the recovery path behind an explicit operator action (or retry remotely) rather than changing execution location automatically.
  • Resolve security concern: Automatic fallback bypasses the worker isolation boundary - The proposed failed-placement branch calls the local runner after a cloud-worker bootstrap failure. Cloud-worker documentation assigns agent tools to the remote worker, so this can execute the same workload on the Gateway host without an operator choosing that change.
  • Resolve merge risk (P1) - Merging would silently change a configured cloud-worker session into Gateway-host tool execution after a bootstrap failure, crossing the documented worker isolation boundary without an operator decision.
  • Resolve merge risk (P1) - The proposed reset clears durable worker metadata and the recovery diagnostic; even for pre-worker failures, maintainers need explicit agreement on whether an automatic placement downgrade is an acceptable compatibility contract.
  • Resolve merge risk (P1) - The PR body reports focused mocked/static checks only; it still lacks redacted after-fix runtime proof of a real failed bootstrap followed by the intended recovery path.
  • Complete next step (P2) - A maintainer must decide the cloud-worker security and compatibility contract before an automated repair can safely choose between explicit local recovery and remote-only retry.
  • Improve patch quality - Resolve whether cloud-worker failures may ever run tools on the Gateway without an explicit operator action.
  • Improve patch quality - Revise the recovery flow to match that decision and add focused regression coverage for the chosen contract.
  • Improve patch quality - Attach a redacted real failed-bootstrap recovery transcript, logs, or terminal output after the final behavior is implemented.

Findings

  • [P1] Keep cloud-worker execution on its selected boundary — src/gateway/worker-environments/worker-turn-launcher.ts:577-582
  • [high] Automatic fallback bypasses the worker isolation boundary — src/gateway/worker-environments/worker-turn-launcher.ts:577
Agent review details

Security

Needs attention: The patch introduces a concrete execution-boundary regression by automatically running cloud-worker session tools on the Gateway after failure.

PR surface

Source +51, Tests +230, Docs +1. Total +282 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 52 1 +51
Tests 2 230 0 +230
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 283 1 +282

Review metrics

Metric Value Why it matters
Execution-boundary change 1 automatic cloud-worker-to-Gateway fallback The branch changes where the session’s agent tools execute after failure, not only placement bookkeeping.
Production versus test delta production +53/-1, tests +230, docs +1 Most added code is regression coverage, but the production delta introduces an automatic execution-location change that needs a named security and product justification.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/placement-store-reclaim.test.ts, durable storage schema: src/gateway/worker-environments/placement-store.ts, durable storage schema: src/gateway/worker-environments/worker-turn-launcher.test.ts, durable storage schema: src/gateway/worker-environments/worker-turn-launcher.ts, unknown-data-model-change: src/gateway/worker-environments/placement-store-reclaim.test.ts, unknown-data-model-change: src/gateway/worker-environments/worker-turn-launcher.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Make recovery explicit before merge (recommended)
    Replace the automatic local execution branch with an operator-visible recovery action for pre-worker failures, preserving the existing worker-owned reconciliation fence.
  2. Accept Gateway fallback as product policy
    Land automatic fallback only after maintainers explicitly accept the cloud-worker-to-Gateway execution change and the PR supplies redacted live proof plus updated operator-facing documentation.
  3. Pause the fallback approach
    Close or defer this branch if the desired recovery cannot preserve the cloud-worker execution boundary without a broader recovery design.

Technical review

Best possible solution:

Keep pre-worker placement recovery, but make the worker-to-local transition a visible, operator-selected recovery action that retains the failure diagnostic; continue requiring drain and reconciliation for any worker-owned placement.

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

Yes for source reproduction, but not a live run: current main makes failed terminal and rejects it at worker-turn admission; the submitted branch adds a pre-admission local-run fallback. A real failed-bootstrap setup was not attached to the PR.

Is this the best way to solve the issue?

No: preserving the pre-worker recovery goal is sound, but silently moving a cloud-worker session’s tools to the Gateway is not the narrowest safe fix. An explicit operator recovery action or a remote-only retry path preserves the documented boundary.

Full review comments:

  • [P1] Keep cloud-worker execution on its selected boundary — src/gateway/worker-environments/worker-turn-launcher.ts:577-582
    Late finding: this unchanged head reclaims a failed cloud placement and immediately calls the Gateway-local runner. Cloud-worker docs put the agent loop and tools on the worker, and the design treats that machine as the isolation boundary, so a bootstrap error can silently move tool execution onto the Gateway host. Preserve the recovery path behind an explicit operator action (or retry remotely) rather than changing execution location automatically.
    Confidence: 0.94
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A failed cloud-worker bootstrap can either brick a live session today or, under this branch, silently reroute its tools to the Gateway host.
  • merge-risk: 🚨 compatibility: Existing configured cloud-worker sessions may begin running locally after an error, changing their established execution behavior without an explicit upgrade or consent path.
  • merge-risk: 🚨 session-state: The branch transitions durable failed placement records to local and clears worker metadata and the recovery diagnostic.
  • merge-risk: 🚨 security-boundary: Cloud-worker documentation places agent tools on the worker and identifies it as the isolation boundary, while this branch invokes the Gateway-local runner.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body explicitly says the validation is mocked/static and no redacted after-fix failed-bootstrap-to-local runtime trace, terminal output, recording, or logs are attached; add proof only after the execution-boundary decision is resolved, with private details redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [high] Automatic fallback bypasses the worker isolation boundary — src/gateway/worker-environments/worker-turn-launcher.ts:577
    The proposed failed-placement branch calls the local runner after a cloud-worker bootstrap failure. Cloud-worker documentation assigns agent tools to the remote worker, so this can execute the same workload on the Gateway host without an operator choosing that change.
    Confidence: 0.94

What I checked:

Likely related people:

  • Peter Steinberger: Available blame attributes the current placement transition and local execution helper to the grafted main-history snapshot; the checkout lacks deeper reachable history for stronger ownership attribution. (role: current-main source-history candidate; confidence: low; commits: e87fb689b533; files: src/gateway/worker-environments/placement-state.ts, src/gateway/worker-environments/worker-turn-launcher.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-07-28T01:59:07.012Z sha d5f9d224fb3af65d5763ed756779ce5c4a662c7a :: needs real behavior proof before merge. :: [P1] Preserve reconciliation before falling back from a failed placement
  • reviewed 2026-07-28T03:00:35.742Z sha 18412b3 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T00:17:10.064Z sha 18412b3 :: needs real behavior proof before merge. :: none

A failed cloud-worker placement was a terminal sink: turns rejected via
requireActivePlacement and sessions.dispatch/sessions.reclaim both refused it,
so one bootstrap/dispatch failure bricked the session until a manual
state-store repair. Reclaim failed placements to local at turn admission so the
session keeps working; cloud dispatch is available again from local once the
underlying cause is fixed.
Address review (openclaw#114850): reclaiming every failed placement to local also
covered failures reached from reconciling, where a worker may have produced
unreconciled workspace changes. Guard the recovery on activeOwnerEpoch so only
pre-worker (dispatch/bootstrap) failures auto-reclaim to local; post-worker
failures keep worker ownership and recover via drain/reconcile instead of a
local reset that could discard remote work. Encode the invariant in
reclaimFailedToLocal and add regression coverage for post-worker failures.
@jokemanfire
jokemanfire force-pushed the fix/worker-failed-placement-local-recovery branch from d5f9d22 to 18412b3 Compare July 28, 2026 02:56
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 2, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for surfacing failed-placement recovery. Current main already permits failed -> requested and failed -> local through the placement owner: explicit redispatch resets stale state, while sessions.reclaim retries and authorizes worker teardown before restoring local execution. placement-store.redispatch.test.ts and placement-dispatch-reclaim.test.ts cover both flows. The proposed automatic cloud-to-Gateway execution fallback is intentionally not adopted because it changes the operator-selected execution boundary. Closing as superseded by the canonical explicit recovery paths.

@steipete steipete closed this Aug 25, 2026
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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants