Skip to content

improve(doctor): reduce repeated state copies during update checks - #145577

Merged
VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/doctor-lint-private-reads
Sep 13, 2026
Merged

VACInc merged 1 commit into
openclaw:mainfrom
VACInc:fix/doctor-lint-private-reads

Conversation

@VACInc

@VACInc VACInc commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Summary

High Level TLDR

Doctor's post-plugin readiness check makes a private copy of shared state, then unnecessarily copies that private database again for subsequent reads. This change keeps those reads on the disposable database already owned by the check.

What Problem This Solves

Fixes an issue where update finalization performs redundant full shared-state copies during Doctor lint. The existing real-SQLite readiness scenario produces three snapshots: the original operator-state snapshot and two copies of that temporary database.

Root Cause

Doctor correctly wraps lint in artifact-preserving reads and creates a private plugin-state view. The shared read owner inherits the artifact-preserving context even after reads have been redirected to that disposable view, so fresh reads snapshot it again.

Why This Change Was Made

The shared read owner now recognizes an explicitly scoped disposable path. Doctor activates that scope only around its own private database. Native read-only handles, schema checks, and tracked handle cleanup remain with their existing owners. Other paths retain artifact-preserving reads, nested scopes remain independent, and inherited asynchronous contexts lose the exemption when their owner finishes.

No persistent schema, data representation, migration, configuration option, or cross-run cache changes. Installed update drivers remain unchanged; the optimization runs inside the candidate's existing Doctor lint path. Rollback needs no data conversion.

User Impact

A synthetic 206,671,872-byte shared database produces one full snapshot instead of three, avoiding 413,343,744 bytes of redundant copied output and two snapshot workers per exercised readiness pass. This is a bounded I/O optimization, not a claim to resolve all update latency.

Verification

Real behavior proof

The existing registered post-plugin readiness scenario runs real SQLite readers and snapshot workers. Its new assertion fails on the original code because two extra private paths are copied, and passes with this patch. It still reports the required missing local-embedding setup error, preserves the operator database family byte-for-byte, and never opens the operator database in the parent.

  • 70 focused tests passed, including nested path scopes, read-only writes being rejected, unrelated source protection, and revocation of inherited async contexts.
  • Targeted lint, formatting, and git diff --check passed.
  • Independent Astra high autoreview: scoped-clean at P0–P2.
  • Full pnpm build and the complete four-file check:changed gate passed, including core/core-test typechecks, dead-export scans, scoped lint, and storage/import guards.
  • Published [email protected] updater × exact candidate 9cdebdc907a1f629174bab85cfc0a3d4c43de329: passed using the repository's isolated Docker sqlite-volume scenario. The actual installed updater performed the npm update; the scenario preserved 4,800 sessions, 23,890 events, and 2,200 cron jobs, verified eight conversations across two agents before and after Gateway restart, and passed repeat Doctor idempotence in 18 seconds.

Focused tests:

node scripts/run-vitest.mjs src/state/openclaw-state-db-readonly.test.ts
node scripts/run-vitest.mjs src/commands/doctor-lint.test.ts src/commands/doctor-lint.state-isolation.test.ts

Published-driver cell (Node 24.19.0/Linux; candidate built and packaged with the canonical package helper):

OPENCLAW_CURRENT_PACKAGE_TGZ=/tmp/doctor-lint-package/openclaw-current.tgz \
OPENCLAW_DOCKER_E2E_SELECTED_SHA=9cdebdc907a1f629174bab85cfc0a3d4c43de329 \
OPENCLAW_UPGRADE_SURVIVOR_PUBLISHED_BASELINE=1 \
[email protected] \
OPENCLAW_UPGRADE_SURVIVOR_SCENARIO=sqlite-volume \
bash scripts/e2e/upgrade-survivor-docker.sh

Copied output:

sqlite-volume sessions=4800 events=23890 cronJobs=2200
sqlite-volume Gateway RPC verified 8 conversations across 2 agents
SQLite volume idempotence doctor completed in 18s (budget 60s).
Upgrade survivor Docker E2E passed [email protected] scenario=sqlite-volume candidate=2026.9.4 updateRestartMode=manual idempotence=18s startup=24s updateRestart=manuals healthz=1s readyz=1s status=1s.

Update receipt: status=ok, mode=npm; published build 2026.9.4-release-3a9d69db306c-2026-09-10T22-53-16.719Z → candidate build 2026.9.4-9cdebdc907a1-2026-09-12T03-42-19.063Z. Local Docker was used because hosted Package Acceptance accepts upstream-reachable refs, while this candidate is on the author fork. Its source-trust gate was preserved.

Performance limits

One warm run showed a large timing difference, but the repeated comparison measured essentially identical warm medians: 0.970 s baseline and 0.977 s candidate. Disk/cache variability prevents a reliable percentage latency claim. Snapshot counts consistently fell from three to one; findings and operator-state bytes remained unchanged.

What was not tested

