Repository navigation
fix(ai): propagate telemetry subscriber stream replacements to execution result (#24970) - #24984
wasim-builds wants to merge 1 commit into
Conversation
|
@wasim-builds is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| const streamDesc = descriptors.stream; | ||
| if (streamDesc && 'value' in streamDesc) { | ||
| descriptors.stream = { | ||
| get() { | ||
| return (value as unknown as { stream: unknown }).stream; | ||
| }, |
|
Ran validation on GitHub Actions against
No competing open PRs for #24970, and no reproduction-only files in the diff. Script for the extra cases and the
|
aayush-kapoor
left a comment
There was a problem hiding this comment.
closing in favor of fix(ai): preserve telemetry stream replacements during credential redaction
Fixes #24970
Background & Root Cause
In
@ai-sdk/aisince 7.0.169,streamTextfails with:when an
ai:telemetrydiagnostics channel subscriber (such as@sentry/nodeordd-trace) interceptsctx.result.streaminasyncEndand wraps it via:Calling
pipeThroughlocks the original stream.When credentials are redacted via
redactTelemetryCredentials(result)before publishing the span,replacePropertiescloned the result object using property descriptors (Object.create(proto, descriptors)). Becausedescriptors.streamwas a static value property descriptor on the cloned object, assigningctx.result.stream = ...only updated the clone. Meanwhile,runWithTracingChannelSpanreturned the original unredactedexecutionResult, leaving itsstreamreferencing the original stream that was now locked by the subscriber'spipeThrough. When the SDK then attempted to read or pipeexecutionResult.stream, it threwTypeError [ERR_INVALID_STATE]: The ReadableStream is locked.Changes
replaceProperties(packages/ai/src/telemetry/redact-telemetry-credentials.ts), if the object has an ownstreamproperty, define getter/setter accessors targeting the underlying object soctx.result.stream = ...directly updatesexecutionResult.stream.runWithTracingChannelSpan(packages/ai/src/telemetry/tracing-channel-publisher.ts), verify aftertracePromisecompletes whethermessage.result.stream !== executionResult.stream(e.g. if a subscriber replaced theresultobject entirely), propagating the subscriber's tapped stream back toexecutionResult.stream.packages/ai/src/telemetry/tracing-channel-publisher.test.tsverifying both in-placectx.result.streamreplacement viapipeThroughand entirectx.resultreplacement.packages/ai/src/telemetry/tracing-channel.test.tsverifying fullstreamTextexecution with tools when anai:telemetrysubscriber tapsctx.result.streamviapipeThrough..changeset/telemetry-stream-replacement.mdforai.