The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(onboarding): deleting the setup chat closes the install flag before the chat goes
alt-glitch3c38bc1a8ff9
diff --git a/agent/onboarding_record.py b/agent/onboarding_record.pyindex ebe88bfd809..50008cd2ed8 100644--- a/agent/onboarding_record.py+++ b/agent/onboarding_record.py@@ -124,11 +124,23 @@ def active_session_id(db) -> str | None:def delete_chat(db, session_id: str, delete: Callable[[], bool]) -> bool:"""Run *delete*; when it removed the chat holding the live run, end that run (``deleted``) on every- compression copy, tell windows once and close the install flag. Only the compression tip holds the- live run, so deleting an older copy ends nothing."""+ compression copy and tell windows once. Only the compression tip holds the live run, so deleting an+ older copy ends nothing. The install flag closes before the delete when no other run is open: a+ failed flag write keeps the chat for a retry, and a refused delete sets the flag again."""+ from hermes_cli.onboarding_run import set_run+record = load(db, session_id)live = is_active(record) and (db.resolve_resume_session_id(session_id) or session_id) == session_id- if not delete():+ last = live and all(sid == session_id for sid in open_session_ids(db))+ if last:+ _close_install_flag()+ deleted = False+ try:+ deleted = delete()+ finally:+ if last and not deleted:+ set_run(True)+ if not deleted:return Falseif live:# Each older copy is written on its own row: a tip-routed write would land every copy on the@@ -137,8 +149,6 @@ def delete_chat(db, session_id: str, delete: Callable[[], bool]) -> bool:if ((older := load(db, sid)) or {}).get("run_id") == record["run_id"]:db.patch_session_model_config(sid, {KEY: _end_deleted(older)})_announce(record.get("run_id"), session_id, "deleted")- if active_session_id(db) is None:- _close_install_flag()return Truediff --git a/tests/tui_gateway/test_onboarding_endings.py b/tests/tui_gateway/test_onboarding_endings.pyindex e9836fba66c..b54328265db 100644--- a/tests/tui_gateway/test_onboarding_endings.py+++ b/tests/tui_gateway/test_onboarding_endings.py@@ -56,3 +56,35 @@ def test_deleting_the_newest_copy_ends_the_run_on_every_copy(db, ended):assert onboarding_record.active_session_id(db) is None and _flag(db) is Falseassert [onboarding_record.load(db, sid)["ended_by"] for sid in ("onb", "mid")] == ["deleted", "deleted"]assert [(e["stored_session_id"], e["outcome"]) for e in ended] == [("tip", "deleted")]+++def _failing_flag_write(monkeypatch):+ from hermes_cli import onboarding_run++ def disk_full(value, **kw):+ raise OSError("disk full")++ monkeypatch.setattr(onboarding_run, "set_run", disk_full)+++def test_a_delete_whose_flag_write_fails_keeps_the_chat_for_a_retry(db, ended, monkeypatch):+ with monkeypatch.context() as failing:+ _failing_flag_write(failing)+ with pytest.raises(OSError):+ onboarding_record.delete_chat(db, "onb", lambda: db.delete_session("onb"))++ assert db.get_session("onb") is not None and onboarding_record.active_session_id(db) == "onb" and ended == []+ assert onboarding_record.delete_chat(db, "onb", lambda: db.delete_session("onb"))+ assert _flag(db) is False and [e["outcome"] for e in ended] == ["deleted"]+++def test_a_delete_refused_by_the_write_guard_leaves_the_flag_set(db, ended):+ from hermes_state_errors import SessionActiveWriteGuardError++ def guarded():+ raise SessionActiveWriteGuardError("active turn lease")++ with pytest.raises(SessionActiveWriteGuardError):+ onboarding_record.delete_chat(db, "onb", guarded)++ assert onboarding_record.active_session_id(db) == "onb" and _flag(db) is True and ended == []