From 08f4e115b9c163fd335e60c1f081a89988ffe9aa Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Sat, 21 Feb 2026 17:33:12 +0200 Subject: [PATCH] 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 --- bot.py | 5 ++++- voice.py | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/bot.py b/bot.py index 932a585..15a79e7 100644 --- a/bot.py +++ b/bot.py @@ -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", {}) diff --git a/voice.py b/voice.py index ed264ed..badc941 100644 --- a/voice.py +++ b/voice.py @@ -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)