Skip to content

The agent that grows with you

fix(gateway): let internal events bypass topic lobby

embwl0xf174a08c93b6
diff --git a/gateway/run.py b/gateway/run.py
index 5030617d986..a4b267859f3 100644
--- a/gateway/run.py
+++ b/gateway/run.py
@@ -12217,7 +12217,9 @@ class GatewayRunner(GatewayAuthorizationMixin, GatewayKanbanWatchersMixin, Gatew
# No bare text matching — "yes" in normal conversation must not trigger
# execution of a dangerous command.
- if await asyncio.to_thread(self._is_telegram_topic_root_lobby, source):
+ if not is_internal and await asyncio.to_thread(
+ self._is_telegram_topic_root_lobby, source
+ ):
# Debounce the lobby reminder so a user who forgets about
# topic mode and fires ten prompts doesn't get ten copies.
if self._should_send_telegram_lobby_reminder(source):
diff --git a/tests/gateway/test_telegram_topic_mode.py b/tests/gateway/test_telegram_topic_mode.py
index c309a328d51..edeeeb0818e 100644
--- a/tests/gateway/test_telegram_topic_mode.py
+++ b/tests/gateway/test_telegram_topic_mode.py
@@ -183,6 +183,34 @@ async def test_root_telegram_dm_prompt_is_system_lobby_when_topic_mode_enabled(m
runner.session_store.get_or_create_session.assert_not_called()
[email protected]("thread_id", [None, "1"])
+async def test_internal_root_telegram_dm_event_bypasses_topic_lobby(
+ monkeypatch, thread_id
+):
+ import gateway.run as gateway_run
+
+ runner = _make_runner()
+ runner._telegram_topic_mode_enabled = lambda source: True
+ runner._handle_message_with_agent = AsyncMock(return_value="agent response")
+
+ monkeypatch.setattr(
+ gateway_run, "_resolve_runtime_agent_kwargs", lambda: {"api_key": "***"}
+ )
+
+ event = MessageEvent(
+ text="[SYSTEM: kanban task completed]",
+ source=_make_source(thread_id=thread_id),
+ message_id="wake-1",
+ internal=True,
+ )
+ result = await runner._handle_message(event)
+
+ assert result == "agent response"
+ assert runner._handle_message_with_agent.await_count == 1
+ assert runner._handle_message_with_agent.await_args.args[0] is event
+
+
@pytest.mark.asyncio
async def test_root_telegram_dm_new_shows_create_topic_instruction(monkeypatch):
import gateway.run as gateway_run