Skip to content

fix(doctor): resume schema repair after interrupted migration - #159345

Merged
steipete merged 1 commit into
mainfrom
upd/upd-startup-migration-lease-lost
Sep 27, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-startup-migration-lease-lost

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #158114

What Problem This Solves

Fixes an immediate doctor --fix retry refusing agent schema/media repair after the previous migration process was killed.

User Impact

Operators can rerun Doctor after an interrupted migration and start the Gateway once repair completes. Pending schema changes roll back transactionally, session data stays intact, and the existing pre-migration snapshots remain available. Leases written by older versions without process identity still wait for their existing expiry.

Why This Change Was Made

Current main already moved legacy startup migration into Doctor (#151025); the older report's indefinitely repeated five-minute startup-lease failure was not reproduced on this branch. A Linux SIGKILL replay exposed a remaining recovery gap: the 60-second agent-maintenance lease had no process identity, so the next Doctor attempt refused it as held despite its owner having exited.

The schema/media migration owner now explicitly declares that its writers cannot outlive its process. Lease acquisition records its host, PID, and process start identity and reuses the existing dead-owner reclamation helper inside the admitted write transaction. Other lease users may own surviving Git, installer, or plugin subprocesses, so they retain their existing expiry behavior. No schema, configuration, CLI, or timeout changes are included. Deletion-history holds remain intact.

Thanks @desksk, @NobleVision, and @islandpreneur007 for the detailed recovery evidence.

Evidence

  • Before the fix, SIGKILL during a real Doctor schema-21 migration preserved schema 21 and the session row, but the next Doctor run failed with core:agent-database-maintenance/global is held by .... Both new crash regressions failed with OPENCLAW_STATE_LEASE_HELD; graceful exits passed.
  • After the fix, the same isolated Linux replay completed Doctor in 5.814 s, advanced the agent database to schema 23, retained its session row and pre-migration backups, and returned HTTP 200 from the restarted Gateway's /healthz in 6.076 s. Shared/agent quick_check both returned ok.
  • The fixture used the reported 2026.9.5 database shape (shared schema 17, agent schema 21). It was synthetic and exercised the supported pnpm openclaw CLI. This does not claim Windows or a published-updater-driver replay.
  • Four focused suites passed three times: 46 tests per pass, command walls 41.06 / 38.55 / 38.91 s. The process regression includes a non-process-bound crash that must remain held.
  • Fresh Codex autoreview at P1: scoped-clean.
  • node scripts/check-changed.mjs passed on Linux, including production typing, all 25 selected test type graphs, lint, formatting, and repository guards.
  • Direct and one-barrel dependent batches passed 91 files: 1,369 tests passed and 7 existing skips; command walls 832.57 s and 94.34 s. No individual test exceeded 30 s or file test time exceeded 120 s.
  • pnpm test src/state/openclaw-state-lease.test.ts --maxWorkers=1: 7 tests passed; 22.05 s command wall (including shared build/setup), 8.17 s Vitest wall, approximately 5.6 s test time. Hosted PR CI duration is pending.
  • Linux Testbox backing runs: live interruption and focused passes, changed checks and dependent suites. Evidence above comes from the remote command exit/results; lease cleanup can cancel the backing workflow.

LOC: production +43/-6 (net +37); tests/support +37/-13 (net +24); docs +7. The production growth carries the explicit process-lifetime contract through both acquisition transports and keeps subprocess-owning leases conservative.

Record process identity for schema/media migration leases and reclaim only demonstrably dead process owners. Preserve expiry for work that can outlive its parent, existing snapshots, and transactional migration recovery.

Refs #158114. Linux SIGKILL recovery and three focused passes passed; 91 dependent files and changed checks passed; P1 autoreview clean.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Sep 27, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 10:55 PM ET / September 27, 2026, 02:55 UTC.

ClawSweeper review

What this changes

Doctor records process identity on agent schema and media migration leases so a retry can reclaim a lease after its owner dies, with recovery guidance and crash regression coverage.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open. Current main still makes an immediate Doctor retry wait for a dead maintenance lease, and the branch addresses that demonstrated recovery failure. The original released startup outage is broader than the Linux retry scenario proved here.

Priority: P1
Reviewed head: 3f0a8824631266927bba9a2d9efb7dd0f3e69920

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and direct Linux recovery evidence are useful, but the required released-updater recovery cell still limits merge confidence.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (terminal): The changed owner is Doctor's shared SQLite migration lease. The captured PR body reports a real Linux pnpm openclaw doctor --fix kill-and-retry on synthetic older state, observing schema completion, retained session and backups, SQLite integrity, and healthy Gateway startup. That proves the direct CLI recovery path; the published-updater handoff remains a separate required gate. The persisted lease payload reuses the existing owner shape, and source plus the non-process-bound control support compatibility with older null-payload leases.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed owner is Doctor's shared SQLite migration lease. The captured PR body reports a real Linux pnpm openclaw doctor --fix kill-and-retry on synthetic older state, observing schema completion, retained session and backups, SQLite integrity, and healthy Gateway startup. That proves the direct CLI recovery path; the published-updater handoff remains a separate required gate. The persisted lease payload reuses the existing owner shape, and source plus the non-process-bound control support compatibility with older null-payload leases.
Evidence reviewed 8 items Introduced Doctor lease scope: The pinned PR hunk opts only the agent schema and media migration call into process-bound ownership.
Acquisition and authority boundary: The worker records host, PID, and process start identity for opted-in leases, then checks dead-owner status inside the admitted acquisition transaction before claiming the lease.
Conservative old-lease handling: A missing process payload cannot prove death; acquisition retains the existing expiry path. The new crash test also checks that a non-process-bound lease remains held.
Findings None None.
Security None None.

How this fits together

Doctor repairs existing SQLite state before the Gateway can start. A shared lease controls access to agent database migrations and determines whether repair proceeds or reports another owner.

flowchart LR
A[Existing SQLite state] --> B[Doctor repair]
B --> C[Shared migration lease]
C --> D{Lease available or owner dead?}
D -->|No| E[Report held lease]
D -->|Yes| F[Schema and media repair]
F --> G[Gateway startup]
Loading

Before merge

  • Resolve merge risk (P1) - The released updater driving this candidate through an interrupted migration has not been exercised. The direct Doctor replay proves the retry path, but not the installed upgrade handoff required by repository policy.
  • Complete next step (P2) - Prove an installed published updater driving this candidate through an interrupted migration, immediate Doctor recovery, and the next Gateway start on copied state.
Agent review details

Security

None.

PR surface

Source +37, Tests +24, Docs +7. Total +68 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 8 43 6 +37
Tests 2 37 13 +24
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 87 19 +68

Review metrics

Metric Value Why it matters
Production and test growth production +43/-6; tests/support +37/-13 The production growth carries the process-lifetime contract through both lease acquisition transports; the tests cover killed and non-process-bound owners.

Merge-risk options

Maintainer options:

  1. Prove the released upgrade handoff (recommended)
    Run a published updater against copied pre-upgrade state with this candidate, interrupt migration, then verify Doctor recovery and Gateway startup.

Technical review

Best possible solution:

Keep Doctor as the migration owner, retain safe dead-process retries and old-lease expiry behavior, and provide a visible Fix or Doctor launcher when an update cannot start the Gateway.

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

Yes. The captured PR evidence reports a current-main Linux SIGKILL during Doctor's schema repair followed by an immediate retry refused with OPENCLAW_STATE_LEASE_HELD; the null-payload lease path in source explains that result.

Is this the best way to solve the issue?

Yes for the demonstrated retry failure. The patch reuses the existing transactional lease owner and dead-process check, while keeping leases without process identity expiry-bound.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: An interrupted Doctor migration can block immediate repair and delay restoration of an unavailable Gateway.
  • add merge-risk: 🚨 compatibility: Migration lease behavior changes during upgrades of existing state, while the released updater handoff remains unproven.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed owner is Doctor's shared SQLite migration lease. The captured PR body reports a real Linux pnpm openclaw doctor --fix kill-and-retry on synthetic older state, observing schema completion, retained session and backups, SQLite integrity, and healthy Gateway startup. That proves the direct CLI recovery path; the published-updater handoff remains a separate required gate. The persisted lease payload reuses the existing owner shape, and source plus the non-process-bound control support compatibility with older null-payload leases.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed owner is Doctor's shared SQLite migration lease. The captured PR body reports a real Linux pnpm openclaw doctor --fix kill-and-retry on synthetic older state, observing schema completion, retained session and backups, SQLite integrity, and healthy Gateway startup. That proves the direct CLI recovery path; the published-updater handoff remains a separate required gate. The persisted lease payload reuses the existing owner shape, and source plus the non-process-bound control support compatibility with older null-payload leases.

Label justifications:

  • P1: An interrupted Doctor migration can block immediate repair and delay restoration of an unavailable Gateway.
  • merge-risk: 🚨 compatibility: Migration lease behavior changes during upgrades of existing state, while the released updater handoff remains unproven.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed owner is Doctor's shared SQLite migration lease. The captured PR body reports a real Linux pnpm openclaw doctor --fix kill-and-retry on synthetic older state, observing schema completion, retained session and backups, SQLite integrity, and healthy Gateway startup. That proves the direct CLI recovery path; the published-updater handoff remains a separate required gate. The persisted lease payload reuses the existing owner shape, and source plus the non-process-bound control support compatibility with older null-payload leases.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed owner is Doctor's shared SQLite migration lease. The captured PR body reports a real Linux pnpm openclaw doctor --fix kill-and-retry on synthetic older state, observing schema completion, retained session and backups, SQLite integrity, and healthy Gateway startup. That proves the direct CLI recovery path; the published-updater handoff remains a separate required gate. The persisted lease payload reuses the existing owner shape, and source plus the non-process-bound control support compatibility with older null-payload leases.

Evidence

What I checked:

  • Introduced Doctor lease scope: The pinned PR hunk opts only the agent schema and media migration call into process-bound ownership. (src/infra/state-migrations.media-persistence.ts:456, 3f0a88246312)
  • Acquisition and authority boundary: The worker records host, PID, and process start identity for opted-in leases, then checks dead-owner status inside the admitted acquisition transaction before claiming the lease. (src/state/openclaw-state-lease-worker.ts:157, 3f0a88246312)
  • Conservative old-lease handling: A missing process payload cannot prove death; acquisition retains the existing expiry path. The new crash test also checks that a non-process-bound lease remains held. (src/state/openclaw-state-lease-store.ts:88, 3f0a88246312)
  • Current-main necessity: At the fetched main revision, Doctor's media migration acquires the maintenance lease without process-bound identity. The PR's recovery behavior is absent there. (src/infra/state-migrations.media-persistence.ts:456, 23ad3a56a0b7)
  • Production-path proof reported: The captured PR body reports a Linux SIGKILL during Doctor repair on synthetic 2026.9.5-shaped state, followed by a successful immediate Doctor retry, retained session and backups, SQLite quick checks, and Gateway /healthz HTTP 200. It expressly does not claim a Windows or published-updater-driver replay.
  • Related report and prior cutover: The linked report contains Windows and Linux release-outage observations. The merged Doctor-ownership cutover changed the older startup mechanism; this PR is a candidate fix for the remaining immediate Doctor retry failure. (src/infra/state-migrations.prelude.ts:209, 2a1402cd3e39)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason (Json): Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Show the published-updater-driver × candidate interruption and recovery result on copied existing state.

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.

@steipete
steipete marked this pull request as ready for review September 27, 2026 03:47
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete enabled auto-merge (squash) September 27, 2026 03:56
@steipete
steipete merged commit 4ec35b5 into main Sep 27, 2026
300 of 301 checks passed
@steipete
steipete deleted the upd/upd-startup-migration-lease-lost branch September 27, 2026 04:02
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…aw#159345)

Record process identity for schema/media migration leases and reclaim only demonstrably dead process owners. Preserve expiry for work that can outlive its parent, existing snapshots, and transactional migration recovery.

Refs openclaw#158114. Linux SIGKILL recovery and three focused passes passed; 91 dependent files and changed checks passed; P1 autoreview clean.
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant