Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7343,7 +7343,12 @@ def _sync_voice_mode_state_to_adapter(self, adapter) -> None:
except Exception:
_auto_tts_default = False
if hasattr(adapter, "_auto_tts_default"):
adapter._auto_tts_default = _auto_tts_default
# A2A never inherits the global speak default. Desktop/wake-word
# may flip voice.auto_tts; agent peers still get text only.
if getattr(platform, "value", None) == "a2a":
adapter._auto_tts_default = False
else:
adapter._auto_tts_default = _auto_tts_default

prefix = f"{platform.value}:"
if isinstance(disabled_chats, set):
Expand Down Expand Up @@ -21806,6 +21811,13 @@ def _should_send_voice_reply(
if not response or response.startswith("Error:"):
return False

# A2A is agent-to-agent text. The adapter has no native send_voice, so
# global voice.auto_tts (Desktop "Read replies aloud") would synthesize
# an MP3 and then fail delivery with "Couldn't deliver the audio
# attachment." Keep /voice scoped to human platforms.
if getattr(event.source.platform, "value", None) == "a2a":
return False

chat_id = event.source.chat_id
voice_key = self._voice_key(event.source.platform, chat_id)
voice_mode = self._voice_mode.get(voice_key)
Expand Down
22 changes: 22 additions & 0 deletions tests/gateway/test_auto_voice_reply_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ def test_should_send_voice_reply_voice_only_still_requires_voice_input(self):
voice_event = _make_event(Platform.TELEGRAM, chat_id="123", message_type=MessageType.VOICE)
assert runner._should_send_voice_reply(voice_event, "hello", [], already_sent=True) is True

def test_should_send_voice_reply_a2a_ignores_global_auto_tts(self):
"""A2A text tasks must stay text even when voice.auto_tts is on.

Desktop Read-replies-aloud writes the global default. The runner used
that default for every adapter with no /voice mode, including A2A,
which cannot deliver native audio (#90103).
"""
runner = _make_runner()
a2a = Platform("a2a")
adapter = _make_adapter(a2a)
adapter._should_auto_tts_for_chat = MagicMock(return_value=True)
runner.adapters[a2a] = adapter
event = _make_event(a2a, chat_id="ctx-peer")

assert runner._should_send_voice_reply(event, "audit findings", []) is False

telegram = _make_event(Platform.TELEGRAM, chat_id="999")
telegram_adapter = _make_adapter(Platform.TELEGRAM)
telegram_adapter._should_auto_tts_for_chat = MagicMock(return_value=True)
runner.adapters[Platform.TELEGRAM] = telegram_adapter
assert runner._should_send_voice_reply(telegram, "hello", []) is True

def _make_runner() -> GatewayRunner:
with patch("gateway.run.GatewayRunner._load_voice_modes", return_value={}):
runner = GatewayRunner.__new__(GatewayRunner)
Expand Down