Repository navigation
serve: a think or Qwen call tag is markup only where its special token was generated, so the same text in ordinary tokens stays content - #1020
Conversation
…n was generated, so the same text in ordinary tokens stays content
Keep string and number endings from consuming the prefix of a forced special token across grammar frames. Cover whole and streamed required calls, and a model-ended reasoning span inside its budget.
Carry each special token's byte length beside its offset through the generation events, the outcome and the parsers. A vocabulary may hold a special token that spells only the start of a tag; such a token followed by ordinary pieces that complete the tag's text no longer opens or closes a think span or a tool call.
There was a problem hiding this comment.
Verdict: CLEAN: No merge-blocking defect found in special-token tracking, reasoning boundaries or tool-call parsing.
Non-blocking
⚠ Supply dispatch timing evidence: crates/serve/src/genloop.rs:2598 decodes each emitted special token again. With Vocab, this adds a byte buffer and an owned String per nonempty special token; sending also allocates metadata for each event carrying one. The body supplies correctness results but no timing comparison. Attach the same-lease base/head A/B required by AGENTS.md's Measuring contract.
Checked
Duplicates: The existing Qwen/GLM push wrappers delegate to separate scanners. Sharing these short wrappers would add an abstraction.
Complexity: Gen::pump adds a special-offset branch to token emission.
Silent failure: SpecialTags::find preserves text matching for vocabularies without a special marker.
Tests: Static mutation analysis, not execution. Bypass the special checks at crates/serve/src/reasoning.rs:57 and line 66: the ordinary-id and ordinary-close assertions fail.
Tests: Drop the guard at crates/serve/src/constrain/program.rs:1119: constrained_calls_keep_special_markers_whole fails its closing-token assertion.
Tests: Remove the upper bound at crates/serve/src/genloop.rs:2254: a_held_special_is_reported_only_when_its_text_is_sent fails its event-offset assertion.
Gates: No tolerance relaxed or test removed; model-tax limits decrease. The body supplies FAIL-first evidence for ordinary-token tag handling.
Escapes: No C1–C4 pattern matches. The diagnostic uses a quoted heredoc and propagates Python failures. Shell and embedded Python syntax checks pass.
Notes
Rust tests and hardware runs were not executed in this review. The body lacks the required nvidia-smi output and exact model file path.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8 출력에서 think와 tool_call 태그를 그 special 토큰이 생성된 자리에서만 경계로 읽고, 일반 토큰으로 쓴 같은 글자는 content로 두는 수정입니다.
What and why
Qwen3.8 can write
<think>,</think>and<tool_call>as ordinary text tokens, for example when it quotes or copies them. The parsers matched those characters in the decoded text, so ordinary text was read as markup: a quoted</think>closed the reasoning early, and a copied<tool_call>XML example became a real tool call.The generation loop now records where each special token's text starts. The think split and the Qwen call scan treat a tag as markup only at those offsets. A model whose vocabulary does not hold a tag as one special token keeps the previous text match. Chat, responses and messages hand the offsets to the parser in both whole and stream replies. Raw completions are unchanged.
Release notes: Fixed: Qwen3.8 replies that quote or copy
</think>or<tool_call>as ordinary text are no longer cut into reasoning or turned into tool calls.Code shape
The review reads these first. A box left unticked needs one line of why.
copying it (
AGENTS.md"Common code first",docs/rust-quality.mdR14). Where I found an existing copy, Inamed it below.
(tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
tools/check-comments.sh).cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none":crates/serve/src/qwenxml.rs:373andcrates/serve/src/glmxml.rs:321both keep a three-linepushwrapper over their ownpush_streamand error type. Both existed before; this change only hands&[]specials to the Qwen one. Merging them needs a shared trait outside this fix.What I ran
Card runs used base
9540dc3fand head65cd45a3; the PR head is2102e9e6c. Both binaries come fromcargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve. Each ran asBLOOMERY_DRAFT=off bloomery-serve --host 127.0.0.1 --port 18739 --parallel 1 --ctx-size 4096 --cache-ram 0 -ub 256 --no-mmprojon the Qwen3.8 FP4-Local checkpoint, and each request ran as a whole reply and as a stream. Both usedtemperature0,seed7,reasoning_formatdeepseek.Request 1 (
enable_thinkingfalse, areport_answertool,tool_choiceauto) asks the model to copy this XML as plain text:Request 2 (
enable_thinkingtrue) asks the model to first copy the literal text</think>as a quoted string inside its reasoning, then explain why 2+2=4, and finally answer OK.tool_calls, 0 content chars and the callreport_answer({"answer":410}); head finished withstop, 97 content chars (the XML) and no tool call.OK.Base, request 1:
"finish": "tool_calls", "reasoning_chars": 0, "content_chars": 0, "tool_calls": [["report_answer", "{\"answer\":410}"]].Head, request 1:
"finish": "stop", "reasoning_chars": 0, "content_chars": 97, "tool_calls": [].Base, request 2:
"finish": "stop", "reasoning_chars": 87, "content_chars": 874.Head, request 2:
"finish": "stop", "reasoning_chars": 958, "content_chars": 2.Both servers exited with
SERVER_EXIT base 0andSERVER_EXIT head 0.Unit test
constrain::tests::a_tag_spelled_in_ordinary_ids_is_textdrives the real generation loop with a scripted engine that emits ordinary and special ids. It checks that whole and stream replies give the same message, that a copied call stays content, and that a think budget of 20 ignores an ordinary</think>and forces the special one. With the special-token check off it failed withQwen(NoFunction { .. "</think>\n\n<tool_call>..." }); with it on it passes.Host gate on
65cd45a3:12 test binaries ran, 683 tests passed, 0 failed, 0 ignored. The
bloomery-servelib reportedtest result: ok. 465 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out. After the last commitcargo test -p bloomery-serve --libreported 466 passed.Hardware (if the change is for a machine)
One GB10, driver 595.84, CUDA compilation tools 13.3, running the Qwen3.8 FP4-Local checkpoint.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.