fix: make transcript rewrite atomic to prevent data loss on crash - #8077
Closed
tomqiaozc wants to merge 1 commit into
Closed
fix: make transcript rewrite atomic to prevent data loss on crash#8077tomqiaozc wants to merge 1 commit into
tomqiaozc wants to merge 1 commit into
Conversation
rewrite_transcript (used by /retry, /undo, /compress) performed
clear+reinsert as separate SQLite transactions and used bare open("w")
for JSONL. A crash between the clear and completion of inserts lost the
entire conversation history.
- Add SessionDB.rewrite_messages() that runs DELETE + INSERT inside a
single _execute_write() transaction — crash rolls back to original
- Use tempfile + fsync + os.replace for JSONL writes — crash preserves
the original file intact
Closes NousResearch#8029
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Apr 23, 2026
Collaborator
4 tasks
3 tasks
Contributor
|
Thanks for the careful durability work. This is already implemented on current
The transactional implementation shipped in |
13 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.
Summary
SessionDB.rewrite_messages()that runs DELETE + all INSERTs inside a single_execute_write()transaction — a crash during rewrite rolls back to the original messages instead of leaving an empty or partial transcripttempfile+fsync+os.replacefor JSONL rewrites — a crash mid-write preserves the original file intactclear_messages()+ N ×append_message()sequence inrewrite_transcript()Test plan
test_sqlite_rewrite_is_atomic— verifiesrewrite_messagesworks end-to-endtest_jsonl_rewrite_preserves_original_on_error— verifies original JSONL file survives whenos.replacefailstest_reasoning_survives_rewrite— existing regression test still passesCloses #8029
🤖 Generated with Claude Code