Repository navigation
fix(doctor): refresh SQLite planner stats after migration - #134062
Conversation
Run bounded optimizer maintenance before Doctor releases each migrated agent database so existing and newly upgraded stores persist planner statistics. Co-authored-by: VACInc <[email protected]>
Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: bfa72b59-2b29-4a60-92e7-a03ae51acd55
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 8:01 AM ET / 12:01 UTC. ClawSweeper reviewWhat this changesThe PR makes Merge readinessKeep this maintainer-labeled PR open: current main lacks the planner-statistics refresh, while the introduced helper covers both no-op and rewritten Doctor migration paths without a concrete correctness or security defect found. Priority: P1 Review scores
Verification
How this fits togetherDoctor is OpenClaw’s explicit repair command. Its agent-database migration flow opens each registered store under a maintenance lease, normalizes legacy media data and schema, then returns the database to normal Gateway consumers. flowchart LR
A[Operator runs Doctor fix] --> B[Doctor migration orchestration]
B --> C[Agent database maintenance lease]
C --> D[Media and schema migration]
D --> E[Bounded SQLite analysis]
E --> F[Agent database returned to Gateway]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +8, Tests +49. Total +57 across 2 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the bounded analysis at this Doctor-owned migration boundary once exact-head CI and maintainer review accept the supplied pre-3.46 SQLite compatibility evidence. Do we have a high-confidence way to reproduce the issue? Unclear for an independently executed current-main run: source shows no explicit statistics refresh, and the introduced tests define a focused reproduction, but this read-only review did not execute it. Is this the best way to solve the issue? Yes. The change belongs in the Doctor migration owner under its existing stopped-writer lease and covers both successful migration outcomes rather than adding runtime maintenance or a parallel compaction path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 43e9a3d81776. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Use bounded explicit analysis so Doctor refreshes every indexed table on supported pre-3.46 SQLite runtimes. Strengthen the regression around named planner statistics and adopt automatic temp cleanup. Co-authored-by: VACInc <[email protected]>
|
@clawsweeper re-review Exact head
Exact-head CI is running; no merge or automerge is requested. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Exact head |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Exact-head verification for
Known proof gap: configured Blacksmith Testbox could not provision because its host-owned login is unavailable. The dependency-floor proof instead compiled and executed the exact official SQLite source locally in an isolated disposable tree. No production-scale timing fixture was available; the regression proves the missing persisted statistics and both Doctor completion paths. No merge or automerge was requested or enabled. |
…34062) * fix(doctor): refresh SQLite planner stats after migration Run bounded optimizer maintenance before Doctor releases each migrated agent database so existing and newly upgraded stores persist planner statistics. Co-authored-by: VACInc <[email protected]> * fix(doctor): refresh SQLite planner stats after migration Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: bfa72b59-2b29-4a60-92e7-a03ae51acd55 * fix(doctor): cover supported SQLite planner stats Use bounded explicit analysis so Doctor refreshes every indexed table on supported pre-3.46 SQLite runtimes. Strengthen the regression around named planner statistics and adopt automatic temp cleanup. Co-authored-by: VACInc <[email protected]> --------- Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: VACInc <[email protected]>
|
Operator-reported maintenance follow-up (2026-11-05), related to #119884 and #133925. On an Ubuntu deployment of OpenClaw 2026.10.9, the local investigation reported stale statistics for three transcript-related tables while integrity checks passed and the inspected query plans still used indexes. Attempts to acquire a SQLite write lock with 4 s and 45 s timeouts both failed before ANALYZE started. After a maintenance intervention that included statistics refresh and exactly one Gateway restart, the operator's report recorded:
These are before/after observations for a combined intervention, not an isolated causal benchmark or proof that all SQLite delays are resolved. Long-running concurrent load has not been validated. Queue wait is not itself proof of a native SQLite lock wait. The separate local synthetic-test report describes three repeated runs in which restarting alone did not repair persisted stale statistics, and an already-open connection needed to reload the refreshed statistics or be replaced. The local source audit reports that #133925 and #134062 are already present. We have not established that either repair failed, that its triggering maintenance path ran, or that a new upstream defect exists. This comment is based on the operator-provided investigation summaries. The exact SQL, SQLite build details, synthetic fixture and complete local report are not attached or independently revalidated here, so this is a limited field note rather than a reproducible bug submission. No production database, conversation contents, credentials or private paths are included. Potential documentation takeaway: when assessing planner-statistics maintenance, verify both persisted statistics and their use by long-lived connections, while measuring writer-queue wait separately from transaction execution and COMMIT. No reopening, new patch, or duplicate fix is requested. AI contribution acknowledgment: The overall troubleshooting work—including fault investigation, diagnosis, remediation, validation, and preparation of this report—was carried out with technical assistance from GPT-6 Astra and Codex. The operator supplied the environment, authorized the interventions, and confirmed the user-facing recovery. Thanks to Astra and Codex for their technical support throughout this work. This comment was drafted and revised by GPT-6 Astra; the exact model used in each separate Codex session has not been independently verified. This acknowledgment does not expand the verification claims or resolve the evidence gaps described above. |
Related: #119884
Related: #119720
Related: #119739
Supersedes #119901
What Problem This Solves
Fixes an issue where users who ran
openclaw doctor --fixcould finish an agent SQLite schema migration without persisted planner statistics. Large migrated stores could then choose poor query plans, including after the original migration had already completed.Why This Change Was Made
The repair lives in the normal Doctor-owned agent database migration path. Before releasing each database, Doctor runs
ANALYZE mainunder an explicit 1,000-row-per-index analysis limit. This repairs already-current databases as well as newly upgraded ones without adding runtime maintenance, configuration, or an OpenClaw schema change.Explicit
ANALYZEis required for the supported SQLite 3.44.x floor. In that lineage,PRAGMA optimize=0x10002ignores the later all-table bit and skips tables that the short-lived Doctor connection has not queried. The older #119901 patch instead placed fullANALYZEin explicit offline compaction, which does not own the normal migration path and could perform unbounded work on large stores. #119739 remains a related, distinct post-compaction proposal, while #133925 covers runtime bulk cleanup.User Impact
Running
openclaw doctor --fixnow restores planner statistics for affected agent databases. Existing and newly migrated stores can use their indexes with current approximate statistics. Work is bounded to roughly 1,000 visited rows per index and runs only inside Doctor's explicit repair window; there is no new setting or runtime hot-path maintenance.Evidence
no such table: sqlite_stat1.863c171b76cd36e0requiresTF_StatsUsedforPRAGMA optimizeand has no0x10000all-table behavior; SQLite documents that behavior as new in 3.46.0.analysis_limit=1000; boundedANALYZE mainpopulated twosqlite_stat1rows for 100,000 indexed records.sqlite_stat1absent afterPRAGMA analysis_limit=1000; PRAGMA optimize=0x10002;; the repairedANALYZE mainsequence populated indexed tables.idx_agent_transcript_event_sequenceafter v14 migration and for a populatedsession_suggestionsindex that the migration never queries.src/commands/doctor-state-migrations.test.ts.node scripts/check-changed.mjs -- src/infra/state-migrations.media-persistence.ts src/infra/state-migrations.media-persistence.test.tspassed, including formatting, production/test types, lint, database-first, schema, and import-cycle guards.Worked on by
View the OpenClaw team session