Repository navigation
fix(server-utils): Stop Vercel AI v2 models overflowing the stack on ai 6 - #26941
RulaKhaled wants to merge 2 commits into
Conversation
…ai 6 ai 6 wraps spec-v2 models in a get-only Proxy. Assigning our wrapped doGenerate/doStream onto it landed on the proxy target, so ai's forwarding closure and our wrapper called each other until the stack overflowed. Return a wrapping Proxy from the resolveLanguageModel hook instead of mutating the resolved model. Closes #26905 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
size-limit report 📦Compared: 4ed7ba1 (PR test merge using develop at d799281) Against: d799281 (develop) · base run #68208 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsAll optional checks were successful. 63 successful. See the run. Successful checks
|
…el methods Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f5829f9. Configure here.
| const modelCalls = container.items.filter( | ||
| span => | ||
| span.attributes[SENTRY_ORIGIN]?.value === 'auto.ai.vercelai' && | ||
| span.attributes[SENTRY_OP]?.value === 'gen_ai.generate_content', |
There was a problem hiding this comment.
Test uses literal span op
Low Severity
The new v2-model test compares the span op to the string 'gen_ai.generate_content' instead of the @sentry/conventions/op constant. This was flagged because the review rules require integration-test op assertions to use that export when it exists, matching how this file already uses SENTRY_OP and the usage-token constants. I flagged this because it was mentioned in the review rules file.
Triggered by learned rule: E2E span ops from @sentry/conventions
Reviewed by Cursor Bugbot for commit f5829f9. Configure here.


What
With
ai@6and a v2 provider (@ai-sdk/openai@2,@ai-sdk/google@2, ...), everygenerateTextandstreamTextcall failed withRangeError: Maximum call stack size exceededonce Sentry was loaded. These calls now work and still get theirgenerate_contentspans.Why
ai 6 wraps v2 models in a
Proxywith only agettrap. We assigned our wrappeddoGenerate/doStreamonto that proxy, the assignment landed on the model underneath, and ai's forwarding closure and our wrapper called each other forever. TheresolveLanguageModelhook now returns our ownProxyaround the model instead of writing onto it, the same pattern the Workers AI and Google GenAI integrations use.One tradeoff: inside
prepareStep, a v3 model is now our proxy rather than the user's object, somodel === myModelno longer matches. Keeping identity meant continuing to patch objects we don't own, which is what caused this bug.Closes: #26905
🤖 Generated with Claude Code