Repository navigation
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential duplicate found:
This appears to be addressing the exact same issue (dynamically loaded AI SDK V2 providers not preserving token usage). The titles and scopes are nearly identical. You may want to check if PR #50414 is already merged or if it covers the same fix. |
Veld101
force-pushed
the
fix-v2-provider-usage
branch
from
September 22, 2026 07:26
15f76a5 to
6b22c6d
Compare
3 of 6 tasks
Author
|
Superseded by #50797 on �2. dev is not where merges land (recent merges are overwhelmingly into |
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 #50338
Type of change
What does this PR do?
Dynamically loaded AI SDK V2 providers persisted zero token usage, which silently disabled automatic compaction.
session/llm.tspassed every resolved model throughwrapLanguageModel(...)with aspecificationVersion: "v3"middleware. That helper does not convert a V2 model; it returns a new object that hardcodesspecificationVersion: "v3"and forwardsdoStreamunchanged.streamTextthen callsresolveLanguageModel, sees"v3", returns the model as-is, and skips the AI SDK'sasLanguageModelV3compatibility proxy — which is what performsconvertV2StreamToV3on thefinishchunk. Usage (andfinishReason) never reached the session.The middleware was only doing one thing: rewriting
params.promptwithProviderTransform.message(...). That transform is a plainModelMessage[] -> ModelMessage[]function, andstreamTextalready accepts the same input shape through itsmessagesoption, so the transform can run at the call site and the model can be passed unwrapped.ProviderTransform.messagehandles both string and part-array content, so it does not depend on AI SDK's earlier normalization step.I confirmed the failure mode and the fix with a standalone probe against
[email protected]:V3 is unaffected by the wrapper, so unwrapping is safe for V3 and necessary for V2.
finishReasonwas lost alongside usage, which also brokefinish === "content-filter"handling and any other finish-reason branch for these providers.How did you verify your code works?
bun test test/session/llm.test.ts— 30 pass, 0 fail. This file asserts the outgoing payload for Anthropic-compatible, Gemini, and OpenAI Responses models, so it covers the movedProviderTransform.messagecall for the providers it exercises.bun test test/session/— 397 pass / 6 fail, identical to the base commit with this change stashed. The 6 failures are pre-existing 5s timeouts on Windows (stops quickly when aborted during retry backoff,glob tool keeps instance context during prompt runs, tworevert + compact workflowcases,tool execution produces non-empty session diff,stop after token overflow requests compaction) and are unrelated.bun typecheck— clean.prettier --writeapplied to the changed file.I did not add an automated regression test. Every provider fixture in the test suite resolves to a V3 SDK, so a test there passes with or without this fix — I verified that by stashing the change and watching the test still pass. Exercising the bug requires injecting a real
LanguageModelV2, which needs a custom provider loader the harness does not have yet. I would rather leave the suite honest than add a test that cannot fail.Screenshots / recordings
Not a UI change.
Checklist