[GH-ISSUE #843] Tool calls silently dropped in agent sessions after an empty assistant turn (fix: skip empty assistant turns when rendering) #375

Closed
opened 2026-11-04 01:42:25 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @jramirez-uab on GitHub (Oct 4, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/843

Summary

With opencode as the client, Strata sometimes returns an empty assistant turn (no text, no tool call) when the user asks for an
action. Once one such turn is in the history, the model imitates it: later turns close the reasoning and end with
</think>\n\n<|im_end|> without emitting the <tool_call>. The client receives an empty answer and the agent "stops".
Skipping empty assistant turns from the history in serve/frontend.py (render) fixes it in our tests: 0-6/20 → 20/20.

Environment

  • Strata v0.1.39 (engine compiled from source with CUDA 13.2), Linux, 1× NVIDIA L40S (48 GB), 251 GB RAM, AMD EPYC 7402P (AVX2).
  • Models: qwen IQ3_S (GSQ-RCO) and swift IQ3_XXS; 262,144 context, KV int8, images on, default MTP settings.
  • Client requests: the real request opencode sends (its system prompt, 11 tools), replayed with stream: false, reasoning_effort: xhigh,
    at temperature 1.0 (none sent) and 0.3.

How to reproduce

A multi-turn conversation whose history contains assistant turns with empty content and no tool_calls (only reasoning_content),
e.g. the user asked "haz un ls" three times and each assistant turn came back empty, then a fourth "haz un ls".
With STRATA_DEBUG=1 the raw model text of the failing answers is:

The user is asking me to run `ls`. Let me do that.
</think>

<|im_end|>

i.e. the model never writes the tool call; the parser is not at fault.

Results (20 tries per case)

Case T=0.3 T=1.0
fresh request "haz un ls" 20/20 20/20
after a long story, "haz un ls" 20/20 20/20
normal session (earlier turns did call tools) → new request 20/20 20/20
history with 3 empty assistant turns → "haz un ls" (Swift IQ3_XXS) 0/20 18/20
same, unpatched, other runs (Qwen IQ3_S / Swift) 2/5 – 6/20 1/20 – 3/5
same, with the patch below (Swift IQ3_XXS and Qwen IQ3_S) 20/20 20/20

Things we ruled out: the chat template (it is Qwen's original plus Unsloth's fixes), the tool-call parser (the call is never generated),
--prompt-cache 0 (worse: 0/5), --no-coupled-draft (no consistent change), preserve_thinking: false (still 6/20).

Patch

--- a/serve/frontend.py
+++ b/serve/frontend.py
@@ -49,6 +49,14 @@
 
     def render(self, messages: list[dict], tools: list[dict] | None = None, add_generation_prompt: bool = True,
                **kwargs) -> str:
+        # Skip empty assistant turns (no text, no tool calls) from the history, except the last message. With them in the
+        # history Qwen3.8-Flash-Next / Swift imitate the pattern and end the next turn without the tool call (0-6/20 -> 20/20).
+        # STRATA_KEEP_EMPTY_TURNS=1 keeps the old behaviour.
+        import os
+        if not os.environ.get("STRATA_KEEP_EMPTY_TURNS"):
+            messages = [m for i, m in enumerate(messages)
+                        if i == len(messages) - 1 or not (isinstance(m, dict) and m.get("role") == "assistant"
+                                                          and not _text_of(m.get("content")).strip() and not m.get("tool_calls"))]
         return self.template.render(messages=messages, tools=tools, add_generation_prompt=add_generation_prompt,
                                     **kwargs)
 

The last message is never removed. An environment variable (STRATA_KEEP_EMPTY_TURNS=1) keeps the old behaviour; feel free to make it
a config option instead.

  • #804 is different: there the model writes the tool call inside <think>; here it never writes it.
  • Unrelated, but for completeness: with --gpus 0,1 and "parallel": 2 we also hit the engine exit reported in #776
    (captured the batch window over slots 0) on 2× L40S; one GPU with parallel 2, or two GPUs with parallel 1, work.

Thanks for Strata: on a single L40S the prompt speed stays flat (~4,300 tok/s) all the way to 198K tokens.

Originally created by @jramirez-uab on GitHub (Oct 4, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/843 ## Summary With opencode as the client, Strata sometimes returns an **empty assistant turn** (no text, no tool call) when the user asks for an action. Once one such turn is in the history, the model **imitates it**: later turns close the reasoning and end with `</think>\n\n<|im_end|>` without emitting the `<tool_call>`. The client receives an empty answer and the agent "stops". Skipping empty assistant turns from the history in `serve/frontend.py` (`render`) fixes it in our tests: **0-6/20 → 20/20**. ## Environment - Strata v0.1.39 (engine compiled from source with CUDA 13.2), Linux, 1× NVIDIA L40S (48 GB), 251 GB RAM, AMD EPYC 7402P (AVX2). - Models: `qwen` IQ3_S (GSQ-RCO) and `swift` IQ3_XXS; 262,144 context, KV int8, images on, default MTP settings. - Client requests: the real request opencode sends (its system prompt, 11 tools), replayed with `stream: false`, `reasoning_effort: xhigh`, at temperature 1.0 (none sent) and 0.3. ## How to reproduce A multi-turn conversation whose history contains assistant turns with empty `content` and no `tool_calls` (only `reasoning_content`), e.g. the user asked "haz un ls" three times and each assistant turn came back empty, then a fourth "haz un ls". With `STRATA_DEBUG=1` the raw model text of the failing answers is: ``` The user is asking me to run `ls`. Let me do that. </think> <|im_end|> ``` i.e. the model never writes the tool call; the parser is not at fault. ## Results (20 tries per case) | Case | T=0.3 | T=1.0 | |---|---|---| | fresh request "haz un ls" | 20/20 | 20/20 | | after a long story, "haz un ls" | 20/20 | 20/20 | | normal session (earlier turns did call tools) → new request | 20/20 | 20/20 | | **history with 3 empty assistant turns → "haz un ls"** (Swift IQ3_XXS) | **0/20** | 18/20 | | same, unpatched, other runs (Qwen IQ3_S / Swift) | 2/5 – 6/20 | 1/20 – 3/5 | | **same, with the patch below** (Swift IQ3_XXS and Qwen IQ3_S) | **20/20** | **20/20** | Things we ruled out: the chat template (it is Qwen's original plus Unsloth's fixes), the tool-call parser (the call is never generated), `--prompt-cache 0` (worse: 0/5), `--no-coupled-draft` (no consistent change), `preserve_thinking: false` (still 6/20). ## Patch ```diff --- a/serve/frontend.py +++ b/serve/frontend.py @@ -49,6 +49,14 @@ def render(self, messages: list[dict], tools: list[dict] | None = None, add_generation_prompt: bool = True, **kwargs) -> str: + # Skip empty assistant turns (no text, no tool calls) from the history, except the last message. With them in the + # history Qwen3.8-Flash-Next / Swift imitate the pattern and end the next turn without the tool call (0-6/20 -> 20/20). + # STRATA_KEEP_EMPTY_TURNS=1 keeps the old behaviour. + import os + if not os.environ.get("STRATA_KEEP_EMPTY_TURNS"): + messages = [m for i, m in enumerate(messages) + if i == len(messages) - 1 or not (isinstance(m, dict) and m.get("role") == "assistant" + and not _text_of(m.get("content")).strip() and not m.get("tool_calls"))] return self.template.render(messages=messages, tools=tools, add_generation_prompt=add_generation_prompt, **kwargs) ``` The last message is never removed. An environment variable (`STRATA_KEEP_EMPTY_TURNS=1`) keeps the old behaviour; feel free to make it a config option instead. ## Related - #804 is different: there the model writes the tool call inside `<think>`; here it never writes it. - Unrelated, but for completeness: with `--gpus 0,1` and `"parallel": 2` we also hit the engine exit reported in #776 (`captured the batch window over slots 0`) on 2× L40S; one GPU with `parallel` 2, or two GPUs with `parallel` 1, work. Thanks for Strata: on a single L40S the prompt speed stays flat (~4,300 tok/s) all the way to 198K tokens.
Author
Owner

@talisp commented on GitHub (Oct 5, 2026):

One likely source of those empty assistant turns, seen here on the same kind of box (L40S 48 GB, 251 GB RAM, Qwen3.8-Flash-Next IQ3_S): the model writes a complete <tool_call> inside the thinking, without </think> first (#804). The server then returns it as reasoning_content, with no tool_calls and empty content. The client stores an assistant turn with nothing in it, and, as you found, the model then imitates that turn.

We measured 4 such replies in ~1,050 (Hermes Agent); another user reported 13 in ~1,300 (#804). The fix for the stranded call is in #525 (opt-in format_fixes). If you can log reasoning_content of the empty turns in your 0–6/20 runs, a <tool_call> at the end of it would confirm the link.

Also relevant (opinion): clients that drop reasoning_content from the history make every earlier turn render as an empty <think>\n\n</think> block (with preserve_thinking). Some template authors call that "empty think poisoning". Your skip-empty-turns fix and #886 address the fully empty case.

<!-- gh-comment-id:6002043429 --> @talisp commented on GitHub (Oct 5, 2026): One likely **source** of those empty assistant turns, seen here on the same kind of box (L40S 48 GB, 251 GB RAM, Qwen3.8-Flash-Next IQ3_S): the model writes a complete `<tool_call>` **inside** the thinking, without `</think>` first (#804). The server then returns it as `reasoning_content`, with no `tool_calls` and empty `content`. The client stores an assistant turn with nothing in it, and, as you found, the model then imitates that turn. We measured 4 such replies in ~1,050 (Hermes Agent); another user reported 13 in ~1,300 (#804). The fix for the stranded call is in #525 (opt-in `format_fixes`). If you can log `reasoning_content` of the empty turns in your 0–6/20 runs, a `<tool_call>` at the end of it would confirm the link. Also relevant (opinion): clients that drop `reasoning_content` from the history make every earlier turn render as an empty `<think>\n\n</think>` block (with `preserve_thinking`). Some template authors call that "empty think poisoning". Your skip-empty-turns fix and #886 address the fully empty case.
Author
Owner

@Niko1221 commented on GitHub (Oct 6, 2026):

Fixed in 0.1.40: empty assistant turns no longer teach the model to answer with nothing (#886). STRATA_KEEP_EMPTY_TURNS=1 restores the old rendering.

<!-- gh-comment-id:6010888514 --> @Niko1221 commented on GitHub (Oct 6, 2026): Fixed in 0.1.40: empty assistant turns no longer teach the model to answer with nothing (#886). STRATA_KEEP_EMPTY_TURNS=1 restores the old rendering.
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#375
No description provided.