Skip to content

fix(doctor): reconcile residual legacy session imports on an already-migrated store instead of stopping Doctor - #166397

Merged
steipete merged 1 commit into
mainfrom
upd/upd-doctor-residual-legacy-session-import
Oct 7, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-doctor-residual-legacy-session-import

Conversation

@steipete

@steipete steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes openclaw doctor --fix aborting on a populated SQLite session store when unreadable or aliased recovery history accompanies residual legacy inputs. The database-wide empty-store guard stopped session import and prevented post-session plugin and later repairs from running.

Closes #166204.

User Impact

Doctor preserves current session metadata and generations, imports new legacy entries through the existing staged importer, and archives verified originals with recovery receipts. Conflicting or malformed originals with a verified SQLite owner are preserved byte-for-byte as protected archive artifacts and produce target warnings. They are not certified as imported or eligible for cleanup.

Pending plugins retain their source receipts and originals until their existing migration owner finishes. Unverified ownership and unsafe concurrent source changes keep their existing data protection. The same behavior applies during update-time Doctor; backup, archive, and restore ownership stays unchanged. No configuration, CLI, dependency, or SQLite schema changes.

Why This Change Was Made

The reported guard is present in v2026.9.8, but populated SQLite alone does not activate it: unreadable or aliased migration history is the additional condition. Reconciliation now uses each session's canonical owner and transcript verification instead of requiring the entire destination to be empty. The existing historical import writer protects current metadata inside its transaction; the validation and archive owners distinguish verified imports from protected conflicting bytes.

This also carries warnings through Doctor's final session-admission check and the existing deferred-plugin receipt lifecycle. The oversized Doctor coordinator and receipt-retirement implementation are unchanged. Related #165861 touches the same subsystem and documentation page; this patch avoids its coordinator and receipt-retirement edits.

Thanks @coolcoolwcr for the report and upgrade evidence.

Evidence

  • Confirmed the guard and its unreadable/aliased-history trigger in the v2026.9.8 source tag. Three residual regressions fail against pre-fix production with the reported empty-destination error. Additional regressions exposed and then verified the final Doctor session-admission and pending-plugin receipt requirements.
  • The regressions use real SQLite, staged import, archive receipts, and Doctor's final session-admission check. They prove current metadata/history preservation, new entries in a populated store and another agent, protected archival of conflicting/malformed bytes, and retention for pending plugins. The downstream plugin adapter is stubbed only to observe that Doctor reaches it; existing plugin-migration importer suites exercise the actual plugin lifecycle.
  • All four touched suites passed three times (55 cases per pass). All 65 discovered importer files were accounted for: 64 passed with 845 tests; the existing Windows-only file's four cases were skipped on macOS. The CI inventory check initially saw the new unstaged file only through Vitest; after staging, its eight checks passed without a CI code change.
  • node scripts/check-changed.mjs exited 0. Formatting, production types, all 27 test-type graphs, lint, dead-export scans, schema and storage guards, and runtime import-cycle checks passed. git diff --check passed.
  • Codex P1 autoreview returned HTTP 401 and produced no verdict. Lead review of the PR head is required. Auto-merge is off.
  • All proof ran locally with isolated OPENCLAW_STATE_DIR values. No live WSL/systemd or installed-updater end-to-end run was performed.

Final standalone timings, using node scripts/run-vitest.mjs <file> --maxWorkers=1 (the repository-wrapper equivalent of pnpm test <file> --maxWorkers=1):

Test file Command wall Reported case time, summed
session-accessor.sqlite-import.test.ts 125.36 s 20.20 s
doctor-session-sqlite.recovery-generations.test.ts 243.55 s 192.38 s
doctor-session-sqlite.recovery-shared-owners.test.ts 207.00 s 173.21 s
doctor-session-sqlite.residual.test.ts 61.72 s 23.88 s

The existing recovery suites repeatedly exercise real import, restore, shared-owner publication, and cleanup; their test time exceeds the campaign threshold and is recorded under its pre-existing-suite exception. An earlier shared-owner case reached 78.84 s on the loaded host. Worker preparation ranged from about 53 to 235 s separately from test time. The new fixture initially spent 131.47 s on two cases; seeding migrated state directly and isolating unrelated plugin work reduced the final four-case fixture to 23.88 s. It retains the real importer, archive, and final admission boundary. CI seconds are not yet available at this authoring handoff.

