From 8f6afbaf0d48ec26149fa297df64e20e4c77cefb Mon Sep 17 00:00:00 2001 From: salch-cred <141555468+salch-cred@users.noreply.github.com> Date: Fri, 11 Sep 2026 07:06:05 +0530 Subject: [PATCH] fix(tui_gateway): handle deleted profiles gracefully in _response_profile_name (#107829) --- .../test_default_profile_session_name.py | 13 +++++++++++++ tui_gateway/server.py | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/tui_gateway/test_default_profile_session_name.py b/tests/tui_gateway/test_default_profile_session_name.py index 16767354a4..953d19d56f 100644 --- a/tests/tui_gateway/test_default_profile_session_name.py +++ b/tests/tui_gateway/test_default_profile_session_name.py @@ -168,3 +168,16 @@ def test_custom_default_root_real_session_db_owner_stamping(tmp_path, monkeypatc assert launch_db.get_session("lazy-default") is None assert launch_db.get_session("seeded-default") is None assert launch_db.get_session("branched-default") is None + + +def test_deleted_profile_falls_back_to_current_profile(tmp_path, monkeypatch): + """Deleted/non-existent profiles must not raise FileNotFoundError in _response_profile_name.""" + from tui_gateway import server + + default_home, launch_home = _profile_layout(tmp_path) + monkeypatch.setattr(Path, "home", lambda: tmp_path) + monkeypatch.setenv("HERMES_HOME", str(launch_home)) + monkeypatch.setattr(server, "_hermes_home", launch_home) + + assert server._response_profile_name("non-existent-profile-123") == server._current_profile_name() + diff --git a/tui_gateway/server.py b/tui_gateway/server.py index 91faeb3caf..195f572a20 100644 --- a/tui_gateway/server.py +++ b/tui_gateway/server.py @@ -474,7 +474,12 @@ def _canonical_profile_request(name: str) -> str: def _response_profile_name(profile: str | None = None) -> str: """Profile name for session.* payloads: the requested real non-launch profile, else the launch one.""" name = _canonical_profile_request((profile or "").strip()) - return name if name and _profile_home(name) is not None else _current_profile_name() + if not name: + return _current_profile_name() + try: + return name if _profile_home(name) is not None else _current_profile_name() + except FileNotFoundError: + return _current_profile_name() def _db_unavailable_error(rid, *, code: int):