Repository navigation
fix(sessions): prevent cleanup from deleting readable transcripts - #123495
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 11:44 AM ET / 15:44 UTC. ClawSweeper reviewWhat this changesThis PR makes session cleanup preserve unreadable transcripts and stores intentional transcript deletions atomically in SQLite before publishing recoverable archive files. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep open for maintainer review: current main still converts any transcript-read failure into a cleanup deletion, while this PR moves recovery into the SQLite lifecycle owner and adds a durable archive contract that warrants explicit review. Priority: P1 Review scores
Verification
How this fits togetherThe sessions cleanup service is reached through the CLI and the Gateway RPC, then delegates durable removal to the SQLite session lifecycle. The lifecycle deletes session rows and transcript events, while this change records a recovery archive before that deletion and publishes a derived file afterward. flowchart LR
A[CLI cleanup command] --> C[Shared cleanup service]
B[Gateway cleanup RPC] --> C
C --> D[Transcript inspection]
D --> E{Safe to remove?}
E -->|Unreadable or contains message| F[Keep session]
E -->|Confirmed message-free| G[SQLite lifecycle transaction]
G --> H[Archive record and recovery file]
Decision needed
Why: The patch changes persisted session recovery and retention behavior beyond the local classifier correction; repository policy reserves protected maintainer work for explicit handling. Before merge
Agent review detailsSecurityNone. PR surfaceSource +1016, Tests +603, Generated +17, Other +1. Total +1637 across 34 files. View PR surface stats
Review metrics
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: Keep archival in the per-agent SQLite deletion transaction, publish only derived recovery files afterward, and retain the additive-schema compatibility checks as the single recovery path. Do we have a high-confidence way to reproduce the issue? Yes — current main’s catch-to-false classifier and subsequent removal path provide a high-confidence source reproduction for an unreadable transcript row; the linked report also supplies a concrete SQLite cleanup scenario. Is this the best way to solve the issue? Yes — persisting the recovery payload at the session lifecycle owner before deletion is safer than the old unarchived removal or a consumer-side guard, subject to maintainer acceptance of the durable storage contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a5603681c617. 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 (9 earlier review cycles; latest 8 shown)
|
f72c7f1 to
db472f4
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
d3dd152 to
20dd5e1
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Remeasure physical disk usage after archive publication so budget results and pruning use the bytes actually present on disk. Refs oc-8e9
6db8532 to
6be365e
Compare
…enclaw#123495) * fix(sessions): make transcript archival atomic * fix(sessions): stabilize SQLite archive CI * test(gateway): synchronize lifecycle patch race * fix(sessions): finish archive recovery accounting * fix: key transcript archives by generation Remeasure physical disk usage after archive publication so budget results and pruning use the bytes actually present on disk. Refs oc-8e9 * fix(sessions): normalize doctor archive generations (oc-a28) --------- Co-authored-by: Josh Lehman <[email protected]>
Doctor canonical-session repair rebuilt each accumulated candidate array for every appended row. One deep alias group bypasses the usefulness of the 64-group batch limit: the existing 12,001-candidate scale fixture causes the two grouping loops to copy 144,012,000 existing references before repair can finish. This change appends to function-owned arrays, preserving candidate order, database grouping, the first resolved database scope, SQL, transactions, and repair decisions. It changes two files (+16/-4); no new API, check, schema, or SQLite operation is introduced. The two quadratic expressions originated in `61221c4c20ec` (#126353) and `fc4d5d744fad` (#123495). The observed scale failure on [the earlier repair candidate](https://github.com/openclaw/openclaw/actions/runs/38283393506/job/114926176837) was a child SIGTERM at its existing 60-second limit; the last recorded phase was repair entry. This establishes the failing flow and workload, not that grouping alone caused that timeout. No causal parent control or before/after timing benchmark is claimed. Focused production-path proof: | Test | Exact composed head | Result | Vitest / wrapper wall time | | --- | --- | --- | --- | | `pnpm test src/commands/doctor-session-canonical-keys.scale.test.ts --maxWorkers=1` | `7ac691f4a04689c9711192262ad0bc3c73b6ad92` | 1/1; case 66.300 s | 126.26 / 172.89 s | | `pnpm test src/commands/doctor-session-canonical-keys.owner-repair.test.ts --maxWorkers=1` | `f1979f3b6f5ac9aa59a3f4c83dbe20b9ac49b535` | 4/4 | 234.79 / 526.36 s | The unchanged scale test executes both edited loops through a real Node child under Doctor maintenance ownership and verifies that all 200,000 transcript events survive, one expected canonical node remains, and foreign keys are valid. The owner tests preserve required creation provenance, replace a stale owner with the selected winner, recover a stolen transcript window without losing history, and verify a repeat repair is a no-op. Both receipts ended at their original clean heads with no surviving processes. These are composed-head results; the composition also contained temporary phase diagnostics excluded from this change. [Composed-head CI](https://github.com/openclaw/openclaw/actions/runs/38292637049) passed build, production and test types, all core lint stripes, source contracts, Knip, architecture/Madge, and database worker/dialect ratchets. The [published-driver update cell](https://github.com/openclaw/openclaw/actions/runs/38292637049/job/114965277486) executed and passed from published 2026.10.2 to candidate 2026.10.2 at `f1979f3b6f5a`: candidate checksum matched, update completed, readiness returned 200, and running version was verified. One Codex autoreview returned no findings. The publication preserves the newer main-key admission change. The two grouping bodies retain the reviewed and tested behavior; no standalone publication-head static run is represented as already complete. The separate low-heap dry-run memory test remains unresolved: at `f1979f3b6f5a` it exceeded its existing 90-second case limit (90.277 s; Vitest 444.68 s / wrapper 557.96 s). Its child runs `apply:false`, so neither changed grouping loop executes. This is not a passing memory result or an inferred timeout root cause. The separate fixture-only commit `c92696a32a7bd33d7ca98be7f94f09f42d2acb8f` moves its unchanged minified/split bundle preparation to `beforeAll`; its runtime rerun is pending. That fixture keeps the existing 160 MiB heap, 60-second child and 90-second case limits. This Doctor-only in-memory optimization does not remove SQLite reads, writes, or authority checks. No T1 reduction or warmed-turn SQL/request saving is claimed. Update and repair behavior remain unchanged; only group construction loses its quadratic copying cost. Direct-main publication was refused by the repository ruleset; this emergency repair uses the authorized head-pinned PR squash fallback. Main is not yet established green. Applicable newer static proof is also green at `8d087040fefe324e5ff7fa76faf497fadb542c08` in [CI run 38298120555](https://github.com/openclaw/openclaw/actions/runs/38298120555): production types, all core/general lint, source contracts, Knip/dependencies, architecture and baseline ratchets. The changed test graphs passed in core stripe 5 (`commands-doctor`, job 114974448774) and stripe 4 (`agents-sessions`, job 114974448893). The pending core-3 test stripe owns neither graph. These remain composed-head proofs with the integration limits stated above.
Doctor canonical-session repair rebuilt each accumulated candidate array for every appended row. One deep alias group bypasses the usefulness of the 64-group batch limit: the existing 12,001-candidate scale fixture causes the two grouping loops to copy 144,012,000 existing references before repair can finish. This change appends to function-owned arrays, preserving candidate order, database grouping, the first resolved database scope, SQL, transactions, and repair decisions. It changes two files (+16/-4); no new API, check, schema, or SQLite operation is introduced. The two quadratic expressions originated in `fee9ee2148a3` (openclaw#126353) and `cd4f2480c2f5` (openclaw#123495). The observed scale failure on [the earlier repair candidate](https://github.com/openclaw/openclaw/actions/runs/38283393506/job/114926176837) was a child SIGTERM at its existing 60-second limit; the last recorded phase was repair entry. This establishes the failing flow and workload, not that grouping alone caused that timeout. No causal parent control or before/after timing benchmark is claimed. Focused production-path proof: | Test | Exact composed head | Result | Vitest / wrapper wall time | | --- | --- | --- | --- | | `pnpm test src/commands/doctor-session-canonical-keys.scale.test.ts --maxWorkers=1` | `7ac691f4a04689c9711192262ad0bc3c73b6ad92` | 1/1; case 66.300 s | 126.26 / 172.89 s | | `pnpm test src/commands/doctor-session-canonical-keys.owner-repair.test.ts --maxWorkers=1` | `f1979f3b6f5ac9aa59a3f4c83dbe20b9ac49b535` | 4/4 | 234.79 / 526.36 s | The unchanged scale test executes both edited loops through a real Node child under Doctor maintenance ownership and verifies that all 200,000 transcript events survive, one expected canonical node remains, and foreign keys are valid. The owner tests preserve required creation provenance, replace a stale owner with the selected winner, recover a stolen transcript window without losing history, and verify a repeat repair is a no-op. Both receipts ended at their original clean heads with no surviving processes. These are composed-head results; the composition also contained temporary phase diagnostics excluded from this change. [Composed-head CI](https://github.com/openclaw/openclaw/actions/runs/38292637049) passed build, production and test types, all core lint stripes, source contracts, Knip, architecture/Madge, and database worker/dialect ratchets. The [published-driver update cell](https://github.com/openclaw/openclaw/actions/runs/38292637049/job/114965277486) executed and passed from published 2026.10.2 to candidate 2026.10.2 at `f1979f3b6f5a`: candidate checksum matched, update completed, readiness returned 200, and running version was verified. One Codex autoreview returned no findings. The publication preserves the newer main-key admission change. The two grouping bodies retain the reviewed and tested behavior; no standalone publication-head static run is represented as already complete. The separate low-heap dry-run memory test remains unresolved: at `f1979f3b6f5a` it exceeded its existing 90-second case limit (90.277 s; Vitest 444.68 s / wrapper 557.96 s). Its child runs `apply:false`, so neither changed grouping loop executes. This is not a passing memory result or an inferred timeout root cause. The separate fixture-only commit `c92696a32a7bd33d7ca98be7f94f09f42d2acb8f` moves its unchanged minified/split bundle preparation to `beforeAll`; its runtime rerun is pending. That fixture keeps the existing 160 MiB heap, 60-second child and 90-second case limits. This Doctor-only in-memory optimization does not remove SQLite reads, writes, or authority checks. No T1 reduction or warmed-turn SQL/request saving is claimed. Update and repair behavior remain unchanged; only group construction loses its quadratic copying cost. Direct-main publication was refused by the repository ruleset; this emergency repair uses the authorized head-pinned PR squash fallback. Main is not yet established green. Applicable newer static proof is also green at `8d087040fefe324e5ff7fa76faf497fadb542c08` in [CI run 38298120555](https://github.com/openclaw/openclaw/actions/runs/38298120555): production types, all core/general lint, source contracts, Knip/dependencies, architecture and baseline ratchets. The changed test graphs passed in core stripe 5 (`commands-doctor`, job 114974448774) and stripe 4 (`agents-sessions`, job 114974448893). The pending core-3 test stripe owns neither graph. These remain composed-head proofs with the integration limits stated above.
Closes #119085
What Problem This Solves
Fixes an issue where operators running
openclaw sessions cleanup --fix-missingcould lose readable SQLite transcript content when one transcript row was malformed. The cleanup classifier treated any read failure as proof that the whole transcript was message-free, then removed the session and its transcript rows without a recoverable archive.The same cleanup owner serves the CLI and the
sessions.cleanupgateway RPC, so both surfaces were affected.Why This Change Was Made
The cleanup classifier now inspects transcript events and the deletion snapshot together and fails safe: malformed or unreadable content keeps the session instead of classifying it as empty. Eligible cleanup removals bind the inspected snapshot into the lifecycle operation so a changed transcript cannot be deleted under a stale decision.
Transcript archival now belongs to the per-agent SQLite lifecycle transaction. A lazily installed, same-version additive table stores the canonical compressed archive, digest, reason, and publication state in the same transaction that removes the session state. After commit, a bounded publisher writes the derived
.deletedartifact without overwriting an existing file, verifies its digest, and retries pending publications after interruption. Retention and disk-budget cleanup prune only published archives and protect unpublished recovery copies.No SQLite schema-version bump is required: the table is additive, lazily ensured on first use, and validated against previous-reader and drift cases.
User Impact
Cleanup no longer silently destroys a readable conversation because another row is corrupt. When cleanup intentionally reclaims transcript content, the recovery copy is committed atomically before deletion and remains recoverable across process crashes or derived-file publication failures.
Evidence
--fix-missingremoval produced no archive. Both pass after the repair.pnpm db:kysely:check,pnpm sqlite:sessions-schema:check, andpnpm lint:kysely.