Skip to content

fix: doctor read-only database inspections time out on large agent databases - #142179

Merged
steipete merged 2 commits into
mainfrom
steipete/sqlite-readonly-snapshot-budget
Sep 8, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/sqlite-readonly-snapshot-budget

Conversation

@steipete

@steipete steipete commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Related: #141918, #141412.

What Problem This Solves

Fixes an issue where read-only inspections of a large SQLite database, such as the memory-core readiness check in openclaw doctor, fail with "SQLite read-only snapshot timed out after 30 seconds" whenever the database is too large to copy in 30 seconds. On the team Gateway the 9.4 GB agent database fails this way on every doctor run.

Why This Change Was Made

The read-only worker builds a private copy with SQLite's online backup API, so its cost grows with file size, but its child process had the fixed 30-second inspection deadline sized for a 300 MiB synthetic database. #141918 already gave the integrity child a size-derived budget; this change moves that budget into one shared helper and applies it to both read-only worker entry points: 30 seconds for startup and shutdown plus one second per 32 MiB, rounded up and capped at 30 minutes. The timeout error names the applied budget and file size, and budgets above the base are logged. Non-goals: when snapshots are taken is unchanged, and whether tiny metadata reads should use a live read-only connection instead of a full snapshot is a separate owner decision.

User Impact

Doctor and other read-only inspections complete on large installs instead of reporting a spurious timeout; operators see the applied budget when a copy genuinely exceeds it.

Evidence

Team host (2026-09-08): openclaw doctor --lint --all --json on the 9.4 GB agent database failed the memory-core check with the 30-second snapshot timeout; a niced online backup of the same file took 115 seconds niced (about 87 MB/s) on 2026-09-08 at 13:06 UTC, against which the size-derived budget for that file is 331 seconds. Regression tests fail on the pre-fix code for the intended reason and verify the size-derived budget for both the async and sync worker paths and the new error text. node scripts/check-changed.mjs passed; focused snapshot, cancellation, integrity, and read-only worker suites pass. Codex-backed autoreview at P1 before landing.

Known Gaps

Each inspection still copies the whole database into the private staging directory; large installs pay that disk and I/O cost per doctor run.

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 8, 2026 13:21
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M maintainer Maintainer-authored PR labels Sep 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 8, 2026
@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 8, 2026, 9:43 AM ET / 13:43 UTC.

ClawSweeper review

What this changes

Scales SQLite snapshot deadlines with database size, shares timeout diagnostics with integrity checks, and updates regression coverage and documentation.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful fix: current main still imposes the snapshot deadline that triggers the reported failure. No blocking correctness findings remain, and the related merged integrity fix does not cover this path.

Priority: P2
Reviewed head: a0a3f0a7a06cb4d2be8bfd48f6a364ec609d8b63

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with meaningful subprocess coverage and no blocking findings.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored exemption applies. The captured report supports the timeout diagnosis, but its separate online-backup measurement does not prove an after-fix Doctor inspection; subprocess tests provide supplemental coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored exemption applies. The captured report supports the timeout diagnosis, but its separate online-backup measurement does not prove an after-fix Doctor inspection; subprocess tests provide supplemental coverage.
Evidence reviewed 8 items Current main still needs the fix: Both snapshot entry points on fetched main use the fixed 30-second deadline; the size-derived resolver applies only to integrity checks.
Bounded lifecycle preserved: The introduced budget is capped at 30 minutes. Async cancellation still sends SIGKILL and waits for close; failed source stats retain the base budget and normal child diagnostics.
Actual Doctor inspection boundary: Memory Core reads existing index metadata through prepareSqliteReadOnlyLocationSync. That path uses a stable private raw copy; the asynchronous path can use SQLite online backup.
Findings None None.
Security None None.

How this fits together

Doctor and other database diagnostics inspect private SQLite snapshots. The snapshot worker controls how long copying may run and returns either a prepared snapshot or an actionable error.

flowchart TD
  A[Doctor and database diagnostics] --> B[Read source file size]
  B --> C[Calculate bounded time budget]
  C --> D[Private snapshot worker]
  D --> E[Snapshot ready]
  D --> F[Timeout or cancellation]
  E --> G[Inspect database]
  F --> H[Join child and clean staging]
Loading

Before merge

  • Resolve merge risk (P1) - The size-derived allowance remains an estimate: the supplied 115-second online-backup measurement does not establish after-fix performance for Doctor's synchronous private-copy path.
Agent review details

Security

None.

PR surface

Source +26, Tests +131, Docs +4. Total +161 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 60 34 +26
Tests 2 136 5 +131
Docs 1 6 2 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 202 41 +161

Review metrics

Metric Value Why it matters
Production versus test growth production +26 net lines; tests +131 net lines Production growth centralizes budget calculation and diagnostics; tests cover both subprocess modes and failure handling.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Use one bounded, size-aware inspection budget while preserving private snapshots, cancellation cleanup, and quiet diagnostic output.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Use one bounded, size-aware inspection budget while preserving private snapshots, cancellation cleanup, and quiet diagnostic output.

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

Yes, from source: Doctor's snapshot subprocess is killed after 30 seconds even when copying a valid large database takes longer; no runtime reproduction was executed here.

Is this the best way to solve the issue?

Yes. Extending the existing integrity-budget policy to snapshot workers repairs the workload mismatch at its owner without changing snapshot selection or stored data.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 865f1bbdbf44.

Labels

Label justifications:

  • P2: Repairs false diagnostic timeouts on large databases without evidence of a broader current runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored exemption applies. The captured report supports the timeout diagnosis, but its separate online-backup measurement does not prove an after-fix Doctor inspection; subprocess tests provide supplemental coverage.

Evidence

What I checked:

Likely related people:

  • steipete: 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 (1 earlier review cycle)
  • reviewed 2026-09-08T13:27:33.393Z sha f4733c8 :: needs maintainer review before merge. :: none

Use the same size-derived lifetime budget for asynchronous and synchronous
read-only snapshots and the integrity child: 30 seconds plus one second
per 32 MiB, rounded up and capped at 30 minutes. Keep one budget resolver,
size formatter, info log, and timeout message, with integrity phase details
preserved. Failed source stats retain the base budget and child diagnostics.

Release-note context: SQLite read-only diagnostics now allow large database
snapshots to finish instead of stopping at a fixed 30-second deadline.
Timeout errors report the applied budget and source size. This covers
Doctor readiness and other existing snapshot callers without changing when
snapshots are taken or how databases are read.
The info-level snapshot budget line polluted quiet CLI stdout and stderr
contracts pinned by the gateway, health, Doctor, and ACP process tests.
Keep routine budget diagnostics at debug level while preserving the size
and applied budget in timeout errors.

Update the existing logging assertions and documentation. Changed checks
and Codex autoreview passed; focused worker and CLI process validation
passed 77 tests with one existing platform-dependent skip.
@steipete
steipete force-pushed the steipete/sqlite-readonly-snapshot-budget branch from a0a3f0a to 60f4f8f Compare September 8, 2026 15:48
@steipete
steipete merged commit c245214 into main Sep 8, 2026
177 checks passed
@steipete
steipete deleted the steipete/sqlite-readonly-snapshot-budget branch September 8, 2026 16:14
@steipete

