Repository navigation
improve(doctor): stop copying each database twice to classify its engine - #197277
Conversation
Maintenance-owned Doctor captures classified every database engine in the parent, then the backup worker classified the same sources again. Each artifact-preserving engine probe copies and hashes the whole source, so a standalone `openclaw doctor` read a 422 MB agent database four extra times just to learn it is SQLite. The parent now hands its classification to the worker, which reuses it instead of probing. On a 422 MB agent database, plain Doctor agent-DB reads drop from 8,481 MiB to 6,869 MiB and `doctor --fix` from 11,711 MiB to 10,100 MiB.
Covers the 29 added test lines plus 21 lines of inherited base debt, which the test-line ratchet allows an exact grant to reconcile.
|
🦞👀 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 Summary: ✅ CompletedThis 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: needs changes before merge. What this changesThis PR passes the maintenance parent's database-engine classifications to the backup worker to avoid repeating full-copy probes. Example: Run plain Doctor with a seeded 422 MB agent database and a retained capture.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this PR removes measurable redundant Doctor work, but its added regression test contains a type error that needs repair. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherDoctor's maintenance capture discovers database files, classifies their engines, and launches an isolated backup worker that produces verified recovery snapshots. flowchart LR
A[Doctor maintenance capture] --> B[Discover database paths]
B --> C[Parent engine classification]
C --> D[Isolated backup worker]
D --> E[Verified recovery snapshots]
D --> F[Probe unclassified sources]
Technical reviewBest possible solution: Keep the existing classification handoff and repair the regression test by retaining its engine map through the typed producer. Do we have a high-confidence way to reproduce the issue? Current-main source independently classifies maintenance-owned sources in the parent and worker; the PR also records matched native CLI measurements, but no target code was executed during this review. Is this the best way to solve the issue? Reusing the existing parent's classification is a small, appropriate fix: canonical paths match the worker inventory, fresh worker observations take precedence, and unclassified sources retain their existing probe. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a87a4bf29d36. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +8, Tests +29, Other +2. Total +39 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 11, 2026, 11:11 AM ET / 16:11 UTC. |
…gine reuse Use a pass-through catch instead of Promise.reject for the sidecar lstat fence, type the test's expected engine map, and allocate exactly the 26 added test lines.
|
Merged via squash.
|
|
Correction to the landed squash message (314f747), which concatenated earlier commit messages:
The PR body above has the full measurements and the remaining follow-ups. |
- Resolve src/infra/update-database-backup.ts: keep inspectRestorableDatabaseFiles in update-database-backup-files.ts (moved by this PR for the max-lines cap) and carry main openclaw#197277 sidecar lstat change into it; keep main engine-reuse changes.
…ine (openclaw#197277) * perf(doctor): reuse the parent's engine classification in backup workers Maintenance-owned Doctor captures classified every database engine in the parent, then the backup worker classified the same sources again. Each artifact-preserving engine probe copies and hashes the whole source, so a standalone `openclaw doctor` read a 422 MB agent database four extra times just to learn it is SQLite. The parent now hands its classification to the worker, which reuses it instead of probing. On a 422 MB agent database, plain Doctor agent-DB reads drop from 8,481 MiB to 6,869 MiB and `doctor --fix` from 11,711 MiB to 10,100 MiB. * test: allocate test lines for the Doctor engine probe reuse regression Covers the 29 added test lines plus 21 lines of inherited base debt, which the test-line ratchet allows an exact grant to reconcile. * fix(doctor): satisfy CI lint, test types and test-line ratchet for engine reuse Use a pass-through catch instead of Promise.reject for the sidecar lstat fence, type the test's expected engine map, and allocate exactly the 26 added test lines.
) * feat(database): keep PostgreSQL rollback captures in PostgreSQL - Exact update rollback and Doctor pre-migration captures copy the store into a frozen restore_<uuid> schema on the same server - The copy runs in one REPEATABLE READ transaction: generated DDL, INSERT ... SELECT per table, sequences from captured allocations - Manifest hashes come from a separate source read in the same snapshot and are checked against the copy - The manifest keeps today's fields and adds carrier "postgres-schema" plus the schema name; only anchor.sqlite and manifest.json are written locally - Restore copies the frozen schema into a fresh namespace and checks the manifest hashes, so the capture survives a failed or repeated rollback - Verified update retirement drops capture schemas through the restore namespace guard before removing the snapshot directory - Capture schemas carry a comment naming their directory; before each pre-migration capture, Doctor drops this store's captures whose directory was removed - The portable SQLite export stays the default for archives, ports, repairs and the candidate state copy; the shared state family keeps it for client credential rollback - inspectRestorableDatabaseFiles and readPostgresPortCapabilities move unchanged to their own modules to stay under the line cap * fix(database): resolve CI failures for PostgreSQL schema captures - Doctor's PostgreSQL capture no longer writes database.sqlite; the client credential Doctor test reads the captured token from the capture schema and drops it on cleanup - Rename the worker-side prune to pruneOrphanedPostgresCaptures so prunePostgresSchemaCaptures has one exported spelling (export-name-collisions) - Set the test-lines allocation to the CI-counted net delta (384) * feat(database): make PostgreSQL server recovery captures opt-in - Add database.postgres.recoveryCaptures ("portable" default, "server") - Update and Doctor captures use restore_<uuid> schemas only when "server" - Doctor still prunes orphaned capture schemas regardless of the setting - Shared state family and candidate state copy stay portable - Document the server carrier trade-offs in database-engines.md - Raise core config baseline 2638 -> 2639 for the new setting - Raise test-lines allocation 384 -> 421 for the opt-in tests * fix(database): prune only capture schemas this role can drop - Restrict Doctor capture pruning to schemas the runtime role can use (pg_has_role USAGE) - Another role's marked restore_ schema under the same path no longer fails Doctor - Test two isolated roles with one directory prefix; fails without the fix - Raise test-lines allocation 421 -> 466 for the new test * Merge origin/main into feat/postgres-native-captures - Resolve docs/.generated/config-baseline.{counts.json,sha256} by regenerating with pnpm config:docs:gen (core 2641 -> 2642). * test(database): raise schema capture test-line allocation to 469 - Net test lines of this change against current main are +469 (was 466 against the old base). * docs(database): note original state captures stay portable - Server recovery captures cover update rollback and Doctor pre-migration captures only. - Original state captures before an update or standalone doctor --fix still write SQLite images of PostgreSQL stores. * Merge origin/main into feat/postgres-native-captures - Resolve docs/.generated/config-baseline.{counts.json,sha256} by regenerating with pnpm config:docs:gen (core 2645 -> 2646). * Merge origin/main into feat/postgres-native-captures - Resolve docs/.generated/config-baseline.sha256 by regenerating with pnpm config:docs:gen (counts unchanged, core 2646). * Merge origin/main into feat/postgres-native-captures - Bring in #197058, which retires the ui-e2e scenario failing on main. - Resolve docs/.generated/config-baseline.{counts.json,sha256} by regenerating with pnpm config:docs:gen (core 2645 -> 2646). * Merge origin/main into feat/postgres-native-captures - Resolve src/infra/update-database-backup.ts: keep inspectRestorableDatabaseFiles in update-database-backup-files.ts (moved by this PR for the max-lines cap) and carry main #197277 sidecar lstat change into it; keep main engine-reuse changes. * Merge origin/main into feat/postgres-native-captures - Resolve docs/.generated/config-baseline.{counts.json,sha256} by regenerating with pnpm config:docs:gen (core 2647 -> 2648). * fix(database): commit recovery capture metadata atomically Write the cleanup marker through the existing post-data renderer so it commits with the copied schema. Preserve owner-specific DDL and keep ordinary restores unmarked. Release note: keep PostgreSQL recovery captures discoverable after a client interruption at COMMIT. Validation: the unchanged parent loses its marker after a real client SIGKILL; the fixed PostgreSQL 17.11 capture module passes all eight cases. Targeted lint, formatting, and independent P0-P2 correction review pass. Missing public.unaccent was reproduced on the parent and corrected through documented test-server initialization. * fix(snapshot): keep capture custody paths private * fix: refresh the reviewed correction baseline Baseline-Refresh: 5211f64faa02cea25424c18dc6bcc3512926c76f * fix(config): regenerate capture recovery baseline Co-authored-by: Mitchell Etzel <[email protected]> Co-authored-by: Mitchell Etzel <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
…claw#196236) * feat(database): keep PostgreSQL rollback captures in PostgreSQL - Exact update rollback and Doctor pre-migration captures copy the store into a frozen restore_<uuid> schema on the same server - The copy runs in one REPEATABLE READ transaction: generated DDL, INSERT ... SELECT per table, sequences from captured allocations - Manifest hashes come from a separate source read in the same snapshot and are checked against the copy - The manifest keeps today's fields and adds carrier "postgres-schema" plus the schema name; only anchor.sqlite and manifest.json are written locally - Restore copies the frozen schema into a fresh namespace and checks the manifest hashes, so the capture survives a failed or repeated rollback - Verified update retirement drops capture schemas through the restore namespace guard before removing the snapshot directory - Capture schemas carry a comment naming their directory; before each pre-migration capture, Doctor drops this store's captures whose directory was removed - The portable SQLite export stays the default for archives, ports, repairs and the candidate state copy; the shared state family keeps it for client credential rollback - inspectRestorableDatabaseFiles and readPostgresPortCapabilities move unchanged to their own modules to stay under the line cap * fix(database): resolve CI failures for PostgreSQL schema captures - Doctor's PostgreSQL capture no longer writes database.sqlite; the client credential Doctor test reads the captured token from the capture schema and drops it on cleanup - Rename the worker-side prune to pruneOrphanedPostgresCaptures so prunePostgresSchemaCaptures has one exported spelling (export-name-collisions) - Set the test-lines allocation to the CI-counted net delta (384) * feat(database): make PostgreSQL server recovery captures opt-in - Add database.postgres.recoveryCaptures ("portable" default, "server") - Update and Doctor captures use restore_<uuid> schemas only when "server" - Doctor still prunes orphaned capture schemas regardless of the setting - Shared state family and candidate state copy stay portable - Document the server carrier trade-offs in database-engines.md - Raise core config baseline 2638 -> 2639 for the new setting - Raise test-lines allocation 384 -> 421 for the opt-in tests * fix(database): prune only capture schemas this role can drop - Restrict Doctor capture pruning to schemas the runtime role can use (pg_has_role USAGE) - Another role's marked restore_ schema under the same path no longer fails Doctor - Test two isolated roles with one directory prefix; fails without the fix - Raise test-lines allocation 421 -> 466 for the new test * Merge origin/main into feat/postgres-native-captures - Resolve docs/.generated/config-baseline.{counts.json,sha256} by regenerating with pnpm config:docs:gen (core 2641 -> 2642). * test(database): raise schema capture test-line allocation to 469 - Net test lines of this change against current main are +469 (was 466 against the old base). * docs(database): note original state captures stay portable - Server recovery captures cover update rollback and Doctor pre-migration captures only. - Original state captures before an update or standalone doctor --fix still write SQLite images of PostgreSQL stores. * Merge origin/main into feat/postgres-native-captures - Resolve docs/.generated/config-baseline.{counts.json,sha256} by regenerating with pnpm config:docs:gen (core 2645 -> 2646). * Merge origin/main into feat/postgres-native-captures - Resolve docs/.generated/config-baseline.sha256 by regenerating with pnpm config:docs:gen (counts unchanged, core 2646). * Merge origin/main into feat/postgres-native-captures - Bring in openclaw#197058, which retires the ui-e2e scenario failing on main. - Resolve docs/.generated/config-baseline.{counts.json,sha256} by regenerating with pnpm config:docs:gen (core 2645 -> 2646). * Merge origin/main into feat/postgres-native-captures - Resolve src/infra/update-database-backup.ts: keep inspectRestorableDatabaseFiles in update-database-backup-files.ts (moved by this PR for the max-lines cap) and carry main openclaw#197277 sidecar lstat change into it; keep main engine-reuse changes. * Merge origin/main into feat/postgres-native-captures - Resolve docs/.generated/config-baseline.{counts.json,sha256} by regenerating with pnpm config:docs:gen (core 2647 -> 2648). * fix(database): commit recovery capture metadata atomically Write the cleanup marker through the existing post-data renderer so it commits with the copied schema. Preserve owner-specific DDL and keep ordinary restores unmarked. Release note: keep PostgreSQL recovery captures discoverable after a client interruption at COMMIT. Validation: the unchanged parent loses its marker after a real client SIGKILL; the fixed PostgreSQL 17.11 capture module passes all eight cases. Targeted lint, formatting, and independent P0-P2 correction review pass. Missing public.unaccent was reproduced on the parent and corrected through documented test-server initialization. * fix(snapshot): keep capture custody paths private * fix: refresh the reviewed correction baseline Baseline-Refresh: 5211f64faa02cea25424c18dc6bcc3512926c76f * fix(config): regenerate capture recovery baseline Co-authored-by: Mitchell Etzel <[email protected]> Co-authored-by: Mitchell Etzel <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
What Problem This Solves
Fixes:
openclaw doctorreads the agent database about 20 times its size, partly because the Doctor's pre-repair capture copies each database twice just to learn which engine it uses.User Impact
User impact: standalone
openclaw doctorandopenclaw doctor --fix, including the manual npm update procedure, read and copy less data on large installs. On a 422 MB agent database, plain Doctor reads 19% less from that database and finishes about 9% faster. No behavior or output changes.Why This Change Was Made
During a maintenance-owned original-state capture, the Doctor parent classifies every source's engine (SQLite or a PostgreSQL anchor) before it starts the backup worker. Each classification is an artifact-preserving probe that copies and then compares the whole source in a child process. The backup worker then classified the same sources again with the same full-copy probe. The parent now passes its classification to the worker, which reuses it and probes only sources the parent did not classify. A spelling mismatch falls back to the old probe. PostgreSQL admission checks and the worker's own observations are unchanged.
To stay within the 700-line lint budget for
update-database-backup.ts, the sidecarlstatfence now uses.catch(ignoreMissingPath). Only sidecarENOENTis ignored, as before.Refs: daily update-reliability sweep follow-up to G65's Doctor read measurement; no tracking issue.
Evidence
classifies maintenance-owned sources once for the backup worker(src/infra/update-database-backup.test.ts): red on base (the worker receives no classification), green with the fix. All 316 tests in the backup and database-engine suites pass on Crabbox AWS.tsgo:core,oxfmt,oxlintand the test-line ratchet are clean.ac7e941722a. Agent-database bytes were counted withstraceacross Doctor and all its children.doctor(retained capture present)doctor --fix(first run, no retained capture)Engine probes per plain Doctor run drop from 4 to 2: one in the reuse comparison and one in the fresh capture, each now probed only by the parent.
Remaining read amplification (follow-ups, not in this PR)
After this change, plain Doctor still reads about 16 times the agent database size:
sourceMatchesCopy). That doubles every child and accounts for about 47% of reads. A cheaper proof under maintenance custody, where no writer exists, would be a snapshot-owner design change.doctor --fixopens six separate full-copy session readers (archive preparation, database preflight, migrations, Database engines, SQLite database size). None of them share a private image.Update-driven Doctor runs skip "Preserve original state" when an update recovery capture is already retained, so these mostly affect standalone Doctor and the manual npm procedure.