Skip to content

fix(doctor): stop stale builds before repair guidance - #117913

Merged
fuller-stack-dev merged 2 commits into
openclaw:mainfrom
fuller-stack-dev:fix/doctor-schema-preflight
Aug 2, 2026
Merged

fuller-stack-dev merged 2 commits into
openclaw:mainfrom
fuller-stack-dev:fix/doctor-schema-preflight

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Aug 2, 2026 •

Copy link
Copy Markdown
Member

Related: #115008

AI-assisted: yes. I understand the change and validated the observable CLI behavior against isolated fixtures.

What Problem This Solves

Fixes an issue where users running Doctor from a stale OpenClaw installation could receive doctor --fix guidance and a successful exit even though the selected state database used a schema newer than that installation supported.

That guidance is unsafe and unactionable: the stale Doctor cannot reliably interpret the newer persisted state, so it must not enter config or migration planning first.

Why This Change Was Made

Interactive Doctor now reuses the existing read-only database schema preflight already owned by Gateway startup and update safety. A plain interactive git checkout retains Doctor's existing update-first recovery: a successful update replaces the stale process, while a declined or non-handled update reaches the schema preflight. Every surviving Doctor path runs the preflight before config loading, UI/install checks, state migrations, or repairs.

Incompatible state or registered agent schemas fail closed with the refusing build/install, found and supported schema versions, and matching-runtime guidance. Supported schemas and indeterminate/unreadable databases continue into normal Doctor diagnostics. The Gateway startup refusal keeps its existing default wording.

User Impact

Operators can still accept Doctor's documented fetch/rebase/build recovery from an interactive source checkout. If the running build remains incompatible, Doctor exits non-zero and tells the operator to use the state-writing/active Gateway installation or another compatible build; it does not suggest repairs it cannot safely perform.

Release-note context: stale Doctor invocations may update first, then fail before repair guidance when persisted database schemas remain newer than the executing build.

Evidence

  • Red reproduction: OpenClaw 2026.7.1-beta.5 (b6387af) against a synthetic schema-6 fixture exited 0, printed both Repair with openclaw doctor --fix and Run "openclaw doctor --fix", then printed Doctor complete. Before/after SHA-256 checksums matched.
  • Green built CLI: Blacksmith Testbox tbx_01kz0rvw14wwrphrty18dn6dfx (run) built the changed surface and ran a schema-7 fixture against a schema-6 build. Doctor exited 1, emitted Doctor refused to continue, contained no doctor --fix or Doctor changes preview, and preserved both fixture checksums.
  • Ordering regressions: Blacksmith Testbox tbx_01kz1qvn4j5618sw148yz0rzda (run) passed the successful interactive update, non-handled interactive update, and update-disabled refusal cases on the final patch content.
  • Negative control: malformed config without an incompatible database still emitted Config invalid; doctor will run with best-effort config and no schema refusal.
  • Focused tests: shared database preflight 6/6, Doctor updater 11/11, and Doctor ordering E2E 3/3 passed on Testbox.
  • Build: pnpm build passed in the built-CLI Testbox proof.
  • Autoreview: clean; no accepted/actionable findings (Codex, 0.98 confidence).

@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review August 2, 2026 08:27
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 1:33 PM ET / 17:33 UTC.

ClawSweeper review

What this changes

The PR makes the Doctor CLI refuse incompatible newer SQLite schemas before repair guidance while preserving the interactive git-checkout update path.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This PR remains necessary: current main runs Doctor’s update offer and then proceeds into UI, config, and repair-related diagnostics without checking whether the selected state or registered-agent databases are newer than the running build. The revised head resolves the prior ordering finding by allowing a successful interactive source-checkout update to handle Doctor first, then applying the shared read-only schema preflight before state-affecting diagnostics. Because this is member-authored, carries the maintainer label, and intentionally changes stale-install behavior, it should stay open for a maintainer merge decision after exact-head checks finish.

