Skip to content

fix(doctor): analyze SQLite databases after offline compaction - #119901

Closed
clawsweeper[bot] wants to merge 2 commits into
mainfrom
clawsweeper/issue-openclaw-openclaw-119884
Closed

clawsweeper[bot] wants to merge 2 commits into
mainfrom
clawsweeper/issue-openclaw-openclaw-119884

Conversation

@clawsweeper

@clawsweeper clawsweeper Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #119884.

The shared doctor-only SQLite compactor will run one-shot ANALYZE after successful VACUUM/checkpoint work, then checkpoint again before reporting success. This refreshes persisted planner statistics for migrated agent databases without adding periodic runtime maintenance, configuration, schema changes, or weakening existing busy, integrity, ownership, quarantine, and permission guards.

Regression coverage extends the historical v1 agent-database import path and verifies that sqlite_stat1 exists after migration and compaction. Thanks to @gucasbrg for the report and reproduction context.

@clawsweeper clawsweeper Bot added clawsweeper Tracked by ClawSweeper automation clawsweeper:autogenerated PR created automatically by ClawSweeper clawsweeper:autofix Maintainer opted this PR into bounded ClawSweeper-reviewed autofix without merge labels Aug 6, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 6, 2026
@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex review: needs historical verification review before merge. Reviewed August 24, 2026, 1:52 PM ET / 17:52 UTC.

ClawSweeper review

What this changes

The PR adds ANALYZE and a final checkpoint after Doctor’s offline SQLite compaction, with matching documentation and an import-compaction regression assertion.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until a maintainer resolves historical verification - 9 items remain

The PR’s compaction sequence is coherent, but it does not repair the linked Doctor migration path: current doctor --fix can migrate agent databases without reaching the shared compactor. Keep it open for a maintainer decision to move the statistics refresh to the migration owner or narrow the PR and leave the linked issue unresolved.

Priority: P1
Reviewed head: 6f9eb81c559571844f0a4050ce8d2da647afd0ef
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is tidy but misses the normal Doctor migration owner named by the linked report.
Proof confidence 🌊 off-meta tidepool Not applicable: This bot-authored PR is exempt from the external-contributor proof gate; before merge, maintainers should still run the chosen migration path against a representative redacted store and record the observed completion behavior.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This bot-authored PR is exempt from the external-contributor proof gate; before merge, maintainers should still run the chosen migration path against a representative redacted store and record the observed completion behavior.
Historical verification Needs maintainer review A historical verification receipt failed or is malformed. A maintainer must resolve that verification blocker before merge; independently assessed contributor proof remains valid.
Evidence reviewed 6 items PR change scope: The PR adds planner-statistics refresh only inside the shared compactor after VACUUM and its existing checkpoint.
Normal Doctor migration bypasses the compactor: The normal Doctor health contribution calls the agent-database maintenance migrator under the Doctor lock; that path does not invoke the shared compactor or ANALYZE.
Explicit maintenance is a separate route: The CLI sends --session-sqlite to the session SQLite command, whose import and compact modes reach the shared compactor; this is distinct from ordinary Doctor repair.
Findings 1 actionable finding [P1] Refresh statistics from the Doctor migration owner
Security None None.

How this fits together

Doctor has both normal health repairs and explicit session/state SQLite maintenance commands. Agent database migrations can write schema and indexes during normal Doctor repair, while the shared compactor performs checkpoint and VACUUM work for explicit maintenance flows.

flowchart LR
  A[Doctor repair] --> B[Agent schema repair]
  B --> C[Agent database migration]
  D[Explicit session or state maintenance] --> E[Shared offline compactor]
  E --> F[Checkpoint and VACUUM]
  F --> G[Planner statistics and final checkpoint]
  C -. currently bypasses .-> G
Loading

Decision needed

Question Recommendation
Should planner-statistics refresh be part of the normal Doctor migration owner that caused the reported stale statistics, or should this PR be narrowed to explicit compaction and stop claiming the linked migration issue? Repair the migration owner: Move the refresh to the Doctor-owned migration path and add a normal Doctor repair regression, while retaining explicit-compaction behavior only if separately desired.

Why: The branch adds a potentially expensive, fallible maintenance step in a shared compactor, while current normal Doctor migration reaches a different owner boundary; choosing the intended coverage is a maintainer policy decision.

