The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): a dashboard accepts only its own action's completion from the shared root update.log (review actions-root-marker-uncorrelated)
Tekniume7fe60f5c3e0
diff --git a/hermes_cli/web_routers/actions.py b/hermes_cli/web_routers/actions.pyindex b128705aaba..30dea8f558b 100644--- a/hermes_cli/web_routers/actions.py+++ b/hermes_cli/web_routers/actions.py@@ -53,6 +53,7 @@ _ACTION_LOG_TAIL_INITIAL_CHUNK_BYTES = 8 * 1024_ACTION_LOG_TAIL_MAX_CHUNK_BYTES = 64 * 1024_UPDATE_ACTION_COMPLETED_RE = re.compile(r"^=== hermes-update completed ([0-9a-f]{32}) ===$")+_UPDATE_ACTION_STARTED_RE = re.compile(r"^=== hermes-update started .* ([0-9a-f]{32}) ===$")_MANAGED_EXTERNALLY_MESSAGE = "Hermes updates are managed outside this dashboard in containerized environments."@@ -137,6 +138,15 @@ def _durable_completed_update_action_id(lines: List[str]) -> Optional[str]:return completed_action_id if completed_action_id and last_completed > last_start else None+def _latest_spawned_update_action_id(lines: List[str]) -> Optional[str]:+ """Action id named by the latest ``hermes-update started`` header of THIS dashboard's log."""+ for line in reversed(lines):+ if line.startswith("=== hermes-update started "):+ match = _UPDATE_ACTION_STARTED_RE.fullmatch(line.strip())+ return match.group(1) if match else None+ return None++@router.post("/api/gateway/restart")async def restart_gateway(profile: Optional[str] = None):"""Kick off a ``hermes gateway restart`` in the background."""@@ -363,6 +373,10 @@ async def get_action_status(name: str, lines: int = 200):durable_update_action_id = _durable_completed_update_action_id(_tail_lines(get_default_hermes_root() / "logs" / "update.log", 2000))+ if durable_update_action_id != _latest_spawned_update_action_id(_tail_lines(log_dir / log_file_name, 2000)):+ # The root log is shared by every profile: another profile's (or an older) run's+ # completion never certifies the action this dashboard started.+ durable_update_action_id = Noneif durable_update_action_id:marker = f"=== hermes-update completed {durable_update_action_id} ==="if marker not in tail:diff --git a/hermes_cli/web_server_gateway.py b/hermes_cli/web_server_gateway.pyindex 232d0452464..9f4b5bb0c0a 100644--- a/hermes_cli/web_server_gateway.py+++ b/hermes_cli/web_server_gateway.py@@ -457,7 +457,11 @@ def _spawn_hermes_action(from hermes_cli.web_server import PROJECT_ROOT_ACTION_LOG_DIR.mkdir(parents=True, exist_ok=True)log_file = open(_ACTION_LOG_DIR / _ACTION_LOG_FILES[name], "ab", buffering=0)- log_file.write(f"\n=== {name} started {time.strftime('%Y-%m-%d %H:%M:%S')} ===\n".encode())+ # The header carries the action id durably: the update's completion marker lands in the ROOT+ # update.log every profile shares, and only this id ties one to the action THIS log started.+ action_id = (env_overrides or {}).get("HERMES_ACTION_ID")+ stamp = time.strftime('%Y-%m-%d %H:%M:%S') + (f" {action_id}" if action_id else "")+ log_file.write(f"\n=== {name} started {stamp} ===\n".encode())from hermes_cli._launchers import runtime_commandcmd = runtime_command(PROJECT_ROOT, subcommand)@@ -494,7 +498,6 @@ def _spawn_hermes_action(_ACTION_RESULTS.pop(name, None)_ACTION_COMMANDS[name] = tuple(subcommand)_ACTION_PROCS[name] = proc- action_id = (env_overrides or {}).get("HERMES_ACTION_ID")if action_id:_ACTION_IDS[name] = action_idelse:diff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.pyindex 46ed79fd11d..171df54c6d7 100644--- a/tests/hermes_cli/test_web_server.py+++ b/tests/hermes_cli/test_web_server.py@@ -8,6 +8,7 @@ import shutilimport sysimport threadingimport time+import typesfrom pathlib import Pathfrom unittest.mock import patch, MagicMock@@ -1462,7 +1463,7 @@ CONFIG_SCHEMA = ProviderConfigSchema(monkeypatch.setenv("HERMES_HOME", str(root / "profiles" / "coder"))action_id = "c" * 32(tmp_path / "hermes-update.log").write_text(- "=== hermes-update started 2026-08-17 11:19:34 ===\n"+ f"=== hermes-update started 2026-08-17 11:19:34 {action_id} ===\n""pulling updates...\n",encoding="utf-8",)@@ -1487,6 +1488,34 @@ CONFIG_SCHEMA = ProviderConfigSchema(assert data["action_id"] == action_idassert f"=== hermes-update completed {action_id} ===" in data["lines"]+ def test_update_status_ignores_another_profiles_completion_in_the_shared_root_log(self, monkeypatch, tmp_path):+ # Every profile's ``hermes update`` mirrors into the ROOT update.log; profile A's success+ # there must not certify the action profile B's dashboard started (and lost on restart).+ root = tmp_path / "root"+ (root / "logs").mkdir(parents=True)+ monkeypatch.setenv("HERMES_HOME", str(root / "profiles" / "b"))+ b_logs = tmp_path / "b-logs"+ monkeypatch.setattr(_web_server_gateway, "_ACTION_LOG_DIR", b_logs)+ for registry in ("_ACTION_PROCS", "_ACTION_RESULTS", "_ACTION_COMMANDS", "_ACTION_IDS"):+ monkeypatch.setattr(_web_server_gateway, registry, {})+ monkeypatch.setattr(_web_server_gateway.subprocess, "Popen", lambda *a, **kw: types.SimpleNamespace(pid=7))+ b_id = "b" * 32+ _web_server_gateway._spawn_hermes_action(["update"], "hermes-update", env_overrides={"HERMES_ACTION_ID": b_id})+ _web_server_gateway._ACTION_PROCS.clear() # B's dashboard restarted: in-memory result lost++ def status_after_root_completion(action_id):+ (root / "logs" / "update.log").write_text(+ "=== hermes update started 2026-08-17T11:19:35 ===\n"+ f"=== hermes-update completed {action_id} ===\n", encoding="utf-8")+ return self.client.get("/api/actions/hermes-update/status?lines=2000").json()++ foreign = status_after_root_completion("a" * 32)+ assert foreign["exit_code"] is None+ assert "action_id" not in foreign+ own = status_after_root_completion(b_id)+ assert own["exit_code"] == 0+ assert own["action_id"] == b_id+def test_update_hermes_spawns_with_action_id(self, monkeypatch):import hermes_cli.web_server as web_server