Skip to content

Send lk.agent.session messages with one-shot send_bytes instead of stream_bytes - #7751

Merged
1egoman merged 3 commits into
mainfrom
fix/session-transport-send-bytes
Oct 18, 2026
Merged

1egoman merged 3 commits into
mainfrom
fix/session-transport-send-bytes

Conversation

@1egoman

@1egoman 1egoman commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

RoomSessionTransport.send_message now sends each lk.agent.session message with the one-shot LocalParticipant.send_bytes instead of opening an incremental stream_bytes stream per message.

With stream_bytes, an incremental stream always results in three packets being sent on the reliable data channel (header, chunk, trailer) and is never compressed.

With send_bytes the SDK knows the whole payload up front, so for receivers that support data streams v2 it can send a small message as a single inline packet, and compress a large one.

Why it matters

Session events are small and frequent, and today they go to every participant in the room, because the room session host is created with no remote identity. Measured against a JS client (clientProtocol of 3), one agent turn sent ~95 session messages: 89× session_usage_updated, 4× agent_state_changed, 2× conversation_item_added. On the client's data channel:

data channel ↓ per agent turn
stream_bytes (today) ~52 KB / 354 messages
send_bytes (this PR) ~37 KB / 170 messages (−29% bytes, −52% messages)
no session host at all ~11 KB / 83 messages

On constrained mobile links, that traffic queues ahead of RPCs and transcriptions on the reliable channel. That's the head-of-line blocking behind customer reports of agent → client RPC connection timeouts.

TODO

1egoman and others added 2 commits October 12, 2026 12:21
RoomSessionTransport opened an incremental byte stream per session message,
which always costs a header, a chunk and a trailer packet on the reliable data
channel and is never compressed. Session events are small and frequent (~90
per agent turn, mostly session_usage_updated), so this was a large share of
the data sent to every participant.

LocalParticipant.send_bytes knows the whole payload up front, so the SDK can
deliver a small message as a single inline packet, and compress a large one,
for receivers that support data streams v2. Measured against a protocol-3 JS
client, one agent turn dropped from ~52 KB / 354 to ~37 KB / 170 data channel
messages.

Requires livekit-rtc with LocalParticipant.send_bytes (livekit/python-sdks
feat/rtc-send-bytes); the livekit pin must be bumped once that is released.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@1egoman 1egoman changed the title perf(voice): send lk.agent.session messages with one-shot send_bytes Send lk.agent.session messages with one-shot send_bytes instead of stream_bytes Oct 11, 2026
1.1.21 exposes LocalParticipant.send_bytes, which RoomSessionTransport
now uses for lk.agent.session messages.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@1egoman
1egoman marked this pull request as ready for review October 18, 2026 21:02
@1egoman
1egoman requested a review from a team as a code owner October 18, 2026 21:02

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@1egoman
1egoman merged commit a436d83 into main Oct 18, 2026
25 checks passed
@1egoman
1egoman deleted the fix/session-transport-send-bytes branch October 18, 2026 23:11
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.

3 participants