Skip to content

Conversation

@leefaus
Copy link

@leefaus leefaus commented Dec 23, 2025

Fixes #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.

Introduced a new middleware to intercept API responses and filter out empty tool_calls arrays, preventing indefinite waits in the AI SDK. This includes handling both streaming and non-streaming responses. Additionally, updated the OpenAI-compatible provider to utilize this middleware and ensure proper cleanup of pending tool calls in session processing.
…ion processing

Updated the createFilteredFetch function to specify the return type and clarified the filtering mechanism for empty tool_calls. Removed unnecessary middleware wrapping in filterEmptyToolCalls, as filtering is now handled at the fetch level. Enhanced session processing to correctly handle empty tool_calls by updating the error state with the appropriate timestamps.
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.

OpenCode v1.0.25 Hangs Indefinitely with LM Studio + Qwen Models Due to Empty tool_calls Array

1 participant