[PR #3395] [CLOSED] [Other] preserve Chat Completions tool result order #4614

Closed
opened 2026-11-07 15:37:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3395
Author: @j-luwierski
Created: 10/20/2026
Status: ❌ Closed

Base: main ← Head: codex/chat-tool-results-main-20261020


📝 Commits (1)

  • 7b87be6 [Other] preserve Chat Completions tool result order

📊 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

Problem and result

When an OpenAI Chat Completions request contains multiple tool calls and the client returns their tool results in a different order, the serving layer drops the call IDs before rendering the prompt. The model then sees anonymous results in arrival order, even when the results belong to calls with the same function name. The fix restores the call order for complete, unambiguous result runs before removing the temporary IDs.

This follows the closed tracker-reset submission #2952. The new branch is based on current main; the v0.2.0-beta tag is an ancestor of the base revision.

Approach

The Chat Completions conversion retains call IDs only while normalizing a request. It reorders a result run only when call and result IDs are nonempty unique strings with matching sets and counts. Missing, duplicate, unknown, or incomplete IDs keep their received order. IDs are removed before prompt rendering. No engine, template, Anthropic, Responses, or default behavior changes.

Validation

Environment: Linux, Python 3.12.14, dependencies from the repository's pinned requirements.txt.

Passed:

  • Reproduction on unmodified main at 5bda973a43: /tmp/strata-pr2952-venv/bin/python -m unittest serve.test_chat_tool_results -q ran 7 tests and reproduced 4 failures, including reversed same-function results and the HTTP-to-engine prompt order.
  • Fixed revision 7b87be6220: /tmp/strata-pr2952-venv/bin/python -m unittest serve.test_chat_tool_results serve.test_frontend serve.test_server serve.test_responses -q ran 415 tests; OK (skipped=1) in 128.991 seconds.
  • git diff --cached --check passed before commit.

Failed:

  • None on the fixed revision.

Not run:

  • GPU/model inference and CUDA, HIP, SYCL, or Metal builds. This change touches only Python serving code and its tests.

Limits

Only complete, unambiguous tool-result runs are reordered. Incomplete or ambiguous histories preserve their incoming order.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3395 **Author:** [@j-luwierski](https://github.com/j-luwierski) **Created:** 10/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `codex/chat-tool-results-main-20261020` --- ### 📝 Commits (1) - [`7b87be6`](https://github.com/Niko1221/Strata/commit/7b87be62201245a8747f248cd58b006c7ed9b92d) [Other] preserve Chat Completions tool result order ### 📊 Changes **2 files changed** (+166 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+33 -1) ➕ `serve/test_chat_tool_results.py` (+133 -0) </details> ### 📄 Description ## Problem and result When an OpenAI Chat Completions request contains multiple tool calls and the client returns their tool results in a different order, the serving layer drops the call IDs before rendering the prompt. The model then sees anonymous results in arrival order, even when the results belong to calls with the same function name. The fix restores the call order for complete, unambiguous result runs before removing the temporary IDs. ## Related discussion This follows the closed tracker-reset submission [#2952](https://github.com/Niko1221/Strata/pull/2952). The new branch is based on current main; the v0.2.0-beta tag is an ancestor of the base revision. ## Approach The Chat Completions conversion retains call IDs only while normalizing a request. It reorders a result run only when call and result IDs are nonempty unique strings with matching sets and counts. Missing, duplicate, unknown, or incomplete IDs keep their received order. IDs are removed before prompt rendering. No engine, template, Anthropic, Responses, or default behavior changes. ## Validation Environment: Linux, Python 3.12.14, dependencies from the repository's pinned requirements.txt. **Passed:** - Reproduction on unmodified main at 5bda973a4331212494d74cf35927ada7f0e063e7: /tmp/strata-pr2952-venv/bin/python -m unittest serve.test_chat_tool_results -q ran 7 tests and reproduced 4 failures, including reversed same-function results and the HTTP-to-engine prompt order. - Fixed revision 7b87be62201245a8747f248cd58b006c7ed9b92d: /tmp/strata-pr2952-venv/bin/python -m unittest serve.test_chat_tool_results serve.test_frontend serve.test_server serve.test_responses -q ran 415 tests; **OK (skipped=1)** in 128.991 seconds. - git diff --cached --check passed before commit. **Failed:** - None on the fixed revision. **Not run:** - GPU/model inference and CUDA, HIP, SYCL, or Metal builds. This change touches only Python serving code and its tests. ## Limits Only complete, unambiguous tool-result runs are reordered. Incomplete or ambiguous histories preserve their incoming order. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:37:49 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4614
No description provided.