Skip to content

feat: let four more doctor --fix repairs tell when they have nothing to do - #206348

Merged
fuller-stack-dev merged 7 commits into
openclaw:mainfrom
fuller-stack-dev:doctor-pending-step5b
Nov 27, 2026
Merged

fuller-stack-dev merged 7 commits into
openclaw:mainfrom
fuller-stack-dev:doctor-pending-step5b

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Related: #204775

What Problem This Solves

Every openclaw doctor --fix stops 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 (a DELETE on 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 trace pending=none check=owner (64 before). Three repairs no longer take a SQLite write lock when their store is clean, so config-audit-scrub drops 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.

Contribution Check (work when) Read path
config-audit-scrub the config-audit scrub dry run would rewrite an entry; a legacy usage-cost sidecar exists; a registered agent database holds a retired usage-cost row (same WHERE as the DELETE, now one shared expression); skill-upload staging or the old Control UI cache exists read-only agent database open, file stats
legacy-state its two core repairs have work (derived as in #206247); preflight did not already migrate this exact config (the existing in-memory gate); the stored exec-approval policy holds generated grants the cleanup removes (countObsoleteGeneratedExecApprovals) direct read-only state database read (no copy)
release-configured-plugin-installs configured ids exist and either the config has not crossed the release gate (a completed step stamps its touched version) or the repair's pre-lease no-op plan says there is package or record work the repair's existing read-only plan, now one exported function shared by the repair
legacy-plugin-source-captures a legacy capture root exists, or a native capture root the cleanup would reclaim (the cleanup's own walk in its existing collect mode); an incomplete inspection is undecidable. A managed root counts as work even if its payload is retained, because reclaiming it takes the root's SQLite custody lock directory walks only

Read first, then write (each still rereads inside its transaction before writing):

  • noteDoctorAgentDatabasePathHealth opens 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.
  • repairObsoleteGeneratedExecApprovals opens its write transaction only when the store holds such a grant.
  • The usage-cost cleanup calls the retire path only for agent databases that hold a retired row. An unreadable database or one without the agent schema still goes through the retire path, as before.

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 into doctor-health-contribution-runners.state.ts to keep doctor-health-contributions-initial.ts under its line cap; the unused export DoctorContributionPending from #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

Contribution Why it still answers work
state-integrity its path repair now reads first, but noteStateIntegrity decides 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 of noteStateIntegrity with a declining prompter, an injectable note sink and a non-copy migration read
legacy-cron maybeRepairLegacyCronStore loads 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 path
auth-profile-migration the archive resume step decides each receipt after taking the auth store file lock, the plugin model catalog repair runs for every agent under --yes even with nothing detected, and the OAuth id repair loads provider plugins; it also writes config inside the contribution
preview-only owners (session-transcripts, -headers, -labels, codex-session-routes), heartbeat-*, memory-search, sandbox, gateway-auth, auth-profiles, structured-health-repairs not started in this PR; reasons as listed in #206247
config writers, service definition not this lane (config-flow result and a daemon-side plan)

Update 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 add and a session each), /readyz probed every 250 ms. Base is main at 9ced54f9298 (packed as 2026.11.21). Head is 291d0ab0313 (packed as 2026.11.23); later commits only format a non-Error capture failure, make the path count private, merge main (#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 runs doctor --fix --non-interactive --yes three 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 agent work, the old Control UI cache, skill-upload staging, a legacy plugin capture, and a look-alike cache folder), then runs Doctor twice.

healthy install, doctor2 / doctor3 base 9ced54f9298 head 291d0ab0313
decisions 94 94
pending=none check=owner 64 68
pending=work check=default 29 25
undecidable (sqlite-nocow, existing) 1 1
config-audit-scrub run 166 / 169 ms 19.5 / 17.0 ms (check 6.3 / 5.3 ms)
legacy-state run 9.9 / 10.6 ms 3.3 / 2.7 ms (check 6.5 / 5.1 ms)
release-configured-plugin-installs run 3.4 / 3.8 ms 1.4 / 1.5 ms (check 3.1 / 3.2 ms)
legacy-plugin-source-captures run 52.9 / 54.1 ms 75.4 / 47.0 ms (check 32.8 / 23.5 ms)
state-integrity run 304 / 319 ms 306 / 287 ms
/readyz outage, runs 1 / 2 / 3 36.3 / 33.5 / 34.5 s 41.4 / 37.1 / 34.3 s

The 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:

Site base work run → clean run head work run → clean run after both builds
config-audit-scrub (retired row, Control UI cache, skill-upload staging) work default → work default work owner → none owner row and both folders removed; unrelated row and look-alike folder kept
legacy-plugin-source-captures (legacy capture) work default → work default work owner → work owner kept on both: inside the container the process census refuses removal by design ("Could not inspect OpenClaw processes"), so the check keeps reporting it
legacy-state, release-configured-plugin-installs (not seeded) work default none owner

Exec-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 reports work without changing a byte of the store (file snapshot), the repair clears it, then none; 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: none with a migrated preflight and no obsolete grants, work without the preflight, work with a generated grant, removed by the run, then none.
  • doctor-plugin-source-captures.test.ts: none empty, work with a legacy root (no byte changed), removed under maintenance, then none; work for a managed root; undecidable when service inspection fails. runCaptureReport was split into a context and a contribution helper so the new case reuses them.
  • release-configured-plugin-installs.persistence.test.ts: none without configured ids, work before 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 to src/test-utils/store-snapshot.test-support.ts for reuse.
  • Nothing was removed. Net test lines +260 (allowance 400).

Commands and results (on 7a62ba992c0 unless noted; head is 3d3523d6257)

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
=== RED/BASE
cell count-base: Linux, systemd user Gateway, npm install of 2026.11.21 9ced54f9298, 4 agent databases (main 64 MiB), healthy install

---- doctor2: OPENCLAW_GATEWAY_STARTUP_TRACE=1 openclaw doctor --fix --non-interactive --yes
  decisions: 94
    64 pending=none check=owner
     1 pending=undecidable check=owner
    29 pending=work check=default
  this lane's contributions: check decision (check time), then run time
    config-audit-scrub                   pending=work check=default (0.0ms) run 165.9ms
    legacy-state                         pending=work check=default (0.0ms) run 9.9ms
    release-configured-plugin-installs   pending=work check=default (0.0ms) run 3.4ms
    legacy-plugin-source-captures        pending=work check=default (0.1ms) run 52.9ms
    state-integrity                      pending=work check=default (0.1ms) run 303.8ms
    legacy-cron                          pending=work check=default (0.1ms) run 747.8ms
    auth-profile-migration               pending=work check=default (0.1ms) run 26.7ms
  doctor: The Gateway was stopped for 34.2 s.

---- doctor3: OPENCLAW_GATEWAY_STARTUP_TRACE=1 openclaw doctor --fix --non-interactive --yes
  decisions: 94
    64 pending=none check=owner
     1 pending=undecidable check=owner
    29 pending=work check=default
  this lane's contributions: check decision (check time), then run time
    config-audit-scrub                   pending=work check=default (0.0ms) run 169.3ms
    legacy-state                         pending=work check=default (0.0ms) run 10.6ms
    release-configured-plugin-installs   pending=work check=default (0.0ms) run 3.8ms
    legacy-plugin-source-captures        pending=work check=default (0.1ms) run 54.1ms
    state-integrity                      pending=work check=default (0.1ms) run 319.0ms
    legacy-cron                          pending=work check=default (0.0ms) run 797.5ms
    auth-profile-migration               pending=work check=default (0.1ms) run 30.5ms
  doctor: The Gateway was stopped for 34.8 s.

---- /readyz outage (250 ms probe)
  doctor1: OUTAGE (/readyz) 36.3 s, doctor wall 52.2 s
  doctor2: OUTAGE (/readyz) 33.5 s, doctor wall 50.8 s
  doctor3: OUTAGE (/readyz) 34.5 s, doctor wall 50.6 s

---- doctor2: decisions that are not none
  doctor.pending.client-credentials (0.0ms) pending=work check=default
  doctor.pending.state-database-repair (0.0ms) pending=work check=default
  doctor.pending.database-migrations (0.0ms) pending=work check=default
  doctor.pending.runtime-checks (0.0ms) pending=work check=default
  doctor.pending.config-flow (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:write-config-migrations (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:auth-profile-migration (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:auth-profiles (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:gateway-auth (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:structured-health-repairs (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:legacy-state (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:session-transcripts (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:release-configured-plugin-installs (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:legacy-plugin-source-captures (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:state-integrity (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:codex-session-routes (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:session-transcript-headers (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:session-transcript-labels (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:config-audit-scrub (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:legacy-cron (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:sandbox (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:skills (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:heartbeat-cadence-migration (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:heartbeat-scratch-migration (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:heartbeat-task-cron-migration (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:memory-search (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:write-config (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:final-config-validation (0.0ms) pending=work check=default
  doctor.pending.sqlite-nocow (0.0ms) pending=undecidable check=owner
  doctor.pending.service-definition (0.1ms) pending=work check=default

=== guard cell guard-base (2026.11.21 9ced54f9298): seed work while the Gateway serves, then doctor --fix twice
  seeded: retired usage-cost row + unrelated row in agent 'work', control-ui-assets cache, skill-uploads staging, legacy plugin capture, look-alike cache dir
  -- doctorwork
     doctor.pending.contribution.doctor:auth-profile-migration (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:legacy-state (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:release-configured-plugin-installs (0.0ms) pending=work check=default
     doctor.pending.contribution.doctor:legacy-plugin-source-captures (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:state-integrity (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:config-audit-scrub (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:legacy-cron (0.1ms) pending=work check=default
  -- doctorclean
     doctor.pending.contribution.doctor:auth-profile-migration (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:legacy-state (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:release-configured-plugin-installs (0.0ms) pending=work check=default
     doctor.pending.contribution.doctor:legacy-plugin-source-captures (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:state-integrity (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:config-audit-scrub (0.0ms) pending=work check=default
     doctor.pending.contribution.doctor:legacy-cron (0.1ms) pending=work check=default
  -- sites after doctorwork, then after doctorclean
     absent  cache/control-ui-assets
     absent  tmp/skill-uploads
     present cache/control-ui-assets-keep
     present tmp/openclaw-plugin-build-guard
     row     guard-keep/keep
     absent  cache/control-ui-assets
     absent  tmp/skill-uploads
     present cache/control-ui-assets-keep
     present tmp/openclaw-plugin-build-guard
     row     guard-keep/keep
     │  Legacy capture cleanup skipped: Error: Could not inspect OpenClaw     │
  doctor1: OUTAGE (/readyz) 40.6 s, doctor wall 57.6 s
  doctorwork: OUTAGE (/readyz) 35.3 s, doctor wall 54.5 s
  doctorclean: OUTAGE (/readyz) 36.3 s, doctor wall 52.4 s
Raw evidence, head
=== GREEN/HEAD
cell count-final: Linux, systemd user Gateway, npm install of 2026.11.23 291d0ab0313, 4 agent databases (main 64 MiB), healthy install

---- doctor2: OPENCLAW_GATEWAY_STARTUP_TRACE=1 openclaw doctor --fix --non-interactive --yes
  decisions: 94
    68 pending=none check=owner
     1 pending=undecidable check=owner
    25 pending=work check=default
  this lane's contributions: check decision (check time), then run time
    config-audit-scrub                   pending=none check=owner (6.3ms)   run 19.5ms
    legacy-state                         pending=none check=owner (6.5ms)   run 3.3ms
    release-configured-plugin-installs   pending=none check=owner (3.1ms)   run 1.4ms
    legacy-plugin-source-captures        pending=none check=owner (32.8ms)  run 75.4ms
    state-integrity                      pending=work check=default (0.1ms) run 305.9ms
    legacy-cron                          pending=work check=default (0.1ms) run 846.1ms
    auth-profile-migration               pending=work check=default (0.1ms) run 31.0ms
  doctor: The Gateway was stopped for 37.6 s.

---- doctor3: OPENCLAW_GATEWAY_STARTUP_TRACE=1 openclaw doctor --fix --non-interactive --yes
  decisions: 94
    68 pending=none check=owner
     1 pending=undecidable check=owner
    25 pending=work check=default
  this lane's contributions: check decision (check time), then run time
    config-audit-scrub                   pending=none check=owner (5.3ms)   run 17.0ms
    legacy-state                         pending=none check=owner (5.1ms)   run 2.7ms
    release-configured-plugin-installs   pending=none check=owner (3.2ms)   run 1.5ms
    legacy-plugin-source-captures        pending=none check=owner (23.5ms)  run 47.0ms
    state-integrity                      pending=work check=default (0.0ms) run 287.4ms
    legacy-cron                          pending=work check=default (0.0ms) run 784.3ms
    auth-profile-migration               pending=work check=default (0.1ms) run 26.7ms
  doctor: The Gateway was stopped for 34.5 s.

---- /readyz outage (250 ms probe)
  doctor1: OUTAGE (/readyz) 41.4 s, doctor wall 58.4 s
  doctor2: OUTAGE (/readyz) 37.1 s, doctor wall 57.6 s
  doctor3: OUTAGE (/readyz) 34.3 s, doctor wall 52.9 s

---- doctor2: decisions that are not none
  doctor.pending.client-credentials (0.0ms) pending=work check=default
  doctor.pending.state-database-repair (0.0ms) pending=work check=default
  doctor.pending.database-migrations (0.0ms) pending=work check=default
  doctor.pending.runtime-checks (0.0ms) pending=work check=default
  doctor.pending.config-flow (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:write-config-migrations (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:auth-profile-migration (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:auth-profiles (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:gateway-auth (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:structured-health-repairs (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:session-transcripts (0.2ms) pending=work check=default
  doctor.pending.contribution.doctor:state-integrity (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:codex-session-routes (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:session-transcript-headers (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:session-transcript-labels (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:legacy-cron (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:sandbox (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:skills (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:heartbeat-cadence-migration (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:heartbeat-scratch-migration (0.1ms) pending=work check=default
  doctor.pending.contribution.doctor:heartbeat-task-cron-migration (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:memory-search (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:write-config (0.0ms) pending=work check=default
  doctor.pending.contribution.doctor:final-config-validation (0.0ms) pending=work check=default
  doctor.pending.sqlite-nocow (0.0ms) pending=undecidable check=owner
  doctor.pending.service-definition (0.1ms) pending=work check=default

=== guard cell guard-final (2026.11.23 291d0ab0313): seed work while the Gateway serves, then doctor --fix twice
  seeded: retired usage-cost row + unrelated row in agent 'work', control-ui-assets cache, skill-uploads staging, legacy plugin capture, look-alike cache dir
  -- doctorwork
     doctor.pending.contribution.doctor:auth-profile-migration (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:legacy-state (4.3ms) pending=none check=owner
     doctor.pending.contribution.doctor:release-configured-plugin-installs (2.9ms) pending=none check=owner
     doctor.pending.contribution.doctor:legacy-plugin-source-captures (22.3ms) pending=work check=owner
     doctor.pending.contribution.doctor:state-integrity (0.0ms) pending=work check=default
     doctor.pending.contribution.doctor:config-audit-scrub (4.2ms) pending=work check=owner
     doctor.pending.contribution.doctor:legacy-cron (0.0ms) pending=work check=default
  -- doctorclean
     doctor.pending.contribution.doctor:auth-profile-migration (0.1ms) pending=work check=default
     doctor.pending.contribution.doctor:legacy-state (4.9ms) pending=none check=owner
     doctor.pending.contribution.doctor:release-configured-plugin-installs (2.9ms) pending=none check=owner
     doctor.pending.contribution.doctor:legacy-plugin-source-captures (21.5ms) pending=work check=owner
     doctor.pending.contribution.doctor:state-integrity (0.0ms) pending=work check=default
     doctor.pending.contribution.doctor:config-audit-scrub (4.7ms) pending=none check=owner
     doctor.pending.contribution.doctor:legacy-cron (0.0ms) pending=work check=default
  -- sites after doctorwork, then after doctorclean
     absent  cache/control-ui-assets
     absent  tmp/skill-uploads
     present cache/control-ui-assets-keep
     present tmp/openclaw-plugin-build-guard
     row     guard-keep/keep
     absent  cache/control-ui-assets
     absent  tmp/skill-uploads
     present cache/control-ui-assets-keep
     present tmp/openclaw-plugin-build-guard
     row     guard-keep/keep
     │  Legacy capture cleanup skipped: Error: Could not inspect OpenClaw     │
  doctor1: OUTAGE (/readyz) 32.8 s, doctor wall 47.8 s
  doctorwork: OUTAGE (/readyz) 31.5 s, doctor wall 47.8 s
  doctorclean: OUTAGE (/readyz) 31.8 s, doctor wall 49.0 s
Raw evidence, read-first lock tests
=== RED/BASE 9ced54f9298: clean stores while another connection holds the write lock
 × |unit| src/state/read-first-locks.red.test.ts > agent database paths: a clean registry under a held write lock 5523ms
   → database is locked
 × |unit| src/state/read-first-locks.red.test.ts > exec approvals: a store without obsolete grants under a held write lock 5427ms
      Tests  2 failed (2)
 × |commands| src/commands/doctor-usage-cost-cache.red.test.ts > legacy runtime file pending check > leaves clean agent databases unopened for writing, so a held write lock is not waited on 6719ms
   → expected "vi.fn()" to not be called with arguments: [ Anything, 'Doctor warnings' ]
+   "- Agent main database <tmp>/agents/main/agent/openclaw-agent.sqlite: database is locked",
    "Doctor warnings",
      Tests  1 failed | 18 skipped (19)

=== GREEN/HEAD 29fd37927af: same steps
 ✓ |commands| src/commands/doctor-usage-cost-cache.test.ts > legacy runtime file pending check > leaves clean agent databases unopened for writing, so a held write lock is not waited on 819ms
      Tests  1 passed | 18 skipped (19)
 ✓ |unit| src/state/read-first-locks.red.test.ts > agent database paths: a clean registry under a held write lock 134ms
 ✓ |unit| src/state/read-first-locks.red.test.ts > exec approvals: a store without obsolete grants under a held write lock 64ms
      Tests  2 passed (2)

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.
@clawsweeper

clawsweeper Bot commented Nov 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.

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 3d3523d625754add1087a6449e025c31902440b3
  • Maintainer: @fuller-stack-dev
  • Repository role: maintain

These security sensitive changes were made:

  • src/infra/exec-approvals-generated-migration.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/infra/exec-approvals-store.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. 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. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

Adds 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.

  • Before: Usage-cache cleanup attempts a write transaction and reports database is locked.
  • After: The read finds no retired rows, so cleanup avoids the write transaction.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful owner-aligned work with substantive CLI evidence, but a diff-caused source-contract failure and incomplete upgrade validation prevent a pass.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Healthy Doctor repairs unnecessarily contend for SQLite write locks and lack accurate pending-work answers.
Reason: The maintainer-authored stage removes demonstrated clean-store write contention while preserving repair behavior and the existing staged design.

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: 7a62ba992c05ed045c03043d7edc582e2e381ed0

Before merge

  • Disambiguate the two flow adapter exports to restore the source gate (P2) - This module newly defines checkLegacyRuntimeFilesPending and checkLegacyPluginSourceCapturesPending, while the command modules also newly export those names. The existing export-collision guard counts these gated, argument-adapting functions as separate definitions, so this head fails check-source-contracts with the annotation 'lint:tmp:export-name-collisions failed'. Give the flow adapters distinct contribution-level names and update their registrations without weakening the guard.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Disambiguate the two flow adapter exports to restore the source gate — src/flows/doctor-health-contribution-runners.state.ts:176-178

Tests

  • Missing end-to-end proof: The author should provide a v2026.11.10-to-candidate upgrade followed by shipped Doctor runs showing the affected repairs preserve valid configuration and data; redact credentials and non-public endpoints.
Agent review details

How this fits together

Doctor 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]
Loading

Technical review

Best 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:

  • [P2] Disambiguate the two flow adapter exports to restore the source gate — src/flows/doctor-health-contribution-runners.state.ts:176-178
    This module newly defines checkLegacyRuntimeFilesPending and checkLegacyPluginSourceCapturesPending, while the command modules also newly export those names. The existing export-collision guard counts these gated, argument-adapting functions as separate definitions, so this head fails check-source-contracts with the annotation 'lint:tmp:export-name-collisions failed'. Give the flow adapters distinct contribution-level names and update their registrations without weakening the guard.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 66a935ded01c.

Provenance checked

  • Doctor pending checks keeps the original intent (5c81526: Give repair owners truthful read-only pending answers before a later conditional-stop change.)
  • Configured-plugin no-op planning keeps the original intent (1d99689: Avoid durable lease writes on healthy repair runs so unchanged state can reuse verified captures.)
  • Agent database path repair keeps the original intent (0798abb: Consolidate Windows namespace aliases while preserving newest facts and updater rollback inventories.)
  • Generated exec-approval cleanup keeps the original intent (1c37c8c: Retire generated grants that predate working-directory-bound reusable approvals.)
  • Retired usage-cache cleanup keeps the original intent (f41b2b6: Keep retired-scope cleanup owned by Doctor while ordinary refresh pruning handles observed stale rows.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit 5c81526 adds src/flows/doctor-health-contribution-runners.state.ts:11 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5c815265d528; files: src/flows/doctor-health-contribution-runners.state.ts)
  • Peter Steinberger: Raw commit 4c0b8b1 adds src/state/openclaw-agent-db-path-repair.ts:62 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4c0b8b1f2d50; files: src/state/openclaw-agent-db-path-repair.ts)
  • Josh Avant: Raw commit 1c37c8c adds src/infra/exec-approvals-generated-migration.ts:31 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1c37c8cdc71b; files: src/infra/exec-approvals-generated-migration.ts)
  • Vincent Koc: Raw commit 314a47d adds src/state/openclaw-agent-db-path-repair.ts:80 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 314a47d16d80; files: src/state/openclaw-agent-db-path-repair.ts)

PR surface

Source +384, Tests +260. Total +644 across 23 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 14 528 144 +384
Tests 9 303 43 +260
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 831 187 +644

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 26, 2026, 11:08 PM ET / November 27, 2026, 04:08 UTC.

@fuller-stack-dev
fuller-stack-dev enabled auto-merge (squash) November 27, 2026 04:58
@fuller-stack-dev
fuller-stack-dev merged commit 4c6105f into openclaw:main Nov 27, 2026
134 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the doctor-pending-step5b branch November 27, 2026 05:02
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant