Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Dec 20, 2025

This PR attempts to address Issue #9551 regarding Kimi K2 Thinking native tool calls not working properly with OpenAI-compatible servers like ik_llama.cpp.

Problem

The original PR #9557 could not be applied to the current codebase because the code has been significantly refactored. Tool call handling now uses NativeToolCallParser instead of the original toolCallAccumulator pattern.

Solution

Modified NativeToolCallParser.processFinishReason() to emit tool_call_end events when ANY finish_reason is present and there are tracked tool calls that have started, not just when finish_reason === "tool_calls".

This ensures compatibility with various OpenAI-compatible servers including ik_llama.cpp that may send finish_reason values like "stop" instead of "tool_calls" when tool calls are made.

Changes

  • Updated processFinishReason() in src/core/assistant-message/NativeToolCallParser.ts
  • Added check for tracked.hasStarted to only emit end events for tool calls that have actually started
  • Added documentation comments explaining the compatibility fix

Testing

  • All existing tests pass
  • Ran NativeToolCallParser tests
  • Ran provider tests (lm-studio, xai, openrouter, roo)
  • TypeScript type checking passes
  • Lint checks pass

Feedback and guidance are welcome!

…alls

This fixes compatibility with OpenAI-compatible servers like ik_llama.cpp
that may send finish_reason values like "stop" instead of "tool_calls"
when tool calls are made.

The change modifies NativeToolCallParser.processFinishReason() to emit
tool_call_end events when ANY finish_reason is present and there are
tracked tool calls that have started, ensuring tool calls are properly
finalized regardless of the specific finish_reason value.

Closes #9551
@roomote
Copy link
Contributor Author

roomote bot commented Dec 20, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The changes correctly modify processFinishReason() to emit tool_call_end events for any finish_reason (not just "tool_calls"), improving compatibility with OpenAI-compatible servers like ik_llama.cpp. The added hasStarted check is a good defensive improvement that aligns with the existing finalizeRawChunks() implementation.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

3 participants