Repository navigation
Recover one turn when tool call arrives as plain text (local MLX small models) - #304
Merged
Merged
Conversation
Small local models served by fusion-mlx intermittently print a tool
call as plain assistant text (Read({...}), call_<id>{...}) instead of
emitting a tool_use block. The turn then looks like a finished text
answer, isResultSuccessful passes on the text block, and the session
ends after one such turn - the dominant failure mode in the
harness-gain suite on Qwen3-8B (see
docs/research/small-model-tool-calling-2026-11.md).
Add a recovery pass in the query loop before stop hooks: when the
final assistant text block matches a tool-call shape (python-call
style with a known tool name, call_<id>{ prefix, or <tools>{ wrapper)
and the provider is local MLX, feed the turn back with an explicit
format-correction meta message and continue the loop, mirroring the
existing max-output-tokens recovery pattern. Capped at 2 corrections;
attempt count derived from marker messages in history, no State field
added. Guarded by FUSION_MLX_ENABLED/FUSION_MLX_AUTO so cloud
providers are untouched.
New Transition reason 'tool_call_text_recovery' in
src/query/transitions.ts. 7 unit tests for the shape detector
(tests/utils/toolCallTextRecovery.test.ts); typecheck clean.
Co-Authored-By: Claude Code <[email protected]>
Co-Authored-By: Claude Code <[email protected]>
Count tool-call-shaped plain-text emissions in each harness run's
stdout (python-call style Name({...}), call_<id>{...}, <tools>{...}
wrapper). The metric is the standard instrument for the small-model
tool-calling reliability track (see
docs/research/small-model-tool-calling-2026-11.md section 4): it
already distinguishes fusion-mlx 0.10.67 (near-universal emission)
from 0.10.68 (occasional) and gives the trainer flywheel a
before/after number for MFC-style fine-tuning.
Aggregated as textEmissions in summary.json and logged per task.
Detector validated against real run logs: catches both observed
formats, zero false positives on a clean task log.
Co-Authored-By: Claude Code <[email protected]>
- Runner: add --dangerously-skip-permissions to the fusion-code driver. -p runs cannot grant write permissions interactively; the suite works in throwaway temp git repos with no network, so blanket-skip so the agent can actually attempt each task. - Query loop: FUSION_CODE_DEBUG_RECOVERY=1 prints the recovery-gate variables (isLocalMlx, aborted, attempts, toolNames, lastText) to stderr for field diagnosis of the tool-call-as-text recovery loop. E2E verified against fusion-mlx 0.10.68 + Qwen3-8B: recovery fires on every tool-shaped text turn, attempt cap (2) engages, Read-shaped calls recover to real tool_use; Edit-shaped calls re-emit as text (8B model limitation, not a harness bug). Co-Authored-By: Claude Code <[email protected]>
Qwen3-8B re-emits identical Edit-shaped text through all recovery corrections (verified E2E) while Read-shaped calls recover on the first. On the second correction, tell the model to prefer whole-file Write — partial edit arguments are the hard part for small models (aider editing-format finding: weak models do better whole than diff). Co-Authored-By: Claude Code <[email protected]>
T13's fixture contains an unfixed infinite-retry loop; pytest on the untouched file hangs forever (verified: killed by SIGKILL at the 60s cap). A verifier must fail, never hang, on an untouched fixture — same principle as the CRLF trap fixed in #297. Applies a 60s timeout to the pytest / command-exit / command-stdout verifiers; timeout counts as unresolved. Found when the opencode suite wedged 4h on T13 (its agent's edit was permission-rejected, leaving the fixture unfixed). Co-Authored-By: Claude Code <[email protected]>
--text and -t are the same flag in goose 1.60.2; passing both ate the prompt. OPENAI_HOST must not carry a /v1 suffix (goose appends the path). Provider/model/key/host now wired from BENCH_MODEL and the engine key like the fusion-code driver. Smoke-tested live: Qwen--Qwen3-8B answers via fusion-mlx. Co-Authored-By: Claude Code <[email protected]>
- GOOSE_MODE=approve is invalid headless (goose errors on first tool call); auto is the only valid non-interactive mode. Smoke-tested live. - T08 verifier trap: dedup refactor verified by behavior tests that pass on the untouched fixture (opencode T08 resolved=true was a false positive). New count-max verifier bounds duplicate-marker occurrences; untouched fixture fails at 3, deduped file passes at 1. Co-Authored-By: Claude Code <[email protected]>
This was referenced Nov 21, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Local MLX small models (Qwen3-8B class) intermittently emit a tool call as
plain text (
Read({file_path: ...}),call_<id>{...},<tools>{...})instead of a tool_use block. The turn then looks like a finished text
answer and the session ends after one such turn — task unsolved.
Root-caused as an engine-side sampling flake (fusion-mlx; dramatically
improved in 0.10.68 but not eliminated). Controlled experiments:
bare requests always return proper tool_calls; fusion-code's real 47k-char
system prompt triggers intermittent text emission. With
tool_choice: "required"the engine returns a well-formed blockdeterministically (grammar-constrained decoding) — but also returns a
non-streaming JSON body despite
stream: true(separate engine ask,filed in the fusion-mlx handoff doc).
Changes
src/query.ts,src/utils/queryHelpers.ts,src/query/transitions.ts): when the final assistant text matches atool-call shape (python-call style with a known tool name,
call_<id>{,<tools>{), feed the turn back with a format-correction meta messageinstead of ending the session. Mirrors the existing max-output-tokens
recovery pattern. Attempt count derived from marker messages in history
(no new State field). Capped at 2 corrections. Gated to local MLX
(
FUSION_MLX_ENABLED/FUSION_MLX_AUTO).benchmarks/harness-gain/run.ts): per-tasktextEmissionscount so engine regressions are visible from the suite.benchmarks/harness-gain/run.ts): pass--dangerously-skip-permissionsin-pmode — the suite runs inthrowaway temp git repos with no network; without it the agent dies on
the first Edit permission error.
FUSION_CODE_DEBUG_RECOVERY=1prints the recovery-gatevariables to stderr for field diagnosis.
Verification
detectToolCallShapedText(python-call style, multiline,call_ prefix, wrapper, unknown-name prose rejected, lowercase rejected,
empty) — all pass.
tool-shaped text turn, attempt cap engages, Read-shaped calls recover to
real tool_use and the task completes. Edit-shaped calls re-emit as text
after 2 corrections — 8B model limitation, not a harness bug (documented
in the research doc).
confirming no regression on non-emitting paths.
Research context
Full survey + ranked options:
docs/research/small-model-tool-calling-2026-11.md(docs branch).🤖 Generated with Claude Code