fix: filter own key events, fix RoomOptions None, wait for participant

- Skip bot own encryption_keys events in on_unknown handler
- Always pass valid RoomOptions to AgentSession.start()
- Wait up to 10s for remote participant to connect before starting pipeline

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-02-21 17:33:12 +02:00
parent 6e1e9839cc
commit 08f4e115b9
2 changed files with 19 additions and 6 deletions

5
bot.py
View File

@@ -370,9 +370,12 @@ class Bot:
await self._route_verification(room, event)
return
# Forward encryption key events to active voice sessions
# Forward encryption key events to active voice sessions (skip our own)
if event.type == ENCRYPTION_KEYS_TYPE:
if event.sender == BOT_USER:
return # ignore our own key events
room_id = room.room_id
logger.info("Got encryption_keys timeline event from %s in %s", event.sender, room_id)
vs = self.voice_sessions.get(room_id)
if vs:
content = event.source.get("content", {})

View File

@@ -214,12 +214,22 @@ class VoiceSession:
logger.info("Connected (E2EE=HKDF), remote=%d",
len(self.lk_room.remote_participants))
# Find the remote participant to link to
# Find the remote participant, wait up to 10s if not yet connected
remote_identity = None
for p in self.lk_room.remote_participants.values():
remote_identity = p.identity
logger.info("Linking to remote participant: %s", remote_identity)
break
if not remote_identity:
logger.info("No remote participant yet, waiting...")
for _ in range(100):
await asyncio.sleep(0.1)
for p in self.lk_room.remote_participants.values():
remote_identity = p.identity
break
if remote_identity:
break
if remote_identity:
logger.info("Linking to remote participant: %s", remote_identity)
# Voice pipeline — German male voice (Daniel)
self._http_session = aiohttp.ClientSession()
@@ -242,13 +252,13 @@ class VoiceSession:
logger.info("AGENT_SPEECH: %s", msg.text_content)
agent = Agent(instructions=VOICE_PROMPT)
room_opts = room_io.RoomOptions(
io_opts = room_io.RoomOptions(
participant_identity=remote_identity,
) if remote_identity else None
) if remote_identity else room_io.RoomOptions()
await self.session.start(
agent=agent,
room=self.lk_room,
room_options=room_opts,
room_options=io_opts,
)
logger.info("Voice pipeline started (voice=%s, linked_to=%s)", voice_id, remote_identity)