Repository navigation
fix(doctor): inspection stages a full copy of the live state database on every run - #193648
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. |
…ull copy Doctor's per-store inspection copied every SQLite source into the snapshot cache before reading its engine marker, schema facts, content version and lease row. A verified live WAL source is now read in place by the existing read-only child inside one read transaction; every other source, and any failure, keeps the private copy.
…y's import graph The read-only operation registry imported the live reader's type, which pulled the snapshot and worker graph back into the registry and formed an import cycle. The registry now reads a leaf contract, and BackupEngine lives with the other leaf engine types.
7bf20df to
5245a19
Compare
|
Codex review: needs maintainer review before merge. What this changesDoctor inspects verified live WAL databases through the existing isolated reader instead of staging a full private copy. Example: Inspect a verified live shared-state database with a 6,128,256-byte database and WAL family.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it addresses unnecessary database copying still present on main, preserves recovery fallbacks, and introduces no definite correctness defect found in this review. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherDoctor supplies store paths and expected schema facts to database diagnostics, which inspect SQLite or PostgreSQL metadata and return health findings and recovery guidance. flowchart TD
A[Doctor inspection] --> B[Store diagnostics]
B --> C[Verified live WAL check]
C --> D[Isolated read transaction]
C --> E[Private copy fallback]
D --> F[Shared metadata inspection]
E --> F
F --> G[Diagnostic result]
Technical reviewBest possible solution: Use the existing isolated reader for verified live WAL inspection, share metadata interpretation with the copy path, and retain private recovery for all other sources. Do we have a high-confidence way to reproduce the issue? Current main visibly stages every inspected SQLite store, and the PR supplies a reported red/green regression using a real WAL writer; this read-only review executed no reproduction. Is this the best way to solve the issue? The change removes unnecessary copying at the diagnostic owner, preserves metadata semantics, and reuses established transport and transaction machinery without introducing persisted state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0499ce287bb8. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +118, Tests +147, Other +4. Total +269 across 10 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. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 5, 2026, 1:25 PM ET / 18:25 UTC. |
|
Merged via squash.
|
… on every run (openclaw#193648) * fix(doctor): inspect a live shared-state database without staging a full copy Doctor's per-store inspection copied every SQLite source into the snapshot cache before reading its engine marker, schema facts, content version and lease row. A verified live WAL source is now read in place by the existing read-only child inside one read transaction; every other source, and any failure, keeps the private copy. * fix(doctor): keep the live-read operation contract out of the registry's import graph The read-only operation registry imported the live reader's type, which pulled the snapshot and worker graph back into the registry and formed an import cycle. The registry now reads a leaf contract, and BackupEngine lives with the other leaf engine types.
… on every run (openclaw#193648) * fix(doctor): inspect a live shared-state database without staging a full copy Doctor's per-store inspection copied every SQLite source into the snapshot cache before reading its engine marker, schema facts, content version and lease row. A verified live WAL source is now read in place by the existing read-only child inside one read transaction; every other source, and any failure, keeps the private copy. * fix(doctor): keep the live-read operation contract out of the registry's import graph The read-only operation registry imported the live reader's type, which pulled the snapshot and worker graph back into the registry and formed an import cycle. The registry now reads a leaf contract, and BackupEngine lives with the other leaf engine types.
What Problem This Solves
Fixes: Doctor's database inspection writes a full private copy of the live shared-state database to the cache on every run, only to read a few rows of metadata. On one Mac host the state database was 12.6 GB, so each
openclaw doctororopenclaw triagerun staged another 12.6 GB copy, and interrupted runs left those copies behind (on Nov 4 they used about 49 GB together with agent-database copies).User Impact
When the Gateway is running, Doctor now inspects the shared-state database in place and stages no copy of it. In the test below, a 6.1 MB live WAL source went from 6,128,256 staged bytes per inspection to 0, with an identical inspection result. Doctor still uses a private copy whenever reading in place would be unsafe or unproven.
Why This Change Was Made
Doctor's per-store inspection reads only the engine marker, schema facts, the state content version and the Gateway lease row. When the source is a live WAL database with both
-waland-shmpresent and a verified live Gateway owner, the existing read-only child now runs that inspection on the source itself: amode=roconnection inside one read transaction (tryInspectSqliteReadOnlyInProcess, the same path startup metadata reads use). The child is a separate process, so closing the source cannot release the Gateway's POSIX locks. A WAL reader takes no lock that a writer's commit waits on, and a read-only connection cannot write the database or its WAL.Everything else keeps today's private copy:
-shmindex, which SQLite would have to rebuild;inspectSqliteSource. Only the shared-state database has a Gateway owner record, and its inspection does not use the descriptor;The inspection steps moved unchanged into
sqlite-store-inspection.ts, so the copy path and the in-place path run the same code on one read-only connection.Not in this PR:
immutable=1). This needs a fence against a Gateway starting mid-read and will come as a separate PR.clone: "never". The cases that still copy are mostly WAL or journal families that need private recovery, and recovery writes into the copy anyway. A clone also leaves the Gateway's database sharing extents with the copy, so the Gateway's later writes copy-on-write and fragment its own file long after Doctor has exited. Removing the copy entirely, as here and in the follow-up, is the better saving.Evidence
Red ran on
480d50305383. The branch is rebased ona54bdb3c608f; the commits in between touch none of the inspection, read-only child, owner or snapshot paths, and the focused tests were rerun after the rebase.Red on base,
pnpm exec vitest run src/infra/database-engine/diagnostics.test.ts:reads a verified live WAL source in place instead of copying itfailed withexpected [ 6128256, 6128256 ] to deeply equal [ Any<Number> ]. Both inspections of a live 6.1 MB source (1,892,352-byte database + 4,235,392-byte WAL) staged a 6,128,256-byte copy.Green on head, same file: 29 passed.
DatabaseStoreDiagnosticresults are equal; the database and WAL SHA-256 are unchanged.busy_timeout=0. The commit succeeds and is visible afterwards.-shmis missing after the writer was killed, and a hot rollback journal left by a killed writer.Other checks:
test/scripts/pr-wrapper-source-closure.test.tsandtest/scripts/eager-import-closure.test.ts: pass, with the two new modules added to the wrapper inventory.src/commands/doctor-database*.test.ts): all pass exceptdoctor-database-diagnostics.test.ts's snapshot. That snapshot fails identically on unmodified main on this Mac because it picks up a realmanaged-update-handoffs.sqlitein the shared/tmp/openclaw-<uid>directory.pnpm check:changed: format and lint pass after fixes. Remaining local failures are unrelated to this diff: changelog attributions (inCHANGELOG/records/2026.11.1.mdon main), dead exports (insrc/gatewayandsrc/cron), and the tsgo wrappers, which refuse this checkout's shared pnpm store. Running the compiler directly (tsrs -p tsconfig.core.jsonand-p test/tsconfig/tsconfig.core.test.infra.json) reports one error, inpackages/ai/src/transports/openai-responses-websocket.ts, which unmodified main reports too. CI's typecheck is the gate.scripts/check-madge-import-cycles.ts: 0 cycles. The first push had one, because the read-only operation registry imported the live reader's type; the registry now reads a leaf contract (database-store-live-read.worker-contract.ts), andBackupEnginemoved to the leafdatabase-engine/types.ts. Runtime import cycles: 0.pnpm check:test-lines-ratchet: passes; the +147 lines are allocated inconfig/test-lines-allocations/doctor-inspect-live-wal-in-place.txt.gpt-6.1-sol, branch mode againstorigin/main, P0–P2): scoped-clean on both commits.Test file audit (
src/infra/database-engine/diagnostics.test.ts, read in full): I removed aprepareSqliteReadOnlyLocationspy that only passed through to the real function and was never asserted. Every other case covers distinct behaviour and is unchanged. The new tests own their temp directories, writer processes and owner record, and clean them up throughonTestFinished.