Skip to content

fix(doctor): avoid repeated database copies in selected reports - #176014

Merged
vincentkoc merged 2 commits into
mainfrom
fix/doctor-selected-snapshot-reuse-20261018
Oct 18, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/doctor-selected-snapshot-reuse-20261018

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where users running openclaw doctor --lint --only ... repeatedly copied shared state between ordinary reads, adding unnecessary I/O and delay on large databases.

User Impact

Selected reports reuse one private shared-state image for ordinary reads. Each new report sees fresh committed data, and inspection preserves the source database, WAL, and shared-memory files.

Why This Change Was Made

Selected reports now enter the same report-owned snapshot scope as full reports, with preparation deferred until the first shared-state read. Synchronous and asynchronous readers join one retained preparation and reuse a stable source identity. The source owner retains private bytes until accepted readers drain, while preserving cancellation, fresh/current reads, and cleanup.

Evidence

  • Regression against the frozen pre-fix implementation: the selected-report case fails because its report snapshot is missing; full-report and absent-database controls pass.
  • Fixed implementation: 95 tests pass across nine Doctor, shared-state lifecycle, and subagent-reader files. Coverage includes mixed sync/async acquisition, cancellation, admission, drainage, cleanup, fresh subsequent reports, and source-file preservation.
  • Type-aware lint, both affected TypeScript test graphs, and the full package build pass. After the final getter-binding correction, the three report regression cases pass again.
  • Exact-head CI passes at 5555cccdfe6, including all three PostgreSQL conformance shards and the repaired wrapper inventory/provisioning paths.
  • Independent review and ClawSweeper's exact-head review found no actionable issues.

Behavior proof uses real database/report harnesses; no packaged-CLI trace or production rollout is claimed.

Production changes are +185 lines, tests +325, docs +1, wrapper inventory +1. The added production logic owns lazy materialization shared by sync/async readers; extracting acquisition and cleanup keeps that ownership separate from reader transport. No config or schema version changes.

Cross-worker auth snapshots and writable plugin inspection copies require their own ownership changes and remain separate follow-ups.

@vincentkoc vincentkoc self-assigned this Oct 18, 2026
@clawsweeper

clawsweeper Bot commented Oct 18, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations size: L labels Oct 18, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review October 18, 2026 02:43
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 18, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 18, 2026
@vincentkoc
vincentkoc enabled auto-merge (squash) October 18, 2026 03:06
@clawsweeper

clawsweeper Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Selected Doctor reports lazily prepare and reuse one private shared-state snapshot across ordinary synchronous and asynchronous reads.

Example: A selected Doctor report performs three ordinary reads of a 160 MB shared-state database.

  • Before: Separate reads can prepare separate full database copies.
  • After: The reads share one private image, which is released after readers finish; the next report obtains fresh data.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent implementation with meaningful integration and lifecycle coverage; supplied execution evidence remains harness-based.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied evidence exercises Doctor and shared-state owners through tests rather than a shipped CLI capture.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Selected Doctor reports repeatedly copy large shared-state databases, adding avoidable I/O and delay.
Reason: Maintainer-authored direction extends an established optimization while retaining lazy inspection, source preservation, and report freshness.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses repeated snapshot copying in selected Doctor reports, and review found no actionable correctness or security defects.

Priority: P2
Reviewed head: 5555cccdfe6b1be7e6d3a240ee9e57b013c41938

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No supplied shipped-CLI trace demonstrates selected-report copy reuse; the body reports a failing pre-fix regression and passing fixed harness cases.
Agent review details

How this fits together

Doctor selects health checks and reads shared state through the database read owner, which supplies private snapshot bytes to native readers and workers and releases them after report drainage.

flowchart TD
  A[Doctor selected report] --> B[Retained read scope]
  B --> C[Lazy snapshot preparation]
  C --> D[Private shared-state image]
  D --> E[Synchronous readers]
  D --> F[Asynchronous workers]
  E --> G[Drain and cleanup]
  F --> G
Loading

Technical review

Best possible solution:

Use the existing report read scope with one lazily materialized source, preserving independent verification, current reads, and reader-drained cleanup.

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

Current main explicitly bypasses report reuse for selected checks, leaving ordinary artifact-preserving reads to prepare separate copies; the supplied regression exercises that path, but no target code was executed during this review.

Is this the best way to solve the issue?

The change addresses the owning snapshot lifetime and shares acquisition across reader transports without introducing a persistent cache or replacing independent verification.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Selected versus full Doctor report snapshot selection changes intended behavior with a stated reason (e71ac74: Full reports reused private bytes while selected checks remained on demand to avoid unnecessary preparation.)
  • Retained reader drainage and source cleanup keeps the original intent (a7d62b6: Accepted readers retain selected snapshot custody through settlement, and closing scopes reject new readers.)
  • Retained snapshot preparation lifecycle keeps the original intent (9c93bc3: Snapshot preparation and cleanup must retain custody through cancellation and worker failure.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 439940b adds src/commands/doctor-lint-runner.ts:194 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 439940bf0bf5; files: src/commands/doctor-lint-runner.ts)
  • Vincent Koc: Raw commit 4ea758d adds src/state/openclaw-state-db-readonly.ts:39 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4ea758dcf92d; files: src/state/openclaw-state-db-readonly.ts)

PR surface

Source +185, Tests +325, Docs +1, Other +1. Total +512 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 337 152 +185
Tests 2 390 65 +325
Docs 1 5 4 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 8 733 221 +512

Review metrics

Metric Value Why it matters
Production versus test changes Production +337/-152 (net +185); tests +390/-65 (net +325). Production growth adds shared lazy acquisition while moving existing eager preparation; tests cover distinct report, cancellation, admission, and cleanup contracts.

Labels

Label changes:

  • add P2: Avoids unnecessary database copying and diagnostic delay, with impact concentrated in selected Doctor reports on larger installations.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Avoids unnecessary database copying and diagnostic delay, with impact concentrated in selected Doctor reports on larger installations.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 17, 2026, 11:06 PM ET / October 18, 2026, 03:06 UTC.

@vincentkoc
vincentkoc merged commit ed2de46 into main Oct 18, 2026
160 of 161 checks passed
@vincentkoc
vincentkoc deleted the fix/doctor-selected-snapshot-reuse-20261018 branch October 18, 2026 03:16
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

steipete added a commit that referenced this pull request Oct 18, 2026
Follow #176014's shared-image contract while comparing native SQLite and retained snapshot paths with the same Windows namespace spelling. Keep the exact one-image and next-report freshness assertions, and normalize the source-isolation comparison too.

Proof: all 15 Doctor state-isolation and 65 SQLite owner tests pass locally with one worker; targeted Doctor types, lint, formatting, and P2 autoreview pass. Windows pathname equivalence is covered by the owner tests and a path.win32 control; no native Windows replay was run.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…claw#176014)

* fix(doctor): avoid repeated database copies in selected reports

* fix(build): retain snapshot source in PR wrapper inventory
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
Follow openclaw#176014's shared-image contract while comparing native SQLite and retained snapshot paths with the same Windows namespace spelling. Keep the exact one-image and next-report freshness assertions, and normalize the source-isolation comparison too.

Proof: all 15 Doctor state-isolation and 65 SQLite owner tests pass locally with one worker; targeted Doctor types, lint, formatting, and P2 autoreview pass. Windows pathname equivalence is covered by the owner tests and a path.win32 control; no native Windows replay was run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. commands Command implementations docs Improvements or additions to documentation scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant