Skip to content

jinja, serve: select/reject filters, so Qwen3-Coder's template renders and its XML tool calls parse - #887

Merged
midagedev merged 4 commits into
mainfrom
mac-ctool
Oct 27, 2026
Merged

midagedev merged 4 commits into
mainfrom
mac-ctool

Conversation

@midagedev

Copy link
Copy Markdown
Owner

What

Qwen3-Coder-30B-A3B's tool calls work through bloomery-serve and bloomery-serve-metal. Before this, a chat request
with tools returned HTTP 500 chat template: |reject takes no arguments.

  • jinja: Jinja2's select, reject, selectattr and rejectattr are implemented: an optional test name with its
    arguments, and truthiness without one. The tests gain in, the comparisons and their aliases, odd, even and
    divisibleby, all through the one binop owner. An undefined input iterates as empty, as Jinja's Undefined does.
    None, a number or an unknown test is a named error.
  • serve: the format probe used to fail on |reject, so the tool format was Unparsed. It is now QwenXml(Lines),
    read by the existing qwenxml owner; there is no second parser. A boolean parameter reads true/false in any case
    (the model writes True). Any other text is NotBoolean.
  • Fixtures: the folder's template, byte for byte, and HF's own renders of it (render_jinja_template, the function
    apply_chat_template calls), with the script that made them.
  • Follow-ups from metal, serve: Qwen3-Coder-30B-A3B's MLX folder runs; a vocabulary that adds no BOS may name none #886's review:
    • the docs lose the tool-call limit;
    • docs/contrib/mac.md gets the Coder evidence row;
    • serve's BOS test leaves the tokenizer's refusal to the test that owns it.

Evidence

  • FAIL-first on the base code:
    • the jinja tests (is in takes no argument, |select takes no arguments: 35 pass, 5 fail);
    • the serve Coder tests (|reject takes no arguments; left: Unparsed right: QwenXml(Lines));
    • a mutant without the boolean branch, red on four rows.
  • Second M1 Pro [dev], bloomery-serve-metal --hf mlx-community/Qwen3-Coder-30B-A3B-Instruct-4bit:
    • a get_weather request returned tool_calls with {"city":"Seoul"} and finish_reason: tool_calls;
    • the tool's result came back as "The current weather in Seoul is clear with a temperature of 21°C.";
    • streaming returned 200.
  • cargo test -p bloomery-jinja -p bloomery-serve rc 0; clippy -D warnings.
  • Box, fixture tier, --round-ledger: the 73 gates tools/recipes.py reach selects, red 0 (2907 s).

AI use: written and checked with Claude Code.

🤖 Generated with Claude Code

midagedev and others added 3 commits October 28, 2026 05:06
… name

Jinja2's four filters: an optional test name and its arguments, truthiness
without one. The tests gain in, the comparisons and their aliases, odd, even
and divisibleby through the one binop owner. An undefined input iterates as
empty, as Jinja's Undefined does; none, a number or an unknown test is a named
error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The template's |reject made the format probe fail, so the tool format was
Unparsed; it is now QwenXml(Lines), read by the existing qwenxml owner. A
boolean parameter reads true/false in any case (the model writes True), and
any other text is NotBoolean. The template and HF's own renders of it are
fixtures, with the script that made them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…st leaves the tokenizer's refusal to its owner

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added documentation Improvements or additions to documentation model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja serve The HTTP server: crates/serve labels Oct 27, 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: the new elements owner duplicates the walk that for still carries as its own copy.

Must fix

1. for keeps a second copy of the walk that elements now owns

crates/jinja/src/lib.rs:1826 matches list, mapping keys, string characters and range items. crates/jinja/src/lib.rs:2603 (elements, added here) is the same match, and its doc comment says it is "the items a for walks". The for arm was not moved onto it. The comment is now false, and a new iterable kind needs two edits. The fix removes lines, so it is allowed.
Fix, in Node::For:

let mut items: Vec<Value> = match elements(self.eval(iter)?) {
    Ok(items) => items,
    Err(V::Undef | V::J(Value::Null)) => Vec::new(),
    Err(other) => return err(format!("cannot iterate {other:?}")),
};

Non-blocking

⚠ The PR body says "an undefined input iterates as empty, as Jinja's Undefined does". The code does the opposite for the four new filters: crates/jinja/src/lib.rs:2728 refuses Undef, and the test select_and_reject_name_their_refusals ({{ missing|rejectattr('x')|join }}) pins the refusal. The doc comment on select_filter states it, so the code is a choice. But a template that HF renders (an unset tools|select(...)) now gives HTTP 500. Fix the body, or let Undef through as join_filter does.

Checked

  • Duplicates: 12 new items checked (elements, select_filter, attribute_path, attribute_of, Step, test_operator, the odd/even/divisibleby arms, boolean, Kind::Bool, NotBoolean, the test arms). One hit: the for copy above. The comparison tests reuse binop, and the boolean arm reuses qwenxml. dryer: 0 pairs.
  • Complexity: select_filter 16 is a new function that is complex on its own, with one job (flag check, path, test name, loop). A split would add elements, so none is asked. test 15→21, parse_call 25→27, partial_call 13→16 and filter 42→43 are even growth (one arm each).
  • Silent failure: 7 sites followed. Undef and Null in the new filters, attribute_path (position too large is a named error), attribute_of (undefined parent is a named error, and spelled[i - 1] cannot underflow because items are never Undef), the test arity checks, divisibleby by zero (named error), the unknown test (named error), boolean None (NotBoolean or a break that parse_call then names). None reaches a consumer as a default.
  • Tests: mutants checked. Flipping keep turns the reject rows red. Swapping odd and even turns red. Replacing eq_ignore_ascii_case with == in boolean turns the True and FALSE rows red. Removing the Bool arm in parse_call turns red. The removed assertion in vocab.rs is owned by crates/tokenizer/src/lib.rs:1437.
  • Gates: no band, tolerance or lint level moved. Fixture count 13 matches the script's CASES.
  • Escape catalog: none matched (no shell code in the diff).
  • Performance: none; template render and tool-call parse are per request, not on the decode step.

Notes

  • The evidence is from an M1 Pro, not an NVIDIA card; no nvidia-smi line.

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

@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: the new commit moves for onto the elements owner, and nothing else changed.

Since the last review:

  • Must fix 1 (for keeps a second copy of the walk): fixed. crates/jinja/src/lib.rs:1826 now calls elements. Undef and Null give an empty list, any other refusal is named as before. The doc comment on elements is true again.
  • ⚠ Undefined input: still open, see below.

Non-blocking

⚠ The PR body says "an undefined input iterates as empty, as Jinja's Undefined does". That is true for for and join. It is false for the four new filters: crates/jinja/src/lib.rs:2722 refuses Undef by name, and the doc comment at line 2698 says so. A template that HF renders (an unset variable through |select(...)) gives HTTP 500 here. Fix the body, or map Err(V::Undef) to an empty list as join_filter does at line 2617.

Checked

  • Duplicates: the new commit adds no item. The for copy is gone. dryer: 0 pairs.
  • Complexity: none of the flagged functions is touched by the new commit.
  • Silent failure: 1 site followed. for over Undef or Null is empty as before; a number, a bool or a namespace is still cannot iterate. A mapping gives its keys in the same order (into_iter and keys walk the same map).
  • Tests: no test changed. The existing for rows still pin the Undef, Null and refusal arms; flipping the Err(V::Undef | ...) arm to an error turns an undefined-iteration row red.
  • Gates: none moved.
  • Escape catalog: none matched.

Notes

  • The evidence is from an M1 Pro, not an NVIDIA card; no nvidia-smi line.

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

@midagedev
midagedev merged commit 3721b36 into main Oct 27, 2026
7 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 model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja serve The HTTP server: crates/serve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant