Repository navigation
fix(gateway): recover failed cloud-worker placement to local - #114850
jokemanfire wants to merge 2 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 3, 2026, 12:45 PM ET / 16:45 UTC. ClawSweeper reviewWhat this changesThis 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 Review scores
Verification
How this fits togetherCloud-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
Decision needed
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
Findings
Agent review detailsSecurityNeeds attention: The patch introduces a concrete execution-boundary regression by automatically running cloud-worker session tools on the Gateway after failure. PR surfaceSource +51, Tests +230, Docs +1. Total +282 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest 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 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against dc1412c145e8. LabelsLabel justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
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.
d5f9d22 to
18412b3
Compare
|
Thanks for surfacing failed-placement recovery. Current |
What Problem This Solves
A cloud-worker session placement that reaches the terminal
failedstate has no recovery path, so a single dispatch/bootstrap failure permanently bricks the session.Once a placement is
failed:Worker turn rejected in placement failed(requireActivePlacementinsrc/gateway/worker-environments/worker-turn-admission.ts).sessions.dispatchrefuses it (session cannot dispatch from placement failed— onlylocal/reclaimedaccepted).sessions.reclaimrefuses it (session cannot stop cloud worker from placement failed— onlyactiveaccepted).failedterminal (failed: []insrc/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-sshprofile whose host lackednpmfailed 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
failedshould 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-workerfailedplacement back tolocalat turn admission, so the session keeps working locally.localis already dispatchable, so cloud dispatch can be requested again from the UI once the underlying cause is fixed.Safety guard (per review):
failedis also reachable fromreconciling, i.e. after a worker has run and may have produced unreconciled remote workspace changes. Reclaiming those tolocalwould bypass the worker→local reconciliation boundary and could discard or diverge remote work. The durable signal isactiveOwnerEpoch: it is set iff the placement reachedactiveworker ownership. The automatic recovery is therefore restricted tofailedplacements withactiveOwnerEpoch === null(dispatch/bootstrap failures). Post-worker failures keep worker ownership and continue to recover through the existing drain/reconcile path.placement-state.ts: allowfailed -> local(the only new outbound edge fromfailed).placement-store.ts:reclaimFailedToLocalstore method — CAS on state+generation, refuses during an active turn, and enforcesactiveOwnerEpoch === nullso a worker-owned failure can never be reset to local through this path. Clears worker metadata and the recovery diagnostic per thelocalrecord shape.worker-turn-launcher.ts: inexecuteTurn, reclaim afailedplacement tolocalonly whenactiveOwnerEpoch === null, then run locally; post-workerfailedplacements 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.tsfailedplacement tolocal, clears worker metadata, rejects wrong state/generation;failedplacement reached after worker ownership (activeOwnerEpochset), the post-worker safety case.node scripts/run-vitest.mjs src/gateway/worker-environments/worker-turn-launcher.test.tsfailedplacement runs locally and reclaims the placement;failedplacement — the turn is rejected and the placement staysfailed(regression coverage for the reconciliation boundary).placement-dispatch.test.tsandplacement-force-abandon.test.tsunchanged.pnpm tsgo:core,oxfmt,oxlintclean 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.