steipete commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 8, 2026
* commit '04869ae4899ad0524c3287759798362b0d62fef8': (677 commits)
  fix(release): pin Kova census refresh (#142104)
  fix: doctor read-only database inspections time out on large agent databases (#142179)
  docs: align v2026.9.3 framing with release announcement (#142307)
  fix(ui): discover models when default-model pickers open (#142105)
  fix(ci): keep Docker upgrade seed baseline older than target (#142273)
  refactor(tests): reuse named OAuth credential fixtures (#142272)
  fix(ci): keep mobile release helpers out of source checks (#142115)
  chore(ui): refresh control ui locales (#142147)
  fix(active-memory): explain why recall was skipped (#138658)
  fix(media): preserve converted images with HEIC filenames (#142263)
  docs: add v2026.9.3 release notes (#142277)
  fix(ui): retire picker focus listeners together (#142258)
  fix(ui): keep menu hover colors consistent across themes (#142243)
  fix(release): keep changelog credits within verified history (#142261)
  fix: keep tool-finalizer placeholders private in message-only groups (#138645)
  perf(tui): carry prepared URL membership through rendering (#142262)
  test(ui): await activity cache imports before teardown (#142282)
  fix(qa): align auth and Workshop proofs with runtime contracts (#142280)
  feat(xai): use one curated catalog and concrete setup default (#142136)
  refactor(outbound): reuse prepared sendability facts (#142252)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
…tabases (openclaw#142179)

* fix(sqlite): scale the read-only snapshot budget with database size

Use the same size-derived lifetime budget for asynchronous and synchronous
read-only snapshots and the integrity child: 30 seconds plus one second
per 32 MiB, rounded up and capped at 30 minutes. Keep one budget resolver,
size formatter, info log, and timeout message, with integrity phase details
preserved. Failed source stats retain the base budget and child diagnostics.

Release-note context: SQLite read-only diagnostics now allow large database
snapshots to finish instead of stopping at a fixed 30-second deadline.
Timeout errors report the applied budget and source size. This covers
Doctor readiness and other existing snapshot callers without changing when
snapshots are taken or how databases are read.

* fix(sqlite): keep snapshot budget diagnostics at debug level

The info-level snapshot budget line polluted quiet CLI stdout and stderr
contracts pinned by the gateway, health, Doctor, and ACP process tests.
Keep routine budget diagnostics at debug level while preserving the size
and applied budget in timeout errors.

Update the existing logging assertions and documentation. Changed checks
and Codex autoreview passed; focused worker and CLI process validation
passed 77 tests with one existing platform-dependent skip.
steipete added a commit that referenced this pull request Sep 17, 2026
Retain unfinished agent inspections under the Gateway lifetime instead of
turning a foreground timeout into a fatal startup error. Keep the agent
degraded until inspection and guarded credential, session, and model
preparation complete; cancel and join that work during shutdown.

Preserve caller cancellation, propagate failures until background handoff,
and keep inherited auth snapshots within their selected state directory.
Thanks to @desksk for the report and offline integrity timings.

Refs #150574, #141918, #142179, #150444.
steipete added a commit that referenced this pull request Sep 17, 2026
Retain unfinished agent inspections under the Gateway lifetime instead of
turning a foreground timeout into a fatal startup error. Keep the agent
degraded until inspection and guarded credential, session, and model
preparation complete; cancel and join that work during shutdown.

Preserve caller cancellation, propagate failures until background handoff,
and keep inherited auth snapshots within their selected state directory.
Thanks to @desksk for the report and offline integrity timings.

Refs #150574, #141918, #142179, #150444.
steipete added a commit that referenced this pull request Sep 17, 2026
Retain unfinished agent database inspections under the Gateway lifetime so a slow healthy database no longer turns its foreground wait timeout into a fatal startup error. Keep affected agents degraded until inspection and guarded credential, session, and model preparation complete; healthy agents can serve in the meantime. Corruption and pending migrations retain Doctor guidance.

Compose deferred admission with the existing Linux spawn-broker owner. Shutdown cancels and joins retained inspection and preparation before broker cleanup. Preserve caller cancellation, foreground failures before handoff, and inherited auth snapshots within their selected state directory.

Thanks to @desksk for the report and offline integrity timings.

Validation: recorded focused and real SQLite-child/HTTP boundary proof, scoped-clean Codex review, and green exact-head CI. Published-updater and retained Windows-service compatibility remain unverified; the PR records the scoped Rank-up skip.

Closes #150574.
Related: #141918, #142179, #150444, #150564.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
…150755)

Retain unfinished agent database inspections under the Gateway lifetime so a slow healthy database no longer turns its foreground wait timeout into a fatal startup error. Keep affected agents degraded until inspection and guarded credential, session, and model preparation complete; healthy agents can serve in the meantime. Corruption and pending migrations retain Doctor guidance.

Compose deferred admission with the existing Linux spawn-broker owner. Shutdown cancels and joins retained inspection and preparation before broker cleanup. Preserve caller cancellation, foreground failures before handoff, and inherited auth snapshots within their selected state directory.

Thanks to @desksk for the report and offline integrity timings.

Validation: recorded focused and real SQLite-child/HTTP boundary proof, scoped-clean Codex review, and green exact-head CI. Published-updater and retained Windows-service compatibility remain unverified; the PR records the scoped Rank-up skip.

Closes openclaw#150574.
Related: openclaw#141918, openclaw#142179, openclaw#150444, openclaw#150564.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant