Skip to content

The agent that grows with you

fix(tui_gateway): /save writes the transcript under the session's own profile (#125241, salvage #125242)

John Paul Soliva46d080127978
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index 2ae67451a2a..20e06ba5c9e 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -18865,6 +18865,40 @@ def test_session_save_writes_under_hermes_home_with_system_prompt(monkeypatch, t
assert payload["messages"] == history
+
+def test_session_save_lands_in_the_sessions_own_profile_a_b_a(monkeypatch, tmp_path):
+ """/save writes under the SESSION's profile home, launch -> secondary -> launch under multiplexing:
+ the RPC runs unscoped, so get_hermes_home() alone names the launch profile (#125241)."""
+ from agent.secret_scope import set_multiplex_active
+ launch_home = tmp_path / ".hermes"
+ work_home = launch_home / "profiles" / "s6probe-work"
+ work_home.mkdir(parents=True)
+ monkeypatch.setenv("HERMES_HOME", str(launch_home))
+ set_multiplex_active(True)
+ parents = []
+ try:
+ for i, home in enumerate((None, work_home, None)):
+ sid = f"save-profile-sid-{i}"
+ server._sessions[sid] = {
+ "agent": types.SimpleNamespace(model="hermes-test", session_id="s1", session_start=None,
+ _cached_system_prompt=""),
+ "session_key": sid, "profile_home": str(home) if home else None,
+ "history": [{"role": "user", "content": "hi"}], "history_lock": threading.Lock(),
+ }
+ try:
+ resp = server._methods["session.save"]("1", {"session_id": sid})
+ finally:
+ server._sessions.pop(sid, None)
+ assert "result" in resp, resp
+ parents.append(Path(resp["result"]["file"]).parent)
+ finally:
+ set_multiplex_active(False)
+
+ saved = launch_home / "sessions" / "saved"
+ assert parents == [saved, work_home / "sessions" / "saved", saved]
+ assert len(list((work_home / "sessions" / "saved").glob("hermes_conversation_*.json"))) == 1
+
+
def test_session_save_proxies_to_compute_host_history(monkeypatch):
"""Isolated turns own history in the host; /save must not export the stale parent mirror."""
sid = "save-host-sid"
diff --git a/tui_gateway/methods_session.py b/tui_gateway/methods_session.py
index 70e1b60d6fc..d0291a15520 100644
--- a/tui_gateway/methods_session.py
+++ b/tui_gateway/methods_session.py
@@ -2064,8 +2064,10 @@ def _(rid, params: dict, session: dict) -> dict:
if _session_uses_compute_host(session):
return _save_via_compute_host(rid, params)
agent = session["agent"]
- # Classic CLI /save: under the profile home, with the system prompt (dashboard parity).
- saved_dir = get_hermes_home() / "sessions" / "saved"
+ # Classic CLI /save: under the profile home, with the system prompt (dashboard parity). The SESSION's
+ # profile: this handler runs unscoped, so get_hermes_home() alone names the launch profile.
+ home = session.get("profile_home")
+ saved_dir = (Path(home) if home else get_hermes_home()) / "sessions" / "saved"
try:
saved_dir.mkdir(parents=True, exist_ok=True)
except Exception as e: