Skip to content

improve: avoid redundant schema repair during Doctor preflight - #155446

Merged
steipete merged 5 commits into
mainfrom
codex/doctor-early-schema-preparation
Sep 22, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/doctor-early-schema-preparation

Conversation

@steipete

@steipete steipete commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Doctor preflight performs a full shared-state repair before plugin preparation even when the database is healthy and current, then performs the full repair again later.

User Impact

Healthy current databases avoid redundant early repair work. Doctor retains fresh integrity checks, historical upgrades, canonical-index repair, quarantine recovery, orphan delivery recovery, and its later full repair. This changes no schema version or stored format and requires no operator action.

Why This Change Was Made

Early preparation only needs to make shared state ready for dependent readers and plugin-obligation writers. The existing schema owner now checks current shape and fresh physical integrity under current ownership admission. Historical shape, failed integrity, or quarantine still invokes the existing full Doctor repair. The later normal migration remains unconditional; no integrity result or database-generation receipt is reused.

Evidence

Seven native SQLite cases pass on Blacksmith Testbox: healthy current schema, a historical release fixture, a missing canonical index, quarantine and orphan delivery recovery, and unrecoverable same-version corruption before early convergence or later repair. They preserve later full repair and already committed plugin obligations. Negative controls demonstrate the unnecessary repair in the original path and the recovery failures of a shape-only shortcut.

After rebasing onto current main, all 63 tests pass across the new file and the existing state-migration, container-upgrade, and update-schema-guard suites (78.16 seconds wall). They cover awaited convergence, lease loss, backup identity, rollback refusal, and database replacement. The new seven-case file takes 21.12 seconds through the repository test wrapper with one worker, including startup; its seven cases also pass hosted CI after main’s schema 18 update, with 26.79 seconds of combined execution under the shared worker load. Fresh independent review found no actionable P0–P2 findings.

On one remote host, a synthetic 17.7 MiB shared-state database with 512 rows measured 16.91 ms median preparation versus 46.12 ms for full repair: 63.3% less time in this phase. The comparison alternated paths for eight measured samples each after warmup. Both retained fresh integrity checks; these figures do not measure whole-Doctor or production-scale latency.

Full changed-file checks pass: formatting, line-cap gate, core and core-test type checks, lint, dead exports, import cycles, and storage/other repository guards.

The published-updater acceptance run passed: the released OpenClaw 2026.9.5 updater installed the tarball built from 3b715571a934, verified automatic migration, completed Doctor, preserved seeded state and unavailable-plugin configuration, and passed Gateway readiness/health checks. Subsequent changes are test-only; the tested production code is unchanged.

The existing pristine CLI process fixture initially timed out in hosted CI while its child processes compiled the source worker graph. The complete ordered file passed on an unloaded Testbox in 92.46 seconds, so the CI timeout was not reproduced there. The fixture now keeps the real source CLI and existing RPC hook while using the prepared real child workers and private fixture package assets. The same five cases pass in 50.57 seconds; the existing-state child decreased from 28.89 to 10.70 seconds. No assertions, deadlines, cases, or production behavior changed. Fresh independent P2 review is clean. The repaired Doctor/pristine process shard passed in the final hosted run, and all 147 checks passed, including the required CI gate (run 35698591709). The unrelated Slack fixture failure is addressed by main’s canonical fix 99f7055b3391, now incorporated.

@clawsweeper

clawsweeper Bot commented Sep 22, 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: M maintainer Maintainer-authored PR labels Sep 22, 2026
@steipete
steipete marked this pull request as ready for review September 22, 2026 04:52
@steipete steipete self-assigned this Sep 22, 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 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 3:22 AM ET / 07:22 UTC (Revision 3).

ClawSweeper review

What this changes

Doctor skips redundant early database repair when fresh schema and integrity checks pass, preserves its recovery paths, and reuses prepared workers in CLI tests.

Merge readiness

✅ Ready for maintainer review

Keep open as useful work with no blocking findings. The published-updater evidence resolves the previous compatibility concern, and the optimization remains absent from fetched main.

Priority: P2
Reviewed head: 3ff9e0fb24bb02c491f0fcfbfeb048483814f131

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful recovery coverage and published-updater evidence; no actionable correctness or security defect was found.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The reported published 2026.9.5 updater-to-candidate run exercises migration, Doctor, state preservation, and Gateway readiness; GitHub confirms that scenario succeeded, and the touched production files match the reviewed head. Native SQLite recovery cases supplement this proof. Existing-state compatibility is supported without a new stored format or migration; raw job logs were inaccessible to this reviewer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The reported published 2026.9.5 updater-to-candidate run exercises migration, Doctor, state preservation, and Gateway readiness; GitHub confirms that scenario succeeded, and the touched production files match the reviewed head. Native SQLite recovery cases supplement this proof. Existing-state compatibility is supported without a new stored format or migration; raw job logs were inaccessible to this reviewer.
Evidence reviewed 9 items Pinned introduced change: Reviewed the merge-base-to-head delta. The change is confined to early schema preparation, its existing database owner, and two test files; it adds no schema version, stored format, dependency, or public configuration.
Fresh checks and existing recovery owner: Doctor preparation retains coordinated ownership admission, checks quarantine, and performs fresh schema and SQLite integrity checks. Any failed check selects the existing fenced Doctor repair; the automatic scope remains the default for other callers.
Later repair remains independent: Preflight prepares shared state before plugin convergence; the subsequent migration graph still constructs its ordinary Doctor schema step and runs full repair. No integrity result or authority receipt is cached across that work.
Findings None None.
Security None None.

How this fits together

Doctor prepares OpenClaw’s shared SQLite state before plugin preparation and later migration steps. This change checks whether early repair is necessary while retaining the later full repair.

flowchart TD
  A[Doctor preflight] --> B[Current ownership admission]
  B --> C{Schema, integrity and quarantine checks}
  C -->|Healthy| D[Plugin preparation]
  C -->|Repair needed| E[Existing full repair]
  E --> D
  D --> F[Later full Doctor repair]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +26, Tests +237. Total +263 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 36 10 +26
Tests 2 240 3 +237
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 276 13 +263

Review metrics

Metric Value Why it matters
Reported preparation latency 16.91 ms versus 46.12 ms median Eight measured samples per path on a synthetic 17.7 MiB database support the optimization, without establishing whole-Doctor latency.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/infra/state-migrations.doctor.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Keep schema readiness checks within the existing database owner, preserving fresh integrity checks, recovery behavior, and the independent later repair.

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

Yes: current-main source shows both early preparation and the later Doctor migration selecting full repair; execution and timing evidence come from the supplied remote validation, not a local run.

Is this the best way to solve the issue?

Yes: extending the existing readiness and repair owner avoids a competing implementation while preserving automatic callers and historical recovery.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Doctor performance improvement with preserved recovery contracts and no reported urgent user 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 (linked_artifact): The reported published 2026.9.5 updater-to-candidate run exercises migration, Doctor, state preservation, and Gateway readiness; GitHub confirms that scenario succeeded, and the touched production files match the reviewed head. Native SQLite recovery cases supplement this proof. Existing-state compatibility is supported without a new stored format or migration; raw job logs were inaccessible to this reviewer.
  • proof: sufficient: Contributor real behavior proof is sufficient. The reported published 2026.9.5 updater-to-candidate run exercises migration, Doctor, state preservation, and Gateway readiness; GitHub confirms that scenario succeeded, and the touched production files match the reviewed head. Native SQLite recovery cases supplement this proof. Existing-state compatibility is supported without a new stored format or migration; raw job logs were inaccessible to this reviewer.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta. The change is confined to early schema preparation, its existing database owner, and two test files; it adds no schema version, stored format, dependency, or public configuration. (src/infra/state-migrations.state-schema.ts:59, 3ff9e0fb24bb)
  • Fresh checks and existing recovery owner: Doctor preparation retains coordinated ownership admission, checks quarantine, and performs fresh schema and SQLite integrity checks. Any failed check selects the existing fenced Doctor repair; the automatic scope remains the default for other callers. (src/state/openclaw-state-db.ts:149, 3ff9e0fb24bb)
  • Later repair remains independent: Preflight prepares shared state before plugin convergence; the subsequent migration graph still constructs its ordinary Doctor schema step and runs full repair. No integrity result or authority receipt is cached across that work. (src/commands/doctor-config-preflight.ts:390, 3ff9e0fb24bb)
  • Recovery regression coverage: The seven added native SQLite cases cover current and historical databases, missing canonical indexes, persisted quarantine, orphan deliveries, and corruption before early convergence or later repair. They check later full repair and preservation of committed plugin obligations. These tests were inspected, not executed during this read-only review. (src/commands/doctor-config-preflight.schema-preparation.test.ts:26, 3ff9e0fb24bb)
  • Published updater acceptance: GitHub confirms the linked package-acceptance run succeeded on candidate 3b71557. The captured PR body reports that the released 2026.9.5 updater installed the candidate, completed migration and Doctor, preserved seeded state and unavailable-plugin configuration, and passed Gateway readiness checks. https://github.com/openclaw/openclaw/actions/runs/35690872858. (3b715571a934)
  • Upgrade scenario and proof continuity: The published-upgrade-survivor job specifically succeeded. All four production files changed by this PR are identical between the tested candidate and reviewed head. Direct job-log retrieval was blocked by the artifact host allowlist; the assessment uses the captured scenario report, verified job result, inspected harness assertions, and source comparison. (src/state/openclaw-state-db.ts:149, 3ff9e0fb24bb)

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 (2 earlier review cycles)
  • reviewed 2026-09-22T05:01:29.709Z sha eb23d3d :: blocked before merge. :: none
  • reviewed 2026-09-22T07:03:31.369Z sha c367231 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 22, 2026
@steipete
steipete enabled auto-merge (squash) September 22, 2026 07:20
@steipete
steipete merged commit 64923d7 into main Sep 22, 2026
198 checks passed
@steipete
steipete deleted the codex/doctor-early-schema-preparation branch September 22, 2026 07:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
…law#155446)

* perf: avoid redundant early Doctor schema repairs

* test: follow the current Doctor schema contract

* test: reuse prepared workers in pristine Doctor CLI fixtures
fuller-stack-dev added a commit that referenced this pull request Nov 28, 2026
…ds nothing (#206694)

* fix(doctor): skip the state schema repair when its read-only plan finds nothing

Doctor's shared-state schema repair ran on every doctor --fix (doctor mode
repairs unconditionally since #155446): a write-mode open of the state,
credential and quarantine stores, the schema lease, write transactions and
a clean-close seal invalidation, even on a healthy install where it changes
nothing.

planOpenClawStateDatabaseDoctorRepair enumerates every condition the
doctor-scope repair acts on at the current schema version, each decided at
its owner from the rows or catalog entries that step writes (delivery queue
compaction and pruning, cron job projection, subagent payloads, approval
references, ACP accounting, credential receipt, canonical catalog, indexes,
integrity and the rest). It reads the live stores through the #206485 guard,
so a store nobody holds is undecidable. The repair runs exactly as before
unless every condition answers none.

The config-flow pending check now records this plan as its first input and
stays at work while the agent database and plugin obligation inputs have no
predicate.

* fix(doctor): include quarantine clearing in the state schema plan and fall back on plan errors

* test(doctor): add guard fixtures for the remaining state schema plan conditions

* fix(doctor): read the schema version predicate through Kysely and record the guard test lines

* fix(doctor): load the state schema plan only for Doctor and list it in the PR wrapper inventory

* refactor(doctor): trace config-flow inputs through the startup helper

* fix(doctor): give the config-flow pending tracer one exported spelling
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…ds nothing (openclaw#206694)

* fix(doctor): skip the state schema repair when its read-only plan finds nothing

Doctor's shared-state schema repair ran on every doctor --fix (doctor mode
repairs unconditionally since openclaw#155446): a write-mode open of the state,
credential and quarantine stores, the schema lease, write transactions and
a clean-close seal invalidation, even on a healthy install where it changes
nothing.

planOpenClawStateDatabaseDoctorRepair enumerates every condition the
doctor-scope repair acts on at the current schema version, each decided at
its owner from the rows or catalog entries that step writes (delivery queue
compaction and pruning, cron job projection, subagent payloads, approval
references, ACP accounting, credential receipt, canonical catalog, indexes,
integrity and the rest). It reads the live stores through the openclaw#206485 guard,
so a store nobody holds is undecidable. The repair runs exactly as before
unless every condition answers none.

The config-flow pending check now records this plan as its first input and
stays at work while the agent database and plugin obligation inputs have no
predicate.

* fix(doctor): include quarantine clearing in the state schema plan and fall back on plan errors

* test(doctor): add guard fixtures for the remaining state schema plan conditions

* fix(doctor): read the schema version predicate through Kysely and record the guard test lines

* fix(doctor): load the state schema plan only for Doctor and list it in the PR wrapper inventory

* refactor(doctor): trace config-flow inputs through the startup helper

* fix(doctor): give the config-flow pending tracer one exported spelling
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: 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