Repository navigation
Surface text stream status and handle stream read failures - #1508
Conversation
setupTextStream subscribed to each reader without an error handler, so
when a sender disconnected mid-stream the errored reader's DataStreamError
was reported by RxJS as an unhandled observable error — rethrown globally
from a timer and surfacing as an uncaught DataStreamError that no
application code could catch.
Give the subscribe full next/complete/error handling and model the result
on TextStreamData via a new `status` field ('pending' | 'complete' |
'failed'), with the error exposed on failed entries. A clean close marks a
stream complete; any read error marks it failed while keeping the text
accumulated so far. No error type is special-cased here — consumers such
as useTranscriptions decide what a partial or failed stream means.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 7128cb6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report 📦
|
Split the inline union into internal TextStreamDataCommon plus Pending/Complete/Failed variants and a Legacy (status?: never) member for backward compatibility, unioned as the exported TextStreamData. Variants stay unexported; only TextStreamData is public. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The chat text-stream handler in setupChat subscribed without an error handler, so a sender disconnecting mid-message errored the reader and RxJS rethrew it globally from a timer — the same uncaught DataStreamError that useTextStream had. Give that subscribe an error handler too. Every error is treated equally, with no special-casing by reason: text streams surface the failure through status, and chat has no such channel so it logs. The attachment byte-stream hang/leak is a separate failure mode and remains a follow-up. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Rather than logging chat stream read errors, model them in the data the same way TextStreamData does. ReceivedChatMessage becomes a discriminated union with a status of 'pending' | 'complete' | 'failed' (error exposed on failed), plus a legacy member with no status so the other construction sites keep type-checking. The chat text-stream subscribe now emits pending as the message streams, complete on a clean close, and failed (keeping the text that arrived) when the read errors — which also stops RxJS from rethrowing the error globally as an uncaught exception. Every error is treated the same; no reason is special-cased. LegacyReceivedChatMessage becomes a type intersection since an interface cannot extend a union. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Without an explicit return type, `send`'s inferred type narrowed the `const receivedChatMsg: ReceivedChatMessage` to the no-status (legacy) member of the new discriminated union and emitted it expanded inline, which broke the react api-extractor report. Annotating the return as `Promise<ReceivedChatMessage>` restores the named reference. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@1egoman The core fix works. The new Claude found a few follow-ups:
Do you want my to address claude to fix these on this branch? |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A text or chat stream that errors before emitting anything now adds no entry, matching how a stream that completes with no chunks is handled. Previously it surfaced an empty failed entry, which rendered as an empty chat bubble or agent transcript. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts resolve With attachments, mergeMap holds each chunk until an attachment resolves, so a stream that failed first had no emitted message (or a stale one) and its text was replaced by an empty string. Track the received text separately and use it for the failed message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Messages from send(), the legacy data-packet decoder, and the dataChannel chat send are whole when produced, so give them status: Complete rather than leaving them on the status-less variant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Streams now re-emit their message on complete/fail to update status, which the message-list merge treated as an edit, so every received message showed "edited". Only set editTimestamp when the text changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TextStreamData and ReceivedChatMessage changed from object types to unions, which breaks downstream `interface X extends ...`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
useSessionMessages built agent/user transcript messages from TextStreamData but dropped its status, so session UIs couldn't tell a transcript that was still streaming, complete, or cut off. Carry status (and error, when failed) onto the transcript messages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Nice thanks for that list @thomasyuill-livekit! I went through and fixed them, plus one other issue that was discovered along the way:
Let me know what you think of these updates and if there's anything else you think needs to be done to get this approved. |
|
@1egoman Thanks, the fixes cover all five points. Claude reviewed the updates and found three small things. None of them blocks the merge.
Review by Claude. |
…-Error failures In a merged transcription segment, an older reader that completed or failed after a newer one took over would mark the whole segment complete/failed and roll its streamInfo back. Ignore complete/error from a reader that no longer owns the entry. Also wrap non-Error read failures in an Error, as setupChat does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ving Each later chunk of a multi-chunk message changes its text, which the message-list merge treated as an edit. Only count a text change as an edit once the existing message has finished streaming. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@thomasyuill-livekit Sweet, would you be willing to approve this in its current state? Per your latest comment, I have fixed 1 (8773082) and 3 (8d9300c). I have left 2 unaddressed - I think keeping the cases distinct in each place is more ideal, because the disciminated union branches being seperate facilutates new use case specific fields being added to each more effectively. So I think a a big union of |
A chat or transcript message's status describes the message's delivery, not the text stream it happens to be carried on (locally sent and legacy messages are Complete without any received stream). Use a transport-neutral ReceivedMessageStatus on ReceivedChatMessage and the transcript messages, keeping TextStreamStatus for TextStreamData, and map between them in useSessionMessages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ReceivedChatMessage, the transcript messages, and TextStreamData are re-exported from components-react, but the enums needed to narrow them by status were not, so React users had to depend on components-core directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This PR bumps
Also bumped
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
Today, when a participant disconnects while one of its text streams is still open,
livekit-clienterrors the open reader with aDataStreamError(AbnormalEnd), by design.However,
setupTextStreamandsetupChatread each stream withfrom(reader).pipe(...).subscribe(next), which has no error handler. Any error that does surface is handled by this and ends up as an uncatchable global error.For voice-agent apps, an error fires whenever the agent leaves mid-segment (interrupted farewell, process exit, crash). That happens often enough to be a nuisance and to clog up error reporting.
This issue was already attempted in #1426, which has been dormant for a few months. That attempt aimed to fix everything within
setupTextStream, so it inherited a lot of extra complexity (e.g. attachments) and grew large. In this PR I've instead exposed the stream's status on the data itself (TextStreamData,ReceivedChatMessage, and the transcript messages fromuseSessionMessages). Any more complex error handling can then live in the hooks, not in the rx-heavy core.Changes
Streaming,CompleteandFailed.TextStreamStatusis forTextStreamData.ReceivedMessageStatusis for received messages (chat and transcripts); it doesn't reference text streams, since a message's status isn't tied to how it was carried. Both are re-exported from@livekit/components-react.TextStreamData(useTextStream/useTranscriptions) andReceivedChatMessage(useChat) are now discriminated unions onstatus. Failed entries also exposeerror, the error that ended the read.next/complete/errorhandling:Streaming, accumulating text as before.Complete; the text is whole.Failed, keeping whatever text arrived. Non-Errorvalues are wrapped in anError. For chat messages with attachments, the received text is kept even if the stream fails before the attachments resolve.CompleteorFailed. An older reader ending later doesn't override the newer one's status orstreamInfo.Complete: the local copy fromsend(), legacy data-packet chat messages, and thedataChannelchat send.editTimestamp. New chunks of a streaming message and status-only re-emits no longer do, so received messages aren't shown as "edited".useSessionMessagesnow carriesstatus(anderror) onto agent and user transcript messages.Failed. Any segment-level interpretation (e.g. treating a benignAbnormalEndafter a complete transcript as acceptable) is left to consumers.Compatibility
TextStreamDataandReceivedChatMessagechange from object types to unions. Each union keeps a status-less variant, so code that builds these objects without astatusstill type-checks. A downstreaminterface X extends ReceivedChatMessagestops compiling, though, so@livekit/components-coreis bumped asminor.Scope
Attachment byte streams are not given a status; only the text stream behind a chat message is tracked.
Tests
New tests drive
setupTextStreamandsetupChatwith readers that complete normally, error mid-stream, and error before emitting. They cover theStreaming → Completetransition, failed streams keeping their text and exposing the error, no entry for streams that fail before any chunk, text kept when a stream with attachments fails,send()returning aCompletemessage, noeditTimestampon status-only re-emits or new streaming chunks, older segment readers not overriding newer ones, and non-Errorfailures being wrapped. Nothing rethrows globally: the error-path tests fail on the unfixed code with the uncaught error.@livekit/components-core(132) and@livekit/components-react(36) suites pass; both packages typecheck and build, and the react api-check passes.