Skip to content

serve: MiMo-V2.6's tool calls parse (the compact Qwen3-Coder framing) - #634

Merged
midagedev merged 2 commits into
mainfrom
mimotool
Oct 22, 2026
Merged

midagedev merged 2 commits into
mainfrom
mimotool

Conversation

@midagedev

Copy link
Copy Markdown
Owner

What and why

MiMo-V2.6's chat template writes a tool parameter as <parameter=KEY>VALUE</parameter>, with no newlines. Our Qwen3-Coder parser read only Qwen3.6's newline framing, so every MiMo tool call (MOPD and RL) ended in a 500. The framing is now read from the call the template renders, and one parser reads both forms.

Release notes: Fixed — tool calls on MiMo-V2.6-Flash no longer fail with "expected a newline after <parameter=KEY>".

Code shape

  • No second copy. One parser; Framing (Lines, Compact) is a parameter of it.
  • Model code holds only architecture facts. The framing comes from the template's rendered call, not a model name.
  • Dead code is gone.
  • No silent failure. Markup that fits neither framing is still a named error.
  • Comments state what is true now. tools/check-comments.sh rc 0.
  • No relaxed gate. Every existing expectation is unchanged.
  • cargo fmt and cargo clippy are clean on what I touched. just mac-lint counts 18 warnings against the ratchet's 11, all in files this PR does not touch.

Duplication found or removed (path:line), or "none": none

