Repository navigation
fix(gateway): allow draining pending workspace result when abandoning placement move source - #146205
MasterSwords1 wants to merge 4 commits into
Conversation
… placement move source
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 3:51 PM ET / 19:51 UTC (Revision 4). ClawSweeper reviewWhat this changesRepairs Continue on Gateway so explicitly abandoned offline-device sessions can discard pending workspace results and recover local ownership, including after restart. Merge readiness✅ Ready for maintainer review This fix remains necessary: current main and the latest release retain the reported drain rejection. The production-path evidence supports the repair, and no introduced blocking defect was found. Priority: P0 Review scores
Verification
How this fits togetherGateway placement management decides where a session runs and retains unfinished worker results. Confirmed abandonment passes through its durable move lifecycle to revoke the old worker claim and return the session to the Gateway. flowchart TD
A[Continue on Gateway] --> B[Validate exact offline device]
B --> C[Persist abandonment and drain]
D[Gateway startup recovery] --> C
C --> E[Retire pending result and worker claim]
E --> F[Restore local session ownership]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +13, Tests +687. Total +700 across 8 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep confirmed abandonment within the existing move owner, retiring only its exact pending result and claim while preserving reconcile-first behavior for ordinary moves. Do we have a high-confidence way to reproduce the issue? Yes, from source: an active placement with a pending workspace result reaches the unconditional drain rejection before abandonment on current main. The linked report supplies a live failure; this review did not execute it. Is this the best way to solve the issue? Yes. The patch enables the existing explicitly destructive recovery path without weakening ordinary drain protection or adding another persistence owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a1e5797a4268. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
…ery with pending results
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…rocess restart recovery
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…tEnvironment types
Related: #146012. Supersedes #146205 by @MasterSwords1. Thanks @jalehman for the report. The contributor's four commits retain their authorship. ## What Problem This Solves **Continue on Gateway** fails after confirmation when an offline device session has a pending workspace result, leaving the session blocked. ## User Impact Confirmed abandonment returns the session to local use. A fresh turn completes, and normal deletion archives its transcript. Ordinary moves still preserve pending results. Unsynced device work can be lost, as the existing confirmation warns. ## Why This Change Was Made The durable move intent is the single owner of the abandonment decision. It permits the pending-result drain; result recovery yields to it, and existing teardown retires the exact result and claim. The placement coordinator orders moves against recovery. No schema, migration, configuration, protocol, or dependency changes. Tests now cover the full user flow and explicit fixture cleanup, removing overlapping handler tests and shutdown-error suppression. The correction commits remove 269 net lines from the contributor version. Remaining growth supplies three real Gateway regressions. ## Evidence Real Gateway capture, using the same exact-source `sessions.move` request with `target: {kind: "gateway"}` and `abandonSource: true`: | Main `a2b2391e3538` | This change | | --- | --- | | `UNAVAILABLE: Cannot drain session … with a pending cloud workspace result` | `ok: true`, `placement.state: local` | | Original claim and pending result remain | Pending result and move intent gone; old claim/result rejected | | Recovery action blocked | One fresh reply: `RECOVERED_SESSION_OK`; deletion returns `deleted: true` with a readable transcript archive | Commands: `pnpm openclaw gateway call sessions.move`, then `chat.send`, `agent.wait`, `chat.history`, and `sessions.delete`. The ordinary-move negative case still rejects. The old device cleanup record remains until its exact stop is acknowledged. Fresh two-parent merge proof: candidate `0801a11ab50c` + main `6f58faf3eb0d` → `ec30ae86f2439`. The repository CI test runner (`node --import tsx scripts/ci-run-node-test-shard.mts`) passed **146 tests in 7 files**, using the Gateway core, server, and isolated-server configurations. Coverage includes move/store ownership, forced abandonment, recovery coordination, startup, fresh turns, and archived deletion. Formatting, changed-file lint, line limits, assertion safety, unused exports, and architecture checks pass. Typechecking remains with CI. Startup cases prove **database reopen plus in-process Gateway startup**, including an already-failed placement with a different error. No physical-device shutdown or operating-system crash claim. ## Reviewed proof scope The read-only review found no blocking source or test correction at `0801a11ab50cdf94e514951b36b68793bb58a0e5`. - The real Gateway proof covers confirmed abandonment, one fresh reply, and exact-session deletion with a readable transcript archive. Ordinary moves still reject the pending result. - The standalone capture used the same three production blobs as the final head. All three maintained full-flow cases also passed on merge `ec30ae86f24390d69e7af606aa7c50cc9683107a`, with candidate `0801a11ab50cdf94e514951b36b68793bb58a0e5` and main `6f58faf3eb0d45cd78a198ce2d838d601deceec5` as parents. The selected suite passed 146 tests in seven files. - Recovery coverage means database reopen plus in-process Gateway startup, including an already-failed placement with a different error. It does not claim a browser click, an operating-system crash, or physical-device shutdown. - The old device cleanup record remains until its exact stop is acknowledged. The tests use an explicit synthetic acknowledgement only during teardown. - The original contributor's four commits retain their authorship. Credit remains with @MasterSwords1 for #146205 and @jalehman for #146012. Closure of #146205 remains a landing step. ## Consumers Confirmed `sessions.move` and startup recovery share the durable abandonment decision. Fresh chat turns and session deletion consume the resulting local placement; ordinary moves retain their existing pending-result guard. Session-change events refresh the existing placement projection. Co-authored-by: MasterSwords1 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
|
Thanks @MasterSwords1! Proof: Superseded by merged #147390, whose PR history keeps your four commits under your authorship. The adopted fix passes real Gateway recovery, a fresh reply, and archived deletion.
|
…law#147390) Related: openclaw#146012. Supersedes openclaw#146205 by @MasterSwords1. Thanks @jalehman for the report. The contributor's four commits retain their authorship. ## What Problem This Solves **Continue on Gateway** fails after confirmation when an offline device session has a pending workspace result, leaving the session blocked. ## User Impact Confirmed abandonment returns the session to local use. A fresh turn completes, and normal deletion archives its transcript. Ordinary moves still preserve pending results. Unsynced device work can be lost, as the existing confirmation warns. ## Why This Change Was Made The durable move intent is the single owner of the abandonment decision. It permits the pending-result drain; result recovery yields to it, and existing teardown retires the exact result and claim. The placement coordinator orders moves against recovery. No schema, migration, configuration, protocol, or dependency changes. Tests now cover the full user flow and explicit fixture cleanup, removing overlapping handler tests and shutdown-error suppression. The correction commits remove 269 net lines from the contributor version. Remaining growth supplies three real Gateway regressions. ## Evidence Real Gateway capture, using the same exact-source `sessions.move` request with `target: {kind: "gateway"}` and `abandonSource: true`: | Main `a9d0dc39c9e8` | This change | | --- | --- | | `UNAVAILABLE: Cannot drain session … with a pending cloud workspace result` | `ok: true`, `placement.state: local` | | Original claim and pending result remain | Pending result and move intent gone; old claim/result rejected | | Recovery action blocked | One fresh reply: `RECOVERED_SESSION_OK`; deletion returns `deleted: true` with a readable transcript archive | Commands: `pnpm openclaw gateway call sessions.move`, then `chat.send`, `agent.wait`, `chat.history`, and `sessions.delete`. The ordinary-move negative case still rejects. The old device cleanup record remains until its exact stop is acknowledged. Fresh two-parent merge proof: candidate `0801a11ab50c` + main `3eafa82bb6c6` → `ec30ae86f2439`. The repository CI test runner (`node --import tsx scripts/ci-run-node-test-shard.mts`) passed **146 tests in 7 files**, using the Gateway core, server, and isolated-server configurations. Coverage includes move/store ownership, forced abandonment, recovery coordination, startup, fresh turns, and archived deletion. Formatting, changed-file lint, line limits, assertion safety, unused exports, and architecture checks pass. Typechecking remains with CI. Startup cases prove **database reopen plus in-process Gateway startup**, including an already-failed placement with a different error. No physical-device shutdown or operating-system crash claim. ## Reviewed proof scope The read-only review found no blocking source or test correction at `0801a11ab50cdf94e514951b36b68793bb58a0e5`. - The real Gateway proof covers confirmed abandonment, one fresh reply, and exact-session deletion with a readable transcript archive. Ordinary moves still reject the pending result. - The standalone capture used the same three production blobs as the final head. All three maintained full-flow cases also passed on merge `ec30ae86f24390d69e7af606aa7c50cc9683107a`, with candidate `0801a11ab50cdf94e514951b36b68793bb58a0e5` and main `3eafa82bb6c63303b7d4341ce8cbe82b61b98c9c` as parents. The selected suite passed 146 tests in seven files. - Recovery coverage means database reopen plus in-process Gateway startup, including an already-failed placement with a different error. It does not claim a browser click, an operating-system crash, or physical-device shutdown. - The old device cleanup record remains until its exact stop is acknowledged. The tests use an explicit synthetic acknowledgement only during teardown. - The original contributor's four commits retain their authorship. Credit remains with @MasterSwords1 for openclaw#146205 and @jalehman for openclaw#146012. Closure of openclaw#146205 remains a landing step. ## Consumers Confirmed `sessions.move` and startup recovery share the durable abandonment decision. Fresh chat turns and session deletion consume the resulting local placement; ordinary moves retain their existing pending-result guard. Session-change events refresh the existing placement projection. Co-authored-by: MasterSwords1 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #146012
What Problem This Solves
Resolves an issue where attempting to execute Continue on Gateway (
sessions.moveRPC withtarget: { kind: "gateway" }, abandonSource: true) on a session with an offline or unreachable paired device failed with:When a paired device worker goes offline after completing a turn but before its workspace results are reconciled, an entry remains in
worker_workspace_pending_resultsandturn_claim_*remains onworker_session_placements. The operator accepts data loss in the Control UI and initiates "Continue on Gateway" to regain control.However,
beginPlacementMoveinsrc/gateway/worker-environments/placement-move-intent.tscalleddrainWorkerSessionPlacementwithout passingallowPendingWorkspaceResult: true. BecausedrainWorkerSessionPlacementstrictly guards against draining sessions with pending results (placement-drain.ts:37), the move was rejected during the initial drain transition beforeoptions.abandonSourceorplacement-force-abandon.tscould execute, leaving the session permanently blocked.Furthermore, during Gateway startup/crash recovery (
placement-dispatch-recovery.ts),recoverPendingWorkspaceResultsruns beforerecoverPlacementMoves. If an abandonment move intent was in flight when the Gateway crashed or restarted,recoverPendingWorkspaceResultswould attempt remote tunnel reconnection and workspace reconciliation on a worker that was meant to be abandoned, or fail the placement with a genericworkerDisappearanceErrorrather than preserving the pending result fence forrecoverPlacementMovesto retire underFORCED_WORKER_ABANDONMENT_ERROR.Why This Change Was Made
Permit Pending Result Draining on Move Abandonment:
In
src/gateway/worker-environments/placement-move-intent.ts(beginPlacementMove), we pass...(abandonSource ? { allowPendingWorkspaceResult: true } : {})todrainWorkerSessionPlacement. When the operator explicitly requests source abandonment, draining the active placement is permitted so the move lifecycle can proceed to force-abandonment and transition the session to Gatewaylocalplacement. Non-abandoning moves continue to omit this flag and strictly reject draining when unrecovered results exist.Yield Ownership During Gateway Recovery:
In
src/gateway/worker-environments/placement-dispatch-pending-results.ts(recoverPendingWorkspaceResults), we checkplacements.getPlacementMove(pending.sessionId)?.abandonSourceat the top of the pending results loop. If an abandonment move owns the session,recoverPendingWorkspaceResultsskips processing that pending result, allowingrecoverPlacementMovesto safely own teardown, retire the pending result underFORCED_WORKER_ABANDONMENT_ERROR, clear turn claims, and restore the session tostate: "local".Fence Recovery Error Alignment:
In
src/gateway/worker-environments/placement-force-abandon.ts(forceAbandonWorkerEnvironment), if the placement is already instate: "failed"but with a different recovery error,placements.failis called withrecoveryError: FORCED_WORKER_ABANDONMENT_ERRORso the contract required byisForceAbandonedWorkerPlacementis satisfied.User Impact
worker_workspace_pending_resultsand staleturnClaimrows are cleanly retired, and the session returns to an active, responsivelocalplacement on the Gateway.Evidence
1. Live Running Gateway Server WebSocket RPC & Process Restart Recovery (
server.worker-placement-startup-context.test.ts)Directly executes against a real live running Gateway server over WebSocket (
startGatewayServerHarness) and through actual Gateway process startup and restart recovery, proving:sessions.moveAbandonment: An offline paired device placement with an existing pending workspace result (worker_workspace_pending_results) and active turn claim receives a livesessions.moveRPC request (expected: active, target: { kind: "gateway" }, abandonSource: true). The live running Gateway successfully completes abandonment, returnspayload: { ok: true, key, sessionId, placement: { state: "local" } }, clearsworker_workspace_pending_results, and revokes the stale turn claim.abandonSource: true, statedraining) and pending workspace result survives a crash/process shutdown. An actual Gateway process starts up, and during startup reconciliation (recoverGatewayWorkerPlacementWorkspaces/recoverPendingWorkspaceResults/recoverPlacementMoves), recovers the abandoned placement directly tostate: "local", clearsworker_workspace_pending_results, closes the turn claim, and settles the move intent.2. Gateway RPC
sessions.moveAbandonment & Restart Recovery (sessions.dispatch.abandonment.test.ts)Directly exercises the Gateway's RPC entrypoint
sessions.move(sessionDispatchHandlers["sessions.move"]) against real SQLite state databases and the full Gateway dispatch service, verifying:localuponsessions.movewithabandonSource: true, clearsworker_workspace_pending_results, and revokes stale turn claims.service.reconcile()completes the persisted abandonment tolocalwithout remote reconciliation.3. Full Gateway Core Placement Test Suites
All 23 placement abandonment integration tests pass:
All 18 placement move store tests pass:
4. Standalone Verification Script Execution (All 8 Scenarios Passing)
Executed
verify-placement-abandon-pending-result.tsagainst real SQLite databases, verifying store, service, negative authority, and gateway restart reconciliation:5. Standalone Verification Harness Implementation
Inspectable Standalone Verification Script Source Code
5. Typecheck and Lint
scripts/run-tsgo.mts -b test/tsconfig/tsconfig.core.test.gateway-other.json test/tsconfig/tsconfig.core.test.gateway-server.json: Exit code 0, 0 errors.oxlint: Passed on all modified source and test files with 0 warnings and 0 errors.