No production update, restart, or operator-state mutation was performed. No claim is made about total update duration or Windows/macOS performance.

Related: #143802 and #145541 avoid agent-database copies during schema/header inspection. This PR addresses repeated shared-state copies inside Doctor's already-isolated lint view.

The first ClawSweeper review found no actionable correctness/security defects and requested the published-updater evidence now recorded above.

@clawsweeper

clawsweeper Bot commented Sep 12, 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 commands Command implementations size: S maintainer Maintainer-authored PR labels Sep 12, 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 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 10:00 PM ET / September 13, 2026, 02:00 UTC (Revision 5).

ClawSweeper review

What this changes

Doctor reuses its temporary shared-state database during health checks, avoiding redundant copies while retaining source-state protection.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful, distinct optimization with no actionable correctness or security findings. The previous data-model compatibility blocker does not apply: no persistent contract changes, and published-updater evidence is already supplied.

Priority: P2
Reviewed head: 5e002cd8f3590bfc8d475beb5fc75597737b0bb6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with useful lifecycle coverage and accepted published-updater proof; no substantive review blocker remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied Linux Docker transcript exercises the published updater installing candidate 9cdebdc907a1f629174bab85cfc0a3d4c43de329, preserving state through restart and repeat Doctor execution; registered real-SQLite readiness evidence demonstrates reduced copying. Reviewed rebase changes retain that optimization and upstream cleanup. This is reused earlier-candidate evidence, not a current-head Docker rerun.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied Linux Docker transcript exercises the published updater installing candidate 9cdebdc907a1f629174bab85cfc0a3d4c43de329, preserving state through restart and repeat Doctor execution; registered real-SQLite readiness evidence demonstrates reduced copying. Reviewed rebase changes retain that optimization and upstream cleanup. This is reused earlier-candidate evidence, not a current-head Docker rerun.
Evidence reviewed 10 items Introduced scope and current-main necessity: The pinned introduction contains only the disposable-read scope, its Doctor integration, and regression assertions. Comparing the two production files against fetched main shows that the optimization remains absent there; unrelated base-branch changes are not attributed to this PR.
Private scope retains existing lifecycle: Doctor creates the private database before activating the exemption. The exemption is revoked on completion, and existing asynchronous handle retirement still precedes file cleanup. No schema, serialized representation, migration, configuration, or installed-updater change is introduced.
Native read-only and admission safeguards: Direct private reads still use the existing connection owner with readOnly enabled and tracked handles. Fresh-open admission, supported-schema checks, synchronous source-read callbacks, and cleanup remain in place; the change does not grant additional principals access.
Findings None None.
Security None None.

How this fits together

Doctor runs health and update-readiness checks against an isolated copy of OpenClaw’s shared state. The shared database reader supplies those checks with data, then Doctor closes private handles and removes the temporary files.

flowchart TD
  A[Doctor health checks] --> B[Snapshot operator state]
  B --> C[Private database scope]
  C --> D{Read targets active private database?}
  D -->|Yes| E[Read private database directly]
  D -->|No| F[Preserve source through snapshot]
  E --> G[Return health findings]
  F --> G
  G --> H[Revoke scope and clean up]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +34, Tests +45. Total +79 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 40 6 +34
Tests 2 45 0 +45
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 85 6 +79

Review metrics

Metric Value Why it matters
Snapshot amplification Reported readiness scenario: 3 snapshots → 1 This removes two full private-database copies; the supplied repeated timings do not establish a latency improvement.
Persistent contract changes 0 schema, migration, or configuration changes The added scope state exists only in memory, resolving the earlier data-model classification concern.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-lint.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep one operator-state snapshot per isolated check scope, reuse its private database, and retain the existing read admission and cleanup owners.

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

Yes, source inspection shows that current main snapshots fresh reads even after Doctor redirects them to its private database. The supplied registered-readiness evidence reports three snapshots before and one after; this review did not execute tests.

Is this the best way to solve the issue?

Yes. The exemption is limited to an active, explicitly owned disposable path and reuses existing read and cleanup machinery without introducing a competing storage implementation.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded reduction in update-readiness disk I/O without an established urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied Linux Docker transcript exercises the published updater installing candidate 9cdebdc907a1f629174bab85cfc0a3d4c43de329, preserving state through restart and repeat Doctor execution; registered real-SQLite readiness evidence demonstrates reduced copying. Reviewed rebase changes retain that optimization and upstream cleanup. This is reused earlier-candidate evidence, not a current-head Docker rerun.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Linux Docker transcript exercises the published updater installing candidate 9cdebdc907a1f629174bab85cfc0a3d4c43de329, preserving state through restart and repeat Doctor execution; registered real-SQLite readiness evidence demonstrates reduced copying. Reviewed rebase changes retain that optimization and upstream cleanup. This is reused earlier-candidate evidence, not a current-head Docker rerun.

Evidence

