Repository navigation
fix(sessions): preserve shared history across startup and repairs - #127241
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 6:05 AM ET / 10:05 UTC. ClawSweeper reviewWhat this changesThe branch preserves shared SQLite session history by keeping reads and repairs on the database’s physical owner, refusing legacy transcript stores at startup, and moving their import to explicit Doctor repair. Merge readinessKeep open: current main still performs the automatic legacy-session startup path, while this branch makes the documented Doctor-mediated migration boundary explicit; source, tests, and history reveal no concrete patch defect. Priority: P2 Review scores
Verification
How this fits togetherSession startup prepares durable SQLite-backed history for the Gateway and embedded TUI. Legacy JSON/JSONL sources now stop startup with a visible repair instruction, while Doctor imports them into the correctly owned SQLite database before normal history reads resume. flowchart LR
A[Legacy JSON or JSONL store] --> B[Session startup]
B --> C{Canonical SQLite store?}
C -->|No| D[Doctor repair and import]
C -->|Yes| E[Physical SQLite database owner]
D --> E
E --> F[Gateway and TUI history reads]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -1092, Tests +1506, Docs +21, Other -1. Total +434 across 75 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain one explicit migration lifecycle: startup refuses legacy files without mutation, Doctor imports and archives them through the physical SQLite owner, and restart reads only the canonical database. Do we have a high-confidence way to reproduce the issue? Yes—source and focused tests define a reproducible legacy-store startup path, source preservation, Doctor import, and restart outcome; this read-only review did not execute the suite. Is this the best way to solve the issue? Yes—the physical-owner model plus an explicit Doctor import prevents startup mutation of legacy files and avoids per-logical-agent shared-history divergence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b576bb41cf4b. LabelsLabel 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
HistoryReview history (8 earlier review cycles)
|
Resolve physical session databases once and carry that identity through startup, search, boards, maintenance, and Doctor. Remove automatic legacy JSON import from Gateway startup while preserving explicit Doctor upgrades. Publish repaired legacy transcripts with strict atomic replacement and preserve the source when backup, write, or rename fails.
|
@clawsweeper re-review The PR now carries the canonical SQLite ownership repair across startup, Doctor, search, cleanup, boards, and progress cards, together with strict atomic publication for the two legacy Doctor repair paths. It removes the retired automatic file-import path and reduces production code by 442 lines. The integrated Doctor failure-injection suite passed, and the full focused ledger covers 846 passing cases across 39 files, including the final startup rerun. Independent Codex review has no remaining actionable P0–P2 findings. The PR body records the current proof and the separate long-history import follow-up. The final build/check refresh, built Gateway replay, and exact-head hosted CI will be recorded before landing. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
Preserve the landed streaming readers and finalization while forwarding physical SQLite ownership and logical selection throughout startup and Doctor repair. Avoid provider setup discovery when Doctor has no auth profile state to repair, and isolate mock provider credentials in both session lifecycle proof modes.
|
@clawsweeper re-review Updated to faf2dc4: composed the landed streaming import work with physical SQLite ownership, added the verified empty-auth Doctor fast path, and isolated mock-provider credentials in both lifecycle modes. Focused regressions, the complete candidate tests/build/changed checks, and both lifecycle tests are green. Fresh published-head shared-store Gateway/UI/restart evidence and exact-head CI remain landing gates; historical proof is not substituted. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…ries Integrate the landed Gateway rollback test repair from main and retain version-1 manifest recovery coverage after Vitest canonicalizes its temporary directory. Reuse the existing platform-root alias fixture and assertions.
|
Final proof is complete for 0e0be0d, tree The final source-bound suite totals 53 unique files and 1,093 passing cases. The complete 97-case Doctor rerun has no skips; full build and all 75-path changed checks pass. Built-CLI then generic upgrade proof ran in the original order with unchanged command/test budgets. It verifies refusal with preserved legacy files, explicit Doctor import, restart/history, backup restoration, downgrade/reupgrade, contention, and shared-store ownership. The real isolated Gateway/Control UI/Doctor restart replay and inspected media are in the PR body; all six retained transcript rows stayed byte-identical without reseeding. The upgrade decision is explicit: runtime uses canonical SQLite, and Dependency implementation evidence for the latest review: I directly inspected the installed, lockfile-pinned The native merge will be checked against its actual parent and this reviewed source, including the complete resulting tree and ancestry. The scoped upstream composition inspections are static evidence; the retained live replay is not represented as runtime proof on a later main revision. Exact final local validation commandsRun at the reviewed revision with Node 24. These are the recorded argument lists with only the host-specific Node executable path normalized to node scripts/run-vitest.mjs run src/commands/doctor-session-sqlite.test.ts --reporter=verbose
node --import ./scripts/tsx.mjs scripts/build-all.mts
node scripts/check-changed.mjs --base 871b18dff5039484e86c76d282699a8defcb1654 -- \
config/assertion-safety-baseline.txt \
docs/cli/doctor.md \
docs/concepts/session.md \
docs/gateway/doctor.md \
src/agents/tools/embedded-gateway-stub.runtime.ts \
src/agents/tools/embedded-gateway-stub.test.ts \
src/agents/tools/embedded-gateway-stub.ts \
src/boards/sqlite-board-store.ts \
src/commands/doctor-auth-flat-profiles.test.ts \
src/commands/doctor-auth-legacy-oauth.ts \
src/commands/doctor-auth.deprecated-cli-profiles.test.ts \
src/commands/doctor-heartbeat-session-target.test.ts \
src/commands/doctor-heartbeat-session-target.ts \
src/commands/doctor-session-incognito-key-repair.test.ts \
src/commands/doctor-session-incognito-key-repair.ts \
src/commands/doctor-session-sqlite-compact.ts \
src/commands/doctor-session-sqlite-readers.ts \
src/commands/doctor-session-sqlite-recover-report.ts \
src/commands/doctor-session-sqlite.shared-store.test.ts \
src/commands/doctor-session-sqlite.test.ts \
src/commands/doctor-session-sqlite.ts \
src/commands/doctor-session-transcript-headers.test.ts \
src/commands/doctor-session-transcript-headers.ts \
src/commands/doctor-session-transcript-labels.test.ts \
src/commands/doctor-session-transcript-labels.ts \
src/commands/doctor-session-transcripts.test.ts \
src/commands/doctor-session-transcripts.ts \
src/commands/doctor-state-integrity.transcripts.test.ts \
src/commands/doctor-state-integrity.ts \
src/commands/doctor-state-migrations.test.ts \
src/commands/doctor/shared/codex-route-session-repair.ts \
src/commands/onboard-agent.persistence.test.ts \
src/commands/tasks-session-registry-maintenance.test.ts \
src/commands/tasks-session-registry-maintenance.ts \
src/config/sessions/cleanup-service.agent-purge.test.ts \
src/config/sessions/cleanup-service.applied-summary.test.ts \
src/config/sessions/cleanup-service.fix-missing.test.ts \
src/config/sessions/cleanup-service.ts \
src/config/sessions/legacy-main-session-migration-operations.ts \
src/config/sessions/legacy-main-session-migration.startup.test.ts \
src/config/sessions/legacy-main-session-migration.test.ts \
src/config/sessions/session-accessor.sqlite-import.ts \
src/config/sessions/session-registry-maintenance.test.ts \
src/config/sessions/session-registry-maintenance.ts \
src/config/sessions/session-transcript-search.test.ts \
src/config/sessions/session-transcript-search.ts \
src/config/sessions/startup-migration.registry-recovery.test.ts \
src/config/sessions/startup-migration.ts \
src/config/sessions/startup-migration.worktree-workspace.test.ts \
src/config/sessions/store-temp-cleanup.test.ts \
src/config/sessions/store-temp-cleanup.ts \
src/config/sessions/targets-collision.ts \
src/config/sessions/targets-discovery.test.ts \
src/config/sessions/targets.test.ts \
src/config/sessions/worktree-workspace-migration.ts \
src/gateway/board-store.test.ts \
src/gateway/board-store.ts \
src/gateway/progress-card-store.ts \
src/gateway/server-methods/sessions-read.ts \
src/gateway/server-methods/sessions-search.test.ts \
src/gateway/server-startup-secret-owner-isolation.test.ts \
src/gateway/server-startup-session-migration.test-support.ts \
src/gateway/server-startup-session-migration.ts \
src/gateway/session-startup-migration.test.ts \
src/gateway/test-helpers.server-env.test.ts \
src/gateway/test-helpers.server.ts \
src/infra/state-migrations.doctor.ts \
src/infra/state-migrations.session-store.ts \
src/infra/state-migrations.test.ts \
src/plugins/legacy-session-surfaces.state-migration.test.ts \
src/tui/embedded-backend.ts \
test/helpers/sqlite-sessions-transcripts-flip-proof-assertions.ts \
test/helpers/sqlite-sessions-transcripts-flip-proof.ts \
test/scripts/sqlite-sessions-transcripts-flip-proof.built-cli.e2e.test.ts \
test/scripts/sqlite-sessions-transcripts-flip-proof.e2e.test.ts
node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts test/scripts/sqlite-sessions-transcripts-flip-proof.built-cli.e2e.test.ts test/scripts/sqlite-sessions-transcripts-flip-proof.e2e.test.ts --reporter=verboseRemaining proof limits: the isolated fixture does not claim a provider turn, native macOS app, Talk or heartbeat coverage. Streaming the retired-main handoff snapshot remains a named scalability follow-up; no failure was reproduced there. No timeout, assertion, approval requirement or failing CI gate was waived. |
|
Merged via squash.
|
…enclaw#127241) * fix(doctor): atomically repair session transcripts * fix(sessions): keep runtime reads and repairs on SQLite owners Resolve physical session databases once and carry that identity through startup, search, boards, maintenance, and Doctor. Remove automatic legacy JSON import from Gateway startup while preserving explicit Doctor upgrades. Publish repaired legacy transcripts with strict atomic replacement and preserve the source when backup, write, or rename fails. * fix(sessions): simplify startup ownership and diagnostics * test(sessions): migrate legacy history through Doctor in CLI proof --------- Co-authored-by: Amp <[email protected]>
Closes #127222
Closes #129217
Related: #131179 (merged). This revision retains #131276's landed streaming import work and includes main's canonical test repair from #131627.
What Problem This Solves
Custom or shared session stores could fail during startup, lose transcript search results, or send maintenance and related state to the wrong physical database. SQLite-only installations could enter legacy migration without a legacy store present. A failed Doctor repair of older transcript files could damage the source or obscure the failure and completed backup.
Why This Change Was Made
Carry the resolved SQLite path and physical owner through startup, Doctor, cleanup, search, boards, and progress cards, separately from logical-agent selection. Runtime uses canonical SQLite; explicit Doctor owns legacy-file conversion. Both legacy transcript repair branches use the same strict atomic publication path, preserving original bytes and completed backups when publication fails.
This deletes automatic startup import/restore plumbing, obsolete legacy-file and temp-store processing, and duplicate owner resolution. It preserves #131276's streaming readers, validation callbacks, finalization, and compaction. Retired-main transfers retain transcript bytes, timestamps, and retry evidence; workspace publication follows completed cleanup.
Lifecycle testing also exposed unnecessary provider discovery when Doctor had no auth state to repair. Doctor now reads each persisted auth candidate once before discovery. Nonempty state still gets broad provider discovery; cleanup rereads authoritative state after config publication. This preserves @obviyus's persisted-retired-profile repair in #129052 (
750a64e), with a net-zero production diff in the auth repair. The test fixture separately isolates canonical provider credential names before installing its synthetic credential; production consent behavior is unchanged.User Impact
Custom/shared stores keep history and related state in their configured physical database, including when the recorded owner is retired. Unfiltered search selects the logical agent before applying its limit. Absent databases are not created by inspection, and SQLite locators are never parsed or archived as JSON.
The stable upgrade path for
sessions.jsonand transcript JSONL remainsopenclaw doctor --fix. Startup no longer imports, restores, or rewrites those files. An actual legacy source produces a visible refusal with the Doctor command for the active profile. Stop the Gateway, retain a backup, and run Doctor against the same state/config before restarting. Existing--session-sqlitemodes and legacy selectors remain supported. See the Doctor migration guide.No config option, public flag, SQLite schema version, or migration format is added. This cannot recover history already lost.
Evidence
Published revision:
0e0be0d806f2e43934c65771c628e4103b900783, complete source tree4f006da9982edd11b4824902862d06510975e80b. Local tests, build, and checks ran against that complete tree before publication; independent comparison of all 34,537 entries and the official metadata refresh bind the same source and runtime artifacts to the published head.0e0be0d.The pinned-main comparison is complete across all 75 changed paths, with no missing objects or lazy fetch needed to materialize the patch. The four upstream overlap resolutions were independently reviewed, and the full 34,537-entry expected tree matches publication. This resolves the earlier promisor-object comparison gap for the pinned composition; it does not claim a review of every later commit on moving main.
One premature restart attempt began 107 milliseconds before artifact-binding verification finished. It was stopped successfully and excluded from the proof. A fresh binding then completed before the accepted restart; the later RPC/UI replay and cleanup passed. The failed ordering attempt remains recorded separately.
The intermediate 50-file run passed 1,078 cases and skipped one platform-alias case after main's #131313 change canonicalized
TMPDIR. The final correction reuses the existing alias fixture and capability predicate, retaining all three restoration assertions and non-root symlink rejection. Its complete 97-case rerun passed without skips, and the full build was rerun with that final test input. The earlier skip is not counted as a pass.The prior CI run 33152114028 failed with TS2459 and three runtime errors because an upstream test imported a now-private channel-restart helper. Neither affected path is in this PR's diff. Landed #131627, included here as
871b18d, moves that test to the public rollback operation; the fresh exact-head run above is green.Historical
faf2dc4local and live proof remains archived separately. Earlier unchanged-budget Doctor timeout, fixture-consent, and stale automatic-import failures also remain recorded. The rejected all-bundled-plugin assertion was a test-design error, not proof of incorrect artifact routing or a packaged production slowdown. No timeout was enlarged and no product assertion was weakened.Publication-failure regressions verify exact original bytes, completed backups, and visible errors across both legacy repair branches. Startup coverage includes absent databases, custom/shared stores, projections, and preserved legacy sources requiring explicit Doctor import. The empty-auth regression failed before repair while its positive cases already passed. The credential-registry source received separate direct source audits and owner tests where the managed review service excluded that path.
The refreshed ClawSweeper review covers this exact head, reports no actionable code or security findings, and passed its six startup tests. Its final upgrade/refusal lifecycle and exact-head CI requests are now complete. This maintainer-authored change accepts explicit Doctor migration as the supported upgrade path, following the requested SQLite-only runtime cleanup; automatic startup import is deliberately removed. The description records the changed behavior, validation, and remaining scalability risk requested by its Rank-up move. The live fixture uses synthetic isolated state; it does not exercise a provider turn, native macOS app, Talk, or heartbeats. The independent audit viewed the six PNGs; the maintainer separately inspected 14 distinct video frames.
Before restart, retained history:
After restart, the same history and search result:
After-restart recording:
session-store-0e0be0-after-video.mp4
Classified against
871b18d: 75 paths; production +471/−913 (net −442), tests/support +2,593/−1,737 (net +856), docs +68/−47 (net +21), and baseline −1: whole PR net +434. The removed 651-line Gateway wrapper andsrc/gateway/test-helpers.server.tsare test support, not production. Pure discovery-test moves do not add coverage.Follow-up
The retired-main handoff snapshot still materializes transcript rows in memory. No failure was reproduced there; the heap scenarios do not establish bounded memory for every Doctor operation. Streaming that snapshot remains separate scalability work, not a missing correctness repair in this PR.