fix(provider): prevent spurious tool events from Qwen 3.7 Plus/Max (via OpenRouter)#33504
Closed
BernhardGruen wants to merge 1 commit into
Closed
fix(provider): prevent spurious tool events from Qwen 3.7 Plus/Max (via OpenRouter)#33504BernhardGruen wants to merge 1 commit into
BernhardGruen wants to merge 1 commit into
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Related PR FoundPR #32909: fix(session): keep AI SDK tool result names This PR is directly related to the current PR #33504. According to the PR description, #32909 was an insufficient upstream fix on its own—the A/B testing shows that #32909 alone only reduced errors from 14-15 down to 6, but this PR's guards are necessary and sufficient to eliminate all symptoms (0 errors). The PR documentation explicitly notes this relationship and how the two fixes work together. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
c54a9a5 to
c07db8a
Compare
…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
c07db8a to
c522da8
Compare
Author
|
Will create a new one. |
Author
|
New PR: #33622 |
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 #21090
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
If this is a UI change, please include a screenshot or recording.
Checklist
If you do not follow this template your PR will be automatically rejected.