Skip to content

[Contribute] fix: preserve parallel tool call order by index (#291) - #296

Open
love9rose wants to merge 1 commit into
spring-ai-alibaba:mainfrom
love9rose:contribute-springai-2026-08-05
Open

[Contribute] fix: preserve parallel tool call order by index (#291)#296
love9rose wants to merge 1 commit into
spring-ai-alibaba:mainfrom
love9rose:contribute-springai-2026-08-05

Conversation

@love9rose

Copy link
Copy Markdown

Problem

DashScope returns parallel tool calls each carrying an explicit index. Previously �uildGeneration mapped them to AssistantMessage.ToolCall without preserving that order, so when parallel tool calls arrive as interleaved stream chunks they could be aggregated into the wrong positions downstream.

Fix

  • Extracted the ordering into a package-private static helper sortToolCallsByIndex(...) that sorts tool calls by their index (tool calls without an index sort last).
  • �uildGeneration now calls this helper before mapping to AssistantMessage.ToolCall.
  • Single tool calls are unaffected (sorting is a no-op).

Test

  • Added estParallelToolCallIndexOrderPreserved: feeds two tool calls in reversed index order (index=1 before index=0) and asserts they come back ordered by index (get_weather before get_time).
  • The test calls the helper directly, avoiding the tool-execution path, so it runs deterministically.

Verification

mvn -pl models/dashscope test -Dtest=DashScopeChatModelTests#testParallelToolCallIndexOrderPreserved -> BUILD SUCCESS.

Related issue: #291

…aba#291)

DashScope returns parallel tool calls each carrying an explicit `index`.
In buildGeneration we now sort the tool calls by their `index` before
mapping them to AssistantMessage.ToolCall, so interleaved stream chunks
are aggregated into the correct positions downstream. Single tool calls
are unaffected (sorting is a no-op).

The sorting logic is extracted into a package-private static helper
sortToolCallsByIndex(...) so it is unit-testable without the tool-execution
path. Added test testParallelToolCallIndexOrderPreserved feeds two tool
calls in reversed index order and asserts they come back ordered by index.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


baizhan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant