Skip to content

feat(sessions): recover offline device placements - #126284

Merged
steipete merged 18 commits into
mainfrom
steipete/runner-offline-recovery
Aug 20, 2026
Merged

steipete merged 18 commits into
mainfrom
steipete/runner-offline-recovery

Conversation

@steipete

@steipete steipete commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

When a paired device hosting an active session disconnected, the durable placement correctly remained active, but operators could not see that the runner was offline. The UI treated it as a generic cloud placement, ordinary Move/Stop tried to reconcile an unreachable workspace, and there was no safe choice between waiting for reconnect and explicitly continuing from the Gateway's last synced state.

Why This Change Was Made

This adds a Gateway-owned availability and recovery boundary without weakening durable placement ownership:

  • active device placements project a closed runner: { kind: "device", status: "available" | "offline" } fact from the exact worker-environment binding and current v5 node proof;
  • node disconnect, replacement, pairing invalidation, and generation changes publish real runner-availability edges and advance the sessions.list cache fence before clients refresh;
  • waiting is the safe default: remote workspace and worker authority remain intact, with explicit retry-after-reconnect guidance;
  • Continue on Gateway… is an explicit destructive choice. After confirmation, an exact-source durable move intent records abandonment, persists the held assistant partial, force-fences turn/tool/workspace-result/environment authority, and atomically returns the same session to local placement without replay;
  • exact retries join the existing abandonment intent before source validation or partial persistence, so a post-intent failure remains restart-safe and idempotent;
  • background recovery now reports only authoritative committed move transitions through canonical emitSessionsChanged, advancing the same session mutation/cache fence as interactive moves. Failed, waiting, and no-op attempts stay silent, and notification failure cannot unwind the durable transition;
  • terminal transcript updates carry producer-owned run identity through session.message, preventing stale or duplicate assistant rows after continuation;
  • shared startup/history and sidebar lineage reconciliation preserve newer canonical placement state instead of overwriting it with stale supplemental rows;
  • ordinary Move and Stop remain reconcile-first. Offline Stop is disabled with an actionable reconnect-or-continue reason because unsynced device files and in-flight work may be lost.

The move table gains one bare nullable abandon_source INTEGER column through the existing lazy additive-column mechanism. NULL means false; older readers can omit it safely. SQLite user_version remains 9 and the Gateway protocol remains v4.

Production is +1,277/−462, net +815; tests are +3,863/−97, net +3,766. Tooling is net +27, documentation net +41, generated files net +27, and configuration net −1. Production growth is the explicit data-loss authorization boundary, restart-safe intent, authority closure, process-current availability projection, canonical freshness ownership, and transcript run identity; existing move, abandonment, session-event, and cache owners are reused rather than duplicated.

AI-assisted: yes. I reviewed the complete placement lifecycle, node-currentness proof, exact-source CAS, restart recovery, authority fencing, transcript ownership, SQLite compatibility, UI freshness, generated protocol models, tests, and real paired-device behavior.

User Impact

When a device hosting a session goes offline, both open panes now show Device offline and wait by default. Operators can retry after reconnect, or choose Continue on Gateway… after acknowledging that unsynced device changes and in-flight work may be lost. The session identity and transcript remain the same, the abandoned partial is preserved once, and the continued local reply appears once.

Evidence

  • Exact reviewed head: 3801ebf7ca785b39416baac6c31d384b5aec8e19.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32385684953 — 245 checks complete, none failing or pending.
  • Final direct AWS paired-node run: https://crabbox.openclaw.ai/portal/runs/run_fa7bac8554d6 — all ten checks passed on a real paired current-v5 session host with two available slots.
  • Offline propagation was 460 ms; explicit Gateway continuation was 379 ms, exactly one request with a newly minted joined:false intent.
  • The held partial was durable before the move response. Environment, claim, tool, workspace, intent, and credential authority were closed before response; the restored stale worker was rejected as invalid-credential.
  • No stale final, interrupted-turn replay, stale workspace import, duplicate assistant row, unkeyed duplicate, or duplicate badge occurred. Both panes remained singular after full history reload.
  • Canonical list revision advanced from 2 to 4; both panes moved from offline active placement to local placement without reload.
  • The review-found later-sweep defect has a captured pre-fix failure (expected ... called once, got 0 after durable local completion) and exact-head deterministic coverage: 26 executions across the move owner and Gateway event/cache-fence boundary. A live one-shot teardown fault would require modifying immutable production source/private closures or owner SQLite; it was therefore not faked. The full real owner flow plus the exact first-failure/later-sweep regression is the strongest honest proof.
  • Final recovery repair: 248 focused tests across 18 project/file combinations, full changed-file core/core-test gate, production/test typechecks, formatting, lint, import cycles, database guards, and git diff --check passed.
  • Whole-branch Codex autoreview completed with no accepted P0/P1 findings.
  • Same-version SQLite proof covers lazy creation, previous-reader open/use, candidate reopen, unchanged user_version, maintenance, and generated Kysely types.
  • Frozen runtime hashes remained unchanged through proof; all screenshots and the video were inspected; the AWS lease and every owned process were released.

Visual proof

Before: no offline runner distinction or recovery action.

Before: offline device treated as generic cloud placement

Exact-head offline state in two panes:

Exact-head offline device recovery state

Explicit destructive confirmation:

Exact-head Continue on Gateway confirmation

Final singular partial and local reply in both panes:

Exact-head recovered local session in two panes

runner-offline-recovery-3801ebf7.webm

@clawsweeper

clawsweeper Bot commented Aug 19, 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 plugin: file-transfer labels Aug 19, 2026
@steipete
steipete marked this pull request as ready for review August 19, 2026 09:43
@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Aug 19, 2026
@clawsweeper clawsweeper Bot added 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. 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 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 20, 2026, 11:27 AM ET / 15:27 UTC.

ClawSweeper review

What this changes

Adds offline paired-device session recovery with an explicit, destructive option to continue the same session on the Gateway from its last synced state.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer review. The prior recovery-event blocker is addressed at the current head; the remaining merge work is exact-head paired-node validation and normal protected-label review.

Priority: P1
Reviewed head: 3801ebf7ca785b39416baac6c31d384b5aec8e19

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The current head addresses the prior functional blocker with focused event-path coverage; exact-head paired-node evidence remains the main confidence upgrade.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor proof gate, though its promised exact-head paired-node proof remains valuable before landing.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor proof gate, though its promised exact-head paired-node proof remains valuable before landing.
Evidence reviewed 5 items Prior P1 is resolved: Recovered move transitions now obtain the session-change context and emit a scoped sessions.changed event after the durable transition.
Recovery event coverage: The new test advances the later periodic sweep, verifies the sessions.changed payload, and checks the session mutation-version cache fence.
Abandonment authority boundary: The owner validates the exact active placement and offline runner, force-fences the remote environment, then requires failed fenced state before transitioning to local.
Findings None None.
Security None None.

How this fits together

Gateway session placement owns the durable location and recovery state of a session. Current node connectivity projects device availability into session responses and Control UI, while an explicit operator action can fence the offline device owner and return the session locally.

flowchart LR
  Device[Paired device runner] --> Availability[Runner availability]
  Availability --> Gateway[Gateway placement state]
  Gateway --> Decision{Device offline}
  Decision --> Wait[Wait for reconnect]
  Decision --> Continue[Continue on Gateway]
  Continue --> Recovery[Durable abandonment recovery]
  Recovery --> UI[Session event and Control UI]
  UI --> Operator[Operator sees current state]
Loading

Before merge

  • Resolve merge risk (P1) - The nullable durable abandonment bit changes recovery semantics for existing state databases; maintainers should retain the stated older-reader and candidate-reopen proof before landing.
  • Resolve merge risk (P1) - The PR body still says exact-head paired-node disconnect, continuation, and stale-node proof will be added; screenshots demonstrate the UI but not that full authority-recovery path.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test growth production +436, tests/support +849, docs +41, generated types +1 The feature adds a durable destructive recovery boundary spanning Gateway state, protocol projection, and Control UI behavior.

