Skip to content

The agent that grows with you

fix(gateway): a typed stop phrase only ends a LOCAL voice chat

Teknium256374d1509f
diff --git a/gateway/session_controls.py b/gateway/session_controls.py
index daae1a48cf4..8d8d63aeed5 100644
--- a/gateway/session_controls.py
+++ b/gateway/session_controls.py
@@ -700,13 +700,19 @@ class AuthorityConnection:
async def _typed_voice_stop(self, ref, params):
"""TUI-26: a bare stop phrase typed while the session's voice chat is on ends the chat
(the sidecar's ``methods_prompt._consume_typed_stop_phrase``, its typed twin of the spoken
- stop) and is never admitted. Only a submitter attached to the session may end it."""
+ stop) and is never admitted. Only a submitter attached to the session may end it, and only
+ on a LOCAL session: a messaging lane's own ``/voice`` mode belongs to that chat, so a
+ viewer's typed text there is admitted untouched."""
text = params.get('text')
if not isinstance(text, str):
return False
if ref.session_id not in self.subscriptions:
return False # submission() refuses it as permission_denied
self.authority.authorize(self.actor, ref, 'session:submit')
+ live = self.authority.sessions.get(ref.session_id)
+ source = getattr(live, 'source', None)
+ if source is None or source.platform != Platform.LOCAL:
+ return False
from gateway.session_config import local_voice_enabled
if not local_voice_enabled(ref.session_id):
return False
diff --git a/tests/gateway/test_canonical_typed_voice_stop.py b/tests/gateway/test_canonical_typed_voice_stop.py
index 90e488780e0..32afa6a3ef8 100644
--- a/tests/gateway/test_canonical_typed_voice_stop.py
+++ b/tests/gateway/test_canonical_typed_voice_stop.py
@@ -13,12 +13,16 @@ from tests.gateway.test_session_authority_cancel_settlement import _authority
def voice_owner(tmp_path, monkeypatch):
from types import SimpleNamespace
+ from gateway.config import Platform
from tui_gateway import server
- db, authority = _authority(tmp_path, monkeypatch)
+ db, authority = _authority(tmp_path, monkeypatch, platform=Platform.LOCAL) # TUI-26 is the local voice chat
# The owner's voice mode is keyed by the session's source (``_voice_key_for_source``). Ending the
# LOCAL push-to-talk capture is ``set_local_voice_mode``'s job, pinned in
# tests/tui_gateway/test_canonical_voice_mode_writers.py.
authority.sessions['s'].source.chat_id = 's'
+ # A LOCAL session belongs to its launching user: the viewer ``_connection`` attaches as.
+ from gateway.session_identity import authenticated_subject
+ authority.sessions['s'].source.user_id = authenticated_subject({'user_id': 'human'})
monkeypatch.setattr(authority, '_schedule', lambda ref: None) # admit only; never run a turn
runner = authority.runner
runner._voice_mode = {}
@@ -67,6 +71,20 @@ async def test_a_stranger_cannot_end_the_voice_chat(voice_owner):
assert voice_owner.runner._voice_mode['s'] == 'voice_only'
+async def test_a_messaging_lane_viewer_typing_stop_is_admitted_untouched(voice_owner):
+ """TUI-26 is the LOCAL voice chat: a Telegram lane whose chat ran ``/voice on``, viewed from
+ Desktop or Ink, keeps its voice mode and gets the typed text admitted as a turn."""
+ from gateway.config import Platform
+ voice_owner.authority.sessions['s'].source.platform = Platform.TELEGRAM
+ voice_owner.runner._voice_mode['s'] = 'voice_only'
+ with voice_owner.db:
+ reply = await _call(_connection(voice_owner.authority), 'prompt.submit', text='stop', submission_id='r1')
+ assert reply.get('result', {}).get('status') == 'queued', reply
+ assert voice_owner.runner._voice_mode['s'] == 'voice_only'
+ assert _ledger(voice_owner.db) == ['r1']
+
+
def test_the_canonical_contract_declares_the_voice_stopped_reply():
from tui_gateway.contracts.registry import CANONICAL_METHODS
contract = CANONICAL_METHODS['prompt.submit']