Before merge

  • Resolve historical verification - A historical verification receipt failed or is malformed. A maintainer must resolve that verification blocker before merge; independently assessed contributor proof remains valid.
  • Refresh statistics from the Doctor migration owner (P1) - The linked report is about normal doctor --fix migration, but that health contribution migrates agent databases through migrateOpenClawAgentDatabaseForMaintenance without calling this compactor. These added lines therefore cover explicit session import/compact and state compaction only, leaving the reported migration path unchanged while the PR claims to fix it. Put the refresh after the actual Doctor-owned migration and add coverage for that route, or narrow the PR and leave the issue open.
  • Resolve merge risk (P1) - The Node SQLite dependency contract could not be independently inspected because the local source was unavailable and network DNS failed; an exact-head run against a representative migrated store should establish the maintenance-time cost before landing.
  • Resolve merge risk (P1) - The overlapping open implementation at fix(doctor): refresh planner statistics (ANALYZE) after SQLite compaction #119739 is not a proven replacement, so maintainers should select one canonical repair before either PR is merged.
  • Complete next step (P2) - A maintainer must choose the intended migration boundary before an automated repair can safely change when ANALYZE runs.
  • Improve patch quality - Move the refresh to the normal Doctor migration owner or remove the linked-fix claim.
  • Improve patch quality - Add a regression that runs the normal Doctor repair contribution and verifies persisted planner statistics.
  • Improve patch quality - Capture a redacted exact-head maintenance run on a representative migrated database after the owner boundary is chosen.

Findings

  • [P1] Refresh statistics from the Doctor migration owner — src/commands/doctor-sqlite-compact.ts:55-57
Agent review details

Security

None.

PR surface

Source +3, Tests +7, Docs +1. Total +11 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 0 +3
Tests 1 7 0 +7
Docs 1 5 4 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 15 4 +11

Review metrics

Metric Value Why it matters
Production versus test delta production +8/-4; tests +7/-0 The runtime addition is small and documented, but its placement misses the normal migration owner claimed by the linked issue.

Stored data model

Persistent data-model change detected: migration/backfill/repair: docs/cli/doctor.md, migration/backfill/repair: src/commands/doctor-session-sqlite.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119884
Summary: This PR is a candidate repair for the canonical migration-performance issue, but its current owner boundary does not cover the reported Doctor migration path.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Route the repair through normal Doctor migration (recommended)
    Update the migration owner and prove the normal Doctor repair path writes planner statistics before merging.
  2. Accept an explicit-compaction-only improvement
    Retain the current compactor change only after removing the linked migration-fix claim and keeping the issue open.
  3. Pause for a canonical implementation
    Choose between this PR and the overlapping open proposal before adding competing SQLite maintenance policies.

Technical review

Best possible solution:

Refresh planner statistics immediately after the actual Doctor-owned agent schema/index migration, then cover normal doctor --fix repair and keep explicit compaction behavior as a separate, documented maintenance choice.

Do we have a high-confidence way to reproduce the issue?

Yes, by source: normal doctor --fix reaches the agent migration owner without the shared compactor, while the PR only adds ANALYZE to explicit import/compact flows. A live large-store reproduction was not run in this read-only review.

Is this the best way to solve the issue?

No. The compactor change is internally coherent, but it is not the best fix for the linked migration report because the normal Doctor migration path bypasses it.

Full review comments:

  • [P1] Refresh statistics from the Doctor migration owner — src/commands/doctor-sqlite-compact.ts:55-57
    The linked report is about normal doctor --fix migration, but that health contribution migrates agent databases through migrateOpenClawAgentDatabaseForMaintenance without calling this compactor. These added lines therefore cover explicit session import/compact and state compaction only, leaving the reported migration path unchanged while the PR claims to fix it. Put the refresh after the actual Doctor-owned migration and add coverage for that route, or narrow the PR and leave the issue open.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3c2667ca40f1.

Labels

Label justifications:

  • P1: The linked report describes severe agent-session latency and gateway event-loop starvation, and this PR currently leaves the named Doctor migration route unchanged.
  • merge-risk: 🚨 other: The branch adds a synchronous, fallible database-maintenance step to shared explicit compaction, but its intended coverage and operational cost need maintainer acceptance.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.

Evidence

