mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2952] [CLOSED] fix(serve): order chat tool results by tool_call_id #4356
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4356
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2952
Author: @j-luwierski
Created: 10/17/2026
Status: ❌ Closed
Base:
main← Head:codex/chat-tool-result-order📝 Commits (1)
4038e08fix(serve): order chat tool results by tool_call_id📊 Changes
2 files changed (+166 additions, -1 deletions)
View changed files
📝
serve/frontend.py(+33 -1)➕
serve/test_chat_tool_results.py(+133 -0)📄 Description
Summary
Chat Completions history conversion drops assistant tool-call IDs and tool-result
tool_call_idvalues. If an assistant callsread_file(a.txt)followed byread_file(b.txt)and the client sends results B then A, the template receives two anonymous<tool_response>blocks in B/A order. Their association with the calls is lost. Responses already handles call-ID ordering independently.Preserve IDs during Chat Completions conversion and reorder each complete result run to the preceding assistant turn's call order before removing the IDs. This also handles multiple calls of the same function, where matching by name cannot help.
What changed
serve/frontend.py: retain temporary call IDs and normalize result order only when the calls and results have matching sets of unique, nonempty string IDs and equal counts.serve/test_chat_tool_results.py: add seven tests for reversed same-function results, unchanged ordered/legacy prompts, missing/duplicate/unknown/malformed IDs, incomplete histories, separate turns, JSON-encoded history, image-bearing results, input immutability and HTTP-to-engine ordering.Missing, ambiguous or incomplete IDs keep the received order; results never move across an intervening message. Private IDs are removed before rendering. No request or response fields are added.
Anthropic conversion, Responses ordering, templates, sampling, engine code and defaults are unchanged. The existing Responses helper is left alone so its treatment of incomplete histories does not change.
Validation
Linux, Python 3.13, based on upstream
477ac13cbe8e582c20484871ce459d20d82df09d:python -m unittest serve.test_chat_tool_results serve.test_server serve.test_responses -q: 384 tests pass, 1 skipped, 110.4 s. Uses the repository's existing Python environment.git diff --checkpasses.Tests use the real chat template and a mock engine. No GPU/model inference or model-quality measurement was performed; no CUDA/HIP/SYCL source or build files are touched, and backend builds were not run.
Related work
Searched open issues and PRs for
tool_call_id, tool results and out-of-order handling; no matching Chat Completions fix found.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.