KeyError in Room._on_room_event for local_track_published (track SID missing from local_participant.track_publications)
Bug Description
KeyError logged and bubbles through _listen_task’s error logging
error running user callback for local_track_published: room_handle: 6 local_track_published { track_sid: "TR_AMLxYxTEBo2L7c" } Traceback (most recent call last): File "/home/appuser/.venv/lib/python3.12/site-packages/livekit/rtc/room.py", line 589, in _listen_task self._on_room_event(event.room_event) File "/home/appuser/.venv/lib/python3.12/site-packages/livekit/rtc/room.py", line 636, in _on_room_event lpublication = self.local_participant.track_publications[sid] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^ KeyError: 'TR_AMLxYxTEBo2L7c'
Expected Behavior
Event should be ignored or publication map populated; shouldn’t raise
Reproduction Steps
- Start LiveKit Agents voice session;
- User speaks immediately after join;
- SDK emits local_track_published before the publication map is populated
- KeyError logged from Room._on_room_event
Operating System
Linux
Models Used
No response
Package Versions
livekit-agent=1.3.6
Session/Room/Call IDs
No response
Proposed Solution
Additional Context
No response
Screenshots and Recordings
No response
Hi, I tried reproducing this and had no luck. Do you get this error consistently, and do you set up a listener for local_track_published or does it happen on its own? Also, what version are you using for livekit?
Hi, I tried reproducing this and had no luck. Do you get this error consistently, and do you set up a listener for
local_track_publishedor does it happen on its own? Also, what version are you using forlivekit?
It happens on its own, from time to time.
I'm using 1.3.6. Not sure if it's a new issue since I only have error logs restored in recent few weeks.
We just encountered this after what appears to be an automatic reconnect of the socket. See attached logs leading up to the error. This was running 1.3.8 on LK Cloud.