Skip to content

fix(mlx-stream): recover degraded call_<hex> tool-call emissions - #321

Merged
dahai80 merged 1 commit into
mainfrom
fix/textemit-recover-args-only
Nov 24, 2026
Merged

dahai80 merged 1 commit into
mainfrom
fix/textemit-recover-args-only

Conversation

@dahai80

@dahai80 dahai80 commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Problem

Engine-side degradation (dahai80/fusion-mlx#1694): under concurrent decoding load, a request occasionally emits its tool call as plain text in the shape

call_8a3b4f2e{"file_path": "/tmp/hg-T17/difftool.py"}

No tool name key, so the existing text-recovery patterns (all require a name) cannot match. The call never executes and the bench task typically times out. Observed in 2 of 4 full 27B bench runs (T14 + T17 slips in run 2026-11-23T09-18-37-611Z).

Fix

Add a last-priority extraction pattern in extractToolCallsFromText:

  • Locate \bcall_[0-9a-f]{6,}{ and extract the balanced JSON after it (handles { } inside string args, e.g. heredoc commands).
  • Infer the tool name from the argument signature, ordered so specific signatures win: Edit (old/new_string) → Write (content) → Bash (command) → WebSearch/WebFetch/Grep → Read (file_path).
  • Slips matching no known signature stay as visible text — no guessing.
  • Fresh toolu_ id generated, so no collision with a prior structured call that shares the slip id (T14's slip id was already consumed by a real executed call).
  • Runs last, so all well-formed formats keep priority. Shared by streaming and non-streaming paths.

Tests

Three new cases in tests/services/api/fusion-mlx-stream.test.ts, two using the verbatim slip texts from the T14/T17 bench transcripts:

  • Read recovery from call_8a3b4f2e{"file_path": ...}
  • Bash recovery with braces inside string args
  • Unknown-signature slip left as plain text

bun test: 1824 pass, 0 fail. typecheck, lint, bun run build clean.

🤖 Generated with Claude Code

Local engine (fusion-mlx #1694) occasionally emits a tool call as plain
text `call_<hex>{"arg": ...}` with no tool name when a concurrent decode
row is realigned. The call never executed and the agent task timed out.

Add a last-priority extraction pattern: balanced-JSON parse after the
call id, tool name inferred from the argument signature (Edit/Write
before Read since both carry file_path). Slips matching no known
signature stay as visible text instead of being guessed. A fresh
toolu_ id is generated so it cannot collide with a prior structured
call that shares the slip id.

Covered by both streaming (text buffer) and non-streaming response
paths, which share extractToolCallsFromText. Real slip texts from bench
transcripts T14/T17 (run 2026-11-23T09-18-37-611Z) are used as tests.

Co-Authored-By: Claude Code <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant