[Engine] Qwen4: a tool call written inline inside the thinking is dropped (the answer comes back reasoning-only, stop_reason "stop")

Open Beginner friendly
#8,057 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
79/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

The issue points to serve/frontend.py, in OutputParser._feed()'s reasoning state while pending calls are handled. Start by reading that branch and run the parser-only reproduction from the issue with inline and newline tool calls. Done means both cases emit the two tool calls without refusing them.

Written by the indexing model from the issue text.

Description

[Engine] Qwen4: a tool call written inline inside the thinking is dropped (the answer comes back reasoning-only, stop_reason "stop")

What happens

Serving Qwen4-35B-A3B UD-Q4_K_XL through the Anthropic /v1/messages route, with thinking enabled and tools declared, the model sometimes writes its tool calls inside the thinking block and never closes the thinking. When the first <tool_call> of such a run is written inline (no newline between the preceding sentence and <tool_call>), Strata's parser refuses the calls: the client receives an assistant message with a single reasoning block and stop_reason: "stop".

An agent client (Claude-Code-style) sees "no tool call, answer finished" and ends the turn; the user has to type "continue" every time. In one real session this happened on 3 of the last 11 assistant steps (the session had 7 turns / 38 steps in total; each failing reply was 3.5-4.5k tokens, almost all thinking).

Minimal reproduction (parser only, no model needed)

import sys
sys.path.insert(0, "<control-0.1.74>")          # /root/.local/share/strata/components/control/0.1.74
import os
os.chdir("<control-0.1.74>")
from serve import frontend

C1 = ("<tool_call>\n<function=read>\n<parameter=file_path>\n/etc/hostname\n"
      "</parameter>\n</function>\n</tool_call>")
C2 = ("<tool_call>\n<function=grep>\n<parameter=pattern>\nPRIVATE_KEY\n"
      "</parameter>\n</function>\n</tool_call>")
tools = [{"name": "read", "description": "", "input_schema": {"type": "object"}},
         {"name": "grep", "description": "", "input_schema": {"type": "object"}}]

for name, text in {
    "inline":  "Let me check." + C1 + C2,     # <tool_call> on the same line as the text
    "newline": "Let me check.\n" + C1 + C2,
}.items():
    p = frontend.OutputParser(thinking=True, tools=tools, stream_tools=False, recover=True)
    ev = p.feed(text)
    out = p.finish(None)
    calls = [e for e in list(ev) + list(out) if getattr(e, "kind", None) == "tool_call"]
    print(f"{name:8s} rescued={p.rescued} refused={p.refused} calls={len(calls)}")

Actual on control 0.1.74:

inline   rescued=0 refused=2 calls=0
newline  rescued=2 refused=0 calls=2

Expected: both cases deliver the 2 calls (the model meant both as actions; the turn ends right after them).

Why

In serve/frontend.py, OutputParser._feed(), the elif self.state == "reasoning": if self.pending: branch holds calls found in the reasoning until </think> or the end of the turn. When parsing a wrapped call, the code can leave the call's own </tool_call> in self.buf (the drop = 0 path, which happens when the call is written inline). On the next loop the pending-call branch sees a buffer that starts with </tool_call> — not <tool_call>, not </think>, not a bare <function= — and takes the final else: self._release(False), i.e. it decides the calls were quoted prose and returns them as reasoning text.

Suggested patch

In serve/frontend.py, _feed(), inside the elif self.state == "reasoning": if self.pending: branch, right after if not self.buf: return out:

                     if not self.buf:
                         return out
+                    if self.buf.startswith(CALL_END):      # the closer of the call just stored
+                        self.buf = self.buf[len(CALL_END):]
+                        continue
                     bare = self._bare_in_reasoning() if self.recover and self.schemas else None

With that line, the reproduction above prints rescued=2 refused=0 for both rows, and a live Anthropic request with thinking: {type: "enabled", budget_tokens: 31999} plus a declared read tool returns stop_reason: "tool_use" with the correct tool_use block.

Impact

Any Anthropic/OpenAI client that relies on tool calls in the answer: a reasoning-only answer is indistinguishable from "the model finished", so the turn ends early. The Anthropic route is the one Claude-Code-style harnesses use.

Environment

  • Strata / Control 0.2.26 / 0.1.74 (the parser lives in Control's serve/frontend.py)
  • Model Qwen4-35B-A3B UD-Q4_K_XL (Unsloth GGUF), engine q4_lite 0.1.74-linux-x86_64-cuda-cuda12
  • Tesla V100-SXM2-32GB, Linux, driver 580.196.07
  • Request: Anthropic /v1/messages, thinking: {type: "enabled", budget_tokens: 31999} (→ effort high), tools declared
  • Client: DeepSeek Harness agent (Anthropic provider)

Workaround

Patch the parser as above (the running server picks it up after a restart), or make sure the model starts every <tool_call> on a new line (not reliable — the model chooses).

Dominant language
C++
Stars
11.6k
Forks
1k
Avg merge
4d 17h
Merged PRs (30d)
28

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Niko1221/Strata

All issues in Niko1221/Strata

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.