Skip to content

The agent that grows with you

fix(gateway): /login on a local session shows its sign-in code to the session's viewers

Teknium8cdcf0b6596e
diff --git a/gateway/session_commands.py b/gateway/session_commands.py
index 1789a9a8825..eb357f044bf 100644
--- a/gateway/session_commands.py
+++ b/gateway/session_commands.py
@@ -22,7 +22,8 @@ _CONTROL_COMMANDS = frozenset({'title'})
# local session: goal/loop/heartbeat state on the session's row, the review/refine forks of its
# cached agent, the /debug summary upload, /blueprint's job creation. A turn the handler would have
# pushed onto the adapter FIFO comes back as a ``send`` directive (gateway/session_command_sink.py).
-_HANDLER_CONTROLS = frozenset({'goal', 'subgoal', 'loop', 'heartbeat', 'review', 'refine', 'debug', 'curator'})
+_HANDLER_CONTROLS = frozenset({'goal', 'subgoal', 'loop', 'heartbeat', 'review', 'refine', 'debug', 'curator',
+ 'login'})
# Idle-path commands the messaging gateway answers by rewriting the turn (``_hm_cmd_<name>``,
# gateway/run_inbound.py): the rewritten text is returned as the client's ``send`` directive.
_PROMPT_COMMANDS = frozenset({'plan', 'learn', 'init', 'initiate-setup', 'moa', 'blueprint', 'egress'})
diff --git a/gateway/slash_commands_login.py b/gateway/slash_commands_login.py
index 231bce1482d..2b0e85d29f8 100644
--- a/gateway/slash_commands_login.py
+++ b/gateway/slash_commands_login.py
@@ -36,6 +36,24 @@ class _SignInAttempt:
_LOGIN_BLOCKED_PLATFORMS = frozenset({"ntfy", "raft", "a2a"})
+def _publish_local_notice(runner, source, text: str) -> bool:
+ """A LOCAL session's adapter ``send`` is a no-op (viewers read the event stream), so the
+ sign-in link/code/result reach its viewers as a sticky ``notification.show``. False when
+ *source* is not a live local session (the platform push applies)."""
+ from gateway.config import Platform
+ if getattr(source, "platform", None) != Platform.LOCAL:
+ return False
+ from gateway.session_authorities import active_authority
+ authority = active_authority(runner)
+ live = authority.sessions.get(source.chat_id) if authority is not None else None
+ if live is None:
+ return False
+ live.event_stream.publish(source.chat_id, {"text": text, "level": "info", "kind": "sticky",
+ "key": "login:" + uuid4().hex[:8]},
+ event_type="notification.show")
+ return True
+
+
class GatewayLoginCommandsMixin:
_LOGIN_SINGLE = _LOGIN_SINGLE
@@ -152,6 +170,8 @@ class GatewayLoginCommandsMixin:
async def _push_login(self, attempt: _SignInAttempt, text: str) -> None:
"""Push one notice without allowing a transport failure to abort the state drain."""
try:
+ if _publish_local_notice(self, attempt.source, text):
+ return
await self._deliver_platform_notice(attempt.source, text)
except Exception:
logger.warning("/login %s: push failed", attempt.attempt_id, exc_info=True)
diff --git a/tests/gateway/test_login_command.py b/tests/gateway/test_login_command.py
index d9f98600e72..52343e07411 100644
--- a/tests/gateway/test_login_command.py
+++ b/tests/gateway/test_login_command.py
@@ -524,3 +524,27 @@ async def test_login_dispatches_mid_turn():
assert await runner._dispatch_busy_slash_command(event, command, "", event.source) == "started"
runner._handle_login_command.assert_awaited_once_with(event)
+
+
+async def test_a_local_session_gets_the_sign_in_code_on_its_event_stream(monkeypatch):
+ """A local CLI/TUI/Desktop session is a DM on the LOCAL adapter, whose ``send`` is a no-op: the
+ link, code and outcome reach its viewers as ``notification.show`` events, never the platform push."""
+ from gateway import session_authorities
+ runner = _runner(monkeypatch)
+ published = []
+ live = SimpleNamespace(event_stream=SimpleNamespace(
+ publish=lambda sid, payload, event_type: published.append((sid, event_type, payload["text"]))))
+ authority = SimpleNamespace(sessions={"local-1": live})
+ monkeypatch.setattr(session_authorities, "active_authority", lambda _runner: authority)
+ states = [anon_auth.Code("https://example.test/sign-in", "CODE-1", 900, 5), anon_auth.Declined()]
+ monkeypatch.setattr(anon_auth, "run_sign_in", lambda **_kwargs: iter(states))
+
+ event = SimpleNamespace(source=_source(platform=Platform.LOCAL, chat_id="local-1"))
+ assert await runner._handle_login_command(event) == anon_auth.UPGRADE_START
+ await _finish_tasks(runner)
+
+ assert [(sid, kind) for sid, kind, _ in published] == [("local-1", "notification.show")] * 4
+ assert [text for *_, text in published][:2] == ["https://example.test/sign-in", "CODE-1"]
+ assert published[-1][2] == anon_auth.Declined().copy
+ runner._deliver_platform_notice.assert_not_awaited()