fix(opencode): prevent spurious tool events from Qwen 3.7 Plus/Max via OpenRouter#33622
Open
BernhardGruen wants to merge 1 commit into
Open
fix(opencode): prevent spurious tool events from Qwen 3.7 Plus/Max via OpenRouter#33622BernhardGruen wants to merge 1 commit into
BernhardGruen wants to merge 1 commit into
Conversation
…uter
Qwen-Plus via OpenRouter sends spurious tool-input-delta and tool-input-end
events AFTER tool-result for the same call ID, causing:
- Empty tool names ("unknown") in UI
- SchemaError: Missing key at ["name"]
- Tool execution aborted (up to 15 per session)
Fix: Add guards in processor.ts to reject events for tool calls that are
not in ctx.toolcalls (i.e., already completed or unknown).
Added 3 integration tests in processor-effect.test.ts.
A/B tested with 3 runs per configuration:
- Original: 14/15/5 errors (✗-unknown/aborted/invalid)
- Guards only: 0/0/0 errors
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Finding: The PR #33622 references PR #32909 ("fix(session): keep AI SDK tool result names") as possibly related. According to the PR description, #32909 alone was insufficient to fix the issue (reducing errors from 14 to 6), but the guards added in this PR (#33622) are necessary and sufficient (reducing errors to 0). However, PR #32909 is a related PR that was already merged/discussed as a partial solution, not a duplicate. This PR (#33622) is the complete fix. No duplicate PRs found |
This was referenced Jun 24, 2026
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 #33618
Related
processor.tsguardsType of change
What does this PR do?
This PR fixes "unknown" / "invalid" tool call messages that occur repeatedly.
Problem
Qwen 3.7 Plus/Max (via OpenRouter) sends spurious
tool-input-deltaandtool-input-endevents that arrive AFTERtool-result/tool-errorfor the same call ID, violating the expected event sequence:This causes:
"") displayed in UISchemaError: Missing key at ["name"]errorsTool execution aborted(up to 15 per session)✗ unknown Unknown failederrorsRoot Cause
OpenRouter's proxy layer reorders events for streaming optimization. The processor in
processor.tsaccepted these spurious events and created phantom tool entries with no name and corrupted state.Solution
Added guards in
processor.tsto reject spurious events for already-completed tool calls:This is the minimal, sufficient fix per YAGNI principle.
How did you verify your code works?
I did multiple A/B tests (3 per run to increase significance) that compared OpenCode 1.17.9 using Qwen 3.7 Plus (via OpenRouter) with my development branch that contained only the fix.
A/B-Test Evidence
Tested with Qwen 3.7 Plus via OpenRouter, 3 runs per configuration:
Finding:
processor.tsguards are necessary and sufficient. Additionalai-sdk.tschanges provide no measurable benefit.Testing
processor-effect.test.tsScreenshots / recordings
Before fix: https://opncd.ai/share/XIq1kE7k
After fix: https://opncd.ai/share/X0zavMRl
Checklist
If you do not follow this template your PR will be automatically rejected.