fix(llm): collapse system messages when plugin appends a single entry - #34267
Closed
kagura-agent wants to merge 1 commit into
Closed
fix(llm): collapse system messages when plugin appends a single entry#34267kagura-agent wants to merge 1 commit into
kagura-agent wants to merge 1 commit into
Conversation
The post-hook collapse condition checked `system.length > 2` but the
initial system array always has length 1 (all prompts are joined before
the plugin trigger). When a plugin pushes exactly one entry the array
becomes length 2, which does not satisfy `2 > 2`, so no collapse fires
and two separate {role: "system"} messages are sent — breaking
OpenAI-compatible providers.
Change the threshold to `> 1` so the collapse fires whenever a plugin
appends anything.
Closes anomalyco#34243
6 tasks
Contributor
Author
|
Hi 👋 Friendly check-in — this PR has been open for about a week. Would appreciate a review when you get a chance. Happy to rebase or make adjustments if needed. 🙏 |
Contributor
Author
|
Checking in again — this fix for system message collapsing has been open 9 days now. The change is minimal (single-entry system messages get merged into the initial system block instead of being appended as standalone entries). Happy to adjust anything if needed. 🙏 |
Contributor
Author
|
Closing per lifecycle policy — this PR has been open 12 days with no review despite two check-ins. Happy to reopen if there's interest in the fix. Thanks for the project! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #34243
Type of change
What does this PR do?
The post-hook collapse logic in
packages/opencode/src/session/llm/request.tscheckssystem.length > 2to decide whether to join plugin-appended entries into a single system message. However the initialsystemarray always starts at length 1 (all base prompts are pre-joined). When a plugin pushes exactly one entry viaexperimental.chat.system.transform, the array becomes length 2 — which does not satisfy2 > 2, so no collapse happens. This produces two separate{role: "system"}messages that OpenAI-compatible providers reject with:The fix changes the threshold from
> 2to> 1so collapse fires whenever any plugin appends to the system array.How did you verify your code works?
systemis initialized as[joinedPromptString](length 1). After plugin trigger with one push, length becomes 2. With> 1, the collapse path activates correctly.bun test --filter "trigger"— plugin trigger tests pass (2/2).bun test --filter "system"— system prompt tests pass (88/88).Screenshots / recordings
N/A — logic fix, no UI change.
Checklist