Repository navigation
fix(sessions): manual compaction deletes transcript history while claiming it was archived - #111122
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 10:15 PM ET / July 19, 2026, 02:15 UTC. Summary PR surface: Source +31, Tests +120. Total +151 across 7 files. Reproducibility: no. independent current-main run was possible in this review because the read-only command backend failed before repository inspection. The PR nevertheless provides a concrete reproduction using a real gateway, CLI, isolated state directory, and authoritative transcript-row checks. Review metrics: none identified. Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Security Review detailsBest possible solution: Keep the archive-before-delete repair focused at the SQLite transcript writer boundary, then complete direct review of the shared archive lifecycle and transactional revalidation before merging. Do we have a high-confidence way to reproduce the issue? No independent current-main run was possible in this review because the read-only command backend failed before repository inspection. The PR nevertheless provides a concrete reproduction using a real gateway, CLI, isolated state directory, and authoritative transcript-row checks. Is this the best way to solve the issue? Unclear pending direct source review. Reusing the existing durable archive writer and revalidating the snapshot inside the destructive transaction appears to be the narrowest maintainable fix, provided its archive lifecycle contract matches reset/delete behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ead8f691eacf. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +31, Tests +120. Total +151 across 7 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
Review history (1 earlier review cycle)
|
e0b5415 to
cb5018a
Compare
1701687 to
d0f53eb
Compare
…eletes rows openclaw sessions compact <key> --max-lines N deleted the trimmed SQLite transcript rows without writing any backup, then returned an archived value that was a fabricated marker string pointing at nothing, so the CLI told users their history was archived when it was permanently gone. Regression from the SQLite storage flip (openclaw#98236): the previous flat-file path renamed the live transcript to a real .bak.<timestamp> file before replacing it. The manual compact trim now exports the complete pre-compaction transcript through the shared durable session archive writer (exclusive create, 0o600, fsync, atomic rename, optional zstd) as <sessionId>.jsonl.bak.<timestamp>[.zst] in the per-agent sessions archive directory before any rows are deleted, and archived returns that real path. The backup is written outside the SQLite transaction; the destructive replacement revalidates the row snapshot inside the write transaction and aborts, removing the fresh backup, if the transcript changed after the snapshot. Backup failure aborts compaction with every original row intact.
d0f53eb to
537c39e
Compare
|
@clawsweeper re-run |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: fix(sessions): manual compaction deletes transcript history while claiming it was archived This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
|
Maintainer landing note: the exact-head ClawSweeper artifact for I am not rebasing again solely for behind-main drift: this exact head has 83 successful checks with zero failures or pending jobs, including the session accessor/transcript/SQLite proof lanes and the full Node matrix; |
|
Merged via squash.
|
…iming it was archived (openclaw#111122) * fix(sessions): archive the full transcript before manual compaction deletes rows openclaw sessions compact <key> --max-lines N deleted the trimmed SQLite transcript rows without writing any backup, then returned an archived value that was a fabricated marker string pointing at nothing, so the CLI told users their history was archived when it was permanently gone. Regression from the SQLite storage flip (openclaw#98236): the previous flat-file path renamed the live transcript to a real .bak.<timestamp> file before replacing it. The manual compact trim now exports the complete pre-compaction transcript through the shared durable session archive writer (exclusive create, 0o600, fsync, atomic rename, optional zstd) as <sessionId>.jsonl.bak.<timestamp>[.zst] in the per-agent sessions archive directory before any rows are deleted, and archived returns that real path. The backup is written outside the SQLite transaction; the destructive replacement revalidates the row snapshot inside the write transaction and aborts, removing the fresh backup, if the transcript changed after the snapshot. Backup failure aborts compaction with every original row intact. * fix: preserve reused compaction archives on conflict --------- Co-authored-by: Josh Lehman <[email protected]>
Related: #98236
What Problem This Solves
Fixes an issue where users running
openclaw sessions compact <key> --max-lines Nwould permanently lose the trimmed part of their conversation history while the CLI told them it had been archived. Since the SQLite storage flip (#98236, commit 0a8e360), the manual compaction path deletes the trimmed transcript rows without writing any backup, then returns anarchivedvalue that is a fabricated marker string (sqlite:<agent>:<session>:<store>.bak.<timestamp>) pointing at nothing. The CLI printsArchived transcript: <marker>, so users believe the full history is recoverable when it is gone. Before the flip, manual compaction renamed the live JSONL transcript to a real.bak.<timestamp>file before writing the trimmed replacement, so the full pre-compaction history was always recoverable.Why This Change Was Made
The fix restores the pre-flip safety contract at the SQLite transcript writer boundary: before any rows are deleted, the complete pre-compaction transcript is exported to a real, durable archive file, and
archivednow returns that file's actual path. The archive reuses the existing session archive writer that the reset/delete lifecycle flows already use (exclusive create, 0o600, fsync file and directory, atomic rename, optional zstd), with the artifact named<sessionId>.jsonl.bak.<timestamp>[.zst]in the same per-agent sessions archive directory. The.bakshape is already recognized by the archive artifact classifiers, so cleanup and disk-budget treat it exactly like reset/delete archives. The backup is written outside any SQLite transaction; the destructive replacement then revalidates the row snapshot inside the write transaction and aborts while retaining the durable backup if the transcript changed after the snapshot, so concurrently appended rows can never be deleted. If backup creation fails, compaction aborts with an error and every original row stays in place. Active-run and lifecycle fencing in thesessions.compactRPC is unchanged.User Impact
openclaw sessions compact <key> --max-lines Nis safe again: the printedArchived transcript:path is a real file containing every pre-compaction transcript event in order, recoverable with the same tooling that reads reset/delete archives. If the backup cannot be written, compaction fails without deleting anything instead of silently destroying history.Evidence
Live before/after against a real gateway and the real CLI, identical inputs. For each phase: fresh isolated
OPENCLAW_STATE_DIR, a session seeded with 7 transcript events (session header plus messagesimportant message 1..6) through the production accessor, gateway started from the built dist (node openclaw.mjs gateway --port <port>), thennode openclaw.mjs sessions compact main --max-lines 3 --url ws://127.0.0.1:<port> --token .... Nothing was mocked.Before, on pristine main 62c5a8b:
Four transcript events were deleted, the printed "archive" is a marker string, the archive directory was never created, and no backup exists anywhere. The trimmed history is unrecoverable.
After, this patch:
The printed path is a real file (mode 0600), and decompressing it yields all 7 pre-compaction events in order, including the 4 trimmed ones, parsed back through the shared archive reader.
Validation on the changed surface (all green locally):
node scripts/run-vitest.mjs src/config/sessions/session-accessor.test.ts src/commands/sessions-compact.test.ts(72 + 10 passed)node scripts/run-vitest.mjs src/gateway/server.sessions.compaction.test.ts(21 passed)node scripts/run-vitest.mjs src/config/sessions/session-accessor.conformance.test.ts src/config/sessions/transcript.test.ts src/config/sessions/artifacts.test.ts(123 passed)node scripts/run-tsgo.mjs -p tsconfig.core.jsonand-p test/tsconfig/tsconfig.core.test.jsoncleannode scripts/run-oxlint.mjsandoxfmt --checkclean on all changed files;git diff --checkcleanControl red: with only the four production files reverted to main, the updated trim test plus the two new tests fail in
session-accessor.test.ts(3 failed) and the updated gateway archive test fails inserver.sessions.compaction.test.ts(1 failed); with the patch they all pass.New regression coverage:
.bakartifact holding every original event, parseable via the archive reader; backup-write failure (archive directory path occupied by a file) leaves all rows untouched and errors; a row appended after the backup snapshot aborts the replacement with a conflict error, deletes nothing, and preserves the durable backup.sessions.compactwithmaxLinesreturns anarchivedpath that exists on disk and contains all 500 seeded pre-compaction events.Archived transcript:line is exactly the RPC'sarchivedpath.Not tested live: Bun runtime (plain JSONL archive fallback path, exercised by the shared writer used unchanged by reset/delete flows) and Windows.
Siblings: session reset and delete flows already archive through the same writer and are unchanged.
sessions.compactwithout--max-lines(LLM summarization) rewrites via compaction checkpoints, not row deletion, and is unaffected.