fix(session): make compaction snapshots crash-safe - #599
Merged
Kaguya-19 merged 2 commits intoSep 18, 2026
Merged
Conversation
Persist replacement context in a single flushed JSONL boundary record and replay only validated complete snapshots. Retain original context for legacy or invalid boundaries, and separate truncated tails before resumed writes. Cover snapshot replay before turn completion, invalid snapshots, fsync, mutation isolation, append failures, and every byte truncation including UTF-8 boundaries. Co-authored-by: WUU Agent <305930189+wuu-agent[bot]@users.noreply.github.com>
blueberrycongee
force-pushed
the
fix/crash-safe-compaction
branch
from
September 17, 2026 07:53
8a4692c to
5c11283
Compare
Kaguya-19
approved these changes
Sep 18, 2026
18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Compaction persists a boundary followed by individual replacement messages. A crash after the boundary but before all replacement messages are written can cause replay to discard original history and recover only partial context. Even complete replacement records are skipped until the active turn has a turn_result. A truncated JSONL tail can also absorb the next append after restart.
Changes
Compatibility
Legacy boundaries cannot prove replacement completeness, so they conservatively restore original history. This may require compaction again after resume. Original transcript records remain on disk.
Validation
On Node.js 22.23.2, all 119 related tests passed: 57 session/compaction-engine/Web replay tests and 62 Agent loop/session/subagent/turn-environment tests. Full TypeScript typecheck, npm run build, and git diff --check also passed.
Regression coverage includes replay before turn completion, invalid and successive snapshots, multimedia/tool content, snapshot immutability, fsync, append failures, and every byte truncation of a snapshot record including UTF-8 boundaries followed by resumed writes.
The full repository suite and real-provider E2E were not run. The branch starts from the fork origin/main; this PR contains one fix commit affecting seven files.