fix(opencode): collapse plugin-pushed system messages into one - #34322
fix(opencode): collapse plugin-pushed system messages into one#34322MADEVAL wants to merge 1 commit into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #34267: fix(llm): collapse system messages when plugin appends a single entry 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. |
|
affected by this too. |
|
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:
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. |
Issue for this PR
Closes #34321
Type of change
What does this PR do?
When a plugin uses experimental.chat.system.transform to push additional system instructions, the collapse guard
system.length > 2was one too high. The initial array has 1 element and a plugin that pushes 1 entry makes it 2, so2 > 2never fired. The result was multiple {role: "system"} messages, which OpenAI-compatible providers reject.The fix changes the guard from
> 2to> 1. Thesystem[0] === headercheck 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