MTPLX icon indicating copy to clipboard operation
MTPLX copied to clipboard

[BUG] edit_file tool-call arguments intermittently collapse to {} on Qwen3.6 27B (mode-independent, ~10% of edit turns)

Open druide67 opened this issue 4 months ago • 4 comments

Summary

On agentic tool-call sessions, edit_file-style calls (whose arguments carry an array of objects) intermittently arrive with empty arguments ({}), while simpler calls on the same session are fine. 2.1.0 fixed the MTP-specific half of this (nice work, details below); a mode-independent residual of about 10% of edit turns remains, and the evidence points at the chat template rather than the decode path.

Same disclosure as #169: measured with asiai (open-source bench tool, I build it), drafted with AI assistance, everything reproduces from the commands below.

Environment

Same as #169: M5 Max 128 GB, macOS 26.5.1, MTPLX 2.1.0 (venv-2.1.0, mlx 0.32.0), Youssofal/Qwen3.6-27B-MTPLX-Optimized-Speed (qwen3_next), serial scheduler, temp 0 suite (deterministic), --chat-template-profile local_qwen36, --ssd-session-cache off.

Numbers (8-turn deterministic agentic suite, 3 runs = 24 turns per cell)

Version Mode clean turns empty-args events edit turns clean
2.0.2 (measured 2026-07-14) MTP d3 75.0% 6 33%
2.0.2 AR 87.5% 3 66.7%
2.1.0 (yesterday) MTP d3 91.7% 2 77.8%
2.1.0 AR 87.5% 3 66.7%

Two reads: (1) the 2.0.2 MTP penalty is gone in 2.1.0, MTP now scores at or above AR on tool calls; (2) the residual failure rate is the same in both generation modes, so it does not look decode-side.

Why I suspect the template

The upstream Qwen3.6 chat template builds tool-call examples through the Jinja |items filter, which several non-Python renderers mishandle; the known symptom is exactly this one, nested object arrays collapsing to {}. Same model family served by llama.cpp with the community-fixed template (froggeric's, which replaces |items) scores 100% on the identical suite and hardware. I have not read how local_qwen36 renders, so this is a hypothesis with a matching fingerprint, not a diagnosis.

Repro

Any OpenAI-compat client exercising multi-turn edit_file calls with edits: [{search, replace}, ...] arrays shows it; the deterministic version is asiai bench --code --code-suite tool-call --runs 3 --url <server> and read count_empty_object_bug / arguments_raw per turn in the output JSON.

druide67 avatar Jul 17 '26 20:07 druide67

Traced the full path of tool-call arguments through the server to test the template hypothesis — results, and a PR that should make the residual localizable: #189.

The |items / template-rendering theory doesn't hold on MTPLX's path. History rendering is double-guarded: _template_tool_call strict-validates every history tool call's arguments into a dict (malformed → protocol error, not silent) before the template adapter runs, and MTPLX renders through real Jinja2, not the non-Python renderers where the |items bug lives. Nested edits:[{search,replace}] arrays roundtrip byte-intact through both layers — now pinned by regression tests. So the froggeric-template comparison on llama.cpp doesn't transfer here; the input side is clean.

The output side is where {} can appear, and it had five silent paths: missing-arguments defaults in two parse paths, an unparseable-bracket fallback, the final serialization catch-all, and swallowed native-parser exceptions that drop a call entirely. From your harness's viewpoint all five are indistinguishable from "the model emitted {}" — which is exactly why this issue has resisted localization.

#189 makes each substitution counted and categorized: mtplx_stats.tool_arguments_degraded + tool_arguments_degraded_reasons (missing_arguments / unparseable_arguments / non_object_arguments) plus tool_parser_exceptions, with genuine model-emitted {} explicitly not flagged. On your next asiai run, cross-reading count_empty_object_bug against these counters splits the residual cleanly: counters firing → parser losing real arguments (and the reason says where); counters silent → the model genuinely emits {} on those turns, which is a conditioning problem — and #188's strict tool-call mode (MTPLX_TOOL_CALL_STRICT=1) makes that unsamplable by construction, since the grammar won't allow an empty object when the tool schema marks properties required.

If you can rerun the 8-turn suite once #189 lands, the reasons breakdown would pin the mechanism within one run.

PhilipJohnBasile avatar Jul 20 '26 22:07 PhilipJohnBasile

Fixed in 2.3.0 (imminent). The root cause was ours, in two places: the streaming Qwen-XML tool parser silently discarded function-body text that wasn't wrapped in <parameter=> blocks — so a model writing its arguments as a JSON object inside the <function=...> envelope (the common slip on nested edits arrays) became a schema-valid call with empty arguments — and the final extraction lane fabricated {}-argument calls from bodies it couldn't read. Both now share one strict contract: a pure JSON-object body is the arguments payload; unreadable bodies stay visible content instead of becoming empty calls. Validated with a 168-turn live A/B on Qwen3.6-27B (zero collapses; baseline reproduced them) plus differential probes on the exact shapes that fabricated {} on 2.2.0. Thanks for the report — your ~10% frequency estimate matched what we measured.

youssofal avatar Jul 21 '26 05:07 youssofal

Reran our 8-turn tool-call suite against 2.3.0 (MTP depth 3 and AR lanes, 3 repeats each, temp 0.6, Apple M5 Max): zero fabricated {} arguments across all 48 turns, every call carried full valid JSON. Same suite on 2.0.2 showed 6/24 (MTP) and 3/24 (AR) empty-args calls. The remaining unclean edit turns are genuine model tool-choice slips (search_code before editing, or write_file rewriting the whole file instead of edit_file), well-formed in both lanes — the conditioning side of the split @PhilipJohnBasile described, nothing left on the parser side. Digging in also exposed a scoring bug in our own harness: well-formed wrong-tool calls were lumped into the empty-args count (fixed in druide67/asiai#85). Confirmed fixed from our side. Thanks for the fast turnaround.

druide67 avatar Jul 22 '26 16:07 druide67

Closing the loop from the reporter's side: confirmed fixed in 2.3.0 on the exact configuration this issue was filed against.

Setup: Youssofal/Qwen3.6-27B-MTPLX-Optimized-Speed, M5 Max 128 GB, mtplx 2.3.0 (clean venv), --chat-template-profile local_qwen36, serial scheduler, --ssd-session-cache off, deterministic temp-0 suite (asiai bench --code --code-suite tool-call --runs 3, asiai 1.31.0).

Mode turns empty-args events json_valid
MTP d3 24 0 100%
AR 24 0 100%

Against the filed history (2.0.2: 6 MTP / 3 AR events; 2.1.0: 2 / 3): zero events in 48 turns on 2.3.0, matching @druide67's independent 48/48. Every edit_file call carried a real payload (args_char_len 20–70+; no {} anywhere).

One scope note so nobody conflates metrics: current asiai also scores tool-selection accuracy (did the model pick the tool the suite expected), and this 27B sits at 58–75% on that judgment-level metric — but every such miss carries well-formed, non-empty arguments for a different tool, so it's model judgment, not this defect. #170's actual bug — structured arguments collapsing to {} — is gone in both generation modes. Thanks for the fast root-cause and fix.

PhilipJohnBasile avatar Jul 22 '26 23:07 PhilipJohnBasile