fix(agent): rewrite SessionDB transcript after message-sequence repair#24419
Open
luoxiao6645 wants to merge 1 commit into
Open
fix(agent): rewrite SessionDB transcript after message-sequence repair#24419luoxiao6645 wants to merge 1 commit into
luoxiao6645 wants to merge 1 commit into
Conversation
Collaborator
|
Competing fix for #24187, alongside #24211 and #24326. All three address the same SessionDB persistence bug where |
This was referenced Jun 11, 2026
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
Fixes a SessionDB persistence bug where the current turn can be silently skipped after
_repair_message_sequence()mutates the in-memory transcript before persistence.The previous append-only flush logic used
len(conversation_history)and_last_flushed_db_idxas boundaries. That breaks when repair shortens or rewrites the livemessageslist:toolmessages may be droppedusermessages may be mergedIn those cases, append-only persistence is not sufficient. The SQLite transcript may need to be rewritten, not just appended.
Fixes #24187.
What changed
self._session_db_needs_rewritetoAIAgent_repair_message_sequence()actually mutatesmessages, mark the SessionDB transcript dirty_flush_messages_to_session_db():SessionDB.replace_messages(...)_last_flushed_db_idxflush_fromso stale offsets cannot overflow the sliceWhy this approach
A simple clamp like:
python
flush_from = min(max(start_idx, self._last_flushed_db_idx), len(messages))
prevents the empty-slice failure, but it does not fix the more important case where repair merges the current turn into an already-persisted historical user row. That
case requires rewriting the stored transcript, not appending.
This patch uses the existing SessionDB.replace_messages() path, which already matches transcript-rewrite flows like /retry, /undo, and /compress.
Tests
Added regression coverage for the key failure shape: