The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): pin the turn-explainer `hermes` commands to the failing profile
kshitijk4poor60945c70bd01
diff --git a/agent/turn_explainers.py b/agent/turn_explainers.pyindex 9c9bac8f3fa..0c17293d7a6 100644--- a/agent/turn_explainers.py+++ b/agent/turn_explainers.py@@ -117,14 +117,16 @@ _PERSISTENCE_CAUSE_EXPLANATIONS: Dict[str, str] = {"replaced": ("the session database file was replaced while Hermes was running, so this ""message was not saved (a copy is kept in {home}/sessions/). Stop Hermes "- "(`hermes gateway stop`), run `hermes doctor` — not `hermes doctor --fix`, which "+ "(`hermes {profile_arg}gateway stop`), run `hermes {profile_arg}doctor` — not "+ "`hermes {profile_arg}doctor --fix`, which ""would repair the wrong file in place — then start it again and send your message ""once more. Advanced recovery steps are in the log."),"deleted_wal": ("the session database was changed or replaced while Hermes was running, so this ""message was not saved (a copy is kept in {home}/sessions/). Stop Hermes "- "(`hermes gateway stop`), run `hermes doctor`, then start it again and send your "+ "(`hermes {profile_arg}gateway stop`), run `hermes {profile_arg}doctor`, then start it "+ "again and send your ""message once more. Advanced recovery steps are in the log."),"corrupt": (@@ -163,7 +165,8 @@ _PERSISTENCE_CAUSE_EXPLANATIONS: Dict[str, str] = {_PERSISTENCE_DEFAULT_EXPLANATION = ("Hermes couldn't save this conversation, so it stopped rather than lose your messages. ""Possible causes: the drive is out of room, or another Hermes process is holding the "- "database. Close other Hermes windows, run `hermes doctor` to check storage, then send "+ "database. Close other Hermes windows, run `hermes {profile_arg}doctor` to check storage, "+ "then send ""your message again.")@@ -366,19 +369,22 @@ class TurnExplainersMixin:if body is not None and "{model}" in body:body = body.format(model=model or "The model")if body is None and reason == "session_persistence_failed":- from hermes_constants import display_hermes_home-- body = _PERSISTENCE_CAUSE_EXPLANATIONS.get(- persistence_cause or "unknown", _PERSISTENCE_DEFAULT_EXPLANATION- ).replace("{home}", display_hermes_home())+ from hermes_constants import display_hermes_home, profile_cli_selector++ # Copy-pasteable, so pin every `hermes` command to the profile whose store failed:+ # a multi-profile backend (Desktop serve) hosts sessions whose state.db is NOT the+ # process default, and a bare `hermes` follows active_profile (#105887).+ body = (+ _PERSISTENCE_CAUSE_EXPLANATIONS.get(+ persistence_cause or "unknown", _PERSISTENCE_DEFAULT_EXPLANATION+ )+ .replace("{home}", display_hermes_home())+ .replace("{profile_arg}", profile_cli_selector())+ )if persistence_cause in ("corrupt", "fts_index"):- # Copy-pasteable, so name the store that actually failed and pin the profile:- # a multi-profile backend (Desktop serve) hosts sessions whose state.db is NOT- # the process default, and a bare `hermes` follows active_profile (#105887).- from hermes_constants import get_default_hermes_root, profile_cli_selector+ from hermes_constants import get_default_hermes_rootfrom hermes_state import _default_db_path- body = body.replace("{profile_arg}", profile_cli_selector())body = body.replace("{db_path}", str(db_path or _default_db_path()))body = body.replace("{backups_dir}", str(get_default_hermes_root() / "backups")diff --git a/tests/agent/test_turn_completion_explainer.py b/tests/agent/test_turn_completion_explainer.pyindex ac5a7ad21df..7031a143342 100644--- a/tests/agent/test_turn_completion_explainer.py+++ b/tests/agent/test_turn_completion_explainer.py@@ -18,6 +18,7 @@ pass identically in CI and locally."""import hermes_state_errors+import pytestimport osimport uuidfrom types import SimpleNamespace@@ -220,6 +221,24 @@ def test_deleted_wal_cause_is_plain_first_steps_not_a_forensic_runbook():assert "~/.hermes" not in out # display_hermes_home(), never a hardcoded path[email protected]("cause", ["replaced", "deleted_wal", "unknown"])+def test_persistence_commands_are_pinned_to_the_failing_profile(monkeypatch, tmp_path, cause):+ """Every copy-pasteable ``hermes`` command in a persistence explanation names the profile+ whose store failed — a multi-profile backend serves sessions whose state.db is not the+ process default, and a bare ``hermes`` follows the sticky active_profile (#105887). The+ corrupt/fts_index causes already did this; replaced/deleted_wal/default did not."""+ from hermes_constants import profile_cli_selector++ monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes" / "profiles" / "research"))+ monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)+ selector = profile_cli_selector()+ assert selector.strip(), "fixture must resolve to a named profile"+ out = AIAgent._format_turn_completion_explanation("session_persistence_failed", cause)+ assert "{profile_arg}" not in out+ assert f"`hermes {selector}doctor" in out+ assert "`hermes doctor" not in out and "`hermes gateway" not in out++def test_explanation_persistence_unknown_cause_is_neutral():"""None/'unknown' cause must not claim disk-full — point at diagnostics."""for cause in (None, "unknown"):