Uh oh!
There was an error while loading. Please reload this page.
fix(opencode): coalesce system messages for OpenAI-compatible providers - #42801
fix(opencode): coalesce system messages for OpenAI-compatible providers#42801ondrejch wants to merge 1 commit into
Conversation
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs FoundPR #38671 -
PR #39905 -
PR #19961 -
PR #16981 -
The most significant one is #38671, which you've already acknowledged in your PR description as a related prior approach to this problem. |
| ), | ||
| ...input.messages, | ||
| const systemMessages = | ||
| input.model.api.npm === "@ai-sdk/openai-compatible" && system.length > 1 |
There was a problem hiding this comment.
Wouldn't it be cleaner to include an optional system transformer principle in @ai-sdk/openai-compatible and to apply it?
It would be null for the other providers and would make this code generic as it would be sufficient to apply the pipeline.
Here you're introducing a bit of spaghetti, while this should definitely be part of the OpenAI compatible sauce.
There was a problem hiding this comment.
I kept this in LLMRequestPrep on purpose. @ai-sdk/openai-compatible is an upstream Vercel package; OpenCode only patches it for SDK bugs. The join is OpenCode policy (plugin system.transform + backends that reject multiple system messages), so it belongs next to the other model.api.npm request shaping, not in the SDK.
A generic transformer registry would also change Anthropic, which we are deliberately not doing (prompt-cache boundaries). Happy to move the join into ProviderTransform.message if a maintainer prefers that existing hook.
There was a problem hiding this comment.
my understanding is that it would not, because by default the "transformer" (not the best word i suppose with the domain we're working on) would be a map function that would default to being undefined.
But i see code just before already has openai-specific quirks to it so your change is fine by me although it's not to my taste. IANAM :-)
Enough1122
commented
Aug 21, 2026
Scope: coalesces multiple system messages into one only for
|
Issue for this PR
Fixes#34321
Related: #15059, #23656, #34322, #38671
Type of change
What does this PR do?
Plugins can append system instructions through
experimental.chat.system.transform, producing multiple system messages.OpenAI-compatible local backends such as SGLang/vLLM serving Qwen reject
that message shape with
System message must be at the beginning.This coalesces system blocks only for
@ai-sdk/openai-compatiblebeforedispatch. Other providers retain their existing multi-system behavior,
including Anthropic prompt-cache boundaries.
Unlike #38671, this does not globally merge adjacent system messages.
How did you verify your code works?
bun test test/provider/transform.test.tsfrompackages/opencodebun typecheckfrompackages/opencodeScreenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist