[PR #2039] [CLOSED] serve: preserve literal </tool_call> in prompts #3820

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2039
Author: @CC-David-CC
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: fix/2026-literal-tool-call-output


📝 Commits (1)

  • fcb4190 fix(serve): preserve literal tool-call closers in prompts

📊 Changes

2 files changed (+202 additions, -4 deletions)

View changed files

📝 serve/frontend.py (+6 -4)
➕ serve/test_literal_tool_tags.py (+196 -0)

📄 Description

Title

serve: preserve literal </tool_call> in prompts

Issue: Resolves https://github.com/Niko1221/Strata/issues/2026

Summary

Asking the model to print </tool_call> verbatim can produce an empty final response. The tokenizer treats this spelling as a user-defined special token even inside ordinary message text. Protecting it as plain text in the prompt makes the reported reproduction return the requested string.

What changed

  • Add TOOL_LITERAL_TAGS with one entry, </tool_call>, to the existing literal-span protection.
  • Protect occurrences in messages, assistant history/reasoning, tool results, definitions, and argument values while preserving template-generated tool-call closers as special tokens.
  • Add regressions for prompt token IDs, literal model output, all two-part streaming boundaries, real tool calls, explicit stop sequences, and streaming/non-streaming HTTP responses.

This is a standalone fix against main; it does not depend on #1886. No new state machine, retry, configuration option, or engine change is required. Prompts without the target literal retain identical token IDs.

Extra Notes

Validation

The issue's exact prompt was run through the service with a real IQ3_XXS model on Linux/CUDA (RTX PRO 6000 Blackwell). Ten interleaved before/after pairs used seeds 42-51, temperature 0.6, top_p 0.95, top_k 20, thinking enabled, and no tools. Both arms used the PR code; the baseline restored the original literal registry. Raw input/output token IDs were captured.

Result Original registry With fix
Exactly </tool_call> 0/10 10/10
Empty final response 9/10 0/10
Incorrect <|im_start|> response 1/10 0/10

The </aaa> and </mcp_tool> controls each passed before and after. The reporter's IQ3_S/Windows/AMD configuration was not tested.

339 tests passed on the standalone PR branch (Windows, Python 3.13.15). Regression command (no model/GPU required):

python -m unittest serve.test_literal_tool_tags serve.test_frontend serve.test_reasoning_tools serve.test_tool_name_space serve.test_server -q

Removing the new registry entry makes 20 prompt-protection subcases fail; restoring it passes them. Existing output parsing already preserves a standalone closer, so the production fix stays in prompt tokenization.


🔄 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/2039 **Author:** [@CC-David-CC](https://github.com/CC-David-CC) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/2026-literal-tool-call-output` --- ### 📝 Commits (1) - [`fcb4190`](https://github.com/Niko1221/Strata/commit/fcb4190c7046c4514c6bea3b8a4047010c8e4230) fix(serve): preserve literal tool-call closers in prompts ### 📊 Changes **2 files changed** (+202 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+6 -4) ➕ `serve/test_literal_tool_tags.py` (+196 -0) </details> ### 📄 Description ## Title serve: preserve literal `</tool_call>` in prompts Issue: Resolves https://github.com/Niko1221/Strata/issues/2026 ## Summary Asking the model to print `</tool_call>` verbatim can produce an empty final response. The tokenizer treats this spelling as a user-defined special token even inside ordinary message text. Protecting it as plain text in the prompt makes the reported reproduction return the requested string. ## What changed - Add `TOOL_LITERAL_TAGS` with one entry, `</tool_call>`, to the existing literal-span protection. - Protect occurrences in messages, assistant history/reasoning, tool results, definitions, and argument values while preserving template-generated tool-call closers as special tokens. - Add regressions for prompt token IDs, literal model output, all two-part streaming boundaries, real tool calls, explicit stop sequences, and streaming/non-streaming HTTP responses. This is a standalone fix against `main`; it does not depend on #1886. No new state machine, retry, configuration option, or engine change is required. Prompts without the target literal retain identical token IDs. ## Extra Notes ### Validation The issue's exact prompt was run through the service with a real IQ3_XXS model on Linux/CUDA (RTX PRO 6000 Blackwell). Ten interleaved before/after pairs used seeds 42-51, temperature 0.6, top_p 0.95, top_k 20, thinking enabled, and no tools. Both arms used the PR code; the baseline restored the original literal registry. Raw input/output token IDs were captured. | Result | Original registry | With fix | | --- | ---: | ---: | | Exactly `</tool_call>` | 0/10 | 10/10 | | Empty final response | 9/10 | 0/10 | | Incorrect `<\|im_start\|>` response | 1/10 | 0/10 | The `</aaa>` and `</mcp_tool>` controls each passed before and after. The reporter's IQ3_S/Windows/AMD configuration was not tested. 339 tests passed on the standalone PR branch (Windows, Python 3.13.15). Regression command (no model/GPU required): ```sh python -m unittest serve.test_literal_tool_tags serve.test_frontend serve.test_reasoning_tools serve.test_tool_name_space serve.test_server -q ``` Removing the new registry entry makes 20 prompt-protection subcases fail; restoring it passes them. Existing output parsing already preserves a standalone closer, so the production fix stays in prompt tokenization. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:31:00 +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#3820
No description provided.