What I ran

  • Oracle: llama.cpp mainline tools/ref/chat_parse_ref with the MiMo template parses <parameter=city>Seoul</parameter> to {"city":"Seoul"}, and the newline form to {"city":"\nSeoul\n"}. The new tests pin both, at every stream cut.
  • FAIL-first on three mutants: the framing forced to Lines (6 red), Compact read as Lines (10 red), no close-tag hold while streaming (3 red).
  • cargo test -p bloomery-serve -- --include-ignored: 536 passed, 0 failed.
  • Served, RTX A6000: a tool call on MiMo-V2.6-Flash-MOPD MXFP4 is a 500 on main and a 200 with get_weather {"city":"Seoul"} on this branch. Sage-A1.5 (Qwen3.6's framing) is a 200 on both.
  • just narrow: ptx-scan identical, 24 gates kept; the fixture-tier batch result follows in a comment.

🤖 Generated with Claude Code

@github-actions github-actions Bot added documentation Improvements or additions to documentation serve The HTTP server: crates/serve labels Oct 21, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MUST_FIX: framing detection can select a header example or silently assume a framing that changes argument bytes.

Must fix

1. Detect the probe call with the scanner's complete delimiters

crates/serve/src/qwenxml.rs:105 A template header containing <parameter=location>\nSeoul\n</parameter> before a compact assistant call selects Lines. The scanner then rejects the actual compact call with a 500.
The detector also duplicates an incomplete Lines delimiter (R14): it ignores the required newline after </parameter>. The new small-template assertion at crates/serve/tests/qwenxml.rs:604 passes although that rendered call ends in Unterminated.
Reuse the delimiter owner now, before more templates depend on a different detection rule. Scope detection to the final probe call:

pub(crate) fn of_rendered(rendered: &str, key: &str, value: &str) -> Option<Framing> {
    let (_, call) = rendered.rsplit_once(CALL_OPEN)?;
    let opener = format!("{PARAM_OPEN}{key}>");
    let (_, after) = call.split_once(&opener)?;
    [Framing::Lines, Framing::Compact]
        .into_iter()
        .find(|framing| {
            after.starts_with(&format!(
                "{}{value}{}",
                framing.value_open(),
                framing.value_close()
            ))
        })
}

Extend the detection test with a header example. Emit the small Lines fixture's closing newline through an expression so {%- endfor cannot trim it:

let example = "<tool_call><function=get_weather><parameter=location>\nSeoul\n</parameter>\n</function></tool_call>";
assert_eq!(
    ToolFormat::of_template(&format!("{example}{}", small("{{ v }}"))),
    compact
);
assert_eq!(
    ToolFormat::of_template(&small("\n{{ v }}\n").replace("</parameter>", "</parameter>{{ '\\n' }}")),
    lines
);

2. Reject framing that the probe did not establish

crates/serve/src/dsml.rs:527 A compact template that calls raise_exception when tools[0].function.parameters.properties.location is undefined rejects this probe: its schema has no properties. Real requests supplying that property still render, but the fallback chooses Lines, passed to the scanner at api.rs:3893. A compact value \nSeoul\n</parameter>\n then reaches the client as "Seoul", losing both payload newlines.
Reject the unknown framing through the existing Unparsed/501 path now; otherwise each new template inherits this silent corruption. Replace the fallback:

framing().map_or(ToolFormat::Unparsed, ToolFormat::QwenXml)

Update the fallback documentation and the no-call test expectation:

assert_eq!(ToolFormat::of_template(no_call), ToolFormat::Unparsed);

Non-blocking

⚠ Remove failure history from the test comment: crates/serve/tests/qwenxml.rs:1128 recounts the previous 500. State the current test contract with /// MiMo's compact calls return the reference arguments in streamed and non-streamed responses.

Checked

Duplicates: the detector repeats the existing framing delimiters; the proposed fix reuses their owner.
Complexity: framing adds dispatch and probe extraction.
Silent failure: the framing fallback reaches state.tool_format, tool_scan and QwenScan.
Tests: static checks confirm header selection, the incomplete fixture delimiter and newline loss. Rust tests were not executed.
Gates: no thresholds relaxed or cases removed in the diff. FAIL-first mutants are reported in the PR body.
Escape catalog: C1–C4 do not match. No inference hot path changed.

Notes

The reported card run lacks the nvidia-smi line, both hashes and gate-command output required for GPU evidence.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

Filed outside this PR: #636

Comment thread crates/serve/src/dsml.rs Outdated
if let Some(spelling) = KvSpelling::of_template(source) {
ToolFormat::KvMarkup(spelling)
} else if qwen.iter().all(|tag| source.contains(tag)) {
ToolFormat::QwenXml(framing().unwrap_or(Framing::Lines))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A failed or unmatched probe does not establish Lines; reject the framing to avoid stripping compact payload newlines.

Suggested change
ToolFormat::QwenXml(framing().unwrap_or(Framing::Lines))
framing().map_or(ToolFormat::Unparsed, ToolFormat::QwenXml)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the last review:

  • Fixed: header examples no longer select the framing; detection reuses the scanner's complete delimiters at qwenxml.rs:103.
  • Fixed: unknown framing becomes Unparsed, reaching the existing 501 rejection at dsml.rs:527.
  • Fixed: the test comment states the current contract at tests/qwenxml.rs:1139.

Verdict: CLEAN: The increment addresses the previous findings and introduces no proven must-fix defect.

Non-blocking

⚠ Pin rejection of the incomplete delimiter: crates/serve/tests/qwenxml.rs:607 repairs the valid fixture, but a detector that drops the required closing newline still passes these assertions.
Keep the rejected boundary covered before more templates depend on it. Add this assertion beside the valid case:

assert_eq!(ToolFormat::of_template(&small("\n{{ v }}\n")), ToolFormat::Unparsed);

Checked

Duplicates: 1 renamed item checked; no duplicate framing owner. The dryer finalization pair was read; both functions are unchanged in this increment.
Complexity: crapper flagged no changed function; the increment changes probe selection and fallback behavior.
Silent failure: 2 parse/render error conversions followed; failed probes produce Unparsed and the server's named 501 rejection.
Tests: static inspection shows first-call selection and default-Lines mutants contradict the updated assertions; rejection of the incomplete delimiter is not asserted. Rust tests were not executed.
Gates: no tolerance or threshold moved; the no-call expectation now requires rejection.
Escape catalog: C1–C4 do not match. Only template probing changed; no inference hot path changed.

Notes

The reported card run lacks the nvidia-smi line, both commit hashes and gate-command output required for GPU evidence.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

midagedev and others added 2 commits October 22, 2026 10:04
MiMo-V2.6's chat template writes a parameter as <parameter=KEY>VALUE</parameter>, with no newlines. The Qwen3-Coder
parser read only Qwen3.6's newline framing, so every MiMo tool call (MOPD and RL; their templates are byte-identical)
ended in a 500, "expected a newline after <parameter=KEY>".

ToolFormat::QwenXml now carries a Framing, Lines or Compact, read once from the call the template renders. One parser
reads both: under Compact a value is the bytes between the two tags, as llama.cpp mainline's chat_parse_ref parses the
MiMo template's output ({"city":"Seoul"}, and "\nSeoul\n" when the model writes newlines). Lines is unchanged.

Tests: the two oracle outputs at every stream cut, the template's framing for MiMo and Qwen3.6, and a re-render of a
parsed MiMo call; FAIL-first on three mutants (framing forced to Lines, Compact read as Lines, no close-tag hold).
A served tool call on the MOPD file: 500 before, 200 with get_weather {"city":"Seoul"} after; Sage-A1.5 (Lines) 200.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s delimiters; an unread framing is Unparsed

A header example before the probe's call no longer picks the framing, and a
Lines match needs the newline after </parameter> the scanner consumes. A
template that spells the Qwen3-Coder tags but renders no call in either
framing is Unparsed (501) instead of a guessed Lines that would strip a
compact value's newlines. The probe's schema names its property, so a
template that reads it renders. qwen_framing is probe_framing (model-tax).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: carried from 22b0eee2, not re-reviewed.

The approval of 22b0eee2 stands for b5910554. This pull request's 2 commits are the same patches in the same order: git patch-id --verbatim (the changed lines, the lines around them and whitespace) and the subject are equal for every commit. That review ran under the reviewer instructions, tools and slag ledger that review this head, and it approved.

The base moved and also changed docs/serving.md, which this pull request changes too. Each of its hunks still applies with the same context lines.

A carry covers each patch's own lines and the lines around them. What the base changed elsewhere is covered by CI on this head and by the landing gates.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@midagedev

Copy link
Copy Markdown
Owner Author

Landing evidence at b591055 (rebased on f6e7fab):

  • Fixture batch, 24 gates from just narrow: DONE total=24 red=0 (wall 1209 s). 28 items deferred to the real tier.
  • Real tier: gate-gpu-qwen3-serve green at 22b0eee (193 PASS, 0 FAIL). It is the same parser as here; the rebase moved only kernels and a pin test.
  • Mac: cargo test -p bloomery-serve -- --include-ignored passed, except slots::hw_drafted_passes_interleave_across_slots. That test also fails 4 of 6 runs on the unchanged base (a timing flake, filed in the triage).
  • MOPD tool call before the fix: 500. After: 200 get_weather {"city":"Seoul"}. Sage (Lines framing): 200.

@midagedev
midagedev merged commit e9cdd25 into main Oct 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation serve The HTTP server: crates/serve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant