Skip to content

Declare the UTF-8 byte length in the sendText stream header - #1184

Merged
hiroshihorie merged 4 commits into
livekit:mainfrom
Stahgah:fix/utf8-send-text
Sep 1, 2026
Merged

hiroshihorie merged 4 commits into
livekit:mainfrom
Stahgah:fix/utf8-send-text

Conversation

@Stahgah

@Stahgah Stahgah commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Description
sendText() currently calculates the total stream size using text.codeUnits.length.

This does not correspond to the actual number of bytes produced when the text is encoded as UTF-8. As a result, messages containing non-ASCII characters such as accented characters or emojis can cause the receiver to reject the stream with:

StreamError: read length exceeded total length specified in stream header

For example, é is one UTF-16 code unit but requires two bytes in UTF-8.

Fix

Use the UTF-8 encoded byte length when setting the total stream size:

final textInBytes = utf8.encode(text);
final totalTextLength = textInBytes.length;

This ensures that the size declared in the stream header matches the actual UTF-8 payload size.

Testing

Tested with messages containing:

ASCII characters
Accented characters (é, à, è, etc.)
Emojis
Multibyte Unicode characters

Before this change, messages containing accented characters could trigger the StreamError. After the change, they are correctly received by the LiveKit Agents backend.

Related issue

Fixes #1054

@CLAassistant

CLAassistant commented Aug 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

@hiroshihorie hiroshihorie changed the title Fix/utf8 send text Declare the UTF-8 byte length in the sendText stream header Sep 1, 2026
@hiroshihorie
hiroshihorie merged commit b0e5db2 into livekit:main Sep 1, 2026
13 of 14 checks passed
rokk4 added a commit to rokk4/client-sdk-flutter that referenced this pull request Sep 1, 2026
Brings in three upstream commits:

  8827c32  Resolve a default audio session from engine state when no
           policy was pushed (livekit#1182)
  f014f69  Request microphone permission before audio capture starts (livekit#1183)
  b0e5db2  Declare the UTF-8 byte length in the sendText stream header (livekit#1184)

Upstream touched none of the files this fork patches, so the only conflict
was pubspec.lock (matcher, meta, test_api - all SDK-vendored). Resolved by
re-resolving with Flutter 3.47.2, the SDK the consuming app builds against.
The lock now differs from upstream by two lines: our flutter_webrtc
1.6.0+hotfix.1 pin, which the podspecs' WebRTC-SDK 144.7559.10 depends on.

The two audio commits are Apple-platform only (LiveKitPlugin.swift); they do
not overlap the Android audio-routing work in the app.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] sendText silently drops non-ASCII messages on receiver (emoji, Cyrillic)

3 participants