What I checked:

  • Introduced scope and current-main necessity: The pinned introduction contains only the disposable-read scope, its Doctor integration, and regression assertions. Comparing the two production files against fetched main shows that the optimization remains absent there; unrelated base-branch changes are not attributed to this PR. (src/state/openclaw-state-db-readonly.ts:28, 5e002cd8f359)
  • Private scope retains existing lifecycle: Doctor creates the private database before activating the exemption. The exemption is revoked on completion, and existing asynchronous handle retirement still precedes file cleanup. No schema, serialized representation, migration, configuration, or installed-updater change is introduced. (src/commands/doctor-lint.ts:361, 5e002cd8f359)
  • Native read-only and admission safeguards: Direct private reads still use the existing connection owner with readOnly enabled and tracked handles. Fresh-open admission, supported-schema checks, synchronous source-read callbacks, and cleanup remain in place; the change does not grant additional principals access. (src/state/openclaw-state-db-read-connection.ts:27, 5e002cd8f359)
  • Meaningful regression coverage: The registered post-plugin readiness test delegates to real SQLite and snapshot implementations and asserts one source snapshot, unchanged findings, no parent-process source open, and byte-preserved operator state. The shared-reader test covers nested paths, rejected writes, unrelated source protection, and expired inherited scopes across three reader entrypoints. Tests were inspected, not executed during this read-only review. (src/commands/doctor-lint.test.ts:796, 5e002cd8f359)
  • Published-updater proof: The captured PR body records Linux Docker execution of the actual published [email protected] updater installing candidate 9cdebdc907a1f629174bab85cfc0a3d4c43de329. Copied terminal output reports preservation of 4,800 sessions, 23,890 events, 2,200 cron jobs, eight conversations across two agents, restart survival, and repeat Doctor idempotence in 18 seconds. This is earlier-candidate proof, not a newly executed current-head run. The captured discussion explicitly clarifies that distinction. (9cdebdc907a1)
  • Proof continuity across rebases: GitHub’s original-candidate commit patch contains the same disposable-read implementation and regression assertions. Its Doctor wrapper was adapted around main’s asynchronous cleanup. GitHub’s prior-reviewed commit patch matches the current introduced hunks. Local older-revision comparisons could not load historical objects, so pinned GitHub commit records supplied this comparison. (src/state/openclaw-state-db-readonly.ts:34, 9cdebdc907a1)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • thien-ngn: 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 (4 earlier review cycles)
  • reviewed 2026-09-12T03:50:13.367Z sha 9cdebdc907a1f629174bab85cfc0a3d4c43de329 :: blocked before merge. :: none
  • reviewed 2026-09-12T04:00:41.081Z sha 9cdebdc907a1f629174bab85cfc0a3d4c43de329 :: blocked before merge. :: none
  • reviewed 2026-09-12T21:31:00.599Z sha 813671de69b9719f770daa37cc5279a3ef5dd602 :: blocked before merge. :: none
  • reviewed 2026-09-13T01:50:22.100Z sha 813671de69b9719f770daa37cc5279a3ef5dd602 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 12, 2026
@VACInc
VACInc marked this pull request as ready for review September 12, 2026 20:58
@VACInc
VACInc force-pushed the fix/doctor-lint-private-reads branch from 9cdebdc to 813671d Compare September 12, 2026 21:08
@VACInc

VACInc commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

Rebased onto main at d093d65; head 813671de69b. Preserved upstream asynchronous private-state cleanup and retained disposable-reader scope. Focused Doctor lint and read-only state suites: 55 tests passed. Formatting and diff checks passed.

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

Please reconcile the remaining Add data-model compatibility proof item with the published-updater evidence already accepted in the current review.

At head 813671de69b9719f770daa37cc5279a3ef5dd602, the four-file diff adds process-local disposable-read scope tracking and applies it only to Doctor’s private database. It does not change schemas, schema versions, migrations, stored representations, configuration, or installed update drivers. The existing read-connection owner still opens native read-only handles and applies the existing schema admission checks; Doctor still retires the private handles before deleting the snapshot.

The PR body records the actual published [email protected] updater installing candidate 9cdebdc907a1f629174bab85cfc0a3d4c43de329: 4,800 sessions, 23,890 events, 2,200 cron jobs, eight conversations across two agents surviving restart, and repeat Doctor idempotence. The latest review explicitly accepts this evidence and distinguishes its candidate SHA from the mechanically rebased current head. This is not a claim of a new current-head Docker run.

Please determine whether the remaining item is a false-positive data-model classification, or identify the specific changed persistent contract that still lacks proof. CI failures are being diagnosed separately; this request is review-only, not automerge.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@VACInc

VACInc commented Sep 13, 2026

Copy link
Copy Markdown
Member Author

#143802 merged to main with an agent schema-shape read optimization. This PR's reuse of Doctor's already-disposable shared-state lint database is complementary work; neither change supersedes the other.

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

Labels

commands Command implementations maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants