Skip to content

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

Closed
MADEVAL wants to merge 1 commit into
anomalyco:devfrom
CyberSecureAgency:fix-system-collapse
Closed

fix(opencode): collapse plugin-pushed system messages into one#34322
MADEVAL wants to merge 1 commit into
anomalyco:devfrom
CyberSecureAgency:fix-system-collapse

Conversation

@MADEVAL

@MADEVAL MADEVAL commented Jun 28, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #34321

Type of change

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

What does this PR do?

When a plugin uses experimental.chat.system.transform to push additional system instructions, the collapse guard system.length > 2 was one too high. The initial array has 1 element and a plugin that pushes 1 entry makes it 2, so 2 > 2 never fired. The result was multiple {role: "system"} messages, which OpenAI-compatible providers reject.

The fix changes the guard from > 2 to > 1. The system[0] === header check still protects against intentional header replacement by plugins.

How did you verify your code works?

Added a test in transform.test.ts that simulates a plugin pushing to system and verifies the prepared messages array has exactly one system message containing the extra instructions. Traced the full code path: system array construction, plugin trigger, collapse guard, and message construction.

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 Duplicate Found

PR #34267: fix(llm): collapse system messages when plugin appends a single entry
#34267

This appears to be addressing the same issue—collapsing multiple system messages when plugins append entries. This PR likely covers the same fix for handling plugin-pushed system instructions.

@matchaxnb

Copy link
Copy Markdown

affected by this too.

@github-actions

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.

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.

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

2 participants