Skip to content

The agent that grows with you

fix(onboarding): an interrupted TUI setup turn auto-continues again

alt-glitcha8907dcadb85
diff --git a/agent/initiate_setup_prompt.py b/agent/initiate_setup_prompt.py
index d9852caef61..976282b4f6f 100644
--- a/agent/initiate_setup_prompt.py
+++ b/agent/initiate_setup_prompt.py
@@ -105,13 +105,14 @@ def initiate_setup_prelude(message, surface: str, tools, history):
return _opening(*so_far)
-def intro_resends(prompt: str) -> bool:
+def intro_resends(prompt: str, surface: str) -> bool:
"""True while the desktop intro owns recovery of this ``/initiate-setup`` turn: after a relaunch the
app sends the command again (the prelude replays only the unanswered opening cards), so a generic
- auto-continue of the cut-off turn would race it."""
+ auto-continue of the cut-off turn would race it. A TUI chat has no intro to resend it."""
from hermes_cli.setup_profile import onboarding_eligible, read_state
- return prompt.startswith(HEADER) and onboarding_eligible() and read_state().get("intro") == "unseen"
+ return (surface == "desktop" and prompt.startswith(HEADER) and onboarding_eligible()
+ and read_state().get("intro") == "unseen")
def _opening(said: set, replies: dict):
diff --git a/tests/tui_gateway/test_auto_continue.py b/tests/tui_gateway/test_auto_continue.py
index 3b1698cbcbb..3565fcecc0d 100644
--- a/tests/tui_gateway/test_auto_continue.py
+++ b/tests/tui_gateway/test_auto_continue.py
@@ -409,6 +409,34 @@ def test_hosted_room_marker_is_left_to_the_driver(schedule_env, marker_home):
assert read_turn_marker(marker_home, "session-key") is not None
+def unseen_intro(monkeypatch):
+ """An onboarding-enabled install whose desktop intro has not been seen yet."""
+ import hermes_cli.setup_profile as setup_profile
+ monkeypatch.setattr(setup_profile, "onboarding_eligible", lambda: True)
+ monkeypatch.setattr(setup_profile, "read_state", lambda: {"intro": "unseen"})
+
+
+def test_desktop_setup_turn_is_left_to_the_intro(schedule_env, marker_home, unseen_intro):
+ record_turn_start(marker_home, "session-key", "[/initiate-setup]\nset me up")
+
+ result = server._maybe_schedule_auto_continue("sid", _session(source="desktop"), "session-key")
+
+ assert result is None
+ assert not schedule_env
+ assert read_turn_marker(marker_home, "session-key") is None
+
+
+def test_tui_setup_turn_still_auto_continues(emits, schedule_env, marker_home, unseen_intro):
+ record_turn_start(marker_home, "session-key", "[/initiate-setup]\nset me up")
+
+ result = server._maybe_schedule_auto_continue("sid", _session(source="tui"), "session-key")
+
+ assert result is not None
+ (text, _kwargs), = schedule_env
+ assert "[/initiate-setup]" in text
+
+
def test_stale_marker_is_cleared_not_continued(schedule_env, marker_home, monkeypatch):
record_turn_start(marker_home, "session-key", "old prompt")
monkeypatch.setattr(
diff --git a/tui_gateway/session_auto_continue.py b/tui_gateway/session_auto_continue.py
index 1b908464c08..9615b5a927b 100644
--- a/tui_gateway/session_auto_continue.py
+++ b/tui_gateway/session_auto_continue.py
@@ -69,7 +69,7 @@ def _maybe_schedule_auto_continue(sid: str, session: dict, session_key: str) ->
if not marker.get("auto_continue", True):
return None # The mailbox owns recovery and receipt identity for imported turns.
from agent.initiate_setup_prompt import intro_resends
- if intro_resends(marker["prompt"]):
+ if intro_resends(marker["prompt"], _session_source(session)):
clear_turn_marker(home, session_key) # the desktop intro sends /initiate-setup again itself
return None
# Ownership, not forensics: a sibling backend sharing this HERMES_HOME can be mid-turn on this very session, so