Skip to content

fix(session): make compaction snapshots crash-safe - #599

Merged
Kaguya-19 merged 2 commits into
OpenBMB:mainfrom
blueberrycongee:fix/crash-safe-compaction
Sep 18, 2026
Merged

Kaguya-19 merged 2 commits into
OpenBMB:mainfrom
blueberrycongee:fix/crash-safe-compaction

Conversation

@blueberrycongee

Copy link
Copy Markdown
Contributor

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

  • Persist the entire replacement context as a versioned snapshot in one compact-boundary record and flush it before resolving.
  • Serialize before queued I/O to prevent caller mutations from changing a pending snapshot.
  • Only validated complete snapshots replace prior context, independently of turn completion.
  • Retain original history for legacy or invalid boundaries and ignore partial legacy replacements.
  • Separate unterminated tails before resumed writes without deleting crash debris or valid JSON missing a final newline.

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.

blueberrycongee and others added 2 commits September 17, 2026 15:36
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
blueberrycongee force-pushed the fix/crash-safe-compaction branch from 8a4692c to 5c11283 Compare September 17, 2026 07:53
@Kaguya-19
Kaguya-19 merged commit cd52c9a into OpenBMB:main Sep 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants