Repository navigation
improve(doctor): speed up schema checks for large databases - #143802
Conversation
|
🦞👀 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. Reviewed September 13, 2026, 2:01 AM ET / 06:01 UTC (Revision 9). ClawSweeper reviewWhat this changesDoctor and restart readiness checks inspect eligible agent databases in a read-only child process, avoiding full copies while preserving ownership checks and recovery snapshots. Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this remains a useful optimization absent from main. The prior configured-agent finding is resolved, and the remaining migration notice is unsupported because the patch changes read orchestration without changing persisted contracts. No actionable correctness or security finding remains. Priority: P2 Review scores
Verification
How this fits togetherDatabase preflight checks whether existing OpenClaw state is compatible before Doctor or Gateway readiness completes. It reads agent database metadata and returns compatibility, ownership, or repair diagnostics. flowchart TD
A[Doctor or restart readiness] --> B[Agent database preflight]
B --> C{Safe direct inspection?}
C -->|Yes| D[Read-only child transaction]
C -->|No| E[Private snapshot]
D --> F[Ownership and schema checks]
E --> F
F --> G[Ready or diagnostic refusal]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +305, Tests +225, Docs +6. Total +536 across 13 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Retain the existing maintenance validator and snapshot recovery owner while using coherent child reads for eligible schema-only checks; no data migration is needed. Do we have a high-confidence way to reproduce the issue? Yes: current main visibly copies agent databases for schema-shape checks, and the supplied real-SQLite readiness benchmark exercises that cost. This read-only review did not execute tests or benchmarks. Is this the best way to solve the issue? Yes: the optimization reuses existing validation and source-lifetime owners while retaining required recovery snapshots. The final helper substitution preserves behavior, and an additional migration requirement would not match this diff. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 99d4a259ebf7. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
* fix(pr): recover partially written review transitions Classify index and working-tree entries independently against the journaled source and target before replaying an interrupted native restore. Preserve foreign bytes, ignored overlaps, and hidden index metadata, including intent-to-add and resolve-undo state. Rebuild the validated source index so completed index deletions can still remove their remaining source files. Preserve the reserved .local artifact namespace and existing journal endpoints. Unknown zero-byte files remain refused rather than inferred as owned writes. Validation: 66 native owner cases, complete changed checks, and independent review. Regression cases demonstrate worktree-first and index-first recovery, plus fail-before/pass-after coverage for intent-to-add and resolve-undo guards. Related: #143802 * fix(pr): register the journal validator executable entry * test(pr): preserve Git reader coverage for journal recovery Exercise the active Node-helper Git reader in the failure fixture and keep operation artifacts in the reserved .local namespace. Record reader starts and delayed exits after stdout closure so successful validation still proves every producer joined before lock release. Validation: focused reader cases changed from two failures to five passes; full operation-lock suite passed 114 tests with one Linux-only zombie case skipped on macOS. Complete changed checks and focused independent review passed. Production runtime bytes are unchanged. * fix(pr): preserve leading BOM characters in Git path records Treat Git output as pathname records rather than a BOM-framed text document. Preserve an initial U+FEFF while keeping fatal UTF-8 decoding, so an untracked lookalike cannot be misclassified as a target path before native replay. The native regression previously changed HEAD before final refusal; it now preserves the source state. All 67 owner tests, complete changed checks, and focused independent review pass.
* fix(pr): recover partially written review transitions Classify index and working-tree entries independently against the journaled source and target before replaying an interrupted native restore. Preserve foreign bytes, ignored overlaps, and hidden index metadata, including intent-to-add and resolve-undo state. Rebuild the validated source index so completed index deletions can still remove their remaining source files. Preserve the reserved .local artifact namespace and existing journal endpoints. Unknown zero-byte files remain refused rather than inferred as owned writes. Validation: 66 native owner cases, complete changed checks, and independent review. Regression cases demonstrate worktree-first and index-first recovery, plus fail-before/pass-after coverage for intent-to-add and resolve-undo guards. Related: openclaw#143802 * fix(pr): register the journal validator executable entry * test(pr): preserve Git reader coverage for journal recovery Exercise the active Node-helper Git reader in the failure fixture and keep operation artifacts in the reserved .local namespace. Record reader starts and delayed exits after stdout closure so successful validation still proves every producer joined before lock release. Validation: focused reader cases changed from two failures to five passes; full operation-lock suite passed 114 tests with one Linux-only zombie case skipped on macOS. Complete changed checks and focused independent review passed. Production runtime bytes are unchanged. * fix(pr): preserve leading BOM characters in Git path records Treat Git output as pathname records rather than a BOM-framed text document. Preserve an initial U+FEFF while keeping fatal UTF-8 decoding, so an untracked lookalike cannot be misclassified as a target path before native replay. The native regression previously changed HEAD before final refusal; it now preserves the source state. All 67 owner tests, complete changed checks, and focused independent review pass.
32df716 to
1ac4a99
Compare
|
@clawsweeper re-review Rebased onto current main; head |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Final head Fresh final-head 2 GiB active-WAL preflight measurements also passed: 9.647 s baseline → 1.463 s candidate median, with identical results and unchanged database/WAL hashes. Please reassess the compatibility/proof blockers using these results. Full CI remains red on documented unrelated base UI/localization failures; those are not claimed green. No schema or persisted representation changes are introduced. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
8a466d4 to
b368458
Compare
|
Rebased onto main at d093d65; head b368458615e. Preserved upstream bounded header reads, ownership admission, and startup-readiness snapshots; schema-shape-only inspections retain the PR worker optimization. Focused preflight and worker suites: 41 tests passed. Formatting and diff checks passed. Core typecheck stops at the unchanged upstream src/gateway/server-startup-finish.ts:416 (GatewayPostReadySidecarHandle array mismatch); not a green full typecheck. |
|
Related update: #145577 has merged. It removes redundant copies of Doctor's already-isolated shared-state lint database, whereas this PR targets agent database schema-shape inspection. These are complementary changes, not equivalent fixes. #145541 separately addresses header-only agent startup checks. This PR should remain open; the merge of #145577 is not a reason to close it as superseded. |
Co-authored-by: VACInc <[email protected]>
Co-authored-by: VACInc <[email protected]>
Co-authored-by: VACInc <[email protected]>
Carry ownership metadata through the coherent child read, retain native source admission through failed close, and cover actual Doctor/restart callers. Keep explicit agent-file preflight with the agent inspector to stay under the source-size gate. Remove the upstream unused secret-ref import that blocked typechecking without changing its public re-export. Co-authored-by: VACInc <[email protected]>
7e531c6 to
6ebd8d5
Compare
|
@clawsweeper re-review Rebased again onto main d0ec2f1; current head 6ebd8d5. The configured-agent routing finding is fixed without weakening ownership admission: the worker returns coherent ownership metadata and the parent retains default/system refusal and secondary-agent isolation. Actual Doctor/restart DELETE and WAL cases fail before the repair and pass afterward. Also repaired a native-close lifetime gap found during integration: the canonical source-read owner retains its lease after failed close until child exit. The real two-process regression fails before and passes after; coherent metadata, read failure, and cancellation remain covered. 100 focused tests passed before the mechanical second rebase; all nine affected configured-agent/admission tests and core typecheck passed again on this head. Main’s optional/defaulted schema-version pair is preserved. all changed-surface gates passed (core/test typechecks, typed lint, dead exports, import cycles, database guards), and final autoreview is scoped-clean at its default P0 threshold. The PR body now has a configured-agent readiness benchmark (538 MB active-WAL fixture: 2.807 s to 2.249 s median, identical DB/WAL hashes), accurate current revision, historical-only upgrade evidence, and explicit proof limits. There is no persisted schema/data/migration change. The original full local build passed, but the final build was invalidated at declaration publication by a dependency input changing during compilation; not claimed green. Hosted exact-head CI is now running and will provide the final build/CI result. Please reassess the current integration and the documented compatibility evidence. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Co-authored-by: VACInc <[email protected]>
|
@clawsweeper re-review Current head d4817de fixes the sole observed CI architecture failure by replacing the copied raw pragma setup with the canonical SQLite connection helpers. The same timeout/query-only/trusted-schema values are retained. Full pnpm check:architecture, 13 explicit-file/configured-readiness tests, and fresh autoreview passed. New exact-head CI: https://github.com/openclaw/openclaw/actions/runs/34741433361 . Additional current data-model compatibility evidence is now in the PR body: 52 Doctor post-upgrade, legacy-schema-preflight, and repair-completion tests passed; canonical schema definitions, schema-version contracts, and generated row contracts have zero diff against the rebased main. The copied-file tests check byte/file preservation. No migration is required because this patch changes read orchestration, not stored formats or writers. The older published-updater E2E remains explicitly historical, not current-head proof. Please reassess the remaining data-model compatibility notice against these current results. Your latest review already reports accepted runtime proof and no actionable findings; please distinguish an unchanged stored format that needs no migration from missing proof for an actual migration. Do not waive a genuine compatibility issue if one remains. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…#143802) * improve(doctor): avoid full copies for schema-only inspections Co-authored-by: VACInc <[email protected]> * test(doctor): follow the snapshot owner after rebase Co-authored-by: VACInc <[email protected]> * fix(doctor): comply with SQLite query guardrails Co-authored-by: VACInc <[email protected]> * fix(doctor): preserve ownership in fast schema checks Carry ownership metadata through the coherent child read, retain native source admission through failed close, and cover actual Doctor/restart callers. Keep explicit agent-file preflight with the agent inspector to stay under the source-size gate. Remove the upstream unused secret-ref import that blocked typechecking without changing its public re-export. Co-authored-by: VACInc <[email protected]> * fix(doctor): reuse canonical read-only SQLite pragmas Co-authored-by: VACInc <[email protected]> --------- Co-authored-by: VACInc <[email protected]> Co-authored-by: roboclaw-bot <[email protected]>
What Problem This Solves
Doctor and Gateway restart readiness checks copy whole agent databases even when they only need schema metadata. The copy cost and temporary disk requirement grow with stored transcripts. The previous revision also bypassed the optimization for configured agents—the actual Doctor and restart callers.
Related: #139870. The shared-state lint-copy improvement in #145577 and header-only startup optimization in #145541 are complementary, not replacements.
Why This Change Was Made
Eligible agent schema checks read version, shape, and ownership metadata in one coherent read-only child transaction. The parent applies the existing ownership admission decision, including isolating secondary agents and refusing default/system-agent mismatches.
The child uses the canonical source-read lifetime owner, retaining its lease if native SQLite close fails until the child exits. Empty files, rollback recovery, incomplete WAL families, owner-provided snapshots, and full startup readiness keep the existing snapshot path. Ordinary busy/I/O failures are not retried as full copies.
The explicit copied-agent-file preflight now lives beside the agent schema inspector; its CLI and test callers were moved without changing behavior. This keeps the main preflight owner below the lint size limit. The earlier unused-import CI repair is now present on main and no longer contributes to this PR.
Data compatibility: no schema version, table, index, stored-row format, config, migration writer, or recovery writer is changed. The existing maintenance validator remains authoritative. Removing this optimization requires no data conversion.
User Impact
Configured agents get the intended schema-inspection optimization without weakening ownership admission or startup integrity checks. A source whose native close fails cannot prematurely allow canonical replacement.
Evidence
Current head:
d4817de7b5f93a8445d3b26b88d284bc736e5d04, rebased again onto maind0ec2f18a5b. CI is not claimed green until its exact-head run finishes.assertOpenClawDatabasesReadyfor Doctor and Gateway restart failed before the repair with “No space for a full agent database snapshot.” They pass after the repair, including foreign-owner refusal, fresh newer-schema metadata, and missing-index detection.@peculiar/asn1-csr); this is not claimed as a passing final full build. Exact-head hosted CI must establish final build completion. Testbox was unavailable because Blacksmith was not authenticated, so trusted-source local fallback was used. No remote success is claimed.The second rebase preserves main’s newly optional/defaulted schema-version pair. All nine affected configured-agent/admission tests, core typecheck, formatting, and diff checks passed again. The prior 100-test suite and changed-surface gates cover the unchanged repair; hosted CI verifies the full new base.
Configured-agent performance on real SQLite
The actual Doctor readiness entry point was compared with pinned main
aac6465ffeeusing the same 538,669,056-byte synthetic agent database, an active WAL writer, and a configured default agent. Linux / Node v26.8.2; one warm-up per variant, then three alternating samples:All calls completed successfully. SHA-256 hashes of the database and WAL were unchanged. This is a synthetic configured-agent readiness measurement (about 20% lower median), not full Doctor CLI latency. The baseline module was read from the pinned Git revision with imports resolved to the same dependencies. The subsequent explicit copied-file preflight move does not change this measured readiness path.
Data-model compatibility proof
No migration is required. A zero-diff check against the rebased main confirms that both canonical schema definitions, both schema-version contracts, and both generated database row contracts are unchanged. The patch changes read orchestration and connection setup only.
On the current repair, 52 existing Doctor post-upgrade, schema-preflight, and repair-completion tests passed. They include supported legacy-registry admission, newer-database refusal before repair, and preserving/revalidating repair ownership through restart. Thirteen explicit copied-file and configured-agent tests also passed; the copied-file tests verify that the reader does not mutate or create databases, including wrong-owner and sidecar refusals. These are current compatibility regression tests, not a claim of a fresh published-updater E2E run.
The full
pnpm check:architecturegate now passes after replacing the moved raw pragma setup with the existing SQLite connection helpers. That follow-up preserves the same busy timeout, query-only mode, and trusted-schema setting.Retained historical upgrade proof—not rerun for this refresh
The published
[email protected]updater installed earlier candidate8a466d4562c067098218213573ac2b4f83e6be77in the isolated Dockersqlite-volumeupgrade-survivor scenario. It preserved 4,800 sessions, 23,890 events, and 2,200 cron jobs; Gateway RPC verified eight conversations across two agents before and after restart; repeat Doctor completed in 13 seconds. The prior PR evidence and author comments retain the full command and output. These results support that earlier revision only, not a fresh upgrade claim.Nonblocking follow-ups
A future simplification can remove the schema-only inspector’s unused startup-readiness option; startup stays on its established parent/snapshot path. Cold/PERSIST rollback-journal residue still selects a private snapshot conservatively, so it does not receive the fast path. Neither limitation weakens admission or recovery.
Proof limits
No production database or Gateway was touched. No live external channel was exercised. Windows/macOS large-database performance and published-updater E2E were not rerun in this refresh. Full integrity scans and recovery snapshots retain their existing costs.
View the OpenClaw team session