Skip to content

fix(doctor): skip duplicate legacy state scan after settled preflight - #180442

Closed
MertBasar0 wants to merge 1 commit into
openclaw:mainfrom
MertBasar0:fix/doctor-dedupe-legacy-state-detection
Closed

MertBasar0 wants to merge 1 commit into
openclaw:mainfrom
MertBasar0:fix/doctor-dedupe-legacy-state-detection

Conversation

@MertBasar0

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw doctor --fix / --yes scans legacy state twice and re-prints detection notices and warnings when preflight has already settled all pre-session state migrations on the unchanged config.

User Impact

User impact: openclaw doctor --fix / --yes no longer performs a redundant second detectLegacyStateMigrations scan across the state directory, session stores, SQLite tables, and plugin contracts when preflight already completed cleanly on the same config, and does not print duplicate detection notices or warnings when a second scan is required.

Why This Change Was Made

During loadAndMaybeMigrateDoctorConfig, runDoctorConfigPreflight (src/commands/doctor-config-preflight.ts:340-361) already runs autoMigrateLegacyState with doctorOnlyStateMigrations: shouldRepair, which executes detectLegacyStateMigrations and all pre-session migration steps and emits their changes, notices, and warnings. Later in the same health flow, runLegacyStateHealth (src/flows/doctor-health-contributions.ts:238-291) unconditionally called detectLegacyStateMigrations a second time and re-emitted any detection notices and warnings.

  • prepareDoctorConfigMigrationResult (src/commands/doctor/shared/config-migration-result.ts:121-141) now records preflightLegacyStateSettled: true when the preflight plan was bound (doctorOnlyStateMigrations: true), no config write or plugin inventory change occurred during config flow, no plugin migrations are deferred, params.cfg still matches preflight.baseConfig, and every pre-session step receipt completed or was skipped with no warnings.
  • runLegacyStateHealth (src/flows/doctor-health-contributions.ts:238-291) still runs core/doctor/removed-workspaces-state and repairObsoleteGeneratedExecApprovals, but skips the redundant detectLegacyStateMigrations pass when preflightLegacyStateSettled holds and ctx.cfg still matches ctx.configResult.cfg. When detectLegacyStateMigrations does run (for example in read-only openclaw doctor or after an earlier contribution mutates ctx.cfg), any notices or warnings already recorded on the preflight migration-detection receipt are filtered out before printing.
  • Consolidated duplicate dynamic note imports and manual changes/notices/warnings loops in src/flows/doctor-health-contributions.ts, src/flows/doctor-health-contribution-runners.config.ts, and src/flows/doctor-health-contribution-runners.state.ts through noteDoctorRepairResult (src/flows/doctor-health-contribution-utils.ts:32-40), keeping production LOC net -1 (+77 / -78).

Evidence

  • Unit & flow tests:
    • node scripts/run-vitest.mjs src/flows/doctor-health-contributions.legacy-state.test.ts src/flows/doctor-health-contributions.test.ts src/commands/doctor-config-flow.plugin-session-plan.test.ts (all 87 tests pass, including the new skips duplicate legacy state detection when preflight settled unchanged config and deduplicates prior notes when rerun regression test in src/flows/doctor-health-contributions.legacy-state.test.ts).
  • Lint & formatting:
    • npx oxlint and npx oxfmt --check on all touched files (0 warnings, 0 errors).

@clawsweeper

clawsweeper Bot commented Oct 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 labels Oct 22, 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

The PR skips legacy-state detection after settled preflight and suppresses repeated detection notices.

Example: Run openclaw doctor --fix with unchanged configuration and successful preflight migration receipts.

  • Before: The later health contribution scans legacy state again.
  • After: The health contribution skips that scan while retaining removed-workspace and generated-approval cleanup.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused and has no definite introduced defect, but mocked tests do not satisfy the required real-behavior and upgrade evidence.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Repairing Doctor repeats legacy-state scanning and can repeat detection notices already emitted by preflight.
Reason: Avoiding source-confirmed duplicate work has clear value and uses the existing migration owner without adding configuration or public APIs.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: this PR addresses duplicate Doctor work still present on main, and review found no definite introduced correctness bug.

Priority: P2
Reviewed head: ab0ac038486e73740403bbbe362e07fbad331cb4

Before merge

  • Add real behavior proof - The supplied test exercises the handoff with synthetic receipts and mocked migration owners, but no shipped Doctor execution demonstrates the avoided scan and preserved fallback behavior; provide redacted terminal output or logs showing both scenarios, keeping IPs, credentials, phone numbers, and non-public endpoints private. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Complete next step - Resolve GitHub's reported merge conflict while retaining current-main configuration provenance and migration behavior.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Supply real CLI evidence for the settled skip and changed-config fallback, including latest-stable upgrade preservation; red-on-base regression execution is not shown.
Agent review details

How this fits together

Doctor preflight detects and migrates legacy state, then hands configuration and migration receipts to ordered health contributions that perform remaining diagnostics and repairs.

flowchart TD
  A[Doctor CLI] --> B[Config preflight]
  B --> C[Legacy migration owner]
  C --> D[Config and receipts]
  D --> E[Legacy state health]
  E --> F[Conditional detection]
  E --> G[Remaining cleanup]
Loading

Technical review

Best possible solution:

Reuse settled preflight receipts to avoid redundant detection while preserving fallback scans and existing cleanup owners.

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

Source establishes detection during preflight and again in the later health contribution; no product execution was performed during this read-only review.

Is this the best way to solve the issue?

Carrying settlement through the existing configuration handoff is a focused solution, and the patch preserves detection for unsettled or changed configuration.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Migration receipts and deferred post-session work keeps the original intent (6277d6d: Preserve Doctor migration selection, ordered outcomes, and refusal closure through configuration and session repair.)
  • Plugin inventory changes during configuration repair keeps the original intent (4842a3b: Refresh deferred plugin migration plans against the committed inventory after installation.)
  • Shared repair-result rendering keeps the original intent (56689a9: Consolidate Doctor reporting mechanics while retaining explicit repair and publication policies.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit 6277d6d adds src/flows/doctor-health-contribution-types.ts:43 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6277d6da1331; files: src/flows/doctor-health-contribution-types.ts)
  • Vincent Koc: Raw commit 4842a3b adds src/commands/doctor/shared/config-migration-result.ts:111 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4842a3b8f0f4; files: src/commands/doctor/shared/config-migration-result.ts)

PR surface

Source -1, Tests +126. Total +125 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 6 77 78 -1
Tests 1 126 0 +126
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 203 78 +125

Labels

Label changes:

  • add P2: Repeated Doctor scans and notices create avoidable work and confusing output without establishing an urgent runtime failure.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Repeated Doctor scans and notices create avoidable work and confusing output without establishing an urgent runtime failure.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 22, 2026, 4:33 AM ET / 08:33 UTC.

@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 22, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Oct 22, 2026
@MertBasar0 MertBasar0 closed this Oct 22, 2026
steipete added a commit that referenced this pull request Oct 22, 2026
)

Doctor rescanned legacy state even when the update preflight had already settled the same scan, doubling slow work on large installs. Doctor now reuses settled preflight results when config is unchanged, rescans after pending config writes, plugin inventory changes or metadata invalidation, and keeps independent cleanup. Supersedes #180442, thanks @MertBasar0.

Co-authored-by: MertBasar0 <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Thanks @MertBasar0. We landed this as #180576 (48fcb8b), with you credited as co-author. Doctor now reuses the settled preflight scan while the config is unchanged. It rescans after pending config writes, plugin inventory changes, or metadata invalidation, and independent cleanup still runs.

RomneyDa added a commit that referenced this pull request Oct 22, 2026
)

Doctor rescanned legacy state even when the update preflight had already settled the same scan, doubling slow work on large installs. Doctor now reuses settled preflight results when config is unchanged, rescans after pending config writes, plugin inventory changes or metadata invalidation, and keeps independent cleanup. Supersedes #180442, thanks @MertBasar0.

Co-authored-by: MertBasar0 <[email protected]>
(cherry picked from commit 48fcb8b)
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
…claw#180576)

Doctor rescanned legacy state even when the update preflight had already settled the same scan, doubling slow work on large installs. Doctor now reuses settled preflight results when config is unchanged, rescans after pending config writes, plugin inventory changes or metadata invalidation, and keeps independent cleanup. Supersedes openclaw#180442, thanks @MertBasar0.

Co-authored-by: MertBasar0 <[email protected]>
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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants