Skip to content

feat: retry once on silent fusion-mlx streams - #334

Merged
dahai80 merged 1 commit into
mainfrom
silent-retry
Nov 25, 2026
Merged

dahai80 merged 1 commit into
mainfrom
silent-retry

Conversation

@dahai80

@dahai80 dahai80 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Problem

A local-engine stream that completes with no text and no tool_use (empty or thinking-only) is a degraded-engine slip, not a valid assistant turn. The agent loop previously continued to the next turn, burning one turn of the turn budget on nothing — expensive for small models with a 20-turn cap.

Change

  • Add withSilentStreamRetry in fusion-mlx-stream.ts: buffer leading non-content events (message_start, thinking deltas), flush them on first real content (zero added latency once content flows), and if the stream ends silently, discard the buffer and re-issue the request once. Thinking-only streams count as silent, mirroring Claude Code v2.1.331's silent-reply retry; adapted for the local engine where no non-streaming fallback endpoint exists.
  • Wire at both fusion-mlx entry points: streamFusionMlx generator and the createFusionMlxFetch interceptor (the path the agent loop actually uses).
  • Skipped on the stream-resume path: a re-issued request gets a new stream id and would invalidate the cursor/state side-channels wired to the original response.

Tests

4 new cases: content pass-through (single attempt), silent retry, thinking-only retry, give-up after second silent attempt. Full suite 1841 pass / 0 fail. Build green, doc validator 0 ERROR.

🤖 Generated with Claude Code

A local-engine stream that completes with no text and no tool_use
(empty or thinking-only) is a degraded-engine slip, not a valid
assistant turn. The agent loop previously continued to the next turn,
burning one turn of the budget on nothing.

Add withSilentStreamRetry: buffer leading non-content events
(message_start, thinking deltas), flush them on first real content,
and if the stream ends silently, discard the buffer and re-issue the
request once. Thinking-only streams count as silent, matching Claude
Code v2.1.331's silent-reply retry; adapted for the local engine where
no non-streaming fallback endpoint exists.

Wired at both fusion-mlx entry points (streamFusionMlx generator and
the createFusionMlxFetch interceptor used by the agent loop). Skipped
on the stream-resume path: a re-issued request gets a new stream id
and would invalidate the cursor/state side-channels.

Tests: 4 new cases (pass-through, silent retry, thinking-only retry,
give-up after second silent attempt). Full suite 1841 pass / 0 fail.

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