fix(gateway): use filtered history length for transcript message extraction#395
Merged
teknium1 merged 1 commit intoNousResearch:mainfrom Mar 5, 2026
Merged
Conversation
…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
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.
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.
The transcript extraction used
len(history)to find new messages from each agent turn, buthistoryincludessession_metaentries 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_agentnow returnshistory_offset(the filtered history length actually passed to the agent) in its result dicthistory_offsetinstead oflen(history)for the sliceagent_messagesto returning[], preventing full-history duplication when session_meta count equals agent message countTests
Added
tests/gateway/test_transcript_offset.pywith 6 tests:[]instead of all messagesCloses #394