fix: preserve tool_results request order in ConcurrentToolExecutor#2199
Open
luyao618 wants to merge 1 commit intostrands-agents:mainfrom
Open
fix: preserve tool_results request order in ConcurrentToolExecutor#2199luyao618 wants to merge 1 commit intostrands-agents:mainfrom
luyao618 wants to merge 1 commit intostrands-agents:mainfrom
Conversation
The ConcurrentToolExecutor collects tool results in task completion order rather than the original request order. When a fast tool finishes before a slow tool, the results list does not match the tool_uses ordering. Sort tool_results by the original tool_uses index after all tasks complete using the toolUseId mapping. Closes strands-agents#2112
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.
Problem
ConcurrentToolExecutorcollects tool results in task completion order rather than the original request order. When a fast tool finishes before a slow tool, thetool_resultslist does not match thetool_usesordering.Reported in #2112.
Solution
After all concurrent tasks complete, sort
tool_resultsby the originaltool_usesindex using atoolUseId → indexmapping built before execution. The sort happens in thefinallyblock of_execute()so it applies regardless of how tasks complete.Testing
Added
test_concurrent_executor_preserves_request_orderthat verifiestool_resultsorder matches the originaltool_usesorder when tools complete at different speeds.Closes #2112