Skip to content

fix(server): keep '/' in MiniMax M3 tool-call tag names - #3741

Merged
inureyes merged 4 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/minimax-m3-tool-keys-with-slash
Dec 4, 2026
Merged

inureyes merged 4 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/minimax-m3-tool-keys-with-slash

Conversation

@Jaeyeong-CHOI

@Jaeyeong-CHOI Jaeyeong-CHOI commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #3738.

The MiniMax M3 tool-call parser ended a tag name at /. M3 writes each parameter and each nested object key as its own namespaced element, so the tag name is a JSON object key, and keys with / are ordinary: aws:ResourceTag/team, aws:RequestTag/${TagKey}, application/json. Such a key reached the call's arguments cut at the /, and sibling keys that differ only after it folded into one array. A tag name now runs to the first whitespace or >. On well-formed tags that gives the same names as mlx-vlm after Neywa-Labs/mlx-vlm@2208690a (_TAG_NAME_RE = [^\s<>]+). Upstream applies that regex to everything between < and > and rejects the call when it does not match; this parser keeps its existing, more lenient handling of such tags (see Limits).

What changed

  • src/server/tool_calls/formats.rs, minimax_m3_read_tag: the name terminator drops / (and the > test, which could never fire because the slice already ends before >), keeping whitespace. The doc comment states the rule, cites the upstream commit, says where the parser stays more lenient than upstream (text after whitespace in a tag), and says what happens to a trailing /: <x/> reads as the name x/, as upstream, which has no self-closing form either. Before, <x/> read as x and then looked for a </x> that does not come, so neither version gave it a self-closing meaning.
  • Tests in the same file:
    • minimax_m3_object_keys_keep_slash_and_punctuation: upstream's four keys (aws:SourceAccount, aws:ResourceTag/team, aws:RequestTag/${TagKey}, application/json) under policy -> Condition -> StringEquals, with upstream's tool schema; the parsed arguments must equal the expected object exactly and carry no parse errors. The value is team-a where upstream's test uses true, so the test is about the key alone and does not depend on how a leaf with no schema of its own is read (upstream expects the string "true"; that reading is tracked in fix(server): MiniMax M3 coerces schema-less tool-call leaves that mlx-vlm keeps as strings, dropping leading zeros #3739, see Limits). The test's doc comment says so.
    • minimax_m3_slashed_keys_are_distinct_fold_and_end_at_whitespace: siblings aws:ResourceTag, aws:ResourceTag/team, aws:ResourceTag/env stay three keys; a repeated a/b/c still folds into an array; a key ending in / (path/) reads whole; whitespace still ends a name (<k/v type="s"> is the key k/v). That last case is mlxcel's existing leniency, not upstream's rule: upstream rejects <k/v type="s"> (invalid tag 'k/v type="s"') and with it the whole call. The test pins the behaviour main already had for such a tag, and its comments say it is mlxcel-only.
  • src/server/tool_calls/stream_parity_tests.rs, minimax_m3_slashed_object_keys_parse_the_same_streamed: three slashed keys through assert_parity, which compares the streamed path (every byte-boundary chunking, plus widths 1, 2, 3, 5 and 7) with the non-streamed parse, then checks the arguments. The stream filter has no tag scan of its own (it suppresses the namespaced block and hands the text to try_minimax_m3), so the fix reaches both paths through this one function.

Other callers: minimax_m3_read_tag is private and called only by minimax_m3_find_close and minimax_m3_scan_children; the <invoke name=...> opener is parsed separately and is unchanged. MiniMax M2, Qwen3-Coder, GLM-4.7 and LongCat use other grammars and only share the schema helpers, which this does not touch.

Complexity: unchanged; the name scan is still one pass over the tag.

Verification

Linux 7.0.0-1019-nvidia aarch64 (NVIDIA GB10, CUDA 13.0.88), rustc 1.97.1, --features cuda, --profile test-fast. Base 9402cf893. Commit tree b1674fab, which differs from tree 77d718be only in CHANGELOG.md (an entry since removed). The tests and checks below ran on tree 955138da, which differs from 77d718be only in comments (/// and // lines in src/server/tool_calls/formats.rs) and one CHANGELOG sentence (git diff 955138da 77d718be); cargo fmt --check, clippy and the tool_calls:: tests were re-run on dc7ae92d, and cargo fmt --check and the tool_calls:: tests again on 77d718be (it differs from dc7ae92d in one doc comment).

Tests

cargo test --locked --profile test-fast --features cuda --lib -- --test-threads=1 tool_calls::. The main arm is main plus the three new tests, with only the one-line fix in minimax_m3_read_tag reverted.

main + the new tests fix
formats::tests::minimax_m3_object_keys_keep_slash_and_punctuation FAIL: aws:ResourceTag/team gives {"policy": {"Condition": {"StringEquals": {"aws:ResourceTag": "team-a"}}}} pass
formats::tests::minimax_m3_slashed_keys_are_distinct_fold_and_end_at_whitespace FAIL: {"aws:ResourceTag": ["base", "a", "prod"], "a": ["x", "y"], "path": "p"} pass
stream_filter::stream_parity_tests::minimax_m3_slashed_object_keys_parse_the_same_streamed FAIL: keys aws:ResourceTag, aws:RequestTag, application (streamed and non-streamed agree; both cut) pass
tool_calls:: total 569 passed, 3 failed 572 passed, 0 failed

Re-run on tree dc7ae92d: 572 passed, 0 failed. Re-run on tree 77d718be: 572 passed, 0 failed.

Checks

  • cargo fmt --all -- --check
  • cargo clippy --locked --workspace --all-targets --features cuda -- -D warnings
  • python3 scripts/ci/check_used_by.py (used-by: OK, 78 top-level pub fn in 2 shared files, 57 annotated, 715 caller-file references resolved, 3498 Rust files scanned), bash scripts/ci/check_used_by_test.sh (all cases passed)
  • make verify-test-cuda, tree 955138da before and after: 18,894 passed, 2 failed, 578 ignored over 207 test result lines. Both failures were pre-existing on the base 9402cf893 and are unrelated to this change; current main fixes both (feat(speculative): add DeepSeek-V4.1 bundled DSpark drafter (#3262) #3686, test: restore MLX guard scan and no-GPU catalog test gates #3765):
    • tests/mlx_test_guard_coverage.rs mlx_evaluating_lib_tests_take_mlx_test_guard: src/vision/encoders/nemotron_h_nano_omni_tests.rs:276 pos_embed_resample_runs_in_f32 evaluates MLX without the guard. The new tests here evaluate no MLX arrays and are not listed.
    • tests/step3p7_parity.rs text_decode_delegates_sequence_local_native_batching: assertion failed: !wrapper.supports_padded_prefill().
      On unmodified main (9402cf893), cargo test --locked --profile test-fast --features cuda --test mlx_test_guard_coverage --test step3p7_parity -- --test-threads=1 fails both the same way (5 passed / 1 failed and 7 passed / 1 failed, same messages).

git merge-tree merges the commit onto current origin/main (5bf7b8628) without conflict. On the merged tree, the Python tooling tests (python3 -m unittest discover -s tests -p 'test_*.py'), the scripts/ci checks CI runs and cargo fmt --all -- --check pass.

Model run

No model run. The smallest MLX conversion in the family I found is mlx-community/MiniMax-M3.1-Flash-Text-3bit at 186.5 GB (MiniMaxAI/MiniMax-M3 is 854 GB, mlx-community/MiniMax-M3-4bit 241.5 GB), which does not fit a 121 GB GB10. The parser takes text and returns JSON, so the unit and stream-parity tests drive the whole changed path.

Limits

@Jaeyeong-CHOI
Jaeyeong-CHOI force-pushed the fix/minimax-m3-tool-keys-with-slash branch from 368a9b0 to 65f9e9b Compare December 3, 2026 20:31
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority labels Dec 4, 2026
@Jaeyeong-CHOI
Jaeyeong-CHOI force-pushed the fix/minimax-m3-tool-keys-with-slash branch from 65f9e9b to 2eb860e Compare December 4, 2026 06:23
A parser-level test for the slash-keeping tag names: an invoke to an undeclared tool whose body uses a slashed key is still dropped with an `unknown tool` error (the lablup#3690 reporting path), and a `<x/>` tag or an unclosed slashed key absorbs only the rest of its own invoke body, so the enclosing `</invoke>` is still found and the following invokes parse intact.

Refs lablup#3738
@inureyes

inureyes commented Dec 4, 2026

Copy link
Copy Markdown
Member

Maintainer hardening review

Reviewed against #3738. The one-line change in minimax_m3_read_tag matches the reference: Neywa-Labs/mlx-vlm@2208690a changes _TAG_NAME_RE to [^\s<>]+, and upstream decides open vs close by the </ prefix before the name, as this parser does, so a / inside a name can never turn an open tag into a close tag or vice versa. On well-formed tags the names are identical to upstream.

Checked and found no gap:

  • No loop or over-consumption: minimax_m3_find_close and minimax_m3_scan_children still advance past every tag they read, and the invoke body is bounded by its own name-matched </invoke> scan, so a <x/> or an unclosed slashed key can only absorb the rest of its own invoke body.
  • Streaming and non-streaming share try_minimax_m3; the PR's parity test covers every chunking.
  • fix(server): report undecodable tool calls across APIs #3690 reporting is unaffected: undeclared invoke names are rejected in finish_parse, which does not look at parameter keys.

Added (620e46c): parse_minimax_m3_slashed_keys_keep_undeclared_and_malformed_handling in parser.rs, pinning both points above through parse_tool_calls: an undeclared tool with a slashed key still yields an unknown tool error and no call, and a <x/> tag plus an unclosed <a/b> leave the following invokes intact. Merged current main (5057a47).

Validation (Linux aarch64, default features): cargo test --lib tool_call 643 passed, 0 failed (after the final merge); cargo clippy --all-targets -- -D warnings and cargo fmt --check clean. Scope kept to the tag-name rule; schema-less leaf handling stays with #3754.

@inureyes
inureyes merged commit 1a6b1e1 into lablup:main Dec 4, 2026
36 checks passed
inureyes added a commit to Jaeyeong-CHOI/mlxcel that referenced this pull request Dec 4, 2026
With lablup#3741 merged first, its port of mlx-vlm's test_object_keys_with_json_legal_punctuation_are_kept now uses upstream's value `true`, expecting the string "true" for all four keys under a tool schema. That covers the one-key test added here, so it is dropped.

Add minimax_m3_client_schema_walk_is_bounded: a 60-level anyOf nest parsed through serde_json (the request-body nesting limit is what bounds the new schema-kind recursion) still keeps the item list in schema context, and a self-referential `$ref` is never resolved, so its leaves take the schema-less rule (as in mlx-vlm and vLLM).

Refs lablup#3739, lablup#3754
inureyes added a commit that referenced this pull request Dec 4, 2026
…ol schema (#3754)

* fix(server): keep schema-less MiniMax M3 leaves as strings under a tool schema

mlx-vlm's MiniMax M3 parser reads a leaf that has no schema of its own in
"schema context" once the request declares tools: it stays the string the
model wrote, except `null`. Without tools it is JSON-decoded and otherwise
kept as written. mlxcel ran every such leaf through the shared loose
fallback, so with tools `true`, `42` and `02134` came back as `true`, `42`
and `2134` (the leading zero lost), and without tools `02134` still became
`2134`.

Carry mlx-vlm's `schema_context` flag down the M3 descent and read a
schema-less leaf (and mixed `$text`) with an M3-only helper. As in
mlx-vlm, a schema that gives no type to apply (`{}`, a description alone,
`Optional[Any]`) counts as no schema, a named child falls back to an
`additionalProperties` schema, and whether an `item` list keeps the
context follows mlx-vlm's schema-kind inference (`Optional[list]`,
`items` without `type`, `map`/`sequence`/`arr`). Leaves with a declared
type and the shared fallback used by MiniMax M2, Qwen3-Coder, GLM-4.7
and LongCat are unchanged.

Closes #3739.

* test: use upstream value for slashed M3 keys, pin bounded schema walk

With #3741 merged first, its port of mlx-vlm's test_object_keys_with_json_legal_punctuation_are_kept now uses upstream's value `true`, expecting the string "true" for all four keys under a tool schema. That covers the one-key test added here, so it is dropped.

Add minimax_m3_client_schema_walk_is_bounded: a 60-level anyOf nest parsed through serde_json (the request-body nesting limit is what bounds the new schema-kind recursion) still keeps the item list in schema context, and a self-referential `$ref` is never resolved, so its leaves take the schema-less rule (as in mlx-vlm and vLLM).

Refs #3739, #3754

---------

Co-authored-by: Jeongkyu Shin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority status:review Under review type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(server): MiniMax M3 tool-call parser truncates parameter names at "/"

2 participants