Priority: P2
Reviewed head: a4c07d0b484842524cfb69c34f28185164421ffa
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The revised patch cleanly addresses the earlier ordering blocker with focused regression coverage and strong real CLI evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides a before/after built-CLI Testbox reproduction with exit-code, output-absence, checksum-preservation, ordering-regression, focused-test, and build evidence; no contributor action is needed for proof.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides a before/after built-CLI Testbox reproduction with exit-code, output-absence, checksum-preservation, ordering-regression, focused-test, and build evidence; no contributor action is needed for proof.
Evidence reviewed 6 items Current-main gap: Current Doctor returns only when the update helper reports handled; otherwise it continues directly to UI/install checks and configuration loading, with no database-schema preflight in that path.
Revised owner-boundary fix: The PR invokes the shared schema preflight only after an unhandled update result and before config-write permission checks, UI checks, config loading, migrations, or repair contributions.
Shared preflight contract: The shared preflight opens the state and registered agent databases read-only, records newer schemas as incompatible, and treats unreadable databases as indeterminate rather than repairing them.
Findings None None.
Security None None.

How this fits together

Doctor is OpenClaw’s interactive diagnostics and repair command: it receives CLI options, may first offer a source-checkout update, then loads configuration and runs repair checks. The shared database preflight reads the selected state and registered-agent database schema headers so an older Doctor build can stop before it suggests or performs unsafe repairs.

flowchart TD
  A[Operator runs Doctor] --> B[Interactive source-checkout update offer]
  B --> C{Update handled?}
  C -->|Yes| D[Updated process completes Doctor]
  C -->|No| E[Read-only database schema preflight]
  E --> F{Schema compatible?}
  F -->|No| G[Refusal with compatible-install guidance]
  F -->|Yes| H[Config diagnostics and repair flow]
Loading

Decision needed

Question Recommendation
Should maintainers accept the intentional fail-closed Doctor behavior for stale builds once the remaining exact-head checks complete? Merge the update-first schema gate: Accept the safe refusal after an unhandled update attempt, preserving the documented interactive checkout recovery path.

Why: The patch is a focused compatibility safeguard, but the PR is member-authored and explicitly labeled for maintainer handling; accepting the user-visible refusal boundary is a maintainer merge decision.

Before merge

  • Resolve merge risk (P1) - Merging intentionally changes stale builds from best-effort Doctor diagnostics to an early refusal when selected persisted schemas are newer; this is safer, but operators with multiple installs will need the compatible state-writing installation named by the new guidance.
  • Complete next step (P2) - A focused patch is ready for human compatibility approval; no mechanical repair remains after the follow-up commit fixed the prior update-order finding.
Agent review details

Security

None.

PR surface

Source +42, Tests +112. Total +154 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 56 14 +42
Tests 2 112 0 +112
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 168 14 +154

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor.refuses-newer-database-schemas.e2e.test.ts, migration/backfill/repair: src/flows/doctor-health.ts, migration/backfill/repair: src/state/openclaw-database-preflight.ts, serialized state: src/state/openclaw-database-preflight.test.ts, serialized state: src/state/openclaw-database-preflight.ts, unknown-data-model-change: src/commands/doctor.refuses-newer-database-schemas.e2e.test.ts, and 2 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Accept the fail-closed stale-build boundary (recommended)
    Merge after exact-head checks complete, accepting that an older Doctor must refuse newer state rather than offer repairs it cannot safely interpret.
  2. Pause for an alternative recovery contract
    Do not merge if maintainers want stale Doctor to retain a different supported repair workflow; define and test that contract first.

Technical review

Best possible solution:

Keep the update-first recovery path, then use the existing read-only schema preflight as the single gate before Doctor loads config or offers repairs, with clear guidance to run a compatible state-writing installation.

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

Yes—current source shows Doctor reaches config and repair-related flows after an unhandled update without a schema gate, while the PR’s focused test constructs a newer-schema state database and verifies the intended ordering. The PR body also supplies before/after built-CLI Testbox evidence for the reported stale-build behavior.

Is this the best way to solve the issue?

Yes. Reusing the existing read-only database preflight at the Doctor lifecycle boundary is the narrowest maintainable fix; it avoids a separate schema policy and preserves the existing interactive update-first route before refusing an incompatible surviving build.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a3198023ea86.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides a before/after built-CLI Testbox reproduction with exit-code, output-absence, checksum-preservation, ordering-regression, focused-test, and build evidence; no contributor action is needed for proof.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The bug affects stale multi-install Doctor workflows and can otherwise produce unsafe, misleading repair guidance, but it is a bounded compatibility path rather than an emergency outage.
  • merge-risk: 🚨 compatibility: The PR deliberately changes existing stale-install behavior from continuing Doctor diagnostics to refusing before config and repair flows when persisted schemas are newer.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides a before/after built-CLI Testbox reproduction with exit-code, output-absence, checksum-preservation, ordering-regression, focused-test, and build evidence; no contributor action is needed for proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides a before/after built-CLI Testbox reproduction with exit-code, output-absence, checksum-preservation, ordering-regression, focused-test, and build evidence; no contributor action is needed for proof.

Evidence

What I checked:

  • Current-main gap: Current Doctor returns only when the update helper reports handled; otherwise it continues directly to UI/install checks and configuration loading, with no database-schema preflight in that path. (src/flows/doctor-health.ts:47, a3198023ea86)
  • Revised owner-boundary fix: The PR invokes the shared schema preflight only after an unhandled update result and before config-write permission checks, UI checks, config loading, migrations, or repair contributions. (src/flows/doctor-health.ts:17, a4c07d0b4848)
  • Shared preflight contract: The shared preflight opens the state and registered agent databases read-only, records newer schemas as incompatible, and treats unreadable databases as indeterminate rather than repairing them. (src/state/openclaw-database-preflight.ts:92, a3198023ea86)
  • Ordering regression coverage: The new regression test covers successful interactive update handling, an unhandled interactive update followed by refusal, and update-disabled refusal before config and legacy-state migration calls. (src/commands/doctor.refuses-newer-database-schemas.e2e.test.ts:26, a4c07d0b4848)
  • Prior-review repair provenance: The follow-up commit moves the preflight after the update result, directly addressing the earlier review concern that a stale interactive git checkout must retain its documented update-first recovery path. (src/flows/doctor-health.ts:63, a4c07d0b4848)
  • Feature-history provenance: The current shared schema-preflight and Doctor-flow lines trace to the same current-main commit, which added both central modules; that makes its author the strongest available routing candidate for this compatibility boundary. (src/state/openclaw-database-preflight.ts:47, f4e332a72ec0)

Likely related people:

  • Shakker: Commit f4e332a72ec001968b0ed65d78915c05d6ddd201 added the current Doctor-flow and shared schema-preflight surfaces; blame attributes the central preflight error boundary to that commit. (role: shared schema-preflight introducer and recent area contributor; confidence: medium; commits: f4e332a72ec0; files: src/flows/doctor-health.ts, src/state/openclaw-database-preflight.ts)

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 (3 earlier review cycles)
  • reviewed 2026-08-02T08:31:44.478Z sha 2aba1b2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T15:15:38.498Z sha 2aba1b2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T15:56:33.306Z sha 2aba1b2 :: found issues before merge. :: [P1] Preserve the interactive update path before refusing

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 2, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. labels Aug 2, 2026
@fuller-stack-dev
fuller-stack-dev merged commit eef59b5 into openclaw:main Aug 2, 2026
130 of 137 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/doctor-schema-preflight branch August 2, 2026 17:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* fix(doctor): refuse newer database schemas before repairs

* fix(doctor): preserve update before schema refusal
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

1 participant