Skip to content

Finish reason: tool_calls only when a call parsed (count rule); drop made_call - #27

Merged
eejd merged 1 commit into
localfrom
fix/finish-reason-count
Nov 15, 2026
Merged

eejd merged 1 commit into
localfrom
fix/finish-reason-count

Conversation

@eejd

@eejd eejd commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Switch the finish reason for tool calls to upstream's rule (the same as vLLM's resolve_finish_reason): a stop becomes tool_calls only when at least one call parsed (ToolCallFormatter.count). The fork's made_call rule also counted a call dropped as unparseable, so a client could get finish_reason: tool_calls next to an empty tool_calls list. made_call is removed; a response cut by max_tokens keeps length (both rules rewrite only stop).

Follows the discussion after #26 (kept made_call as an open owner decision). mlx-lm's server has no tool_choice handling, so the forced-named-tool case (OpenAI: stop) does not arise.

Tests

  • test_a_call_cut_short_is_dropped now asserts count == 0 (a dropped call is not a call); the other formatter tests assert count instead of made_call.
  • New handler-level tests through the real HTTP handler: test_a_call_that_fails_to_parse_does_not_make_a_tool_call_finish (stop, no calls; fails on the old rule) and test_a_call_cut_by_max_tokens_stays_length (complete call: tool_calls; cut before the end marker: length, no calls; it passes on the old rule too, because made_call only ever changed a stop, so it guards against a regression rather than proving this fix). Disabled in the draft-model subclass like the other scripted-sequence tests.
  • Full suite (mlx 0.32.4+local03, offline): 24 failed, 453 passed, 1 skipped, 1 error; the unchanged base gives 24 failed, 451 passed: identical failure sets (inherited numerical assertions and models not cached on this host), +2 passes are the new tests.

Not verified

  • No real-model run of a dropped call or a cut call; the handler tests script the token stream.
  • Not yet run: port rebuild and the dependents (dflash, rec, optiq) with this tag.

Independent review: approve. Probes through the real handler: a dropped wrapped call gives stop (was tool_calls with an empty list); a recovered bare call and a llama3 <|python_tag|> call ending at EOS still give tool_calls; no consumer (dflash, rec, optiq) reads made_call.

@eejd
eejd marked this pull request as ready for review November 15, 2026 13:24
@eejd
eejd merged commit efe1c32 into local Nov 15, 2026
1 of 2 checks passed
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