fix(vercelai): Avoid double-capturing v4 tool errors in orchestrion mode#22293
Open
mydea wants to merge 3 commits into
Open
fix(vercelai): Avoid double-capturing v4 tool errors in orchestrion mode#22293mydea wants to merge 3 commits into
mydea wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
size-limit report 📦
|
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
In orchestrion mode, a v4 Vercel AI tool error was reported to Sentry twice: once by the channel subscriber (
captureToolError, which captured the raw error mid-execution) and again when the SDK's wrappedAI_ToolExecutionErrorbubbled up to the app's error handling (express handler, or the global unhandled-rejection handler). The two events are different objects (raw error vs. wrapper), so Sentry's already-captured dedup didn't collapse them.This also caused a flaky test:
captures error in tool in express serverused.unordered()with a singleeventexpect and matched whichever of the two error envelopes arrived first — when the express-handler envelope won the race, the tool-tag assertions failed.Root cause
The channel subscriber's tool-
executewrapper always captured the thrown error and re-threw. That capture is required on v5, whereexecuteToolsswallows the rejection intotool-errorcontent so it never surfaces otherwise. On v4 the rejection instead bubbles out of theaicall, so it is already captured by the app's error handling — making the channel capture a duplicate. The OTel integration never had this problem because it doesn't self-capture v4 thrown tool errors; it lets them bubble.Changes:
'v1'model spec version already used elsewhere in the file). On v4 it marks the tool span as errored and lets the error bubble, matching the OTel path — so a single error event is reported._sentry_active_span, reusing the exact mechanism the OTel integration already uses (onunhandledrejectionrestores it at capture time). Without this, an unhandled rejection in a non-OTel (orchestrion) process would start its own trace instead of correlating to the transaction.WeakMap<Span, OperationErrorInfo>({ callSiteSpan, toolErrorsBubbleToCaller }) written once at operation start, rather than two parallel collections.AI_ToolExecutionErrorevent correlated to the transaction, in both orchestrion and OTel modes.Fixes the flaky
suites/tracing/vercelai/test.ts > ... > captures error in tool in express server [cjs].