fix: keep concurrent tool results in request order#2340
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Assessment: Approve Clean, minimal fix that correctly addresses the ordering issue described in #2112. The approach of per-task result lists merged in Review Notes
Nice targeted fix! 👍 |
|
@he-yufeng the implementation looks correct, thanks! Can you please rebase and fix failing CI? |
4d941a7 to
27dda6d
Compare
|
Rebased this branch onto current main and force-pushed 27dda6d. Validation after rebase:
The earlier check-api warning was against the stale local main ref; it passes against current upstream/main after the rebase. Full format-check still reports an unrelated pre-existing formatting difference in tests/strands/models/test_gemini.py, so I did not include unrelated formatting churn in this PR. |
|
Assessment: Approve Clean, minimal fix that correctly addresses the ordering issue described in #2112. The approach of per-task result lists merged in Review Notes
Nice targeted fix. |
|
Hey @he-yufeng, sorry for the trouble, was this contribution made under the terms of Apache 2.0? Asking because we found another license in the codebase that has since been removed, and would otherwise have to revert this. |
Motivation
ConcurrentToolExecutor currently passes the same
tool_resultslist into every running task. Each task appends when it finishes, so the follow-uptoolResultmessage is ordered by scheduler completion instead of by the model's originaltoolUseorder.That makes prompts unstable for parallel tool calls: a fast second tool can appear before a slow first tool, breaking prompt-cache and replay determinism.
Closes #2112.
Changes
tool_resultslist intool_usesorder after all tasks finish.tool_resultsstill follows request order.Testing
.\.venv\Scripts\python.exe -m pytest tests\strands\tools\executors\test_concurrent.py -q.\.venv\Scripts\python.exe -m ruff check src\strands\tools\executors\concurrent.py tests\strands\tools\executors\test_concurrent.py.\.venv\Scripts\python.exe -m ruff format --check src\strands\tools\executors\concurrent.py tests\strands\tools\executors\test_concurrent.py.\.venv\Scripts\python.exe -m mypy src\strands\tools\executors\concurrent.py.\.venv\Scripts\python.exe -m py_compile src\strands\tools\executors\concurrent.py tests\strands\tools\executors\test_concurrent.pygit diff --checkBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.