Repository navigation
fix(doctor): reconcile residual legacy session imports on an already-migrated store instead of stopping Doctor - #166397
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed October 6, 2026, 10:32 PM ET / October 7, 2026, 02:32 UTC. ClawSweeper reviewWhat this changesDoctor 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 Review scores
Verification
How this fits togetherDoctor 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
Before merge
Agent review detailsSecurityNone. PR surfaceSource +47, Tests +162, Docs +9. Total +218 across 11 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…migrated store instead of stopping Doctor (openclaw#166397) Closes openclaw#166204 Reported by @coolcoolwcr.
…migrated store instead of stopping Doctor (#166397) Closes #166204 Reported by @coolcoolwcr. (cherry picked from commit 3a90ed1)
…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").
What Problem This Solves
Fixes
openclaw doctor --fixaborting 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
v2026.9.8source 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.node scripts/check-changed.mjsexited 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 --checkpassed.OPENCLAW_STATE_DIRvalues. 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 ofpnpm test <file> --maxWorkers=1):session-accessor.sqlite-import.test.tsdoctor-session-sqlite.recovery-generations.test.tsdoctor-session-sqlite.recovery-shared-owners.test.tsdoctor-session-sqlite.residual.test.tsThe 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.