Repository navigation
feat: let four more doctor --fix repairs tell when they have nothing to do - #206348
Conversation
Give config-audit-scrub, legacy-state, release-configured-plugin-installs and legacy-plugin-source-captures read-only pending checks that share each repair's own predicate. The agent database path repair, the generated exec-approval cleanup and the retired usage-cost row cleanup now read first and open a write transaction only when they have rows to change.
|
🦞👀 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: blocked before merge. What this changesAdds read-only pending checks for four Doctor contributions and avoids write transactions for three clean-store repairs. Example: Doctor inspects a clean agent database while another connection holds a SQLite write lock.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 2 items remain Keep this PR open: the Doctor improvements are useful, but two new export collisions break the source-contract gate. Reviewed head: Before merge
Findings
Tests
Agent review detailsHow this fits togetherDoctor contributions inspect configuration, registered databases, plugin installations, and capture directories, then report pending work and execute repairs under existing maintenance ownership. flowchart TD
A[Doctor CLI] --> B[Contribution registry]
B --> C[Read-only pending checks]
C --> D[Startup trace]
B --> E[Existing repair owners]
E --> F[Maintenance transactions]
F --> G[Configuration and stores]
Technical reviewBest possible solution: Retain the owner-shared predicates and existing repairs, disambiguate the flow adapter exports, and complete stable-upgrade validation. Do we have a high-confidence way to reproduce the issue? Current-main source still enters the clean-store write paths, and supplied red/base transcripts show lock failures; this review executed no target code. Is this the best way to solve the issue? Sharing each repair's existing predicate is an appropriate focused extension of the established Doctor design. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 66a935ded01c. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +384, Tests +260. Total +644 across 23 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 26, 2026, 11:08 PM ET / November 27, 2026, 04:08 UTC. |
|
Merged via squash auto-merge.
|
…to do (openclaw#206348) * feat(doctor): decide four write-owner repairs before writing Give config-audit-scrub, legacy-state, release-configured-plugin-installs and legacy-plugin-source-captures read-only pending checks that share each repair's own predicate. The agent database path repair, the generated exec-approval cleanup and the retired usage-cost row cleanup now read first and open a write transaction only when they have rows to change. * fix(doctor): throw an Error from the capture check and stop exporting an unused type * refactor(doctor): keep the new read-only SQLite reads on Doctor's host side * fix(doctor): keep the path count private and format a non-Error capture failure * fix(doctor): give the contribution check wrappers their own names
Related: #204775
What Problem This Solves
Every
openclaw doctor --fixstops a healthy Gateway before it knows whether any step has work. To make that stop conditional, each step must answer "is there work?" from a read. After #206247, 29 decisions on a healthy install still answered "work" only because they had no check. Several of them also opened a write transaction on every run just to find nothing to do: the agent database path repair, the generated exec-approval cleanup, and the retired usage-cost cleanup (aDELETEon every agent database).User Impact
Doctor repairs nothing differently. On a healthy install with the trace on (
OPENCLAW_GATEWAY_STARTUP_TRACE=1), 68 of 94 decisions now tracepending=none check=owner(64 before). Three repairs no longer take a SQLite write lock when their store is clean, soconfig-audit-scrubdrops from about 167 ms to about 18 ms on four agent databases, and a clean store no longer fails or waits 5 s when another connection holds its write lock.Why This Change Was Made
Same mechanism as #206247: each check calls the repair's own predicate, split out at its owner where it sat inside the write.
workwhen)config-audit-scrubWHEREas theDELETE, now one shared expression); skill-upload staging or the old Control UI cache existslegacy-statecountObsoleteGeneratedExecApprovals)release-configured-plugin-installslegacy-plugin-source-capturescollectmode); an incomplete inspection isundecidable. A managed root counts as work even if its payload is retained, because reclaiming it takes the root's SQLite custody lockRead first, then write (each still rereads inside its transaction before writing):
noteDoctorAgentDatabasePathHealthopens its write transaction only when the read-only plan finds a registration to repair. The plan is a pure function over the rows; the repair and the check share it.repairObsoleteGeneratedExecApprovalsopens its write transaction only when the store holds such a grant.Also: the new read-only SQLite reads sit in
src/commands/so the main-thread SQLite worker ratchet does not grow;release-configured-plugin-installs' run moved unchanged intodoctor-health-contribution-runners.state.tsto keepdoctor-health-contributions-initial.tsunder its line cap; the unused exportDoctorContributionPendingfrom #206247 is now module-private (the unused-export scan flagged it). No schema, stored field, config option, protocol or retention change.Left on the default, with the reason
workstate-integritynoteStateIntegritydecides its plugin session-route repairs by loading plugin doctor-contract modules and, for explicit runtime selections, a plugin registry inspection; it reads deferred plugin migrations through an artifact-preserving read that can copy the state database; and backup scratch liveness is only provable by taking the scratch lock. A check needs a probe ofnoteStateIntegritywith a declining prompter, an injectable note sink and a non-copy migration readlegacy-cronmaybeRepairLegacyCronStoreloads the mutable cron store, which commits retired-job deletions and runtime-authority repairs before any prompt; the read-only loader hides both and stages a snapshot copy under artifact-preserving reads. Its health detect also disagrees with the repair (misses invalid config rows, flags advisory-only items). Needs read-only counts of retired rows and authority repairs at the cron store owner, and an inference-binding plan that keeps the authorization-restore pathauth-profile-migration--yeseven with nothing detected, and the OAuth id repair loads provider plugins; it also writes config inside the contributionsession-transcripts,-headers,-labels,codex-session-routes),heartbeat-*,memory-search,sandbox,gateway-auth,auth-profiles,structured-health-repairsUpdate behavior
No update-path change. A published updater that runs this release's Doctor runs the same repairs in the same order. The visible differences are trace lines and that three clean stores are no longer opened for writing.
Evidence
Cells: Linux, systemd user Gateway, npm install of a packed build under an unpublished version, four agent databases (main 64 MiB, three seeded through
openclaw agents addand a session each),/readyzprobed every 250 ms. Base ismainat9ced54f9298(packed as 2026.11.21). Head is291d0ab0313(packed as 2026.11.23); later commits only format a non-Errorcapture failure, make the path count private, mergemain(#206246 and others; the focused tests below were rerun after it) and rename two wrapper functions that collided with their owners' export names (the export-name guard in CI). One count cell per build runsdoctor --fix --non-interactive --yesthree times on a healthy install. One guard cell per build seeds work while the Gateway serves (a retired usage-cost row plus an unrelated row in agentwork, the old Control UI cache, skill-upload staging, a legacy plugin capture, and a look-alike cache folder), then runs Doctor twice.9ced54f9298291d0ab0313pending=none check=ownerpending=work check=defaultundecidable(sqlite-nocow, existing)config-audit-scrubrunlegacy-staterunrelease-configured-plugin-installsrunlegacy-plugin-source-capturesrunstate-integrityrun/readyzoutage, runs 1 / 2 / 3The outage is within this host's run-to-run noise (the busy host's load average was 8 to 19 during these cells; the guard cells measured 35.3 / 36.3 s on base and 31.5 / 31.8 s on head). The checks cost milliseconds; the stop is unchanged by design.
Guard cells:
config-audit-scrub(retired row, Control UI cache, skill-upload staging)work default→work defaultwork owner→none ownerlegacy-plugin-source-captures(legacy capture)work default→work defaultwork owner→work ownerlegacy-state,release-configured-plugin-installs(not seeded)work defaultnone ownerExec-approval grants and agent database path sentinels were not seeded in a cell; they are covered by tests on real stores below.
RED/BASE,
9ced54f9298:doctor-pending-5b-red-base.mp4
GREEN/HEAD,
291d0ab0313:doctor-pending-5b-green-head.mp4
Read first, then write: the same steps run against a clean store while another SQLite connection holds its write lock. On base each repair waits out the 5 s busy timeout and fails (
database is locked); on head none of them opens the store for writing:doctor-pending-5b-read-first.mp4
Reproduce:
node scripts/run-vitest.mjs src/commands/doctor-usage-cost-cache.test.ts src/infra/exec-approvals-generated-migration.test.ts src/state/openclaw-agent-db-path-repair.test.ts(the lock cases are the "held write lock" / "reads before writing" / "opens no write transaction" tests).Tests and files audited
doctor-usage-cost-cache.test.ts: each of the five cleanups reportsworkwithout changing a byte of the store (file snapshot), the repair clears it, thennone; a clean agent database under a held write lock is not waited on (red on base, shown above).exec-approvals-generated-migration.test.ts: the stored count before and after the repair; a clean store under a held write lock is not opened for writing.openclaw-agent-db-path-repair.test.ts: a clean registry under a held write lock; sentinel registrations still reach the write transaction and are removed.doctor-health-contributions.legacy-state.test.ts:nonewith a migrated preflight and no obsolete grants,workwithout the preflight,workwith a generated grant, removed by the run, thennone.doctor-plugin-source-captures.test.ts:noneempty,workwith a legacy root (no byte changed), removed under maintenance, thennone;workfor a managed root;undecidablewhen service inspection fails.runCaptureReportwas split into a context and a contribution helper so the new case reuses them.release-configured-plugin-installs.persistence.test.ts:nonewithout configured ids,workbefore the release gate, and the run stamps the touched version.doctor-health-contribution-runners.state.paths.test.ts: its in-memory Windows state fixture now also serves the read-only plan that precedes the write transaction (otherwise the repair would read a nonexistent file and skip).doctor-health-contributions.diagnostic-only.test.ts: its store snapshot helper moved unchanged tosrc/test-utils/store-snapshot.test-support.tsfor reuse.Commands and results (on
7a62ba992c0unless noted; head is3d3523d6257)node scripts/run-vitest.mjson the touched and affected Doctor, cache, exec-approval and plugin-install suites plus the new tests from feat: let doctor --fix tell when its startup repairs have nothing to do #206246, fix: shorten the first update's outage by skipping an idle second Doctor #206227 and fix: keep the full Doctor timing line in update reports #206290 after mergingmain: 260 passed, 4 shards.pnpm tsgo:core: clean.tsgo:core:test,check:changedlint and the remaining guards ran on291d0ab0313: all passed except the unused-export scan and one type-aware lint finding (fixed in29fd37927af), which still flagsreadUpdateDatabaseEngineConfigandformatUpdateSnapshotCapacity, both already unused onmainand not touched here.3d3523d6257: export-name-collision guard,tsgo:core, and the contribution suites (141 tests) pass.check:database-worker-ratchet: no T1 growth. Session identity ratchet: OK. Test lines ratchet: OK.3f0d3beaff8): scoped-clean, no findings.Not proven
macOS, Windows, pnpm and Git installs were not run. The managed native capture reclaim and the exec-approval and path repairs were not exercised in a cell. The container census keeps the legacy capture, so its removal path was proven only in tests.
Raw evidence, base
Raw evidence, head
Raw evidence, read-first lock tests