Skip to content

fix(gateway): use filtered history length for transcript message extraction#395

Merged
teknium1 merged 1 commit intoNousResearch:mainfrom
PercyDikec:fix/transcript-history-offset
Mar 5, 2026
Merged

fix(gateway): use filtered history length for transcript message extraction#395
teknium1 merged 1 commit intoNousResearch:mainfrom
PercyDikec:fix/transcript-history-offset

Conversation

@PercyDikec
Copy link
Copy Markdown
Contributor

The transcript extraction used len(history) to find new messages from each agent turn, but history includes session_meta entries that are stripped before passing to the agent. This mismatch caused 1 message to be lost from the transcript on every turn after the first.

Changes:

  • _run_agent now returns history_offset (the filtered history length actually passed to the agent) in its result dict
  • The caller uses history_offset instead of len(history) for the slice
  • Changed the else branch from returning all agent_messages to returning [], preventing full-history duplication when session_meta count equals agent message count

Tests

Added tests/gateway/test_transcript_offset.py with 6 tests:

  • session_meta causes offset mismatch - core bug: 1 session_meta entry causes 1 message loss
  • no session_meta gives same result - first turn (no session_meta) works correctly with both approaches
  • multiple session_meta entries - 2 session_meta entries cause the else branch to duplicate the whole history
  • system messages also filtered - system messages in history also contribute to the offset drift
  • else branch returns empty list - verifies the else branch fix returns [] instead of all messages
  • tool call messages preserved in filter - tool_calls and tool results pass through the filter correctly, keeping the offset accurate

Closes #394

…action

The transcript extraction used len(history) to find new messages, but
history includes session_meta entries that are stripped before passing
to the agent. This mismatch caused 1 message to be lost from the
transcript on every turn after the first, because the slice offset
was too high. Use the filtered history length (history_offset) returned
by _run_agent instead.

Also changed the else branch from returning all agent_messages to
returning an empty list, so compressed/shorter agent output does not
duplicate the entire history into the transcript.
@teknium1 teknium1 merged commit bd3025d into NousResearch:main Mar 5, 2026
teknium1 added a commit that referenced this pull request Mar 5, 2026
The error return (no final_response) was missing history_offset,
falling back to len(history) which has the same session_meta offset
bug fixed in PR #395. Now both return paths include the correct
filtered history length.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants