Fix: always send stream flag explicitly in LLM request body#438
Merged
altic-dev merged 2 commits intoJun 28, 2026
Merged
Conversation
…#295) Providers like Ollama and other OpenAI-compatible endpoints treat an absent `stream` key as `true`. When streaming was disabled, the key was omitted entirely from the request body, causing the server to return SSE-encoded chunks that the non-streaming parser couldn't handle, resulting in `LLMError.invalidResponse` and silent enhancement failure. Change `buildChatCompletionsBody` and `buildResponsesBody` to always include `stream` regardless of its value: - Before: `if config.streaming { body["stream"] = true }` - After: `body["stream"] = config.streaming` Also relaxes both methods from `private` to `internal` to allow direct unit testing. Four regression tests added in `LLMClientRequestBodyTests` asserting the stream key is present and correct for both endpoints and both streaming states.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug where Ollama and other OpenAI-compatible providers would silently fail AI enhancement when streaming was disabled.
When `config.streaming` was `false`, the `stream` key was omitted entirely from the JSON request body. Providers like Ollama treat an absent `stream` key as `true` — so they returned SSE-encoded chunks, the non-streaming parser couldn't handle them, and the call failed with `LLMError.invalidResponse`. The enhancement would silently fall back to the raw transcript.
The fix is to always send the key explicitly in both `buildChatCompletionsBody` and `buildResponsesBody`:
```swift
// Before — key absent when false; Ollama reads absence as true
if config.streaming {
body["stream"] = true
}
// After — always explicit
body["stream"] = config.streaming
```
Type of Change
Related Issues
Testing
Notes