fix(memory): normalize restored history to a Converse-valid sequence#548
Open
dtaniwaki wants to merge 1 commit into
Open
fix(memory): normalize restored history to a Converse-valid sequence#548dtaniwaki wants to merge 1 commit into
dtaniwaki wants to merge 1 commit into
Conversation
Signed-off-by: Daisuke Taniwaki <daisuketaniwaki@gmail.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.
Thanks for maintaining this integration! Would appreciate your review of the fix below.
Fixes #547.
Problem
With
filter_restored_tool_context=True, stripping tool blocks drops atoolResult-only user turn, which leaves the surrounding assistant turns adjacent and breaks Converse's role alternation. The next invocation then fails with an assistant-prefillValidationException(full details in #547).Solution
After stripping tool blocks,
_filter_restored_tool_contextnow merges adjacent same-role turns and drops leading non-user turns, so the restored history alternates strictly and starts on a user turn:The trailing turn is left as-is, since the runtime appends the next user turn before the model call (forcing a user tail here would create two adjacent user turns). Scoped to the existing
filter_restored_tool_contextopt-in, so behavior is unchanged unless enabled.Note on merging
Merging is lossy: collapsing two assistant turns into one drops the turn boundary, and the merged message keeps a single event id (the earlier turn's id is not retained). This is consistent with what the flag already does — it discards the tool round-trip from restored history — and merging preserves all text content (concatenated as separate content blocks) rather than dropping a turn. Happy to take a different approach if you'd prefer the lost context handled another way.