The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): keep the offline snapshot restore for a remote gateway's chat
kshitijk4poor7a9e1ed4f43d
diff --git a/hermes_cli/cli_snapshot.py b/hermes_cli/cli_snapshot.pyindex 691f58f07f0..4f31497a076 100644--- a/hermes_cli/cli_snapshot.py+++ b/hermes_cli/cli_snapshot.py@@ -32,14 +32,17 @@ def restore_snapshot_command(cli, parts):return print(f" {_t('snapshot.invalid_number', max=len(snaps))}")snap_id = snaps[idx - 1]["id"]store = gateway_store(cli)- gateway = store is not None and getattr(cli, "_gateway_session_open", False)+ chat = store is not None and getattr(cli, "_gateway_session_open", False)+ # A remote gateway's state is not on this host: its chat restores this host's own snapshot offline,+ # as before, and keeps the remote connection open.+ gateway = chat and not os.environ.get("HERMES_TUI_GATEWAY_URL", "").strip()try:# An invalid/missing target must not take a working gateway offline.if gateway and quick_snapshot_dir(snap_id) is not None:restored = _restore_gateway_snapshot(cli, store, snap_id)else:local_db = getattr(cli, "_session_db", None)- if local_db is not None and not gateway:+ if local_db is not None and not chat:with suppress(Exception):local_db.close()cli._session_db = None@@ -83,8 +86,6 @@ def _restore_gateway_snapshot(cli, store, snap_id):from hermes_cli.profiles_remove import wait_profile_unownedfrom hermes_constants import get_hermes_homefrom hermes_state_registry import close_all_under- if os.environ.get("HERMES_TUI_GATEWAY_URL", "").strip():- raise GatewayClientError("Snapshot restore needs the local gateway. Disconnect the remote gateway and retry.")home = get_hermes_home().resolve()observed = discover_gateway_endpoint(home)if observed.state != "ready" or observed.endpoint is None:diff --git a/tests/hermes_cli/test_gateway_snapshot_restore_guards.py b/tests/hermes_cli/test_gateway_snapshot_restore_guards.pyindex c9bb952872f..2f4e8cfd433 100644--- a/tests/hermes_cli/test_gateway_snapshot_restore_guards.py+++ b/tests/hermes_cli/test_gateway_snapshot_restore_guards.py@@ -38,13 +38,18 @@ def _restore_error(sid):("invalid-id", lambda sid: False, "manual", "Snapshot not found: ../outside"),("other-pid-paused", None, "manual", "Gateway refused the snapshot maintenance handoff"),("satellite-unserve-error", None, "manual", "nothing was restored. Park the profile with `hermes -p state"),+ # A remote gateway's chat restores this host's snapshot offline, as on main, and stays connected.+ ("remote", lambda sid: True, None, "Restart recommended"),])def test_restore_reply_follows_the_restore_not_the_rejoin(tmp_path, monkeypatch, capsys,case, restore, supervisor, expected):home = (tmp_path / "state").resolve()home.mkdir()monkeypatch.setenv("HERMES_HOME", str(home))- monkeypatch.delenv("HERMES_TUI_GATEWAY_URL", raising=False)+ if case == "remote":+ monkeypatch.setenv("HERMES_TUI_GATEWAY_URL", "wss://remote.invalid/api/ws")+ else:+ monkeypatch.delenv("HERMES_TUI_GATEWAY_URL", raising=False)(home / "config.yaml").write_text("{}\n", encoding="utf-8")snapshot = create_quick_snapshot(hermes_home=home)old = _Connection()@@ -77,7 +82,8 @@ def test_restore_reply_follows_the_restore_not_the_rejoin(tmp_path, monkeypatch,out = capsys.readouterr().outassert expected in out- if case in {"supervised", "invalid-id"}:+ if case in {"supervised", "invalid-id", "remote"}:assert not paused and not old.final # refused before tearing down the viewer+ assert store.connection is old # a remote chat keeps its connection tooelse:assert "Reconnecting to the gateway failed: permission_denied" in out