[Engine] Qwen4: a tool call written inline inside the thinking is dropped (the answer comes back reasoning-only, stop_reason "stop")
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 79/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Issue chỉ đến serve/frontend.py, tại trạng thái reasoning của OutputParser._feed() trong khi xử lý các lệnh gọi đang chờ. Hãy bắt đầu bằng cách đọc nhánh đó và chạy bản tái hiện chỉ dùng parser trong issue với các lệnh gọi công cụ nằm cùng dòng và có ký tự xuống dòng. Hoàn thành khi cả hai trường hợp đều phát ra hai lệnh gọi công cụ mà không từ chối chúng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
[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}(→ efforthigh), 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).
- Ngôn ngữ chính
- C++
- Star
- 11.6k
- Fork
- 1k
- Merge trung bình
- 4 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 28
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Niko1221/Strata
-
[Benchmark] RX 6900 XT (gfx1030): Linux rx6000 package runs Qwen4-35B-A3B Balanced, 60 tok/s decodeĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 3 ngày
-
[GUI] Status page: Speculation line prints "MTP drafts up to NaN tokens" on the strata-q4-lite hostĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Niko1221/Strata#7970 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Niko1221/Strata#7922 · 3 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Niko1221/Strata#7895 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của Niko1221/Strata
Issue tương tự
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
bot-triaged enhancement module: fft triaged
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
RTL-SDR: re-enumerating while streaming removes the in-use entry from the device selection dialogCó thể đã có người làm @dpc00 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 3 ngày