fix(session-db): advance flush cursor per committed message#21025
Open
LeonSGP43 wants to merge 1 commit intoNousResearch:mainfrom
Open
fix(session-db): advance flush cursor per committed message#21025LeonSGP43 wants to merge 1 commit intoNousResearch:mainfrom
LeonSGP43 wants to merge 1 commit intoNousResearch:mainfrom
Conversation
Collaborator
|
Related to closed PR #19407 (same fix — advance flush cursor per-message). That PR was closed because the author believed the change was already in main, but inspection shows main still only advances the cursor after the full loop completes. This PR is a valid re-implementation of the same fix. |
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 the remaining duplicate-write failure mode from #12563: when
_flush_messages_to_session_db()writes several messages and oneappend_message()fails mid-loop, any earlier rows that already committed must not be retried on the next flush.The current full-success path already avoids duplicate writes, and merged lazy-session creation work covers the missing-row side of the issue. This PR keeps the change narrow to the partial-failure cursor gap: advance
_last_flushed_db_idximmediately after each successful append, while preserving the final success-path cursor assignment.Why now
Under SQLite lock contention,
append_message()can fail after one or more earlier messages have already committed. Previously the cursor stayed at the old value until the whole loop completed, so the next persist path retried committed rows and inflatedmessage_count/ transcript rows.Test coverage
test_flush_advances_cursor_after_each_successful_message, which simulatesdatabase is lockedon the third append and verifies the retry resumes at the third message without duplicating the first two.Verification run locally:
Results:
10 passed, 4 warnings31 passed, 4 warningspy_compilepassedgit diff --checkpassedFixes #12563