Repository navigation
fix(doctor): session SQLite restore installs an empty session index over the valid archive - #117221
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 2:57 AM ET / 06:57 UTC. ClawSweeper reviewWhat this changesThe PR makes Doctor plan all session-SQLite restore archives for a destination before moving any, selecting safe duplicates or a valid nonempty legacy index while recording which archive was consumed. Merge readinessNo blocking correctness finding. This PR moves duplicate-archive selection into the Doctor migration-run owner, preserves per-archive consumption facts, and fails closed before a restore can replace a valid session index with an empty later archive. The embedded redacted built-CLI transcript directly shows the repaired outcome; keep this PR open for normal owner review and exact-head checks. Priority: P1 Review scores
Verification
How this fits togetherDoctor imports legacy session files into SQLite and records source-to-archive moves in migration manifests so operators can later restore file-backed sessions. The restore-report command and startup recovery both call the migration-run restore owner, which decides whether an archived file can safely return to its original path. flowchart LR
Legacy[Legacy session index and transcripts] --> Import[Doctor import]
Import --> Manifests[Migration manifests and archives]
Manifests --> Planner[Duplicate archive planner]
Planner --> Decision[Validate, select, or conflict]
Decision --> Restore[Safe file restore]
Restore --> Report[Doctor report and startup recovery]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +398, Tests +335, Docs +5. Total +738 across 3 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the centralized planner with its archive-provenance and old-manifest upgrade tests, preserving the documented fail-closed outcome for any ambiguous recovery state. Do we have a high-confidence way to reproduce the issue? Yes, source reproduction is high confidence: on current main, multiple manifests for one missing source are restored independently in manifest order, while the branch fixture creates the original nonempty index followed by later empty indexes and verifies the selected result. Is this the best way to solve the issue? Yes. Planning candidates at AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 78486e27511c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
…a store Restore picked the winning archive by manifest iteration order, newest first. When a legacy writer recreated an empty sessions.json between migrations, the newest run had archived that empty file, so restore installed it and then refused the only archive holding real sessions as a conflict. Resolve one winning archive per destination before writing anything, preferring the earliest run whose archive is still restorable. Losing archives are never deleted and stay visible as conflicts. Closes openclaw#116163
39d2718 to
673f77f
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Final P0 landing gate for exact head
Landing via squash with contributor authorship preserved. |
* origin/main: (41 commits) test(ci): update memory helper routing expectation (#117295) fix(canvas): emit successful control results in JSON mode (#117297) fix(imessage): settle native inbound reply delivery (#117282) fix(agents): reject invalid UTF-8 LSP responses (#117271) fix(line): centralize card and template message alt text (#117280) fix(release): validate candidates before Docker publication (#117252) fix(media): validate provider-owned generated media downloads (#117281) fix(feishu): restore custom HTTPS API domains (#117278) fix(models): reuse prepared plugin metadata (#117131) fix(agents): stop fallback after delivered-but-failed attempts (#114628) fix(memory): reuse targeted session corpus snapshot (#117247) fix(matrix): reconcile durable sends after response loss test(release): repair full validation regressions (#116931) fix(linux-canvas): report socket watcher fallback (#109502) fix(codex): preserve authoritative turn completion (#117185) fix(canvas): preserve widgets across derived-name collisions (#117132) fix(channels): config validation rejects documented channels.<id>.configWrites on 13 channels (#117206) fix(msteams): prevent duplicate final replies (#116398) fix(doctor): session SQLite restore installs an empty session index over the valid archive (#117221) fix(plugins): preserve workspace plugins across CLI and control UI (#117265) ...
…ver the valid archive (openclaw#117221) * fix(doctor): restore the pre-migration session index when runs share a store Restore picked the winning archive by manifest iteration order, newest first. When a legacy writer recreated an empty sessions.json between migrations, the newest run had archived that empty file, so restore installed it and then refused the only archive holding real sessions as a conflict. Resolve one winning archive per destination before writing anything, preferring the earliest run whose archive is still restorable. Losing archives are never deleted and stay visible as conflicts. Closes openclaw#116163 * fix(doctor): fail closed on ambiguous session restores * test(doctor): key restore conflicts by archive * fix(doctor): narrow restored archive lookup * fix(doctor): stream restore archive hashing --------- Co-authored-by: Vincent Koc <[email protected]>
* origin/main: (41 commits) test(ci): update memory helper routing expectation (openclaw#117295) fix(canvas): emit successful control results in JSON mode (openclaw#117297) fix(imessage): settle native inbound reply delivery (openclaw#117282) fix(agents): reject invalid UTF-8 LSP responses (openclaw#117271) fix(line): centralize card and template message alt text (openclaw#117280) fix(release): validate candidates before Docker publication (openclaw#117252) fix(media): validate provider-owned generated media downloads (openclaw#117281) fix(feishu): restore custom HTTPS API domains (openclaw#117278) fix(models): reuse prepared plugin metadata (openclaw#117131) fix(agents): stop fallback after delivered-but-failed attempts (openclaw#114628) fix(memory): reuse targeted session corpus snapshot (openclaw#117247) fix(matrix): reconcile durable sends after response loss test(release): repair full validation regressions (openclaw#116931) fix(linux-canvas): report socket watcher fallback (openclaw#109502) fix(codex): preserve authoritative turn completion (openclaw#117185) fix(canvas): preserve widgets across derived-name collisions (openclaw#117132) fix(channels): config validation rejects documented channels.<id>.configWrites on 13 channels (openclaw#117206) fix(msteams): prevent duplicate final replies (openclaw#116398) fix(doctor): session SQLite restore installs an empty session index over the valid archive (openclaw#117221) fix(plugins): preserve workspace plugins across CLI and control UI (openclaw#117265) ...
Fixes #116163
What Problem This Solves
openclaw doctor --session-sqlite restorecould install a later recreated emptysessions.jsoninstead of the original pre-migration index when several migration runs archived the same destination. The old path processed manifests immediately, so filesystem order became an implicit data-selection policy.The initial PR reversed that ordering, but still inferred that a missing losing archive had been consumed by an earlier restore. If the original archive had actually been deleted or lost, Doctor could silently install a later empty index and report success.
Root cause and owner
The violated invariant belongs to the doctor session-SQLite migration-run owner: all archives targeting one destination must be evaluated before any archive is moved, and a missing archive may be suppressed only when durable per-archive evidence proves an earlier restore consumed it.
Repair
The rewritten restore path now plans every duplicate destination before writes:
restore.consumedArchivesprovenance;restore.restoredFilesare upgraded in place when one restored source maps unambiguously to one archive;This does not change the SQLite schema or schema version, and it does not bump the migration-manifest version. The optional manifest field is backward-readable; runtime session storage remains SQLite-only.
Operator-visible behavior
The destructive fixtures use the real
importandrestoreentry points rather than hand-written result objects:Redacted after-fix Doctor transcript from a real built CLI run on Blacksmith Testbox. The fixture performed one import from a nonempty legacy index, two later imports from recreated empty indexes, then restore:
Evidence
Focused destructive, upgrade, and large-archive coverage:
Adjacent callers:
Fresh Blacksmith Testbox changed gate on the frozen branch, including core/test typecheck, changed-file lint, dead exports, database-first guard, native schema-version guard, and import-cycle checks:
tbx_01kyy0t3p6c42jvzr8pzqbpcnqRemote SQLite flip lifecycle E2E:
tbx_01kyxzrc34f6ec68522fzykpb3Autoreview on exact local head
6e956006605ee5595f8f4125b69bd94658b0a72cis clean: patch correct0.91, no accepted/actionable P0 or P1 findings, secret scan clean.ClawSweeper rank-up moves
Scope
Relative to frozen base
1f40646f7e058adb7a796f039e0027eb0052ad83: production is +398 net lines, tests +335, docs +5. The production growth is the cross-manifest planner, safe archive inspection/fingerprint recheck, and persisted upgrade evidence required to remove the silent data-loss path; no unrelated runtime, provider, channel, config, or SQLite behavior changed.