Repository navigation
fix: avoid slow requester checks during Doctor repairs - #162200
Conversation
Reuse maintenance-owned current authority reads after the pre-mutation backup boundary. Revalidate live permission rows, admission, and database identity on each callback, and drain readers with the existing maintenance owner.
|
🦞👀 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: needs maintainer review before merge. Reviewed September 30, 2026, 7:23 PM ET / 23:23 UTC. ClawSweeper reviewWhat this changesDoctor repairs reuse a maintenance-owned SQLite reader for current requester-permission checks after the backup boundary, reducing repeated database snapshots. Merge readiness✅ Ready for maintainer review The current main branch still uses the costly requester read path, and this PR supplies a bounded fix with measured Doctor and upgrade behavior. It remains useful as an active landing candidate. Priority: P1 Review scores
Verification
How this fits togetherDoctor repairs run during managed updates under a maintenance owner. They read shared SQLite state and current requester permissions before continuing config or database changes. flowchart LR
A[Chat update] --> B[Doctor maintenance]
B --> C{Backup boundary passed?}
C -->|Yes| D[Live state reader]
C -->|No| E[Private snapshot]
D --> F{Requester still authorized?}
E --> F
F -->|Yes| G[Repair continues]
F -->|No| H[Further changes refused]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +169, Tests +89, Docs +2. Total +260 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one Doctor-owned reader per admitted maintenance scope, with fresh permission decisions, physical-identity checks, and cleanup before database replacement. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source retains the snapshot-producing requester path, and the PR supplies an instrumented original-implementation control; this read-only review did not execute it. Is this the best way to solve the issue? Yes. Reusing a reader within Doctor's existing maintenance owner addresses the measured cost while retaining current-row and database-identity checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5ca201627d3d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Landed via the admin exception for an unrelated failure (squash Inherited failure on the PR head: |
#162200 left openclaw-state-maintenance-context.ts importing OpenClawDatabaseMaintenanceScope from the lifecycle module that imports values from it, so pnpm check:madge-import-cycles fails on main. The leaf now owns the scope type and its migration helper type; the lifecycle module re-exports the scope type, so importers are unchanged.
Fix check:madge-import-cycles after #162200 introduced the cycle openclaw-state-db-async-lifecycle.ts -> openclaw-state-maintenance-context.ts -> openclaw-state-db-async-lifecycle.ts through a type-only import. Move OpenClawDatabaseMaintenanceScope and AgentSchemaMigration into the maintenance context, and preserve the lifecycle module's public scope type export. Runtime behavior and existing caller imports remain unchanged. Validation: - pnpm check:madge-import-cycles (1 cycle before; 0 cycles after) - pnpm check:import-cycles (0 runtime value cycles) - node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo (passed) - node scripts/run-tsgo-core-test-shards.mjs (all 27 shards passed) - node scripts/run-vitest.mjs src/state/openclaw-state-db-async-lifecycle.test.ts src/state/openclaw-agent-db.storage-migration.test.ts src/state/openclaw-state-db-readonly.worker-lifecycle.test.ts src/state/openclaw-state-lease-async.maintenance.test.ts src/state/openclaw-agent-execution.creation-witness.test.ts src/state/openclaw-state-db-resource-scope.test.ts src/state/agent-deletion-journal.snapshot.test.ts src/state/openclaw-state-db-readonly.snapshot-admission.test.ts (95 tests passed) - node_modules/.bin/oxfmt --check src/state/openclaw-state-maintenance-context.ts src/state/openclaw-state-db-async-lifecycle.ts (passed) - node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/state/openclaw-state-maintenance-context.ts src/state/openclaw-state-db-async-lifecycle.ts (passed) - git diff --check (passed) - Independent Codex autoreview (no actionable findings through P2)
A concurrent main fix for the #162200 check:madge-import-cycles failure moved the same types and used an inline scope re-export. Rebasing the standalone re-export onto that change retained both exports and caused TS2300 at lines 20 and 28. Keep the standalone type re-export and remove the duplicate inline export. Both affected modules now exactly match the previously validated candidate. Validation: - node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo (TS2300 before; passed after) - pnpm check:madge-import-cycles (0 cycles) - node_modules/.bin/oxfmt --check src/state/openclaw-state-maintenance-context.ts src/state/openclaw-state-db-async-lifecycle.ts (passed) - node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/state/openclaw-state-maintenance-context.ts src/state/openclaw-state-db-async-lifecycle.ts (passed) - git diff --check (passed) - Byte-for-byte comparison against the candidate that passed all 95 focused tests and 27 test-type shards (identical for both modules) - Independent Codex autoreview (no actionable findings through P2)
…tory (#162244) #162200 added src/state/openclaw-state-maintenance-context.ts without a scripts/pr-lib/wrapper-components.txt entry; the PR wrapper provisioner failed with MODULE_NOT_FOUND, surfaced by test/scripts/pr-worktree-provision.test.ts as a private-store assertion. pr-wrapper-source-closure.test.ts fails on main without this entry and passes with it.
Doctor requester-authority validation copied the entire SQLite database in a synchronous worker on every authority callback (195 snapshot launches, 31 s for the configured-owner case; candidate Doctor 74 s). Maintenance now owns one reusable live reader; admission, physical file identity, and revocation are re-checked on every reused read, and the reader joins maintenance and database cleanup. Configured-owner case 31.4 s -> 3.6-4.6 s; snapshot launches <= 8 during admission, zero during maintenance. Refs openclaw#161949 Refs openclaw#161867
openclaw#162200 left openclaw-state-maintenance-context.ts importing OpenClawDatabaseMaintenanceScope from the lifecycle module that imports values from it, so pnpm check:madge-import-cycles fails on main. The leaf now owns the scope type and its migration helper type; the lifecycle module re-exports the scope type, so importers are unchanged.
Fix check:madge-import-cycles after openclaw#162200 introduced the cycle openclaw-state-db-async-lifecycle.ts -> openclaw-state-maintenance-context.ts -> openclaw-state-db-async-lifecycle.ts through a type-only import. Move OpenClawDatabaseMaintenanceScope and AgentSchemaMigration into the maintenance context, and preserve the lifecycle module's public scope type export. Runtime behavior and existing caller imports remain unchanged. Validation: - pnpm check:madge-import-cycles (1 cycle before; 0 cycles after) - pnpm check:import-cycles (0 runtime value cycles) - node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo (passed) - node scripts/run-tsgo-core-test-shards.mjs (all 27 shards passed) - node scripts/run-vitest.mjs src/state/openclaw-state-db-async-lifecycle.test.ts src/state/openclaw-agent-db.storage-migration.test.ts src/state/openclaw-state-db-readonly.worker-lifecycle.test.ts src/state/openclaw-state-lease-async.maintenance.test.ts src/state/openclaw-agent-execution.creation-witness.test.ts src/state/openclaw-state-db-resource-scope.test.ts src/state/agent-deletion-journal.snapshot.test.ts src/state/openclaw-state-db-readonly.snapshot-admission.test.ts (95 tests passed) - node_modules/.bin/oxfmt --check src/state/openclaw-state-maintenance-context.ts src/state/openclaw-state-db-async-lifecycle.ts (passed) - node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/state/openclaw-state-maintenance-context.ts src/state/openclaw-state-db-async-lifecycle.ts (passed) - git diff --check (passed) - Independent Codex autoreview (no actionable findings through P2)
A concurrent main fix for the openclaw#162200 check:madge-import-cycles failure moved the same types and used an inline scope re-export. Rebasing the standalone re-export onto that change retained both exports and caused TS2300 at lines 20 and 28. Keep the standalone type re-export and remove the duplicate inline export. Both affected modules now exactly match the previously validated candidate. Validation: - node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo (TS2300 before; passed after) - pnpm check:madge-import-cycles (0 cycles) - node_modules/.bin/oxfmt --check src/state/openclaw-state-maintenance-context.ts src/state/openclaw-state-db-async-lifecycle.ts (passed) - node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/state/openclaw-state-maintenance-context.ts src/state/openclaw-state-db-async-lifecycle.ts (passed) - git diff --check (passed) - Byte-for-byte comparison against the candidate that passed all 95 focused tests and 27 test-type shards (identical for both modules) - Independent Codex autoreview (no actionable findings through P2)
…tory (openclaw#162244) openclaw#162200 added src/state/openclaw-state-maintenance-context.ts without a scripts/pr-lib/wrapper-components.txt entry; the PR wrapper provisioner failed with MODULE_NOT_FOUND, surfaced by test/scripts/pr-worktree-provision.test.ts as a private-store assertion. pr-wrapper-source-closure.test.ts fails on main without this entry and passes with it.
Limit supplemental protected-test expansion to depth two instead of whole owner areas. Preserve the previous PR selection behind OPENCLAW_CI_NODE_SELECTION=full and summarize selected files and rules. Keep six non-import inventory guards on source edits, including the wrapper and swap-fixture regressions from #162200 and #162246. Scheduled and ordinary release inventories stay complete.
Limit supplemental protected-test expansion to depth two instead of whole owner areas. Preserve the previous PR selection behind OPENCLAW_CI_NODE_SELECTION=full and summarize selected files and rules. Keep six non-import inventory guards on source edits, including the wrapper and swap-fixture regressions from openclaw#162200 and openclaw#162246. Scheduled and ordinary release inventories stay complete.
…ions and optional cron cleanup (#171818) * fix(update): success summary repeats settled plugin data/settings upgrades as pending (#170413) * fix(update): retire settled plugin migration warnings from update reports Doctor's config preflight reports a plugin data/settings upgrade as pending, then post-session plugin repairs (acpx, codex) can settle it later in the same pass. The stale warning still reached the updater, which persisted it as a run warning and repeated it in the success summary with "Let the current update finish" guidance after the update had finished. - Doctor drops warnings the ledger shows settled before publishing its update result (new doctor-health-update-result sibling keeps doctor-health under cap). - Finalization retires persisted warning rows a later pass settled or superseded, so the run record and report match the pending ledger. - Post-core convergence is the last migration pass: guidance now says to run the repair command instead of waiting. - The post-core plugin summary names the reason for each informational skip. Fixes #170334 * fix(update): publish an empty warning list when every plugin migration settled * fix(update): leave skipped plugin reasons to the post-core summary owner * fix(update): report a still-pending plugin migration once after post-plugin convergence * test(update): type the settled plugin warning expectation * fix(update): keep warning guidance compatible with recovery bootstrap * fix(doctor): omit absent diagnostics from update publication (cherry picked from commit 7039a32) Backport note: the release line lacks #170392 (post-plugin convergence rereading the ledger and reporting pending migrations as plugin warnings) and the main-only deferredInspectionCheckIds Doctor capture. Dropped the finallyReportedPluginIds supersede path so readiness advisories cannot retire a still-pending Doctor migration warning, omitted deferredInspectionCheckIds from the publication helper, kept the release-line Doctor intro/outro, and adapted the resume-completion test: a still-pending migration is reported once as the final Doctor warning. (cherry picked from commit 46d65ed) Backport adaptation: ported to the 2026.9.33 extended-stable line from the 2026.10.5 adaptation of main's #170413. The 9.33 line has no doctor-health-startup.js or install-owner.js, so doctor-health keeps its release-line exit path and only imports the new publication helper; the config change logging moved with the helper, retiring doctor-health's inline formatUpdateDoctorConfigChange/createSubsystemLogger imports. The helper carries no deferredInspectionCheckIds capture. The 9.33 triage tests are parametrized per update marker; their post-core-convergence cases now expect direct repair guidance, while package-swap cases keep "Let the current update or repair finish". * fix: keep updates moving when optional cron inspection or snapshot cleanup fails (#170754) * fix: keep updates moving through optional cron inspection failures * fix(cron): preserve inspection failures through cleanup * test(cron): prove both failure causes through native workers (cherry picked from commit 1864a74) Backport adaptation: partial backport to the 2026.9.33 extended-stable line. Takes the memory-core dreaming cron inspection catch, the cron read-only snapshot cleanup change (a completed read survives deferred cleanup; a failed read keeps both the inspection and cleanup failures), and the cleanup tests. Drops the store-repair.ts maintenance-reader reuse hunk and its doctor/cron/index.test.ts case, which need #162200 (absent here; 9.33 keeps Doctor cron inspection in src/cron/store/doctor.ts), and drops the matching reader-reuse sentence from the update docs. The 9.33 cold-cleanup test predates main's fault-injection support, so it is adapted in place: its read case completes and now resolves while the registered snapshot retries through cleanupSnapshotOperations, and its copy case asserts the aggregate of the worker copy failure and the snapshot cleanup failure.
Refs #161949
Refs #161867
What Problem This Solves
Fixes slow Doctor repairs and update activation when repeated requester-permission checks copy the entire shared SQLite database.
User Impact
Chat-requested updates keep checking the original owner's live permissions between repair steps without launching a snapshot child for every callback. Revoked or replaced owners still prevent further changes. No configuration, schema, dependency, or operator action changes.
Why This Change Was Made
The requester-authority read path now selects current reads for its exact database. After Doctor's pre-mutation backup boundary, maintenance owns and reuses a live reader when there is no existing managed connection. Every use rechecks admission and physical file identity and reads current authority rows; permission decisions are never cached. Readers join the existing database and maintenance cleanup owners. Other installations retain artifact-preserving, committed-state reads.
The existing maintenance context moved into its own module to keep the lifecycle owner within its line budget. The accepted +169 net production lines replace per-callback full-database copies with one maintenance-owned live reader: an ownership boundary with a measured 31 s → 4 s operator-visible improvement. Admission, file-identity, and revocation checks remain proven. Tests/support add 89 lines and docs add 2. The separate update-progress observer work in #161982 is unchanged.
Evidence
9f73929d7c8c5d2dbaa41a4cd8e6a1d0a21f144c.node scripts/check-changed.mjspassed on the final tree, including all 27 test-typecheck graphs, lint (0 warnings/errors), storage/ownership guards, dead-export scans, and import-cycle checks (0 runtime cycles).paired-node-worker-lifecycle-wire.e2e.test.ts— "keeps local control usable across bundle loss, disconnect, capacity, and role removal" took 182.687 s test / 182.691 s file;paired-node-worker-upgrade-wire.e2e.test.ts— "recovers a completed workspace after a same-version build update and continues the same session" took 107.130 s test / 107.134 s file. These are pre-existing suites on main, and both files remain unchanged. Their test-time STOP is explicitly waived for this lane; the measured costs are retained as a separate follow-up. These are test-body costs, not outer compiler preparation. The shared wire fixture performs real Gateway/worker startup, bundle installation and prewarming, turns and placement changes, recovery, and cleanup. The lifecycle case composes 14 turns and seven dispatches with deliberate bundle deletion/reinstallation; the upgrade case copies dist and restarts a changed runtime. Source review did not establish a safe small fix or the dominant phase. Dedicated phase timing and fixture ownership work are required; no retries, skips, timeout changes, or weakened assertions were used.[email protected]successfully updated the isolatedchannel-owner-policyinstallation to the candidate2026.9.7package. Installed payload equality, owner-policy assertions, two Gateway starts, and health/readiness probes passed; scenario wall time 163 s, update receipt 103.948 s, final candidate Doctor 17.717 s, and package preparation 558 s. Blacksmith Testboxtbx_01m3t4g0yess6brqj5dfw1y7ha(run) packaged carriere0bb89d14c16173eb7f2e7b651b447383fd28981, whose tree is the reviewedcb070331901087989325d2d287b303696542b6d1. This proves published-driver compatibility; the instrumented requester test proves callback cost. Readiness returned HTTP 200 withready: trueand no failing checks while reporting startup event-loop degradation. The build emitted a non-blocking UI gzip-size advisory (217.1 KiB versus 215 KiB)./usr/bin/time -p pnpm test <file> --maxWorkers=1): requester authority 27.24 s wall, read-only 39.99 s, interruption 22.62 s, settlement 19.40 s, stopped activation 17.28 s. All passed; most wall time is transform preparation. The final requester cases took 4.092 s / 4.069 s. Hosted CI timings are not yet available.The new context owner required updating the settlement/interruption test fixtures at their actual mock boundary. Two interruption cases initially waited 120 seconds after their fixture child had already exited. The approval wait now races child closure and reports the initiating error: a negative control fails in 1.421 s; the corrected Linux cases take approximately 0.78–1.01 s, with assertions and timeouts unchanged.
The first complete static run passed all 27 test-typecheck graphs, then found a shadowed callback parameter. The sole follow-up source change renames that local parameter; behavior and package proof remain applicable. The final static gate uses the corrected tree.
An earlier Testbox lease was cancelled externally during runtime compilation; its unfinished checks were not counted as passing. Recovery validation uses Blacksmith Testbox
tbx_01m3t39zdy8bnb94k3svj76c0d(run). No ordinary importer case exceeded the campaign's 30-second test-time threshold and no ordinary importer file exceeded its 120-second test-time threshold; the two pre-existing E2E exceptions above are the named follow-up under the explicit lane waiver. Runtime compilation and serial typecheck preparation are recorded separately from test time.The final remote command completed successfully in 41m19.455s. Auto-merge is off; this PR is for review and is not being landed by this authoring lane.