Diff: production +94/-47, tests +183/-21, docs +13/-4.

Preserve canonical metadata and generations when recovery history cannot
prove a fresh import. Verify and import entries individually, archive
conflicting originals as protected recovery data, and retain plugin inputs
through the existing receipt lifecycle so later Doctor repairs can run.

Closes #166204.
Thanks @coolcoolwcr for the report and upgrade evidence.
@clawsweeper

clawsweeper Bot commented Oct 7, 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 docs Improvements or additions to documentation commands Command implementations size: M labels Oct 7, 2026
@steipete
steipete marked this pull request as ready for review October 7, 2026 02:27
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 6, 2026, 10:32 PM ET / October 7, 2026, 02:32 UTC.

ClawSweeper review

What this changes

Doctor reconciles residual legacy session files with populated SQLite stores, preserves current session metadata, and archives conflicting originals as protected recovery data.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful, bounded fix: current main retains the reported abort guard, and the reviewed patch has no definite correctness finding. Maintainer-authored work also remains protected from automatic closure.

Priority: P1
Reviewed head: 7d5c9be7687216fca8d69541305a4d916d675181

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable repair with meaningful storage regressions and no definite defect; update integration still needs its required evidence.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored PR is exempt from ordinary external-contributor proof. Inspected real-SQLite regressions support existing-state compatibility, including fresh imports, populated-store preservation, and protected archives; the separately required published-updater integration evidence remains outstanding.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from ordinary external-contributor proof. Inspected real-SQLite regressions support existing-state compatibility, including fresh imports, populated-store preservation, and protected archives; the separately required published-updater integration evidence remains outstanding.
Evidence reviewed 9 items Pinned change and merge ownership: Read the introduced merge-base-to-head diff. The raw test-merge commit records fetched main af716af followed by the exact PR head; its result contains the same eleven intended paths.
Fix remains necessary on main: Fetched main still activates requireEmptyStore for unreadable manifests or aliased manifest directories and passes that requirement to the transactional importer. The branch replaces this database-wide restriction with per-session reconciliation.
Current-session preservation: The new reconciliation flag uses the existing historical-only import contract. Inside the write transaction, that contract checks the session-window owner and preserves an existing logical node instead of overwriting its current metadata or pointer.
Findings None None.
Security None None.

How this fits together

Doctor migrates legacy session indexes and transcripts into OpenClaw’s per-agent SQLite stores. Its import and archive results determine whether session admission and subsequent plugin repairs can proceed.

flowchart TD
  A[Legacy session files] --> C[Doctor reconciliation]
  B[Existing SQLite sessions] --> C
  C --> D[Verify ownership and transcript content]
  D --> E[Import compatible history]
  D --> F[Preserve protected originals]
  E --> G[Session admission and plugin repairs]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - Update-time reconciliation and preservation of recovery/rollback artifacts remain unverified through the policy-required published updater × candidate boundary.
  • Complete next step (P2) - Add the policy-required published updater × candidate evidence for residual-session reconciliation and recovery-artifact preservation.
Agent review details

Security

None.

PR surface

Source +47, Tests +162, Docs +9. Total +218 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 94 47 +47
Tests 4 183 21 +162
Docs 1 13 4 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 290 72 +218

Review metrics

Metric Value Why it matters
Production and regression growth production +94/-47; tests +183/-21 Production growth is justified by per-session preservation and deferred-warning handling after removing the global empty-store restriction.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-session-sqlite-discovery.ts, migration/backfill/repair: src/commands/doctor-session-sqlite-import.ts, unknown-data-model-change: src/commands/doctor-session-sqlite-import.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Merge-risk options

Maintainer options:

  1. Verify the published updater boundary (recommended)
    Provide a published-driver × candidate result using populated session state and residual legacy inputs, recording Doctor completion and preservation of current sessions and recovery artifacts.

Technical review

Best possible solution:

Keep reconciliation within the existing import and archive owners, with published-updater evidence confirming the same preservation guarantees during upgrades.

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

Yes, from source: populated session rows plus unreadable or aliased recovery history activate main’s empty-destination refusal during residual import. This review did not execute the scenario.

Is this the best way to solve the issue?

Yes. Reusing the transactional historical importer and protected archive classification is narrower and safer than skipping all residual imports or replacing current session state.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The linked released-version report describes Doctor aborting and blocking downstream repairs on an upgraded installation.
  • add merge-risk: 🚨 compatibility: The changed migration behavior also runs during updates, but the required published-driver compatibility evidence is absent.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The MEMBER-authored PR is exempt from ordinary external-contributor proof. Inspected real-SQLite regressions support existing-state compatibility, including fresh imports, populated-store preservation, and protected archives; the separately required published-updater integration evidence remains outstanding.

Label justifications:

  • P1: The linked released-version report describes Doctor aborting and blocking downstream repairs on an upgraded installation.
  • merge-risk: 🚨 compatibility: The changed migration behavior also runs during updates, but the required published-driver compatibility evidence is absent.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The MEMBER-authored PR is exempt from ordinary external-contributor proof. Inspected real-SQLite regressions support existing-state compatibility, including fresh imports, populated-store preservation, and protected archives; the separately required published-updater integration evidence remains outstanding.

Evidence

What I checked:

  • Pinned change and merge ownership: Read the introduced merge-base-to-head diff. The raw test-merge commit records fetched main af716af followed by the exact PR head; its result contains the same eleven intended paths. (6b97f60a608b)
  • Fix remains necessary on main: Fetched main still activates requireEmptyStore for unreadable manifests or aliased manifest directories and passes that requirement to the transactional importer. The branch replaces this database-wide restriction with per-session reconciliation. (src/commands/doctor-session-sqlite-import.ts:61, af716af2a545)
  • Current-session preservation: The new reconciliation flag uses the existing historical-only import contract. Inside the write transaction, that contract checks the session-window owner and preserves an existing logical node instead of overwriting its current metadata or pointer. (src/config/sessions/session-accessor.sqlite-import.ts:100, 7d5c9be76872)
  • Archive and existing-state compatibility coverage: The four residual scenarios exercise the production session-health entry point with real SQLite and archive receipts, checking metadata/history preservation, new history in two agents, final session admission, protected conflicting/malformed bytes, and pending-plugin originals. Existing recovery suites additionally cover fresh 257-entry imports, restored generations, shared owners, source changes, and rollback artifacts. The PR reports repeated passing runs; this review inspected source without executing tests. (src/commands/doctor-session-sqlite.residual.test.ts:18, 7d5c9be76872)
  • Required update proof remains absent: Root policy requires a published-driver × candidate cell for Doctor and migration changes. The captured PR body explicitly states that no installed-updater end-to-end run was performed; its isolated session regressions do not exercise that driver boundary. (AGENTS.md:70, 7d5c9be76872)
  • Update execution differs from standalone Doctor: The update driver supplies update-in-progress, parent capability, service-repair, and optional plugin-deferral markers. These make the claimed update-time behavior a distinct integration boundary from the standalone session fixture. (src/infra/update-runner-doctor.ts:23, 7d5c9be76872)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record a published updater × candidate result demonstrating residual-session reconciliation and preservation of recovery artifacts.

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.

@steipete
steipete merged commit 3a90ed1 into main Oct 7, 2026
202 of 204 checks passed
@steipete
steipete deleted the upd/upd-doctor-residual-legacy-session-import branch October 7, 2026 03:28
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
RomneyDa pushed a commit that referenced this pull request Oct 11, 2026
…migrated store instead of stopping Doctor (#166397)

Closes #166204

Reported by @coolcoolwcr.

(cherry picked from commit 3a90ed1)
RomneyDa added a commit that referenced this pull request Oct 11, 2026
RomneyDa added a commit that referenced this pull request Oct 11, 2026
…port (#166397 backport)

The #166397 backport assigned record.preserveCurrentSession from import-time
recovery state, overwriting the protection that the already-shipped #167538
backport sets for records recovered behind a foreign or stale import receipt
(doctor-session-sqlite.ts). Doctor then replayed legacy metadata and
generations over current SQLite rows: canonical ACP labels were lost on the
next Doctor pass and live generations were replaced by historical ones.

Main has carried both changes together since #167538 (4c6b10b), which
turned the assignment into `||=`; apply the same composition here.

Fixes FRV failures in doctor-session-sqlite.stale-receipt ("keeps canonical
ACP metadata authoritative on the next Doctor pass" and "preserves live
generations and archived deletions while recovering foreign history").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. 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.

doctor --fix aborts on already-migrated session stores: "Session recovery history cannot be verified; SQLite destination is not empty"

1 participant