opencode icon indicating copy to clipboard operation
opencode copied to clipboard

(FIX) lm studio empty tool calls

Open leefaus opened this issue 11 months ago • 0 comments

Fixes https://github.com/sst/opencode/issues/4255

Problem

OpenCode hangs indefinitely when using LM Studio (and other OpenAI-compatible providers) that include empty tool_calls: [] arrays in responses. The AI SDK sees the tool_calls field and waits for tool execution, but since the array is empty, it never completes.

Solution

Added middleware to filter empty tool_calls arrays from API responses before they reach the AI SDK:

  1. Fetch-level filtering: Intercepts responses at the HTTP layer and removes empty tool_calls: [] when finish_reason is "stop". Works for both streaming (SSE) and non-streaming responses.

  2. Processor fallback: Cleans up any pending tool calls that were never invoked when finish_reason is "stop", handling edge cases where empty arrays slip through.

The fix is applied automatically to all @ai-sdk/openai-compatible providers, ensuring LM Studio and similar providers work correctly without requiring configuration changes.

leefaus avatar Dec 23 '25 18:12 leefaus