Skip to content

The agent that grows with you

fix(onboarding): an old ended chat never closes a newer run's install flag

alt-glitchfb30efb5213d
diff --git a/agent/onboarding_record.py b/agent/onboarding_record.py
index 98d9fef0773..5f8aab84c1e 100644
--- a/agent/onboarding_record.py
+++ b/agent/onboarding_record.py
@@ -39,8 +39,9 @@ def load(db, session_id: str) -> dict | None:
def _transition(db, session_id: str, event: Event | None) -> Step | None:
"""Expire, apply *event* and write the result in one database transaction, so Skip setup pressed
- while a card answer is being applied is never overwritten by the older copy. Every ended run
- then closes the install flag, so a Skip or Done retried after a failed config write repairs it."""
+ while a card answer is being applied is never overwritten by the older copy. An ended run then
+ closes the install flag (a Skip or Done retried after a failed config write repairs it), unless
+ another run is still open: the flag belongs to that run, and an old chat must not end it."""
holder: dict[str, Step] = {}
def update(current: Any) -> Any:
@@ -55,7 +56,7 @@ def _transition(db, session_id: str, event: Event | None) -> Step | None:
db.update_session_model_config_value(session_id, KEY, update)
step = holder.get("step")
- if step is not None and not is_active(step.record):
+ if step is not None and not is_active(step.record) and active_session_id(db) is None:
_close_install_flag()
return step
diff --git a/tests/tui_gateway/test_onboarding_session.py b/tests/tui_gateway/test_onboarding_session.py
index b79697ded1b..114e7cc31da 100644
--- a/tests/tui_gateway/test_onboarding_session.py
+++ b/tests/tui_gateway/test_onboarding_session.py
@@ -199,3 +199,17 @@ def test_a_skip_retried_after_a_failed_config_write_closes_the_install_flag(root
assert read_user_config_raw(root / "config.yaml")["onboarding"]["run"] is True
onboarding_record.advance(db, "onb", SkipAll())
assert read_user_config_raw(root / "config.yaml")["onboarding"]["run"] is False
+
+
+def test_an_old_ended_chat_never_closes_the_flag_of_a_newer_run(root):
+ from hermes_cli.config import read_user_config_raw
+ db = server._get_db()
+ db.create_session("old", "desktop")
+ onboarding_record.start(db, "old", FACTS)
+ onboarding_record.advance(db, "old", SkipAll())
+ db.create_session("new", "desktop")
+ onboarding_record.start(db, "new", FACTS)
+
+ onboarding_record.advance(db, "old", SkipAll()) # the old chat's agent still carries setup_beat
+ assert read_user_config_raw(root / "config.yaml")["onboarding"]["run"] is True
+ assert onboarding_record.active_session_id(db) == "new"