Skip to content

fix(doctor): settle byte-identical duplicate session import archives - #155194

Merged
steipete merged 9 commits into
mainfrom
upd/session-import-duplicate-archives
Sep 22, 2026
Merged

steipete merged 9 commits into
mainfrom
upd/session-import-duplicate-archives

Conversation

@steipete

@steipete steipete commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #155095. Related: #154413. Thanks @fozzels-assistant for the detailed archive analysis and recovery report.

What Problem This Solves

Repeated session imports can leave byte-identical primary archives that Doctor treats as conflicting history. Repair keeps deferring them, and older update flows can strand the installation while waiting for session repair.

User Impact

Doctor automatically keeps one verified original for identical archive claims and redirects every migration manifest to it. Import and recover use the same settlement, including interrupted runs. Genuinely different copies remain preserved and named in warnings; historical-only warnings allow post-session plugin repair to finish.

No new flags, configuration, dependencies, or SQLite schema changes. The existing archive journal preserves retryable disposal and rollback mappings. The historical-only source-index refusal was already addressed by #153097; this change fixes duplicate settlement and the missing durable warning that an archive-only early return exposed.

Why This Change Was Made

One verified surviving original must satisfy every retained run's rollback claim. Merely deleting duplicates or marking their references disposed breaks failed-run recovery. Coalescing also preserves completed import acknowledgments, so it cannot resurrect history that a user deliberately deleted.

Owner Production lines (+/−; net) Why it cannot be smaller safely
Retirement journal (doctor-session-sqlite-retirement.ts:64) +259/−132; +127 Durable intent, claim, unlink, completion and survivor verification make interrupted disposal recoverable through the existing owner.
Manifest redirection and completed acknowledgments (doctor-session-sqlite-migration-coalesce.ts:15, with migration-run keys) +82/−1; +81 Every planned/completed reference must point to the surviving physical file, including partially published runs. Completed historical-import acknowledgments win when references merge, preventing user-deleted history from being imported again.
Identity claims (doctor-session-sqlite-discovery.ts:76,355) +56/−22; +34 The existing collector groups trusted same-target, same-original-path, same-size/SHA claims and excludes restored or acknowledged history. Different original filenames retain independent rollback claims even when their bytes match.
Doctor recovery and warning persistence (doctor-session-sqlite.ts:170,369, target/recovery/type owners, doctor-session-transcripts.ts:528, registered flow runner at doctor-health-contribution-runners.state.ts:163) +200/−108; +92 Recover must select historical-only stores beyond the latest failed run and call the existing importer. Every inspected target persists findings before index publication; a successful settlement remains informational. The existing structured Doctor warning channel carries counts and named conflicts into the published updater's actual output.

The target-selection and manifest-coalescing functions are in coherent sibling modules because the existing files had no line-growth allowance. They retain the same owners and add no alternate scanner, import receipt, or disposal implementation.

Evidence

Head: 24b9ea9eb0dbe865ffeb4e784a6cb69b09e34f65. The branch is rebased onto main 06ce6c415dd293f139181085c9518abe5d47ce36, which includes the final #155138 lifecycle fix at 2fe69089d79. The old embedded prerequisite is removed completely. All lifecycle/pool files and their test helpers exactly match main.

The original settlement delta is unchanged: every added and removed line in its 16 files matches the r1-reviewed patch relative to its original base. The only new edits register doctor-session-sqlite-recovery-inventory.test.ts in the existing SQLite recovery CI owner and add it to the matching strict ownership assertion. This fixes its accidental generic-Doctor placement without changing runner allocation or product test assertions.

Base-relative interdiff from fb11b1e6cbf Result
Runtime production +668/−290 → +597/−263; net 378 → 334
Removed prerequisite production paths src/config/sessions/session-transcript-reconcile-pool.ts (+29/−0 removed); src/config/sessions/session-transcript-reconcile.ts (+42/−27 removed)
Removed prerequisite test paths session-transcript-reconcile-pool.test.ts, session-transcript-reconcile.lifecycle.test.ts, openclaw-test-state.test.ts (+173/−19 removed)
Added planner routing scripts/lib/ci-command-test-plan.mts +1; test/scripts/ci-node-test-plan.commands.test.ts +1
Settlement logic Zero semantic changes; all 16 original file deltas identical
Current-head proof Result
Lease → legacy handoff, same worker 19 passed, lease before handoff with verified worker IDs [1,1]; 27.04 s Vitest wall; no drainage errors
Reconcile memory + polling-handle lifecycle 43 passed (24 memory reconciliation + 19 handle lifecycle); 37.18 s wrapper wall
Planner ownership suite 6 passed, including complete and isolated Doctor ownership; 22.09 s wrapper wall
Doctor session-SQLite suites, once 376 passed, 2 existing platform-alias skips across 31 files, once; 238.00 s wrapper wall
check:changed Passed, all selected format, guard, lint, dead-export and typecheck lanes; remote aggregate command (tests + checks) 39m55.690s, exit 0
Independent combined P1 review Scoped clean, no actionable P0/P1 findings

