Repository navigation
serve: a forced tool call follows the model's own close of an open think span - #1023
Conversation
…ink span With thinking on, tool_choice "required" or a named function started its program at the first generated id, which forced the span's close and left the model no reasoning. The call's program is now held while the model reasons in the span the prompt left open: the reasoning is drawn as free text (the request's sampling and logit_bias), and the program starts on the id after the model's own close, which the engine is fed once. Only the close tag ends that span, in the generation and in the chat parser alike, so a call tag inside the reasoning stays reasoning. A model that ends its generation inside the span is a named error, not a call, and so is a close read by its text whose last token also writes text past it; that text is refused before it goes out. A JSON response_format still closes an open span at once, and a finite reasoning_budget beside structured output is still a 400. The raw completion routes read an open span in the prompt for a forced call too.
There was a problem hiding this comment.
Verdict: CLEAN: No reachable behavior defect or proven quality defect remains in the changed code.
Optimization headroom
- E. Less work: crates/serve/src/genloop.rs:2395, the held reasoning phase disables speculative passes. For R reasoning IDs, reusing the existing pass path with verification at the close boundary could reduce R−1 steps to about (R−1)/a target passes, where a is accepted reasoning IDs per pass [derived].
Checked
Duplicates: 12 new functions/constants checked; none duplicate an existing owner. Dryer reported no candidate pairs.
Complexity: answer 14→19 adds held-phase bias decisions; spend 9→14 adds handoff validation; pump 33→34 adds an EOS refusal; schema::request 16→17 adds a small mode selection. The new merged-close test is 21, covering vocabulary setup, a case matrix and assertions.
Silent failure: 2 fallback sites followed. A missing splitter builds the equivalent tracker. Saturating the retained length handles a stop that starts in earlier text; the caller receives the stop result.
Tests (static mutation review; not executed): removing holding at genloop.rs:2092 fails the own-close unit and API assertions. Dropping bias at 2253 or the EOS refusal at 2649 fails the held-call test. Removing suffix or decoder-tail checks at 2318/2322 fails the merged-close matrix. Dropping named-tool filtering at schema.rs:837 fails the modified Hermes gate.
Gates: no tolerance, threshold or lint moved. The body supplies FAIL-first results for the close-boundary test.
Adversarial checks: special versus ordinary close tags, merged suffixes, incomplete UTF-8, stops spanning tokens, and token/context limits are guarded. Responses and messages reuse chat_plan. A prompt with a closed span still starts the program immediately.
Escape catalog: C1–C4 do not match the changed script; its Python heredoc is quoted.
Notes
GPU evidence is incomplete: the body has no nvidia-smi line or just gate-* commands with output. Reported runs use head c2624dab, rather than the reviewed head a3ae6010. The reported serve-suite results were not rerun during this read-only review.
🔨 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. |
thinking이 켜진 요청에서 tool_choice가 도구 호출을 강제할 때, 모델이 reasoning을 끝낸 뒤에 호출이 시작되도록 고친 수정입니다.
What and why
With thinking on and
tool_choiceset torequiredor a named function, the prompt leaves the think span open. The server closed that span at once and started the forced call, so the model never reasoned before it chose the arguments. On Qwen3.8 a simple arithmetic request came back with a well-formed call and a wrong answer ({"answer":400}for 17 x 23 + 19, where 410 is right).A forced call now lets the model reason freely until it writes the span's close itself, and the call's program starts after that close. Only the close tag ends the span in that case, on chat, responses and messages, whole and stream. Raw
/completionand/v1/completionsread an open span in the prompt the same way. Text the model writes after its close must be the parser's ASCII whitespace; anything else, including a UTF-8 byte the decoder still holds at the close, is refused with the existing error before the close is emitted. A finitereasoning_budgetbeside a forced call is a 400, since the budget would compete with the call for the span's end.docs/serving.mddescribes the behaviour.Release notes: Fixed: a forced
tool_choicewith thinking on now lets the model finish reasoning before the call, instead of closing the think span at once.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).PIN(YYYY-MM-DD):and its reason.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": none. The close-boundary check lives inGen::spend(crates/serve/src/genloop.rs) and reuses the parser'sreasoning::is_spaceand the existingStepError::NoAllowed.What I ran
Card run on a GB10 with the Qwen3.8 FP4-Local checkpoint, base
8a59241band headc2624dab. 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 as:The request asks for
a x b + cwith onereport_answertool ({"answer": integer}),enable_thinkingtrue,temperature0,seed7,max_tokens512,reasoning_formatdeepseek. It ran for 12 arithmetic prompts, each withtool_choiceauto,requiredand a named function, as a whole reply and as a stream. A reply counts as correct when the call isreport_answerand its answer equalsa x b + c.Base,
required, 17 x 23 + 19: the first generated token is</think>,reasoning_charsis 0 and the call is{"answer":400}. Head: the model reasons ("17*23=391, +19=410") and the call is{"answer":410}. No request on either side returned an HTTP error, and both servers exited 0 (SERVER_EXIT base 0,SERVER_EXIT head 0). The run verdict isPASS.Close-boundary unit tests (CPU), at the tested head:
The same boundary test cases, run against the previous
genloop.rs, returnab<|think:end|>\u{a0}andab<|think:end|>followed by U+FFFD as successful replies. They are rejected with the fix.Full serve suite:
test result: okfor every target, 0 failed (lib 472, serve 111, qwenxml 22, anthropic 15, glmxml 14, dsml 13, hermes 13, sampdraft 12, callstream 6, penalty 6, contract 4, limits 3).Hardware (if the change is for a machine)
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.