Repository navigation
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Based on the search results, I found one related PR: #50540 - Why it's related: This PR is explicitly mentioned in the description of PR #50797 as "A V1 variant of the same fix is open as #50540. This PR is the |
1c2fabd to
3aec471
Compare
3aec471 to
49801f6
Compare
|
Confirmed the exact V2 finish-event failure this PR describes in a compiled OpenCode 2.0.31-based build with SAP AI Core. This is user-visible session interruption, not only missing usage: text streams, then LLMEvent.stepFinish rejects reason.normalized and the Session drain stops. A plugin-free production-bridge probe fails with V2 finish events and succeeds with V3 events. Full sanitized evidence and environment: #50338 (comment). Please prioritize review of the V2 compatibility fix. I have not applied or tested this PR locally. |
|
Thanks for the independent confirmation and the sanitized evidence, @ton618to. That matches the failure this PR targets: the V2 finish event rejects |
|
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 #50338
Type of change
What does this PR do?
Dynamically loaded providers that implement AI SDK
LanguageModelV2silently lose token usage, which also disables automatic compaction.packages/core/src/aisdk.tscallslanguage.doStream()directly and reads the result asLanguageModelV3StreamPart. It readsusage.inputTokens.total,usage.outputTokens.total,usage.outputTokens.reasoningandfinishReason.unified. A V2 provider reports flat counts ({ inputTokens: 82057, outputTokens: 4, totalTokens: 82061 }) and a bare reason ("stop"), so every one of those reads wasundefined. Usage reached the session as zero andSessionCompaction.requirednever saw the session approach the model's limit.The fix normalizes both shapes where provider stream parts enter:
Non-
finishevents are already shape-compatible — the AI SDK's own V2-to-V3 converter only rewritesfinish— so nothing else changes.asLanguageModelV3in theaipackage would do the same conversion, but it is not exported, so the normalization lives at the parse boundary instead.How did you verify your code works?
New test
keeps usage and finish reason from a LanguageModelV2 provider: a V2-shaped model (specificationVersion: "v2") reportsinputTokens: 82_057, outputTokens: 4, totalTokens: 82_061andfinishReason: "stop". The response keepsfinishReason: { normalized: "stop", raw: "stop" }and the token counts. Without the fix the test fails on finish-reason schema validation becausenormalizedisundefined.The full
packages/coresuite is 4736 pass / 27 fail. The failures reproduce on unmodifiedv2— I verified a sample with this change stashed — and are Windows environment issues (shell, git worktrees, config discovery), unrelated to this change.A V1 variant of the same fix is open as #50540. This PR is the
v2change for the report.Screenshots / recordings
Not a UI change.
Checklist