fix(server-utils): Surface deferred span-end errors on the channel payload - #24540
Merged
Merged
Conversation
…yload An aborted `streamText` left up to 7 unhandled rejections per abort. The deferred end's `end(error)` annotated the span but never marked the payload, so `beforeSpanEnd` took the success branch and enriched the span from the raw `StreamTextResult` — whose `usage`/`response`/`providerMetadata`/`text`/… are getters that derive a *fresh* promise from the already-rejected stream on every read, each one leaking an unhandled rejection. `AbortError` reasons are suppressed by name in `onUnhandledRejectionIntegration`, but an abort reason is whatever the caller passes (`@hono/node-server` passes a string), so the ignore list can't cover this. Fixes #24532 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
size-limit report 📦
|
Member
Author
|
bugbot review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit de5fc51. Configure here.
The abort path had no coverage at all, so nothing recorded that enrichment used to backfill `gen_ai.response.model` from the request's model id on a span whose model never responded. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Removes the cast in the deferred end: the field is part of the payload's real shape (Node writes it, and every channel context declares it), it was just missing from `TracingChannelPayloadWithSpan`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Aborting from inside `doStream` hits the same pre-first-chunk race without a timer, and the trailing sleep was not load-bearing — the scenario still fails pre-fix without it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Lms24
marked this pull request as ready for review
September 21, 2026 13:43
Lms24
requested review from
JPeer264 and
isaacs
and removed request for
a team
September 21, 2026 13:43
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.
This PR fixes a bug where an abort error thrown in a span with a deferred end, would cause unhandled rejections. This happened because we didn't properly attach the original error was thrown to the
dataobject from the tracing channel. We'd only update the span and its status but the Vercel AI instrumentation listening tobeforeSpanEndwouldn't go into the'error' in databranch due to the missingerrorobject.This PR now attaches the
errorobject or message and adds a regression test covering the scenario reported in #24532Reviewers, this is my first time doing basically anything at tracing channel level. Please let me know if this should be handled differently.
Fixes #24532