Repository navigation
feat: let doctor --fix tell when its startup repairs have nothing to do - #206246
Merged
fuller-stack-dev merged 8 commits intoNov 27, 2026
Merged
Conversation
…ecks Doctor's state database repair, database migrations and runtime checks now trace their real pending decision (work, none or undecidable) instead of the default. Each check reads the live stores without copying them, opening them for writing or creating files, and reuses the predicates its step acts on. No step changes what it does.
Contributor
|
🦞👀 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. |
The state database repair now imports its pending-check module, which the PR wrapper inventory must carry. Also drop a type assertion from the permission drift target list.
# Conflicts: # src/commands/doctor-maintenance-pending.test.ts
… completion check
Member
Author
|
Merged via squash.
|
This was referenced Nov 27, 2026
vincentkoc
added a commit
that referenced
this pull request
Nov 27, 2026
* commit '7df6cb759f9e604921536a700e2f527c5516e7de': (185 commits) docs: clarify what telemetry OpenClaw sends and how to opt out refactor(ui): remove retired stream-follow test seams (#206316) fix: distinguish missing command results from unknown outcomes (#206313) fix(build): reuse stamps after identical pnpm installs (#206282) chore(ci): inventory Gateway model catalog worker lifecycles (#206251) fix: keep failed image inspections inside chat activity (#206283) fix: clarify sent-message labels and chat activity icons (#206048) fix(cron): use the service's free memory for extra automation runs (#206322) test(android): reuse the shared TLS fixture (#206280) fix(ui): restore New Session recovery during startup (#206319) test(macos): align new Gateway URL expectations (#206281) feat: let doctor --fix tell when its startup repairs have nothing to do (#206246) fix(android): pause idle gateway discovery without blocking consumers (#196209) fix(ci): prepare the Android SDK for scheduled CodeQL scans (#203843) fix(memory): read delegated cgroup pressure from the mapped leaf (#206308) improve(config): reuse plugin metadata during auto-enable (#206289) improve: copy only the selected model for agent completions (#206287) fix(pr): refresh tooling before preparing reviewed incoming PRs (#206236) fix: keep Gateway ready while plugins drain after updates (#206299) fix(crabbox): keep unused prepared mirrors reusable (#206267) ...
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Nov 27, 2026
…do (openclaw#206246) * feat(doctor): give the startup maintenance steps read-only pending checks Doctor's state database repair, database migrations and runtime checks now trace their real pending decision (work, none or undecidable) instead of the default. Each check reads the live stores without copying them, opening them for writing or creating files, and reuses the predicates its step acts on. No step changes what it does. * fix(doctor): list the state repair check in the PR wrapper closure The state database repair now imports its pending-check module, which the PR wrapper inventory must carry. Also drop a type assertion from the permission drift target list. * fix(doctor): name the database migrations check apart from the backup completion check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #204775
What Problem This Solves
Every
openclaw doctor --fixstops a healthy Gateway before it knows whether any step has work. The plan in #204775 makes that stop conditional, but only once every step can say "nothing to do" and mean it. This is step 4: the startup steps inside the stop (state database repair, database migrations, runtime checks) still reported the defaultwork, so a later conditional stop could never skip them.User Impact
None yet. Every
--fixstill stops the Gateway and runs every step. WithOPENCLAW_GATEWAY_STARTUP_TRACE=1, these steps now report their real decision:state-database-repairpending=none check=owner, 7 to 10 mspending=work(mode 0644, orphan delivery row), and the repair still runsruntime-checkspending=none check=owner, 17 to 50 mspending=work(unusable deletion journal row), and the quarantine still runsdatabase-migrationspending=undecidable check=owner, under 1 ms (see below)pending=work(pending agent schema migration), and the migration still runsconfig-flowpending=work check=defaultWhy This Change Was Made
Each check lives with its step's owner and calls the predicates the step acts on, so the trace and the write cannot disagree. Contract for every check: no writable open, no file creation, no database copy, no lock. A check that throws counts as undecidable, which counts as work.
State database repair (
state/openclaw-state-db-repair-pending.ts). The existingneedsOpenClawStateDatabaseSchemaRepairanswers a different question (schema version and legacy shapes, for the backup andstate-schemasteps) and copies the database under an updater's capture. The new check opens the live file read-only and decides from what the index and readability scopes act on: broadened file modes (the same mode comparisonensureOpenClawStatePermissionsskips on), a quarantine or recorded open failure, the integrity check the repair runs (quick check, or the full scan's damaged-index plan under--full-integrity-check), the dangling Skill Workshop review index, orphan task delivery rows, and the registry key the repair asserts first. The repair now calls the sharedhasRecordedStateDatabaseDamageandclassifyStateDatabaseIntegrity, andhasOpenClawStatePermissionDriftshares the target list withensureOpenClawStatePermissions.-waland-shmfiles (readOnlyOpenWouldCreateSqliteSidecars). Ownership refusals are not checked; they are preconditions, not work.--full-integrity-checkin both (test "decides damaged index keys").Database migrations (
doctor-heartbeat-migration-backup.ts).checkDoctorMigrationBackupsPendinguses the step's own gates: a pending, refused or indeterminate store in the prepared preflight,needsSharedStateMigrationBackup(now the backup's gate too), an automatic heartbeat repair, andneedsHeartbeatMigrationBackup(now the heartbeat backup's gate). It reads live stores (withLiveStateReads), never copies.none. Making it decidable under the stop needs an immutable read path through the agent read owner; I left that for step 6 rather than widen this PR.Runtime checks (
doctor-health-startup.tscomposes owners): the deletion journal (checkDoctorAgentDeletionJournalPending, the repair's gates plus the rows quarantine reads via the now-exportedreadAgentDeletionJournalRecoverySource), Control UI assets (checkUiProtocolFreshnessPending, the same detector and the prompter's auto-approve rule), the Bun launcher (planning split from the repair) and the pnpm launcher (hasPublishedPnpmLauncherRepairWork, the read-only half of the repair). Source install notes, plugin runtime links, NOCOW inspection and startup hints only print notes. The pnpm launcher repair was written by us (fix: keep the openclaw command and Gateway working after updating a pnpm install #201735, fix(update): repair only this account's pnpm launcher and never keep set-ID bits #203447), not by the updater owner, so it got a check too. A stale launcher owned by another account still reports work although the repair refuses it; that over-reports, never under-reports.Config flow stays at the default. I enumerated its write sites from source (preflight, flow body and
runDoctorRepairSequence). About 50 sites write conditionally. These have no read-only detector:needsOpenClawStateDatabaseSchemaRepair; the media persistence lease and registrylast_seen_at; the cold navigation lease; the post-core plugin convergence lease; plugin source capture directories; and the Tailscale profile migration's writable open.Step 3 measured that these write no store bytes on a clean run. A
noneanswer still needs a detector per site, and several of those depend on network or plugin code. Composing only the existing detectors (detectLegacyStateMigrations,collectCronCodexRuntimePolicyTargetsReadOnly,detectLegacyExecApprovalsand about 20 others) would be wrong in the "none" direction, so the flow keepscheck=default. The site-by-site inventory goes in the step 4 note on Design: prepared-release updates (state, ownership and plan) #204775.The first CI run also flagged one uncommented type assertion in the permission drift helper; it is gone.
No schema, stored field, config option, protocol, dependency, retention or permission change.
Update behavior
No update-path change. A published updater that runs Doctor on this build runs the same repairs in the same order. Under an updater's migration capture every new check reports undecidable, so nothing could be skipped there later either.
Evidence
Cells: Linux, systemd user Gateway, npm install of a pack under an unpublished version, 4.4 GB agent database (3.3 MB state database) under 1 MiB/s of writes,
/readyzprobed every 250 ms. Base ismainatfcc9a0648c2; head isf720994f8f1(this PR's first commit). Each doctor cell runsopenclaw doctor --fix --non-interactive --yesthree times on a healthy install. Each guard cell then seeds real work while the Gateway serves (state database mode 0644, an orphantask_delivery_staterow, an unusable deletion journal row for the reservedopenclawagent) and runsdoctor --fixtwice.fcc9a0648c2f720994f8f1state-database-repair, healthywork check=defaultnone check=owner(6.9 to 9.7 ms)runtime-checks, healthywork check=defaultnone check=owner(17 to 50 ms)database-migrations, healthywork check=defaultundecidable check=owner(under 1 ms)work check=ownerwork check=defaultnone check=ownerThe outage difference (about 1 to 3 s) is larger than the checks' own cost (under 60 ms in total). Host load was 13 at the start of the head doctor cell and about 5 at the start of the base one, so I read it as host noise. Nothing is skipped yet. The checks' cost depends on the state database (quick check) and on the agent database's
heartbeat_outcomesrows, not on the agent database file size, so at 10 GiB I expect the same tens of milliseconds. That is an estimate; I did not run a 10 GiB cell.Recordings replay the raw cell logs.
RED/BASE,
fcc9a0648c2:red-base.mp4
GREEN/HEAD,
f720994f8f1:green-head.mp4
Raw evidence, base (home paths shortened)
Raw evidence, head (home paths shortened)
The guard checker reports "recovery receipts 0" because it only looked under
agents/openclaw/recovery, which is not where this receipt went. Doctor reported recording the receipt, and the journal row is gone on both builds.Tests (real stores, no mocks of the behavior). Each "work" case proves the check leaves bytes, mtimes and inodes unchanged (database and WAL;
-shmby inode only, since its index changes on every read), then runs the real repair and getsnone:src/state/openclaw-state-db-repair-pending.test.ts(new): healthy store (quick and full) isnonewith no snapshot staging calls; a closed WAL store isundecidableand gets no sidecars; mode 0644, a quarantine record, an orphan delivery row, a damaged index key (full only, matching the repair) and the dangling Workshop index each reportworkuntil the repair runs.src/commands/doctor-maintenance-pending.test.ts: a real v26 agent store iswork, the realprepareDoctorMigrationBackupsmigrates it under maintenance, thennone; an unusable journal row iswork, the real repair quarantines it, thennoneand the repair has nothing left.src/infra/update-launcher-repair.test.ts: the stale launcher istruewith unchanged bytes, mtime and inode,falseafter the repair, andfalsein all four "cannot prove it is ours" cases.Red per predicate: removing each clause (mode drift, recorded damage, orphan rows, full index scan, sidecar guard, journal read, pnpm stale detection, pending migrations) fails its test; restored, all pass.
Also green on the merged head:
doctor-agent-deletion-journal.test.ts,doctor-agent-deletion-journal-restore.test.ts,doctor-heartbeat-migration-backup.test.ts,doctor-schema-migrations.test.ts,doctor-bun-cli-launcher.test.ts,doctor-ui.test.ts,doctor-ui.repair.test.ts,doctor-health-startup.test.ts,doctor-health-startup.signal.test.ts,doctor-health.dangling-workshop-index.test.ts,doctor-health.deletion-recovery.test.ts,openclaw-state-db.test.ts,openclaw-state-db.index-repair.test.ts,openclaw-state-db-permissions.test.ts,openclaw-state-db.permissions.test.ts,openclaw-state-db-task-delivery-recovery.test.ts,openclaw-quarantine-store.test.ts,doctor-migration-backup.test.ts,test/scripts/update-restart-module-outcome.test.ts;pnpm tsgo:core,pnpm tsgo:core:test, oxlint and oxfmt on the touched files, the session identity ratchet.test/scripts/pr-wrapper-source-closure.test.tsandeager-import-closure.test.tsfailed in the first CI run:openclaw-state-db-repair.tsis in the PR wrapper's source closure and now importsopenclaw-state-db-repair-pending.ts, soscripts/pr-lib/wrapper-components.txtlists it. The closure test passes locally after that. (Locallyeager-import-closure.test.tscannot run on this worktree's hoisted install, which lacks package-localnode_modules; CI covers it.)Files audited in full:
doctor-maintenance-pending.test.tsandupdate-launcher-repair.test.ts. Nothing was removed; the existing cases still cover distinct behavior, and the launcher cases now also assert the check.Review:
$autoreview(Codex route, branch mode againstorigin/main, P0 to P2) returned scoped-clean.test/scripts/pr-worktree-provision.test.ts(not every launched provisioner received its private store) fails in the first CI run and fails the same way locally on themainparent54c7dc134e8; this PR does not touch it.Not proven
f720994f8f1. The branch then mergedmainthree times, including step 5 (feat: let each Doctor repair say whether it has work before the Gateway stops #206247, the contribution checks; one import conflict indoctor-maintenance-pending.test.ts) and fix: shorten the first update's outage by skipping an idle second Doctor #206227 (idle second Doctor). Their new tests, the focused suites above, all 57 Doctor health and maintenance test files,pnpm tsgo:coreand every baseline ratchet pass on the merged head. The cells did not run again.