[PR #6054] (FIX) lm studio empty tool calls #11717

Open
opened 2026-02-16 18:16:39 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6054

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6054 **State:** open **Merged:** No --- 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.
yindo added the pull-request label 2026-02-16 18:16:39 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11717