Skip to content

fix(gateway): reset _last_flushed_db_idx on cached agent reuse (#44327)#44518

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-44327
Jun 12, 2026
Merged

fix(gateway): reset _last_flushed_db_idx on cached agent reuse (#44327)#44518
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kyssta-exe:auto-fix/issue-44327

Conversation

@kyssta-exe

Copy link
Copy Markdown
Contributor

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).

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 11, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #32760 — same fix (reset _last_flushed_db_idx on cached-agent reuse in _init_cached_agent_for_turn so assistant transcript rows aren't skipped). #32760 is the earliest open canonical; closed twin #44354 and open twin #44425 already point at it. All fix #44327.

@liuhao1024

Copy link
Copy Markdown
Contributor

Verified: Flush cursor reset on cached agent reuse is correct.

Checked:

  • interrupt_depth == 0 gate is correct — only resets on fresh turn, preserves on interrupt re-entry
  • hasattr guard handles agents that don't have _last_flushed_db_idx
  • Without this fix, _flush_messages_to_session_db would skip new-turn messages because the cursor pointed past them
  • Tests verify both paths: reset on depth=0, preservation on depth=1

No issues found. LGTM.

@kshitijk4poor kshitijk4poor merged commit a942bfd into NousResearch:main Jun 12, 2026
28 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway cached-agent reuse can leak _last_flushed_db_idx across turns and skip assistant transcript rows

4 participants