[PR #1068] [CLOSED] serve: a tool call from the reasoning only when it ends the turn (#1058) #3004

Closed
opened 2026-11-04 02:04:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1068
Author: @sergqwer
Created: 10/6/2026
Status: ❌ Closed

Base: main ← Head: pr/reasoning-call-gate


📝 Commits (10+)

  • f4e96d5 tests: gdn_rec_head also compares the PP (variant 4) and two-column (variant 5) recurrence kernels, bitwise
  • 16bc95a prefill: STRATA_HCD_EXACT=1 - the HC down projection by a WMMA kernel with hipBLASLt solution 1176/1177 k order (StaggerU included), bitwise
  • 502fcef #606: the fused SwiGLU q8_1 quantizers keep the block's scale and sum finite too
  • 64d0136 cache: preserve checkpoints when split allocation fails
  • a0d0056 prefill: fused-expert exact wins (table16 via direct selector, float4 moe_combine, LDS alias + occupancy)
  • 5f5452b serve: park_current's try covers the checkpoint split too (#752): a host OOM skips parking
  • 8b19a38 Layer split: --vram-reserve-later-mib, a separate reserve for the later cards
  • ea83d0d Resident RAM mode with a layer split
  • d2d981f setup: the low-RAM mode's resident variant on several GPUs (#642)
  • cd62e5e serve: a split's stage-0 GPU profile line keeps its text (#848); later stages say which stage

📊 Changes

3 files changed (+136 additions, -30 deletions)

View changed files

📝 serve/frontend.py (+60 -11)
📝 serve/server.py (+9 -2)
📝 serve/test_reasoning_tools.py (+67 -17)

📄 Description

Fixes #1058. On 0.1.40 the #804 rescue delivers any complete call to a declared tool that the model wrote inside its thinking. That includes a call the model only quoted there, such as an example, a fenced block or a turn cut by max_tokens mid-thought. The issue shows a quoted rm -rf build returned as a tool_call with finish length.

What changes

A call inside the reasoning is held until the turn ends. It is delivered only if all three of these hold:

  1. its <tool_call> begins a line (the issue's first gate);
  2. after it come only whitespace and further such calls;
  3. the turn ends by itself (a stop token or a stop string), not by max_tokens, a cancel or an error (the issue's second gate).

Otherwise its text goes back to the reasoning unchanged. A call in the answer is unchanged, and so is everything without declared tools.

  • Gate 2 (whitespace only after the call) is the one the issue did not list. A stranding is a call the model wrote and then stopped, so nothing follows it. A quoted example is followed by more thinking or prose, a closing fence, or </think> and an answer, and this gate catches those. Without it, the fenced examples still fire, because the opener after "```xml\n" begins a line. So do mention-trailing-prose and the prose-between-two-blocks entry of #525's corpus.
  • When the call is sent. It goes out when the turn ends instead of as soon as it closes. Nothing comes after a delivered call anyway, so a client gets the same call at the same point in the stream, only no earlier than the end of the turn.
  • Observability (the issue's ask). GET /metrics totals get reasoning_calls_delivered and reasoning_calls_kept_as_text, which counts complete calls to a declared tool that stayed text.

Measured

Both corpora from the issue were run offline through OutputParser. Each was fed whole, one character at a time and in random 1-9 character chunks, and every chunking gave the same result. A natural end is finish == "stop".

0.1.40 this PR
#525's 25 specimens (5 acts, 20 negative controls) 10 negatives deliver a call all 25 as expected
the 12 live strandings (gist from the issue) live-02 (finish length) and live-06 (an envelope, todo_list) deliver a call all 12 as expected
live strandings that are calls (declared name, natural stop) 9 of 9 delivered 9 of 9 delivered

The recall on the recorded live data is unchanged. Every live stranding opens its call on its own line and ends the turn with it.

Tests

serve/test_reasoning_tools.py now expects these semantics:

  • a call that ends the turn (one, two adjacent, and at the start of the reasoning) is delivered and never streamed piece by piece;
  • the quoted shapes from #1058 stay text, with the text unchanged:
    • more thought after the call;
    • mid-sentence;
    • prose after it;
    • a fenced block;
    • </think> after it;
    • a max_tokens cut;
    • prose between two calls;
    • a second call mid-line;
  • the counters;
  • over HTTP, the same call delivered on a stop and kept as text when max_tokens cuts the turn right after it. This test fails if finish() ignores how the turn ended.

The serve suite passes (423 tests).

🤖 Generated with Claude Code

https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio


🔄 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/1068 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/reasoning-call-gate` --- ### 📝 Commits (10+) - [`f4e96d5`](https://github.com/Niko1221/Strata/commit/f4e96d55b6f13622bae6b3ded2f81ca16cbd78f6) tests: gdn_rec_head also compares the PP (variant 4) and two-column (variant 5) recurrence kernels, bitwise - [`16bc95a`](https://github.com/Niko1221/Strata/commit/16bc95ab3e5293a6dd557ad0ec7e2a5eef23640a) prefill: STRATA_HCD_EXACT=1 - the HC down projection by a WMMA kernel with hipBLASLt solution 1176/1177 k order (StaggerU included), bitwise - [`502fcef`](https://github.com/Niko1221/Strata/commit/502fcef6ff29325427ecfb5409b242ac7bea18e1) #606: the fused SwiGLU q8_1 quantizers keep the block's scale and sum finite too - [`64d0136`](https://github.com/Niko1221/Strata/commit/64d01362bee3aa109fb340d9b4144a62d9192522) cache: preserve checkpoints when split allocation fails - [`a0d0056`](https://github.com/Niko1221/Strata/commit/a0d00560fdb3bd728001cac756e223b12e3a09e9) prefill: fused-expert exact wins (table16 via direct selector, float4 moe_combine, LDS alias + occupancy) - [`5f5452b`](https://github.com/Niko1221/Strata/commit/5f5452bec6fabe7c76b44af2397b29daac95feb4) serve: park_current's try covers the checkpoint split too (#752): a host OOM skips parking - [`8b19a38`](https://github.com/Niko1221/Strata/commit/8b19a38a57a80ee9c2bd03d677d8b55fc961d34b) Layer split: --vram-reserve-later-mib, a separate reserve for the later cards - [`ea83d0d`](https://github.com/Niko1221/Strata/commit/ea83d0dc5ef3fd481c53ee6bd99dd8016e10ce78) Resident RAM mode with a layer split - [`d2d981f`](https://github.com/Niko1221/Strata/commit/d2d981f5b2841cfcefcc88872730785b9d23bd78) setup: the low-RAM mode's resident variant on several GPUs (#642) - [`cd62e5e`](https://github.com/Niko1221/Strata/commit/cd62e5e07f5efa6be42a8ccfbbc82b78f6abfe93) serve: a split's stage-0 GPU profile line keeps its text (#848); later stages say which stage ### 📊 Changes **3 files changed** (+136 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `serve/frontend.py` (+60 -11) 📝 `serve/server.py` (+9 -2) 📝 `serve/test_reasoning_tools.py` (+67 -17) </details> ### 📄 Description Fixes #1058. On 0.1.40 the #804 rescue delivers any complete call to a declared tool that the model wrote inside its thinking. That includes a call the model only quoted there, such as an example, a fenced block or a turn cut by `max_tokens` mid-thought. The issue shows a quoted `rm -rf build` returned as a `tool_call` with finish `length`. ### What changes A call inside the reasoning is held until the turn ends. It is delivered only if all three of these hold: 1. its `<tool_call>` begins a line (the issue's first gate); 2. after it come only whitespace and further such calls; 3. the turn ends by itself (a stop token or a stop string), not by `max_tokens`, a cancel or an error (the issue's second gate). Otherwise its text goes back to the reasoning unchanged. A call in the answer is unchanged, and so is everything without declared tools. - **Gate 2** (whitespace only after the call) is the one the issue did not list. A stranding is a call the model wrote and then stopped, so nothing follows it. A quoted example is followed by more thinking or prose, a closing fence, or `</think>` and an answer, and this gate catches those. Without it, the fenced examples still fire, because the opener after "```xml\n" begins a line. So do `mention-trailing-prose` and the prose-between-two-blocks entry of #525's corpus. - **When the call is sent.** It goes out when the turn ends instead of as soon as it closes. Nothing comes after a delivered call anyway, so a client gets the same call at the same point in the stream, only no earlier than the end of the turn. - **Observability** (the issue's ask). `GET /metrics` totals get `reasoning_calls_delivered` and `reasoning_calls_kept_as_text`, which counts complete calls to a declared tool that stayed text. ### Measured Both corpora from the issue were run offline through `OutputParser`. Each was fed whole, one character at a time and in random 1-9 character chunks, and every chunking gave the same result. A natural end is `finish == "stop"`. | | 0.1.40 | this PR | |---|---|---| | #525's 25 specimens (5 acts, 20 negative controls) | 10 negatives deliver a call | all 25 as expected | | the 12 live strandings (gist from the issue) | `live-02` (finish `length`) and `live-06` (an envelope, `todo_list`) deliver a call | all 12 as expected | | live strandings that are calls (declared name, natural stop) | 9 of 9 delivered | 9 of 9 delivered | The recall on the recorded live data is unchanged. Every live stranding opens its call on its own line and ends the turn with it. ### Tests `serve/test_reasoning_tools.py` now expects these semantics: - a call that ends the turn (one, two adjacent, and at the start of the reasoning) is delivered and never streamed piece by piece; - the quoted shapes from #1058 stay text, with the text unchanged: - more thought after the call; - mid-sentence; - prose after it; - a fenced block; - `</think>` after it; - a `max_tokens` cut; - prose between two calls; - a second call mid-line; - the counters; - over HTTP, the same call delivered on a stop and kept as text when `max_tokens` cuts the turn right after it. This test fails if `finish()` ignores how the turn ended. The serve suite passes (423 tests). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:04:50 +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#3004
No description provided.