fix(messageConversion): deduplicate tool results for reused tool_call_ids (#12626)#12627
Open
aryan105825 wants to merge 1 commit into
Open
fix(messageConversion): deduplicate tool results for reused tool_call_ids (#12626)#12627aryan105825 wants to merge 1 commit into
aryan105825 wants to merge 1 commit into
Conversation
…n history Fixes continuedev#12626 When a provider reuses a tool_call_id across turns, Continue was emitting duplicate tool_result entries for that ID on every subsequent request, corrupting provider conversation state. Two fixes in core/util/messageConversion.ts: 1. handleToolResult: scope ID lookup to the current assistant turn only, and consume matched IDs from pendingToolCalls so a reused ID in a later turn starts fresh. 2. convertFromUnifiedHistory: track emitted tool_call_ids in a Set and skip duplicates, as a defensive second layer against any other path that could populate toolCallStates with a reused ID.
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
recheck |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
I have read the CLA Document and I hereby sign the CLA
Description
When a provider reuses a
tool_call_idacross turns, Continue was emittingduplicate
tool_resultentries for that ID on every subsequent request to theprovider. This corrupts provider conversation state, triggers schema validation
errors, and can cause runaway retry loops (the reproducer in #12626 shows 441
duplicate entries across 442 requests for a single reused ID).
Root cause:
handleToolResultinmessageConversion.tsmatched tool resultsagainst a global
pendingToolCallsmap without scoping to the current assistantturn. When the same ID was reused in a later turn, the earlier turn's
toolCallStatesentry still existed and got re-emitted on every serializationpass by
convertFromUnifiedHistory.Two fixes in
core/util/messageConversion.ts:handleToolResult: guard the match so it only applies when thetool_call_idbelongs to the current assistant turn'stoolCallStates.After a successful match, delete the ID from
pendingToolCallsso a reusedID in a later turn is treated as a fresh entry.
convertFromUnifiedHistory: track emittedtool_call_ids in aSetand skip duplicates on emit — a defensive second layer in case any other
code path populates
toolCallStateswith a reused ID.Checklist
Screen recording or screenshot
N/A — this is a bug fix with no visual output. The reproducer in #12626 can be
used to verify: expected output changes from
REPRODUCEDto no duplicateentries logged.
Tests
Added unit tests in
core/util/messageConversion.test.tscovering:tool_call_idis unique across turnstool_call_idis reused across turnsconvertToUnifiedHistory→convertFromUnifiedHistoryround-trip producesa valid, non-duplicated message sequence for reused IDs
Summary by cubic
Deduplicates tool results when a provider reuses a
tool_call_idacross turns, preventing corrupted conversation state and retry loops. Fixes #12626.handleToolResult: only match IDs in the current assistant turn and remove the ID frompendingToolCallsafter emit.convertFromUnifiedHistory: track emittedtool_call_ids in a Set and skip duplicates as a defensive layer.Written for commit 675749d. Summary will update on new commits.