Skip to content

fix(doctor): avoid rereading live state for writable inspections - #176334

Merged
vincentkoc merged 5 commits into
mainfrom
fix/doctor-retained-private-fork-20261019
Oct 18, 2026
Merged

vincentkoc merged 5 commits into
mainfrom
fix/doctor-retained-private-fork-20261019

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Doctor reacquires live database bytes when writable inspections follow a report's existing private state capture. On large databases, that repeats full-database I/O and source comparisons.

User Impact

Writable inspections fork the report's captured state into an independent image. This removes the second live-source acquisition and its full-file comparison. Initial capture and the private copy or reflink remain necessary; this does not claim zero physical copying. No configuration, schema, or runtime upgrade is required by this repair.

Why This Change Was Made

The retained read producer records its private main/WAL family before lending it. The existing isolated worker forks that owned image, holding source custody and checking identity before and after copying. Committed-WAL drift refuses the fork; frame-free WAL creation by read-only SQLite opens is accepted. Failed forks never retry against live state, and completed findings retain advisory disposal warnings.

The shared family type lives in the existing snapshot contract, avoiding a reverse dependency on its implementation. Generic mutable-source copying stays unchanged.

Production LOC: +332/-14 (net +318); tests +746/-157 (net +589); wrapper inventory +1. Growth implements the independent writable-image boundary, IPC validation and custody checks through existing owners.

Related: #176130, #176291

Evidence

  • Original focused proof covered 188 tests across 17 files. Integration 6a8a28a238a86fc2671d7fa635b46213105b9be1 also passed all 66 affected Doctor/worker/plugin lifecycle tests across five files.
  • Coverage includes bounded private-copy reads, independent writes, committed and frame-free WAL handling, source drift, coalescing, cancellation, disposal refusal and Doctor state isolation. The Doctor entry-point test verifies one private fork, no second synchronous live acquisition, a fresh next report and unchanged source artifacts.
  • Full integration pnpm build passed at 6a8a28a on Linux with Node 26.7 and pinned pnpm 12.11.1 in 500 seconds. Its build-only retry used the existing build-owned 4,352 MiB V8 setting within the proof environment's 12 GiB cap.
  • Final candidate 50968766ffea25b379d8dca96c07eef1b4aa8ecf incorporates captured main b1066a5c49101f28f3cbe4bfd3ca42bc66758036, preserves both snapshot helpers and main's wrapper inventory. The runtime algorithms match the tested integration; the CI correction relocates an erased type and adds equivalent test braces. Independent review, qualified formatting and diff checks passed.
  • CI at the preceding head exposed a type-only dependency cycle and ten missing test braces; these are corrected. It also exposed two stale Discord QA expectations inherited from fix(discord): hide tool activity in default progress messages #176470: quiet progress intentionally hides tool activity. A separate test-only commit removes that special-case expectation while preserving headline, enabled-progress, error-redaction, delivery and cleanup assertions. Independent review, formatting and staged line-cap checks passed; final runtime verification remains with exact-head CI.
  • Earlier tests/build are prior-head evidence. Main updates the process-inspection dependency; fresh exact-head CI must qualify the resulting composition. The native rollout builds and validates its selected source before activation.
  • Not deployed; no end-to-end Control UI latency or production byte-savings claim.

The earlier trace request is addressed by boundary tests: ordinary Doctor CLI output reports findings and counts, not retained-image lineage, copy method or copied bytes. The planned single post-deployment Doctor run measures functional outcome and timing only.

Fork the retained report-owned private database family into an independent writable inspection image. Preserve producer-bound main and WAL mutation fences, source admission, and cleanup ownership without acquiring the live source again.

Validation: targeted formatting, diff checks, and independent static review completed. Focused runtime tests and build remain pending; the queued remote allocation was stopped before execution.
Observe only the IPC child created by a fork, excluding the shared retained-source broker. Capture the returned fork cleanup owner for every retirement fixture and retry that exact owner after injected failures.

Validation: targeted formatting and git diff --check pass. The prior source run passed 186 of 188 tests; the two corrected assertions await focused remote proof. Production is unchanged; build remains pending.
@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 scripts Repository scripts commands Command implementations size: XL labels 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. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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
@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Doctor creates writable inspection images from its retained private snapshot instead of reading live database bytes again.

Example: Run openclaw doctor --lint with skills, runtime-tool-schema, and project-clone checks.

  • Before: Writable inspection acquires another live database image after the report has captured shared state.
  • After: Writable inspection forks the captured private image and shares that independent writable image across the report.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful and coherent repair with no concrete introduced defect; behavior evidence is harness-based and exact-head validation remains incomplete.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied evidence describes prior-head real-SQLite and native-child harness runs, without a shipped CLI trace or latest-stable upgrade run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Doctor repeats expensive live-database acquisition and comparison after already capturing state for the report.
Reason: The maintainer-authored direction addresses a source-confirmed remaining cost without adding user configuration or changing stored-data contracts.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it addresses a distinct remaining Doctor I/O problem, and the pinned diff has no actionable findings.

Priority: P2
Reviewed head: 50968766ffea25b379d8dca96c07eef1b4aa8ecf

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped Doctor CLI trace or latest-stable Doctor upgrade run is supplied, and base-red evidence for the new fork regression is not shown.
Agent review details

How this fits together

Doctor captures shared SQLite state for diagnostic reads, supplies disposable writable state to selected inspectors, and retires private handles and files after the report.

flowchart LR
  A[Doctor report] --> B[Retained read owner]
  C[Live SQLite database] --> B
  B --> D[Private main and WAL image]
  D --> E[Isolated fork worker]
  E --> F[Writable inspection image]
  F --> G[Diagnostic checks]
  G --> H[Handle retirement and cleanup]
Loading

Technical review

Best possible solution:

Keep one report-owned read capture and derive an independently writable image through the existing worker and cleanup owners.

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

Current-main source shows the report capture followed by a separate live-source acquisition for writable inspection; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The change fixes acquisition at the existing snapshot owner while preserving writable isolation, source admission, lazy preparation, and cleanup; the simplification pass found no clearly unnecessary production layer.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit 470ba96 adds src/commands/doctor-lint-state-snapshot.ts:90 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 470ba9649aaa; files: src/commands/doctor-lint-state-snapshot.ts)

PR surface

Source +318, Tests +589, Other +1. Total +908 across 23 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 10 332 14 +318
Tests 12 746 157 +589
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 23 1079 171 +908

Review metrics

Metric Value Why it matters
Production versus test growth Production +332/-14; tests +746/-157 Growth supplies independent writable-image preparation through existing lifecycle owners and distinct WAL, cancellation, isolation, and cleanup coverage.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Repeated database acquisition adds avoidable Doctor I/O on large installations without establishing an urgent availability or data-loss incident.
  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-18T18:58:01.654Z sha a8723fc :: needs changes before merge. :: none
  • reviewed 2026-10-18T21:35:01.341Z sha 7b4ed8a :: needs maintainer review before merge. :: none

Reviewed October 18, 2026, 5:53 PM ET / 21:53 UTC (Revision 3).

Baseline-Refresh: 9b089d2345fb25f7334ebce0d8d2d7e39df8efed
@vincentkoc
vincentkoc marked this pull request as ready for review October 18, 2026 21:29
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 7b4ed8a4bc18e958ca46cac35e8f9cd694d4f892. Native baseline refresh preserves both the landed async snapshot accessor and this PR's retained private-fork accessor, plus current main's wrapper inventory. All 21 Doctor source/test files match the tested integration. The PR body distinguishes prior-head build/test proof from fresh CI for the updated dependency composition and records the trace-request limitation.

@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Please review exact head 50968766ffea25b379d8dca96c07eef1b4aa8ecf. Since the reviewed head, the correction moves the unchanged snapshot-family type into its existing contract, adds equivalent test braces, and aligns inherited Discord quiet-progress QA expectations with the intended behavior from #176470. Independent review and local static checks passed; fresh exact-head CI is running. The PR body records prior runtime/build proof and its limits.

@clawsweeper