Stored data model

Persistent data-model change detected: database schema: docs/reference/database-schemas.md, durable storage schema: src/gateway/worker-environments/transcript-commit.ts, serialized state: packages/gateway-client/src/session-projection-conformance.test.ts, serialized state: packages/gateway-protocol/src/schema/session-placement.test.ts, serialized state: packages/gateway-protocol/src/schema/session-placement.ts, serialized state: scripts/lib/control-ui-i18n-catalog.ts, and 34 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Validate the paired-node recovery boundary (recommended)
    Before merge, record exact-head evidence that disconnect, explicit continuation, stale-node fencing, and the resulting session update all occur in sequence.

Technical review

Best possible solution:

Keep the Gateway-owned durable abandonment flow, then land it only after exact-head paired-node recovery proof and required CI validate the destructive path end to end.

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

No high-confidence live reproduction was run here; source and focused tests establish the recovery path, while exact-head paired-node evidence remains outstanding.

Is this the best way to solve the issue?

Yes. The implementation keeps recovery at the Gateway placement owner, records abandonment durably, and uses the existing session-change event path for UI convergence.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • 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: This maintainer-authored PR is outside the external-contributor proof gate, though its promised exact-head paired-node proof remains valuable before landing.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Offline paired-device recovery affects active session continuity and operator-visible placement state.
  • merge-risk: 🚨 compatibility: The PR adds a same-version nullable move-state column and changes recovery behavior for existing state databases.
  • merge-risk: 🚨 session-state: The feature transfers a session from a fenced offline device owner to local Gateway execution.
  • 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: This maintainer-authored PR is outside the external-contributor proof gate, though its promised exact-head paired-node proof remains valuable before landing.

Evidence

What I checked:

Likely related people:

  • steipete: History attributes the original Gateway/session-move feature and the current recovery-event repair to this contributor. (role: feature owner and recent area contributor; confidence: high; commits: f59e945013db, 3801ebf7ca78; files: src/gateway/server-worker-placement-startup.ts, src/gateway/worker-environments/placement-move-service.ts)

