Repository navigation
fix(doctor): avoid repeated agent database integrity scans - #189247
Conversation
Use bounded current-schema admission when no proof exists and retain process-local admission across incomplete checkpoints. Leave full verification owed to Gateway background verification, preserve migration and recovery gates, and execute required synchronous-opener scans in the integrity child.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: blocked before merge. What this changesThis PR defers seal-less current-schema agent verification, retains process-local admission, and moves required synchronous scans into the existing integrity child. Example: Doctor reopens a current-schema agent database after a checkpoint-incomplete close.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep this PR open: it addresses costly repeated scans, but the bounded path bypasses a required index repair and affected consumer tests need updates. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherDoctor, update, and Gateway callers enter the agent database admission owner, which checks ownership and schema, runs required integrity work, and returns an admitted connection. flowchart TD
A[Doctor or update] --> B[Agent admission owner]
B --> C[Lease and file identity]
C --> D[Bounded schema admission]
C --> E[Integrity child]
D --> F[Admitted connection]
E --> F
F --> G[Gateway background verification]
Technical reviewBest possible solution: Retain bounded admission through the existing owner while routing incomplete canonical indexes through its repair path and preserving meaningful consumer coverage. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the repeated foreground gate, and the PR supplies a real Doctor comparison; this read-only review ran no target code. Is this the best way to solve the issue? Extending the existing admission owner and sharing the integrity child is proportionate, provided bounded eligibility does not bypass required schema convergence. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b7cc7ebc9b44. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +83, Tests +55, Docs +23. Total +161 across 12 files. Added test files: 0. View PR surface stats
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 October 31, 2026, 5:39 AM ET / 09:39 UTC. |
Prefer completed full verification before provisional admission, and require canonical indexes before accepting bounded structure proof. Keep real verification and authority coverage in existing fixtures now that missing proof alone no longer forces a scan.
Treat an unclean close without a surviving lease as bounded no-proof admission. Assert that clean close mints neither verification age nor a seal, while keeping corruption rejection and untrusted lease checks intact. Prove the owed check runs during Gateway startup.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 72a81b2105
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| !verification && | ||
| !reuseRuntimeIntegrity && | ||
| integrityCheck !== "full" && | ||
| admitAgentDatabaseStartupStructure(database, pathname, agentId, startupIntegrity, diagnostics) |
There was a problem hiding this comment.
Preserve scoped integrity checks for explicit data repairs
For a current-schema database with no-proof, this early return also applies when a repair caller supplies a nonempty integrityTables list and requests QUICK checking. For example, doctor-session-transcript-headers.ts passes the transcript tables through repairAdmission before rewriting history, but this branch now skips both the scoped table checks and foreign-key verification. Matching schema definitions do not establish that those tables and indexes are healthy, so the repair can proceed on corruption that previously caused admission to refuse. Restrict bounded admission to ordinary opens without required repair coverage, and retain the requested checks before repair mutations.
AGENTS.md reference: AGENTS.md:L66-L66
Useful? React with 👍 / 👎.
…189247) Team's r253 update crossing scanned the 65 GiB roboclaw agent database twice after the schema migration had already finished: Doctor's 'Session transcripts' reopen found no clean-close seal and ran a 584 s whole-file quick_check on the main thread; its close was checkpoint-incomplete, so 'Config audit' reopened with no proof and scanned again (~13 min). The Gateway was down throughout. Agent-database opens without a seal now use the bounded structure admission already used at Gateway startup (openclaw#188459), keep this process's proof across checkpoint-incomplete closes, and run any required scan in the integrity worker. Bounded admission mints neither a verification timestamp nor a seal, so full verification stays owed and the next Gateway start runs it in the background. A lease-less unclean close now takes this bounded path; closes whose lease survives keep their synchronous full check, and a corrupt page is still rejected. Pre-migration checks are unchanged.
What Problem This Solves
Fixes: Doctor and update repeatedly scan entire agent databases when post-migration opens have no reusable clean-close seal.
The supplied Team r253 timeline (2026-10-31, Gateway stopped) shows a scoped pre-migration check at 07:30:53, then a 583,909 ms synchronous whole-file QUICK check at 08:23:54 during Session transcripts. The 08:36:32 close reported
checkpoint-incomplete, and Config audit started anotherno-proofwhole-file check at 08:38:37. The agent database grew from 36 to 65 GiB; small agent databases followed the same reopen pattern.User Impact
Ordinary current-schema Doctor/update opens without corruption evidence use bounded structure admission and leave full verification owed to Gateway's existing background verifier. Pending migrations, required repairs, explicit FULL checks, and corruption recovery keep their required gates. Bounded admission does not certify unchecked pages or publish a clean-close seal; latent corruption remains subject to normal SQLite detection and background verification.
Why This Change Was Made
Extend the existing bounded startup policy to
no-proofopens, and retain its process-local admission across closes that cannot publish a seal. Reuse still respects the lease owner's foreign-writer refusal and physical-file identity. Necessary checks from synchronous agent openers execute in the existing integrity child, sharing its implementation and error contract with asynchronous checks. No new schema, persistent store, retention policy, configuration option, or background scheduler is introduced.The simplification removes the unconditional local-validation override of lease policy. Production delta: +125/-31 lines (net +94 across eight files); tests: +147/-110 (net +37 across seventeen files). The necessary growth is the synchronous transport to the existing integrity child. Documentation describes pending verification and the Doctor/update decision explicitly.
Evidence
Two focused owning-boundary regressions count yielded integrity checks, rather than elapsed time. They cover two Doctor-style callers in one process, both ordinary close and a pinned WAL producing
checkpoint-incomplete: zero whole-file checks, first admissiondeferred/pending, reopencached, no full-verification receipt or seal, and nointegrityCheckSyncMs.Both fail on base
187b16c78550045c44129642be6edf9bdaac2bf0: expected zero checks, received two. With the fix, the complete cache suite passes 24/24 on Node and Bun. The initial owner/cache/timing suites passed 88 tests, one skipped, on each runtime. Maintenance QUICK/FULL cases also pass separately (4/4 each runtime); explicit FULL still detects the latent index corruption.A real isolated
openclaw doctor --fix --non-interactivemigrated a synthetic seal-less v38 agent database (269,467,648 bytes). With runtime and Control UI builds prepared, Doctor wall time was 83.191 s on base and 76.541 s with the fix (single runs on a shared host; not a general performance benchmark). Base logged three whole-file gates: syncno-proof/quick/healthywithintegrityCheckSyncMs=53, syncrevoked/quick/healthywithintegrityCheckSyncMs=102, and asyncno-proof/quick/healthywithintegrityWorkerCheckMs=82, lifetime 362 ms, total gate 364 ms. The fix logged twono-proof/deferred/pendinggates (sync and async), neither with scan time orintegrityCheckSyncMs. Required pre-migration checks were retained; both runs completed v38→v39.An isolated Gateway using a fixed migrated fixture reached HTTP 200 readiness (
ready=true,coreReady=true, no failing checks). Its startup gate wasdeferred/pending; background full verification completed in 1,054 ms, followed by clean shutdown. No live Gateway, Team deployment, or live state was touched.All nine baseline ratchets passed, including SQLite worker T1 168→168. The changed-check bundle ran against base
187b16c78550045c44129642be6edf9bdaac2bf0. Its attributable type/lint errors were repaired and their checks rerun on the final inputs; its remaining unused-export failures are inherited below. All 29 test typecheck graphs passed. No limits, baselines, or ignore exceptions were raised.The unused-export gate is inherited: untouched main at the pinned base reproduces
captureRepositoryClientActor,RepositoryOperation, andRepositoryAuthorizationin production, plusboundEntryandRepositoryAuthorizationin the full-tree scan. Baseline additionally reports five unrelated Talk types. No baseline or ignore exceptions were changed.The first CI run on
0c1930f56aa1043806e811019739ff7685d925c9had ten failed test jobs (57 case failures), plus the aggregate gate. Nine test jobs were attributable: two production defects (available FULL receipt precedence and missing repairable canonical indexes) and verification fixtures that assumed no-proof always forces a scan or observed parent SQL. The repairs retain the existing FULL and repair expectations, explicitly revoke fixture proof when a scan is required, and count the real worker transports. A duplicate parent-SQL interleaving case was removed; the independent real-child test still verifies an external commit between integrity and foreign-key checks.The inherited test job is
checks-node-changed-compact-small-18-2:src/cli/update-cli.target-schema.test.ts > refuses incompatible inspected runtime requirements when a later lookup disagrees. The exact case reproduces on untouched main at the pinned base (1 failed, 23 skipped), with the samevi.fncall mismatch. The other 56 initial failures were attributable, including a deletion-fixture timeout that cascaded through 13 cases.Final targeted failure reruns passed on Node and Bun: 32 admission/authority/corruption cases, 18 migration/repair/reuse/shutdown cases, and 13 deletion cases. The two new no-proof regressions also passed again in the final deletion run (15/15 per runtime). The coordinator follow-up now runs the entire Linux killed-owner recovery loop under Node and Bun, including the previously unreached corrupt-page and interrupted-admission cases; see the exact results below.
Final independent Codex autoreview at
--max-priority P1completedscoped-cleanin a build-free checkout whose complete patch was verified byte-identical to this candidate. One earlier P1 claim about scoped FULL receipts was rejected after inspecting the full owner: FULL always issues unscopedintegrity_check, andtablesis consulted only for QUICK supplementation. The final reviewer independently confirmed this contract.Current head:
72a81b2105a1d81bfec71356fea074a8a4490740. The coordinator confirmed that a lease-less unclean WAL close isno-proofand authorized this additional push. The olddirty-receiptfixture is now namedlease-less-uncleanand expects the bounded path's actual[0,0]FULL/FK work. Foreign-boot, legacy-lease, pid-reused, corruption rejection, and interrupted-admission expectations are unchanged.The bounded case explicitly proves that clean close produces neither
verifiedAtnor an on-disk seal, and that reopening still does not certify integrity. The existing #188459 Gateway-startup test now asserts the missing verification before startup, already asserts it remains missing before the background verdict, and requires a real verification timestamp after successful background verification. The decision table explicitly includes lease-less unclean closes; no full scan was restored.Linux local-container proof used Node 24.22.1 and the repository-selected Bun runtime, with a fresh clone of the pinned head plus the delta and all three changed-file SHA-256 hashes verified. Both commands below completed successfully:
Each passing killed-owner test executes all eight fixture cases.
corrupt-pagerejects with an integrity error and records a check; the loop reaches and passesinterrupted-admission. Both Gateway background-verification variants (healthy and corrupt) pass. No safety assertion was weakened or skipped.The remote Blacksmith Testbox attempt (
tbx_01m68sxq8mfwp1ad2t937wcr7m, allocation run) timed out before any test ran and was stopped. The Linux results above are local Docker proof, not remote Testbox proof; its task-owned container was removed after the successful run.The three-file coordinator delta has zero production changes and net eight test lines. Targeted lint, format, test typecheck, line cap, and
git diff --checkpass. Codex autoreview of the delta at P1 completedscoped-clean. Exact-head CI run 41195930830 completed on the exact head: 91 jobs, 63 successful, 25 skipped, and three failed. The failures are the two inherited jobs below and the dependentopenclaw/ci-gateaggregate. No failure is attributable to this PR.checks-node-changed-compact-large-10-2is the updater-schema mismatch reproduced on pinned main above.check-lint-core-2reports three unawaited SDK resource closes in the untouched Gateway visitor-access helper. Those calls were added on main by #189296, which is included in CI's merge input. A clean worktree at current main7293e892728aef27996d8a15626e006e2d537dccreproduces exactly the three errors at lines 350, 444, and 700 (zero warnings, three errors, exit 1):The original pinned base predates those calls and does not reproduce those diagnostics; current main does. No unrelated repair, CI rerun, additional push, or merge was performed. The bounded watch completed at its 30-minute scheduled snapshot (watcher exit 15 for the failed workflow). The completed-run job list confirms no additional failure. This READY PR remains open and intentionally unmerged for coordinator admin merge.