What I checked:

  • PR change scope: The PR adds planner-statistics refresh only inside the shared compactor after VACUUM and its existing checkpoint. (src/commands/doctor-sqlite-compact.ts:55, 6f9eb81c5595)
  • Normal Doctor migration bypasses the compactor: The normal Doctor health contribution calls the agent-database maintenance migrator under the Doctor lock; that path does not invoke the shared compactor or ANALYZE. (src/commands/doctor-agent-memory-schema.ts:111, 3c2667ca40f1)
  • Explicit maintenance is a separate route: The CLI sends --session-sqlite to the session SQLite command, whose import and compact modes reach the shared compactor; this is distinct from ordinary Doctor repair. (src/commands/doctor.ts:68, 3c2667ca40f1)
  • Regression coverage reaches only explicit import: The added assertion runs runDoctorSessionSqlite in import mode and checks sqlite_stat1; it does not exercise the normal Doctor health contribution. (src/commands/doctor-session-sqlite.test.ts:308, 6f9eb81c5595)
  • Current-main and history check: Current main still has checkpoint → VACUUM → checkpoint → integrity with no ANALYZE; blame dates that implementation to the recent SQLite compactor rewrite. (src/commands/doctor-sqlite-compact.ts:54, 4d8e87cc3c89)
  • Dependency signal and review limitation: The changed owner executes through Node’s node:sqlite API. Local dependency source was absent and DNS prevented retrieving upstream documentation, so this review does not claim external SQLite timing guarantees. (src/commands/doctor-sqlite-compact.ts:3, 6f9eb81c5595)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-08-06T09:34:44.207Z sha 792e4db741ecf70f6cdccb39e435fda59692e24a :: needs changes before merge. :: [P3] Document the ANALYZE step in Doctor compaction
  • reviewed 2026-08-06T10:46:30.894Z sha 6f9eb81 :: passed. :: none
  • reviewed 2026-08-08T07:42:40.963Z sha 6f9eb81 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T15:04:52.338Z sha 6f9eb81 :: passed. :: none
  • reviewed 2026-08-15T15:31:00.317Z sha 6f9eb81 :: passed. :: none
  • reviewed 2026-08-18T09:12:33.943Z sha 6f9eb81 :: passed. :: none

@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

🦞🔧
ClawSweeper applied a repair to this PR branch.

Repair: kept the fix on this contributor branch instead of opening a replacement PR.
Validation: pnpm check:changed
Updated head: 6f9eb81c5595
Run: https://github.com/openclaw/clawsweeper/actions/runs/31089877241

Current state: exact-head review queued immediately; GitHub checks and the review verdict gate final merge.

Automerge progress:

  • 2026-08-06 09:36:15 UTC review requested repair 792e4db741ec (structured ClawSweeper marker: fix-required (finding=review-feedback sha=792e4d...)
  • 2026-08-06 09:59:31 UTC review queued 6f9eb81c5595 (after repair)

@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor Author

🦞🧹
ClawSweeper autofix is enabled.

  • Head: 792e4db741ec
  • Label: clawsweeper:autofix
  • Action: exact-head review queued (workflow sweep.yml, event repository_dispatch).
  • Flow: review this head, repair/rebase only if needed, then re-review the exact repaired head until no actionable findings remain.

This is fix-only; I will not merge this PR.

Re-review progress:

@clawsweeper
clawsweeper Bot force-pushed the clawsweeper/issue-openclaw-openclaw-119884 branch from 792e4db to 6f9eb81 Compare August 6, 2026 09:59
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations size: XS labels Aug 6, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor Author

🦞✅
ClawSweeper is pausing this repair loop for human review.

Source: clawsweeper[bot]
Reason: - [ ] Resolve merge risk (P1) - Every explicit Doctor compaction gains an additional synchronous, fallible SQLite write step; maintainers must accept its completion-time and failure-mode tradeoff. (sha=6f9eb81c559571844f0a4050ce8d2da647afd0ef)

Why human review is needed:
ClawSweeper found a blocker that should be resolved or accepted by a maintainer before the repair or automerge loop continues.

What the maintainer can do as a next step:
If the maintainer accepts the current risk and wants ClawSweeper to continue merge gates, comment @clawsweeper approve. If more work is needed, resolve the blocker first, then comment @clawsweeper automerge to re-review and continue. If automation should stay paused, leave clawsweeper:human-review in place or comment @clawsweeper stop.

I added clawsweeper:human-review and left the final call with a maintainer.

@clawsweeper clawsweeper Bot added clawsweeper:human-review Needs maintainer review before ClawSweeper can continue clawsweeper-recovery-stuck labels Aug 8, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper-recovery-stuck rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper-recovery-stuck and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 18, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper-recovery-stuck rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed clawsweeper-recovery-stuck rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 18, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 28, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Superseded by #134062.

The patch here runs full ANALYZE only from explicit offline compaction, but the linked defect occurs in the normal doctor --fix agent-database migration path. The replacement moves bounded optimizer maintenance to that migration owner and covers both newly upgraded and already-current databases with failing-before/passing-after regression proof.

Closing this PR to keep one canonical repair for #119884. The distinct post-compaction proposal remains tracked in #119739.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:autofix Maintainer opted this PR into bounded ClawSweeper-reviewed autofix without merge clawsweeper:autogenerated PR created automatically by ClawSweeper clawsweeper:human-review Needs maintainer review before ClawSweeper can continue clawsweeper Tracked by ClawSweeper automation commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent/session DB migration doesn't ANALYZE → stale planner stats → 15s session ops + 30-57s event-loop starvation on large stores

2 participants