Rank-up moves

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

  • Add redacted exact-head paired-node evidence for disconnect, continuation, stale-node fencing, and UI refresh.

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 (17 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-19T23:59:37.953Z sha 0e211f0 :: found issues before merge. :: [P1] Join the durable abandonment intent before source validation
  • reviewed 2026-08-20T00:19:55.620Z sha 0e211f0 :: found issues before merge. :: [P1] Join the durable abandonment intent before source validation
  • reviewed 2026-08-20T03:44:16.470Z sha 690ce1324a70ddc79f52b67f98b0b7f7bcd71c91 :: found issues before merge. :: [P1] Join the durable abandonment intent before validating its source
  • reviewed 2026-08-20T04:50:00.992Z sha 95c344b :: needs changes before merge. :: [P1] Join the abandonment intent before validating its source
  • reviewed 2026-08-20T07:55:12.249Z sha 669e167 :: needs changes before merge. :: [P1] Join the abandonment intent before source validation
  • reviewed 2026-08-20T10:30:15.535Z sha c687847 :: needs changes before merge. :: [P1] Join the durable abandonment intent before validating its source
  • reviewed 2026-08-20T12:49:43.012Z sha ed6d7145ab962596f6589cb8ab42dc2c0936bb48 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-20T13:46:39.578Z sha 6f6965d :: found issues before merge. :: [P1] Publish completed abandonment recovery to session clients

@steipete
steipete force-pushed the steipete/runner-offline-recovery branch from d0bccda to 2fc3fff Compare August 19, 2026 10:16
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 19, 2026
@steipete
steipete force-pushed the steipete/runner-offline-recovery branch from 05851fe to a75c425 Compare August 19, 2026 10:58
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 19, 2026
@steipete
steipete force-pushed the steipete/runner-offline-recovery branch from a75c425 to abf982d Compare August 19, 2026 12:09
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Aug 19, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 19, 2026
@steipete
steipete force-pushed the steipete/runner-offline-recovery branch from 697687a to 98a7290 Compare August 19, 2026 13:43
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 19, 2026
@steipete
steipete force-pushed the steipete/runner-offline-recovery branch from ed6d714 to 6f6965d Compare August 20, 2026 13:38
@clawsweeper clawsweeper Bot added 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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Aug 20, 2026
@clawsweeper clawsweeper Bot added 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 20, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Final exact-head proof is complete for 3801ebf7ca785b39416baac6c31d384b5aec8e19.

  • CI: https://github.com/openclaw/openclaw/actions/runs/32385684953 — all 245 checks complete and green.
  • Direct AWS paired-node proof: https://crabbox.openclaw.ai/portal/runs/run_fa7bac8554d6 — all ten checks passed.
  • Offline propagation: 460 ms. Gateway continuation: 379 ms.
  • Exactly one sessions.move request; first intent was newly minted with joined:false.
  • Event order: inventory offline 73 → session offline 74 → durable partial 119 → move notification 120 → failed placement list 128 → local move notification 130 → fenced move response 131 → authoritative local list 139.
  • Canonical list revision advanced 2 → 4; both open panes changed from offline active placement to local placement without reload.
  • Environment, turn claim, tool state, staged workspace authority, move intent, and environment credential were closed before response. The restored stale worker was rejected as invalid-credential.
  • Held partial: run runner-held-d36066a0-d9e6-4571-a6ae-3008ec08f7fe, message b709344c-2d66-41c5-8a74-168f515c8ef3 — exactly once in each pane and after reload.
  • Local final: run runner-gateway-local-ce4b671d-2b07-49ba-b4e2-42a296fb3118, message 88eaee81 — exactly once in each pane and after reload.
  • No stale final, replay, stale workspace import, duplicate assistant row, unkeyed duplicate, or duplicate badge.

The current-head P1 is repaired at the lifecycle owner. A pre-fix regression demonstrated that a later durable recovery completed locally with zero notifications. Exact-head tests now prove: the first failed recovery retains the exact intent and emits nothing; a later sweep completes the same intent; only then does canonical sessions.changed publish and advance the session mutation/cache fence. The 26 deterministic owner-boundary executions pass. Injecting that one-shot teardown fault into the immutable live paired-device runtime would require modifying production source/private closures or owner SQLite, so I did not fake that leg; the real paired-device owner flow above and deterministic first-failure/later-sweep coverage are the stated proof boundary.

All captures were inspected, frozen dist/UI hashes remained unchanged, and the fresh AWS lease plus every owned process were released.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit bbbd705 into main Aug 20, 2026
253 checks passed
@steipete
steipete deleted the steipete/runner-offline-recovery branch August 20, 2026 17:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 21, 2026
* feat(sessions): recover offline device placements

* chore(protocol): refresh session placement models

* perf(ui): lazy-load session placement recovery

* test(ui): remove dropdown timing assertion

* test(ui): await committed cloud recovery route

* fix(sessions): complete explicit abandonment locally

* fix(sessions): fence lists by runner availability

* fix(ui): preserve canonical session freshness

* fix(sessions): preserve recovery contracts after rebase

* test(ui): await durable cloud recovery entry

* test(gateway): complete current runner fixtures

* fix(gateway): publish runner availability edges

* fix(ui): preserve shared session freshness

* fix(ui): preserve canonical sidebar session state

* fix(sessions): preserve abandoned partials and run-owned replies

* fix(sessions): resume durable abandonment retries

* test(gateway): compose provisioning replay with runner availability

* fix(sessions): publish recovered move transitions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR 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. P1 High-priority user-facing bug, regression, or broken workflow. plugin: file-transfer rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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