clawsweeper Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug 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 22:04
@vincentkoc
vincentkoc merged commit ec50e32 into main Oct 18, 2026
156 checks passed
@vincentkoc
vincentkoc deleted the fix/doctor-retained-private-fork-20261019 branch October 18, 2026 22:12
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

steipete added a commit that referenced this pull request Oct 19, 2026
The published 2026.10.5 updater refuses candidate Doctor lint when a retained
report snapshot and its writable inspection use different launch contexts.
#176334 intentionally forks the captured image rather than reading live state,
but the staging runtime kept only one native session and rejected the fork's
scoped state environment.

Reuse compatible sessions and retain independent custody for other launch
contexts. Count and retire directories on their originating session, preserving
failed-close retry without replaying a completed directory retirement. Keep
launch compatibility and source identity checks unchanged.

Cover overlapping Doctor contexts, compatible reuse, independent retirement,
and native-close failure. The reported hourly refusal is independent of the
missing watch-io worker packaging issue.
steipete added a commit that referenced this pull request Oct 19, 2026
Close the retained rehearsal broker before deleting its socket directory. Observe the native snapshot cleanup receipt on Windows rather than a parent-process fs spy, retaining the real open-handle blocker and source preservation assertions. The native-child cutovers in #173154 and #176334 exposed these stale fixture assumptions.
steipete added a commit that referenced this pull request Oct 19, 2026
The plugin-deferral rehearsal fixture applies child-process path variables
to the current process. Artifact-preserving state reads introduced in
#176334 can initialize the process-lived resource broker in that temporary
home; fixture cleanup then removes its socket and breaks subsequent tests.

Keep os.tmpdir stable for this in-process fixture while retaining the full
rehearsal environment and existing migration assertions. Restore both the
spy and Node builtin ESM exports after the test.

Production behavior is unchanged. Focused plugin-deferral and pending-read
checks pass on Node and pinned Bun; formatting, lint, the Doctor test
typecheck, and independent Codex review pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…nclaw#176334)

* fix(doctor): avoid rereading live state for writable inspections

Fork the retained report-owned private database family into an independent writable inspection image. Preserve producer-bound main and WAL mutation fences, source admission, and cleanup ownership without acquiring the live source again.

Validation: targeted formatting, diff checks, and independent static review completed. Focused runtime tests and build remain pending; the queued remote allocation was stopped before execution.

* test(doctor): bind fork fixtures to owned cleanup

Observe only the IPC child created by a fork, excluding the shared retained-source broker. Capture the returned fork cleanup owner for every retirement fixture and retry that exact owner after injected failures.

Validation: targeted formatting and git diff --check pass. The prior source run passed 186 of 188 tests; the two corrected assertions await focused remote proof. Production is unchanged; build remains pending.

* fix(sqlite): isolate the private snapshot family contract

* test(discord): align quiet progress expectations
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
…law#176665)

The published 2026.10.5 updater refuses candidate Doctor lint when a retained
report snapshot and its writable inspection use different launch contexts.
openclaw#176334 intentionally forks the captured image rather than reading live state,
but the staging runtime kept only one native session and rejected the fork's
scoped state environment.

Reuse compatible sessions and retain independent custody for other launch
contexts. Count and retire directories on their originating session, preserving
failed-close retry without replaying a completed directory retirement. Keep
launch compatibility and source identity checks unchanged.

Cover overlapping Doctor contexts, compatible reuse, independent retirement,
and native-close failure. The reported hourly refusal is independent of the
missing watch-io worker packaging issue.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 19, 2026
The plugin-deferral rehearsal fixture applies child-process path variables
to the current process. Artifact-preserving state reads introduced in
openclaw#176334 can initialize the process-lived resource broker in that temporary
home; fixture cleanup then removes its socket and breaks subsequent tests.

Keep os.tmpdir stable for this in-process fixture while retaining the full
rehearsal environment and existing migration assertions. Restore both the
spy and Node builtin ESM exports after the test.

Production behavior is unchanged. Focused plugin-deferral and pending-read
checks pass on Node and pinned Bun; formatting, lint, the Doctor test
typecheck, and independent Codex review pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL 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