Testbox: tbx_01m334yb1jas7vvkpp0g03aabr (run). The lease was stopped after the successful command; terminal state independently verified. The ordering probe inherits the canonical runtime-config owner and uses ignored proof-only sequencing/reporting to verify lease-before-handoff and the same worker. Its first reporter used the wrong Vitest property after all 19 product tests passed; the observer was corrected to diagnostic().workerId, then strict order/worker verification passed. No product/test assertions, retries, timeouts, or committed isolation settings changed. The Doctor suite run had not started before that observer correction.

The previous unmodified published 2026.9.5 updater → candidate proof on head fb11b1e6cbfb8704f48056c4e4779a777a94e60c passed in 106 s with 13 agents and two real imports. Actual update stdout named 1,307 settled copies and all four differing IDs. Standalone Doctor, recover and dry-run exited 0; all eight differing originals stayed byte-identical; all 13,154 retained manifest references resolved with no retired-path references or ENOENT. That prior-head live proof is retained as historical evidence, not relabeled as a new-head package run. This refresh uses the scoped Testbox gates above, as requested.

Earlier regression controls fail for the intended contracts: identical-claim eligibility, retained warning persistence, and distinct-original-path protection. Disabling manifest redirection leaves a retained reference to a physically absent retired file in both interrupted recovery cases; restoring exact bytes passes both cases. No safe recovery recipe was verified for unpatched 2026.9.5; preserve archives and migration manifests rather than moving files independently.

Current split: runtime production +597/−263 (net +334); tooling +1/−0; tests +688/−84 (net +604); docs +10/−0. No new configuration/CLI options, dependencies, schemas, suppressions, or baseline edits.

The final test stages total 444 passed / 2 skipped / zero product failures. No file exceeded 120 s of test time. The existing public bounded-heap proof took 31.445 s total, with 28.362 s of measured import/verification for 25,000 events.

@clawsweeper

clawsweeper Bot commented Sep 21, 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: XL maintainer Maintainer-authored PR labels Sep 21, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 22, 2026, 3:04 AM ET / 07:04 UTC (Revision 10).

ClawSweeper review

What this changes

Doctor consolidates verified identical session archives, redirects recovery manifests to a surviving original, and reports settlement results during recovery and updates.

Merge readiness

⛔ Blocked before merge - 3 items remain

Still needed: current main and the latest release retain the duplicate-archive refusal. The prior recovery-target defect remains unchanged and blocks merge; the recorded archive-settlement proof remains useful.

Priority: P1
Reviewed head: 5f23982f30430440a136b44c86509d0e570da163

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong settlement and upgrade evidence supports the approach, but the unchanged recovery-target defect prevents merge readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded published-updater and Doctor runs exercise duplicate settlement through the production entrypoints, with preserved differing originals and resolved retained references. Existing-state manifest compatibility is supported by that prior-head evidence and interruption regressions; it does not resolve the separate fixed-store target defect.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded published-updater and Doctor runs exercise duplicate settlement through the production entrypoints, with preserved differing originals and resolved retained references. Existing-state manifest compatibility is supported by that prior-head evidence and interruption regressions; it does not resolve the separate fixed-store target defect.
Evidence reviewed 9 items Pinned patch and review continuity: Inspected the introduced delta from the pinned base to head. Comparing the previous reviewed head with this head produces no changes in either file responsible for the outstanding recovery-target finding.
Recovery loses its prepared target: The new historical-recovery branch recursively invokes import with store and agent but omits the prepared sqlitePath. The store branch in the extracted resolver forwards only store. Explicit fixed-store resolution can consequently select the default owner, and the recursive result is returned as the selected target's recovery report.
Dropped agent selector: The explicit-store branch discards params.agent before calling the shared target resolver; the shared resolver otherwise supports an explicit agent and defaults through persisted or configured ownership.
Findings 1 actionable finding [P2] Preserve the selected agent and database through recovery import
Security None None.

How this fits together

Doctor migrates legacy conversation files into agent SQLite databases. Its retained archives and migration manifests preserve originals for recovery and determine whether update-time session repair can finish.

flowchart TD
  A[Legacy archives and manifests] --> B[Doctor target selection]
  B --> C[Verify ownership and bytes]
  C --> D{Identical original copies?}
  D -->|Yes| E[Keep survivor and redirect manifests]
  D -->|No| F[Preserve originals and warn]
  E --> G[Import or recover selected agent]
  F --> H[Doctor and update report]
  G --> H
Loading

Before merge

  • Preserve the selected agent and database through recovery import (P2) - With a fixed session.store, default agent main, and historical archives for a selected non-default agent, this recursive import loses the prepared target. resolveDoctorSessionSqliteTargets forwards only { store }, discarding agent, and this call omits target.sqlitePath. Import can therefore inspect the default owner's database and return its report while the selected history remains unrecovered. Carry the complete prepared target through the importer and cover non-default fixed-store recovery with an unchanged-default-database assertion. This previously reported late finding remains unchanged from the earlier reviewed head.
  • Resolve merge risk (P1) - Non-default fixed-store recovery can inspect or import through the default owner's database and return that report while leaving the selected agent's history unrecovered.
  • Complete next step (P2) - Preserve the complete prepared recovery target through import and add a fixed-store regression that verifies the selected agent is recovered without changing the default database.

Findings

  • [P2] Preserve the selected agent and database through recovery import — src/commands/doctor-session-sqlite.ts:204-211
Agent review details

Security

None.

PR surface

Source +334, Tests +604, Docs +10, Other +1. Total +949 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 10 597 263 +334
Tests 6 688 84 +604
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 18 1296 347 +949

Review metrics

Metric Value Why it matters
Production versus test growth Runtime production net +334 lines; tests net +604 lines The body justifies production growth through durable disposal, manifest redirection, target selection, and warning propagation within existing owners.

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-migration-coalesce.ts, migration/backfill/repair: src/commands/doctor-session-sqlite-migration-run.ts, migration/backfill/repair: src/commands/doctor-session-sqlite-recover-report.ts, migration/backfill/repair: src/commands/doctor-session-sqlite-retirement.ts, migration/backfill/repair: src/commands/doctor-session-sqlite-targets.ts, and 9 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #155095
Summary: This PR is the explicit implementation candidate for the reported duplicate-archive repair failure; related merged repairs address adjacent behavior.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Preserve the prepared recovery target (recommended)
    Repair the import handoff and prove non-default fixed-store recovery leaves the default database unchanged.

Technical review

Best possible solution:

Keep settlement within the existing recovery journal and carry the complete prepared agent, store, and database target through historical import.

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

Yes, source establishes the remaining defect: recover historical archives for a non-default agent sharing a fixed session.store; the recursive import drops its prepared database and agent selection. No runtime reproduction was executed here.

Is this the best way to solve the issue?

The journal-based settlement is appropriate, but the recovery handoff must preserve its already-resolved target instead of resolving it again from an incomplete selector.

Full review comments:

  • [P2] Preserve the selected agent and database through recovery import — src/commands/doctor-session-sqlite.ts:204-211
    With a fixed session.store, default agent main, and historical archives for a selected non-default agent, this recursive import loses the prepared target. resolveDoctorSessionSqliteTargets forwards only { store }, discarding agent, and this call omits target.sqlitePath. Import can therefore inspect the default owner's database and return its report while the selected history remains unrecovered. Carry the complete prepared target through the importer and cover non-default fixed-store recovery with an unchanged-default-database assertion. This previously reported late finding remains unchanged from the earlier reviewed head.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The patch addresses reported session-repair failures that strand existing installations during updates.
  • merge-risk: 🚨 session-state: The introduced recovery handoff can substitute the default database for a selected non-default agent's database.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): Recorded published-updater and Doctor runs exercise duplicate settlement through the production entrypoints, with preserved differing originals and resolved retained references. Existing-state manifest compatibility is supported by that prior-head evidence and interruption regressions; it does not resolve the separate fixed-store target defect.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded published-updater and Doctor runs exercise duplicate settlement through the production entrypoints, with preserved differing originals and resolved retained references. Existing-state manifest compatibility is supported by that prior-head evidence and interruption regressions; it does not resolve the separate fixed-store target defect.

Evidence

What I checked:

  • Pinned patch and review continuity: Inspected the introduced delta from the pinned base to head. Comparing the previous reviewed head with this head produces no changes in either file responsible for the outstanding recovery-target finding. (src/commands/doctor-session-sqlite.ts:204, 5f23982f3043)
  • Recovery loses its prepared target: The new historical-recovery branch recursively invokes import with store and agent but omits the prepared sqlitePath. The store branch in the extracted resolver forwards only store. Explicit fixed-store resolution can consequently select the default owner, and the recursive result is returned as the selected target's recovery report. (src/commands/doctor-session-sqlite.ts:204, 5f23982f3043)
  • Dropped agent selector: The explicit-store branch discards params.agent before calling the shared target resolver; the shared resolver otherwise supports an explicit agent and defaults through persisted or configured ownership. (src/commands/doctor-session-sqlite-targets.ts:31, 5f23982f3043)
  • Current-main necessity: Fetched main still defers every identity with multiple primary records without distinguishing byte-identical copies. Related merged recovery and reporting changes do not implement this settlement. (src/commands/doctor-session-sqlite-discovery.ts:328, 5c42f636bb9b)
  • Latest-release behavior: The v2026.9.5 source also unconditionally defers multiple primary records. The release file was inspected through GitHub after its local blob was unavailable. (src/commands/doctor-session-sqlite-discovery.ts:250, ec9c1a13db89)
  • Recorded production and compatibility proof: The supplied body snapshot, sourceRevision 572b718b79590c5c23d9df8edb3caf25cc463f77cbb0958229bd0f246ec65a21, records an unmodified published 2026.9.5 updater exercising candidate Doctor on 13 agents after two real imports: 1,307 copies settled, all eight differing originals preserved, and 13,154 retained references resolved. This is explicitly prior-head evidence at fb11b1e, not a newly executed current-head run. The body separately records subsequent Testbox validation. (fb11b1e6cbfb)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • leochun92-sudo: 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.

  • Preserve the complete prepared recovery target and add a regression proving non-default fixed-store recovery leaves the default database unchanged.

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 (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-21T21:45:43.459Z sha 9656f98 :: blocked before merge. :: [P2] Preserve the selected agent when importing during recovery
  • reviewed 2026-09-21T22:09:16.557Z sha fb11b1e :: blocked before merge. :: [P2] Preserve the selected agent when importing during recovery
  • reviewed 2026-09-21T22:42:51.785Z sha fb11b1e :: blocked before merge. :: [P2] Preserve the selected agent when importing during recovery
  • reviewed 2026-09-21T22:55:35.309Z sha fb11b1e :: blocked before merge. :: [P2] Preserve the selected agent when importing during recovery | [P1] Make retained lease-cleanup failures recoverable | [P1] Preserve pending work for a replacement incognito owner | [P1] Recover projection work canceled by cached-handle closure
  • reviewed 2026-09-21T23:21:37.287Z sha fb11b1e :: blocked before merge. :: [P2] Preserve the selected agent when importing during recovery
  • reviewed 2026-09-22T00:56:02.315Z sha edcef83 :: blocked before merge. :: [P2] Preserve the selected agent and database through recovery import
  • reviewed 2026-09-22T04:52:26.416Z sha 4a29fb9 :: blocked before merge. :: [P2] Preserve the selected agent and database through recovery import
  • reviewed 2026-09-22T05:57:52.215Z sha 4904804 :: blocked before merge. :: [P2] Preserve the selected agent and database through recovery import

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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: 🐚 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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Sep 21, 2026
@steipete
steipete marked this pull request as ready for review September 21, 2026 22:45
@steipete
steipete enabled auto-merge (squash) September 21, 2026 22:50
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 21, 2026
Coalesce trusted identical archive claims through the recovery journal, redirect retained migration manifests without losing import acknowledgments, and preserve session warnings through Doctor and the installed updater. Recover uses the same settlement for historical-only stores.

Fixes #155095. Related: #154413. Thanks @fozzels-assistant for the detailed report.
@steipete
steipete force-pushed the upd/session-import-duplicate-archives branch from fb11b1e to 24b9ea9 Compare September 22, 2026 00:17
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Sep 22, 2026
@steipete
steipete merged commit 7fb3367 into main Sep 22, 2026
360 of 362 checks passed
@steipete
steipete deleted the upd/session-import-duplicate-archives branch September 22, 2026 08:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
…penclaw#155194)

* fix(doctor): settle byte-identical duplicate session import archives

Coalesce trusted identical archive claims through the recovery journal, redirect retained migration manifests without losing import acknowledgments, and preserve session warnings through Doctor and the installed updater. Recover uses the same settlement for historical-only stores.

Fixes openclaw#155095. Related: openclaw#154413. Thanks @fozzels-assistant for the detailed report.

* fix(ci): register session archive recovery owner
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 maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

1 participant