Skip to content

feat(opencode): respect provider/model streaming: false to disable response streaming - #31357

Closed
sebdanielsson wants to merge 2 commits into
anomalyco:devfrom
sebdanielsson:feat/disable-streaming-option
Closed

sebdanielsson wants to merge 2 commits into
anomalyco:devfrom
sebdanielsson:feat/disable-streaming-option

Conversation

@sebdanielsson

@sebdanielsson sebdanielsson commented Jun 8, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #785

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Some OpenAI-compatible backends either don't support streaming or return broken streamed output. In my case a self-hosted vLLM (Gemma) corrupts streamed tool-call arguments (duplicates characters), so every edit comes back garbled. The existing options.streaming config wasn't actually consumed, so there was no way to opt out.

This makes options.streaming: false (per-model or per-provider) actually work. When set, it adds the AI SDK's simulateStreamingMiddleware, which calls doGenerate (stream: false on the wire) and replays the result as a simulated stream — so the rest of the pipeline is unchanged. Defaults to streaming on, so existing behavior is untouched.

{ "provider": { "vllm": { "options": { "streaming": false } } } }

Only covers the default AI SDK path. The experimental experimentalNativeLlm runtime is a separate path and isn't handled here.

How did you verify your code works?

  • Added a test in test/session/llm.test.ts that sets streaming: false and has the mock server return a non-streaming JSON completion. It only parses if the request was non-streaming (a streamed request expects SSE and fails), and asserts body.stream isn't true.
  • bun test test/session/llm.test.ts -> 27 pass, plus typecheck and oxlint clean.

Screenshots / recordings

No UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings June 8, 2026 12:30
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds a configuration-based way to disable true provider streaming while keeping the rest of the pipeline streaming-compatible by simulating a stream.

Changes:

  • Add simulateStreamingMiddleware() to opt out of on-the-wire streaming when options.streaming === false.
  • Add a test asserting that provider requests are not made with stream: true when streaming is disabled.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/opencode/src/session/llm.ts Adds streaming opt-out logic and conditionally injects simulated streaming middleware.
packages/opencode/test/session/llm.test.ts Adds coverage to confirm provider requests are non-streaming when configured.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/opencode/src/session/llm.ts
Comment thread packages/opencode/test/session/llm.test.ts
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@sebdanielsson
sebdanielsson force-pushed the feat/disable-streaming-option branch from 0da9544 to fda049c Compare June 8, 2026 13:40
@sebdanielsson

Copy link
Copy Markdown
Author

Just this version in a GitHub Action workflow, and it worked without the stream-stripping proxy we're currently using to get around this limitation. 👍

@lmeyerov

lmeyerov commented Jun 8, 2026

Copy link
Copy Markdown

We hit the Bedrock side of this. Meta's Llama models on Bedrock reject tool use over /converse-stream (ValidationException: This model doesn't support tool use in streaming mode), so with tools they're unusable today. streaming: false fixes it: verified against real Llama 4 Maverick, which then made native tool calls and answered correctly, with streaming models unaffected (Claude on Bedrock still streamed, test/session/llm.test.ts green).

One Bedrock-specific gap I ran into: the prompt-transform middleware only runs for args.type === "stream", so under doGenerate the Bedrock message transform gets skipped. Widening that guard to also run when streaming is off makes the Bedrock path correct under streaming: false. Happy to send a patch against this branch.

@sebdanielsson
sebdanielsson force-pushed the feat/disable-streaming-option branch from fda049c to b96bf57 Compare June 8, 2026 22:35
@sebdanielsson

Copy link
Copy Markdown
Author

We hit the Bedrock side of this. Meta's Llama models on Bedrock reject tool use over /converse-stream (ValidationException: This model doesn't support tool use in streaming mode), so with tools they're unusable today. streaming: false fixes it: verified against real Llama 4 Maverick, which then made native tool calls and answered correctly, with streaming models unaffected (Claude on Bedrock still streamed, test/session/llm.test.ts green).

One Bedrock-specific gap I ran into: the prompt-transform middleware only runs for args.type === "stream", so under doGenerate the Bedrock message transform gets skipped. Widening that guard to also run when streaming is off makes the Bedrock path correct under streaming: false. Happy to send a patch against this branch.

Feel free to send it, thanks for testing!👍

@michaeljguarino

Copy link
Copy Markdown

+1 this, we're also dealing with an internal gateway without stream support, and would be great to have an opencode level shim for that.

@sebdanielsson
sebdanielsson force-pushed the feat/disable-streaming-option branch 2 times, most recently from b3a6005 to b8f9017 Compare June 18, 2026 11:24
sebdanielsson and others added 2 commits July 3, 2026 12:40
…ponse streaming

Some OpenAI-compatible backends don't support streaming or return broken
streamed output (e.g. self-hosted vLLM corrupting streamed tool-call args).
The existing options.streaming config wasn't consumed, so there was no way
to opt out.

Honor options.streaming:false (per-model or per-provider) by adding the AI
SDK's simulateStreamingMiddleware, which calls doGenerate (stream:false on
the wire) and replays the result as a simulated stream, leaving the rest of
the pipeline unchanged. Defaults to streaming on.

Fixes anomalyco#785

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… stream values

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sebdanielsson
sebdanielsson force-pushed the feat/disable-streaming-option branch from b8f9017 to 2a1004a Compare July 3, 2026 10:40
@sebdanielsson

Copy link
Copy Markdown
Author

FYI: For those of you having problem using Gemma 4 31B on vLLM with OpenCode. Updating vLLM to 0.24.0 and using the vLLM example template solved all of our issues.

@TomLucidor

TomLucidor commented Jul 8, 2026

Copy link
Copy Markdown

@sebdanielsson so the same thing with E2B/E4B? Is it really just a bad template/parsing issue on Google's side, or (local) inference engine, or harness/scaffold side? NousResearch/hermes-agent#6626 (comment) NousResearch/hermes-agent#19887

@sebdanielsson

sebdanielsson commented Jul 8, 2026

Copy link
Copy Markdown
Author

@sebdanielsson so the same thing with E2B/E4B? Is it really just a bad template/parsing issue on Google's side, or (local) inference engine, or harness/scaffold side? NousResearch/hermes-agent#6626 (comment) NousResearch/hermes-agent#19887

Not my area of expertise but I think both. Many fixes for Gemma 4 landed in the latest 0.24.0 release. Have you tried it + using the vLLM provided template?

This is the arguments we start vLLM with:
vllm-project/vllm#39043 (comment)

Might be worth testing with the smaller MoW models.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@jeremy-london

Copy link
Copy Markdown

This should be merged its blocking AWS Bedrock support for LLama models. Please consider

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is there a way to disable streaming mode?

6 participants