Skip to content

fix(opencode): coalesce system messages for OpenAI-compatible providers - #42801

Open
ondrejch wants to merge 1 commit into
anomalyco:devfrom
ondrejch:fix/openai-compatible-system-messages
Open

fix(opencode): coalesce system messages for OpenAI-compatible providers#42801
ondrejch wants to merge 1 commit into
anomalyco:devfrom
ondrejch:fix/openai-compatible-system-messages

Conversation

@ondrejch

Copy link
Copy Markdown

Issue for this PR

Fixes #34321
Related: #15059, #23656, #34322, #38671

Type of change

  • Bug fix

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-compatible before
dispatch. 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?

  • Added regression coverage for OpenAI-compatible system coalescing.
  • Added regression coverage that Anthropic keeps separate system messages.
  • bun test test/provider/transform.test.ts from packages/opencode
  • bun typecheck from packages/opencode

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PRs Found

PR #38671 - fix(opencode): collapse plugin-pushed system messages into one

PR #39905 - feat(opencode): add system prompt debug command

  • Relates to system message handling and debugging, though not a direct duplicate.

PR #19961 - fix(session): fire system.transform before messages.transform

  • Related to the system transformation pipeline that your PR depends on.

PR #16981 - fix: handle system messages for non-Anthropic providers

  • Similar in spirit to your fix, addressing provider-specific system message handling.

The most significant one is #38671, which you've already acknowledged in your PR description as a related prior approach to this problem.

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.

Multiple system messages break OpenAI-compatible providers when plugins use system.transform

1 participant