The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): the voice ack resolves and plays on the answering bot
Tekniumfabf7e718882
diff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex 5b75fff23a3..1ef76eb432a 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -1129,6 +1129,19 @@ class GatewayTurnMixin(GatewayTurnPrepareMixin, GatewayTurnHygieneMixin, Gateway"interim_assistant_messages_enabled", "needs_progress_queue", "_native_slack_task_cards",)+ def _voice_ack_guild_for(self, source: SessionSource) -> Optional[int]:+ """Guild whose voice call is bound to *source*'s text channel on the bot that ANSWERS it.+ Under multiplexing a secondary profile's call lives on its own adapter, never the default's+ (#139345): reading ``self.adapters`` would miss its call or borrow the primary bot's."""+ if source.platform != Platform.DISCORD:+ return None+ adapter = self._delivery_adapter_for(source)+ bound = getattr(adapter, "_voice_text_channels", None)+ if not (isinstance(bound, dict) and hasattr(adapter, "voice_mixer_active")):+ return None+ return next((gid for gid, channel in bound.items()+ if str(channel) == str(source.chat_id) and adapter.voice_mixer_active(gid)), None)+def _run_agent_build_turn_context(self, disp: GatewayRunner._RunAgentDisplay, AIAgent: Any, *, message: str, source: SessionSource,session_key: Optional[str], run_generation: Optional[int], **turn_params,@@ -1139,15 +1152,7 @@ class GatewayTurnMixin(GatewayTurnPrepareMixin, GatewayTurnHygieneMixin, Gatewayfrom gateway.run_turn_runner import TurnRunner# Discord voice "verbal ack" on the FIRST tool call (discord.voice_fx.enabled): resolve the# guild whose voice connection is bound to this text channel (mirrors DiscordAdapter.play_tts).- _voice_ack_guild: list[Optional[int]] = [None]- if source.platform == Platform.DISCORD:- _va = self.adapters.get(Platform.DISCORD)- _vtc = getattr(_va, "_voice_text_channels", None)- if isinstance(_vtc, dict) and hasattr(_va, "voice_mixer_active"):- _voice_ack_guild[0] = next(- (_gid for _gid, _tc in _vtc.items() if str(_tc) == str(source.chat_id) and _va.voice_mixer_active(_gid)),- None,- )+ _voice_ack_guild: list[Optional[int]] = [self._voice_ack_guild_for(source)]# Auto-cleanup of temporary progress bubbles needs a real ``delete_message`` (getattr on the# type: a fake adapter without it means "can't delete", not a crash).diff --git a/gateway/run_turn_progress.py b/gateway/run_turn_progress.pyindex 758f7d3a85c..0b246ea4b8f 100644--- a/gateway/run_turn_progress.py+++ b/gateway/run_turn_progress.py@@ -790,7 +790,8 @@ class GatewayTurnProgressMixin:if ctx._voice_ack_fired[0] or ctx._voice_ack_guild[0] is None or not ctx._run_still_current():returnctx._voice_ack_fired[0] = True- adapter = self._runner.adapters.get(Platform.DISCORD)+ # The bot whose call the guild was resolved on (#139345), not the default profile's.+ adapter = self._runner._delivery_adapter_for(ctx.source)if adapter is None or not hasattr(adapter, "play_ack_in_voice"):returntry:diff --git a/tests/gateway/test_prompt_tail_freeze.py b/tests/gateway/test_prompt_tail_freeze.pyindex 21de5299605..8701261e2fe 100644--- a/tests/gateway/test_prompt_tail_freeze.py+++ b/tests/gateway/test_prompt_tail_freeze.py@@ -304,6 +304,61 @@ class TestVoiceChannelSidecarNoteMultiplexed:assert note is None+class _AckAdapter:+ """A Discord bot bound to text channel c1's voice call in guild 77."""++ def __init__(self, bound):+ self._voice_text_channels = {77: "c1"} if bound else {}+ self.acks = []++ def voice_mixer_active(self, guild_id):+ return guild_id in self._voice_text_channels++ async def play_ack_in_voice(self, guild_id):+ self.acks.append(guild_id)+++class TestVoiceAckFollowsTheAnsweringBot:+ """#139345, same class: the first-tool-call verbal ack resolves its guild on, and plays through,+ the bot whose call is bound to the turn's text channel, not the default profile's bot."""++ def _runner(self, primary_bound, secondary_bound):+ primary, secondary = _AckAdapter(primary_bound), _AckAdapter(secondary_bound)+ runner = _make_runner(adapters={Platform.DISCORD: primary})+ runner._profile_adapters = {"otto": {Platform.DISCORD: secondary}}+ runner.config = SimpleNamespace(multiplex_profiles=True)+ return runner, primary, secondary++ def test_secondary_in_call_gets_its_guild(self):+ runner, _primary, secondary = self._runner(False, True)+ source = _secondary_source()+ source._transport_adapter_ref = lambda: secondary+ assert runner._voice_ack_guild_for(source) == 77++ def test_secondary_never_borrows_the_primary_call(self):+ runner, _primary, secondary = self._runner(True, False)+ source = _secondary_source()+ source._transport_adapter_ref = lambda: secondary+ assert runner._voice_ack_guild_for(source) is None++ def test_ack_plays_through_the_answering_bot(self):+ from gateway.run_turn_progress import GatewayTurnProgressMixin+ runner, _primary, secondary = self._runner(True, True)+ source = _secondary_source()+ source._transport_adapter_ref = lambda: secondary+ scheduled = []+ progress = SimpleNamespace(+ _runner=runner,+ _ctx=SimpleNamespace(_voice_ack_fired=[False], _voice_ack_guild=[77], _run_still_current=lambda: True,+ _voice_ack_loop=None, source=source),+ _schedule=lambda coro, msg, loop=None: scheduled.append(coro),+ )+ GatewayTurnProgressMixin.voice_ack_callback(progress, "call1", "web_search", {})+ assert len(scheduled) == 1+ assert scheduled[0].cr_frame.f_locals["self"] is secondary+ scheduled[0].close()++# ---------------------------------------------------------------------------# 5. Sidecar note staging: one-shot per turn# ---------------------------------------------------------------------------