fix(gateway): reset _last_flushed_db_idx on cached agent reuse (#44327)#44518
Merged
Merged
Conversation
Collaborator
Contributor
|
Verified: Flush cursor reset on cached agent reuse is correct. Checked:
No issues found. LGTM. |
13 tasks
This was referenced Jun 12, 2026
teddyjfpender
added a commit
to teddyjfpender/superforecasting-agent
that referenced
this pull request
Jun 13, 2026
…a942bfd9c, NousResearch#44518/NousResearch#44327) A cached agent carries its SessionDB flush cursor across turns: a stale _last_flushed_db_idx from the previous turn made _flush_messages_to_session_db skip the new turn's rows, duplicating / dropping chat state on agent reuse. Reset the cursor to 0 in _init_cached_agent_for_turn for fresh external turns (interrupt_depth == 0) only; interrupt-recursive re-entries preserve it because the cursor tracks an in-progress flush. Upstream tests brought verbatim into TestCachedAgentInactivityReset. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #44327. When the gateway reuses a cached AIAgent for a new turn, _init_cached_agent_for_turn did not reset _last_flushed_db_idx. The stale cursor caused _flush_messages_to_session_db to skip persisting new assistant rows, producing transcripts with consecutive user messages and missing assistant replies. The fix resets the cursor to 0 on fresh turns (interrupt_depth=0) while preserving it on interrupt-recursive turns (depth>0).