The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep the operator restart tail on the home-channel storage notice
teknium1968422e7c557
diff --git a/gateway/run_notifications.py b/gateway/run_notifications.pyindex 9d7c3fbd64e..728b4a3ca36 100644--- a/gateway/run_notifications.py+++ b/gateway/run_notifications.py@@ -42,6 +42,9 @@ _VIDEO_EXTS = {'.mp4', '.mov', '.avi', '.mkv', '.webm', '.3gp'}# Routing fields copied verbatim from a process watcher onto its synthetic completion event._WATCHER_ROUTE_FIELDS = ("session_key", "platform", "chat_type", "chat_id", "thread_id", "user_id", "user_name")_IMAGE_EXTS = {'.jpg', '.jpeg', '.png', '.webp', '.gif'}+# Storage causes that clear on their own (one session's lease/compression, not the store): the+# home-channel notice appends the operator restart tail for every OTHER cause.+_SELF_CLEARING_STORAGE_CAUSES = frozenset({"compression", "compression_closed", "turn_lease"})# Durable async-delegation claim transitions: kind -> (tools.async_delegation function, failure log)._DURABLE_CLAIM_OPS = {@@ -944,10 +947,15 @@ class GatewayNotificationsMixin:from hermes_state_user_copy import describe_storage_failurefailure = describe_storage_failure(error)# The cause table owns the remedy: for a held retired-WAL generation a bare `doctor --fix`- # is the second-writer trap this notice used to send users into (#110054).+ # is the second-writer trap this notice used to send users into (#110054). Its copy is+ # user-phrased, so a store-level failure still gets the operator tail — this gateway+ # opened its store at startup and stays broken until it is restarted.+ action = failure.action+ if failure.cause not in _SELF_CLEARING_STORAGE_CAUSES:+ action = f"{action} Then `hermes {profile_arg}gateway restart`."message = ("⚠️ Session database unavailable — messages may not be saved and /resume will be "- f"empty. Cause: {failure.gloss}. {failure.action}"+ f"empty. Cause: {failure.gloss}. {action}")logger.warning("Broadcasting state.db failure warning to home channels: %s", error)from gateway.warning_notifications import present_notificationdiff --git a/tests/hermes_cli/test_sessions_held_store_gate.py b/tests/hermes_cli/test_sessions_held_store_gate.pyindex 8cf6388ca2f..f802ad47677 100644--- a/tests/hermes_cli/test_sessions_held_store_gate.py+++ b/tests/hermes_cli/test_sessions_held_store_gate.py@@ -6,6 +6,7 @@ refusal; the command now runs the same fail-closed holder scan doctor/repair useproduction entry point ``cmd_sessions`` with a REAL second process holding the store."""+import argparseimport subprocessimport sysfrom argparse import Namespace@@ -55,26 +56,50 @@ def foreign_holder(state_db):proc.wait(timeout=10)-def _optimize(force=False):- return Namespace(sessions_action="optimize", force=force)+def _args(action, force):+ common = dict(sessions_action=action, force=force)+ if action == "prune":+ return Namespace(dry_run=False, yes=True, never_active=False, include_archived=False,+ include_pinned=False, **common,+ **{name: None for name in sessions_cmd._FILTER_ARGS})+ if action == "optimize-storage":+ return Namespace(no_vacuum=False, yes=True, **common)+ return Namespace(**common)-def test_optimize_refuses_and_names_the_holder_until_forced(state_db, foreign_holder, capsys):- assert sessions_cmd.cmd_sessions(_optimize()) == 1+def _sessions_subparsers():+ parser = argparse.ArgumentParser()+ from hermes_cli.subcommands.sessions import build_sessions_parser++ build_sessions_parser(parser.add_subparsers(dest="command"), cmd_sessions=sessions_cmd.cmd_sessions)+ subparsers = [a for a in parser._actions if isinstance(a, argparse._SubParsersAction)][0]+ sessions = subparsers.choices["sessions"]+ nested = [a for a in sessions._actions if isinstance(a, argparse._SubParsersAction)][0]+ return nested.choices++[email protected]("action", sorted(sessions_cmd._HELD_STORE_ACTIONS))+def test_store_rewrites_refuse_and_name_the_holder_until_forced(action, state_db, foreign_holder, capsys):+ assert sessions_cmd.cmd_sessions(_args(action, force=False)) == 1out = capsys.readouterr().outassert f"PID {foreign_holder.pid} (" in out- assert "Refusing `hermes sessions optimize`" in out and "--force" in out- assert "Optimized" not in out-- assert sessions_cmd.cmd_sessions(_optimize(force=True)) is None- assert "Optimized" in capsys.readouterr().out+ assert f"Refusing `hermes sessions {action}`" in out and "--force" in out+ # The gate scans the store the command actually opened, not some other resolver's file: no+ # `hermes sessions` subcommand can point the command at another database, so the default+ # resolver IS the operated-on path, and the refusal names it.+ assert str(state_db) in out+ assert not [opt for sub in _sessions_subparsers().values() for a in sub._actions+ for opt in a.option_strings if opt in ("--db", "--db-path", "--database")]++ assert sessions_cmd.cmd_sessions(_args(action, force=True)) != 1+ assert "Refusing" not in capsys.readouterr().outdef test_prune_preview_passes_the_delete_waits_for_a_quiet_store(state_db, foreign_holder, capsys):# A preview never rewrites anything, so it is answered even while the holder lives.- prune_preview = Namespace(sessions_action="prune", dry_run=True, yes=False, force=False, never_active=False,- include_archived=False, include_pinned=False,- **{name: None for name in sessions_cmd._FILTER_ARGS})+ prune_preview = _args("prune", force=False)+ prune_preview.dry_run = True+ prune_preview.yes = Falseassert sessions_cmd.cmd_sessions(prune_preview) is Noneassert "Refusing" not in capsys.readouterr().outprune_preview.dry_run = Falsediff --git a/website/docs/user-guide/session-storage-recovery.md b/website/docs/user-guide/session-storage-recovery.mdindex 3c890a7edef..aa1e522f3f7 100644--- a/website/docs/user-guide/session-storage-recovery.md+++ b/website/docs/user-guide/session-storage-recovery.md@@ -49,8 +49,8 @@ refusal exists precisely so nothing gets lost.## Do not- **Do not run `hermes doctor --fix` while the processes are running.** Doctor refuses the- checkpoint while it can see a holder, but on a host where it cannot inspect processes the- fix path is exactly the second writer that caused the problem.+ checkpoint while it can see a process holding the retired log, but on a host where it cannot+ inspect processes the fix path is exactly the second writer that caused the problem.- **Do not delete `state.db-wal` or `state.db-shm`.** The log holds committed conversationsthat are not yet in `state.db`. Deleting it is the one action that turns a refusal intoreal data loss.