Skip to content

refactor: add restart recovery lifecycle seam - #93735

Merged
jalehman merged 1 commit into
openclaw:mainfrom
jalehman:clawdbot-d02.1.9.1.36/31b-main-session-restart-recovery-seam
Jun 18, 2026
Merged

jalehman merged 1 commit into
openclaw:mainfrom
jalehman:clawdbot-d02.1.9.1.36/31b-main-session-restart-recovery-seam

Conversation

@jalehman

@jalehman jalehman commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a storage-neutral restart-recovery lifecycle accessor for row replacement work.
  • Migrates main-session restart recovery write paths off direct whole-store writer calls.
  • Preserves current file-backed restart lock, startup orphan, failed-session, resume, pending-final-delivery, and stale-lock behavior.
  • Adds ratchet coverage so migrated restart-recovery code cannot reintroduce legacy session store writers.
  • Intentionally out of scope: SQLite runtime flip, JSON fallback, doctor migration, plugin SDK surface, and broader restart recovery cleanup.

Linked context

Related #88838

Requested by maintainer Path 3 task clawdbot-d02.1.9.1.36.

Real behavior proof

Behavior addressed: Main-session restart recovery lifecycle writes go through the storage-neutral accessor seam while preserving file-backed stale-lock restart behavior.

Real environment tested: Local OpenClaw LaunchAgent Gateway on macOS from SHA d58eb87, OpenClaw 2026.6.8, gateway port 18789, LaunchAgent pid 79932 after restart.

Exact steps or command run after this patch:

pnpm build
pnpm openclaw --version
# Seeded one synthetic live main-agent row and stale transcript lock:
# session key: agent:main:proof-93735-20260617201822
# store: $OPENCLAW_STATE_DIR/agents/main/sessions/sessions.json
# transcript: $OPENCLAW_STATE_DIR/agents/main/sessions/proof-93735-20260617201822.jsonl
# backup: /tmp/openclaw-pr-93735-proof-93735-20260617201822-sessions.backup.json
pnpm openclaw gateway restart
pnpm openclaw gateway health --json
pnpm openclaw gateway status --json
# Waited 10 seconds for the restart-recovery sidecar, inspected the seeded row and lock, then removed the seeded row/transcript/lock.

Evidence after fix: Gateway restarted LaunchAgent pid 79932 from the rebuilt dist; /healthz returned ok=true in 65ms with 11 plugins loaded; gateway status RPC was ok and reported OpenClaw 2026.6.8 from SHA d58eb87. The seeded restart-recovery row changed from status=running with a stale .jsonl.lock to status=failed, abortedLastRun=true, endedAt and updatedAt persisted as numbers, and lockExists=false. Cleanup verification after proof returned rowExists=false, transcriptExists=false, and lockExists=false.

Observed result after fix: The real Gateway startup stale-lock sweep exercised the migrated restart-recovery accessor path and persisted the expected restart-recovery failure marker without leaving the proof fixture behind.

What was not tested: SQLite runtime flip, doctor migration, plugin SDK compatibility, and a real interrupted model turn with provider output; this PR remains a file-backed lifecycle seam slice.

Tests and validation

Commands run:

  • node scripts/run-vitest.mjs src/config/sessions/session-accessor.test.ts src/agents/main-session-restart-recovery.test.ts test/scripts/check-session-accessor-boundary.test.ts
  • node scripts/check-session-accessor-boundary.mjs
  • node scripts/run-oxlint.mjs src/config/sessions/session-accessor.ts src/config/sessions/session-accessor.test.ts src/agents/main-session-restart-recovery.ts test/scripts/check-session-accessor-boundary.test.ts
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.test.src.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/test-src.tsbuildinfo
  • git diff --check
  • pnpm exec oxfmt --check --threads=1 src/config/sessions/session-accessor.ts src/config/sessions/session-accessor.test.ts src/agents/main-session-restart-recovery.ts scripts/check-session-accessor-boundary.mjs test/scripts/check-session-accessor-boundary.test.ts
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base upstream/main

Regression coverage added:

  • Accessor seam test proving restart-recovery replacement rows are detached and only explicit replacements persist.
  • Boundary ratchet coverage for src/agents/main-session-restart-recovery.ts.

Risk checklist

Did user-visible behavior change? No

Did config, environment, or migration behavior change? No

Did security, auth, secrets, network, or tool execution behavior change? No

Highest-risk area: Restart recovery can affect interrupted main-session resume/failure state.

Risk mitigation: The existing restart recovery regression suite still passes, and the accessor preserves writer-lock, skip-maintenance, require-write-success, pending-final-delivery, stale/current-row, and exact-key replacement semantics.

Current review state

Next action: Draft review.

Still waiting on: Maintainer review and CI.

Bot/reviewer comments addressed: None yet.

SQLite follow-up: implement the same applyRestartRecoveryLifecycle semantics as transaction-sized row selection/replacement in the SQLite session accessor backend when the runtime flip slice reaches restart recovery.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jun 16, 2026
@jalehman jalehman self-assigned this Jun 18, 2026
@jalehman
jalehman force-pushed the clawdbot-d02.1.9.1.36/31b-main-session-restart-recovery-seam branch 2 times, most recently from c99f715 to ceac137 Compare June 18, 2026 03:14
@jalehman
jalehman force-pushed the clawdbot-d02.1.9.1.36/31b-main-session-restart-recovery-seam branch from ceac137 to d58eb87 Compare June 18, 2026 03:20
@jalehman
jalehman marked this pull request as ready for review June 18, 2026 03:25
@jalehman
jalehman merged commit fd8e3bf into openclaw:main Jun 18, 2026
217 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant