The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): recover update success after restart
Mauricio Ruiz091106092b5d
diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.pyindex 699b8017f82..cc689f07b0b 100644--- a/hermes_cli/web_server.py+++ b/hermes_cli/web_server.py@@ -4406,6 +4406,10 @@ GATEWAY_RESTART_COOLDOWN_SECONDS = 10.0# child exits is the bug this exists to fix._LAST_GATEWAY_RESTART: Optional[Tuple[float, subprocess.Popen, Tuple[str, ...]]] = None+_UPDATE_ACTION_COMPLETED_RE = re.compile(+ r"^=== hermes-update completed ([0-9a-f]{32}) ===$"+)+# ``name`` → completed synthetic action result for actions the server handled# without spawning a subprocess (for example, unsupported Docker updates)._ACTION_RESULTS: Dict[str, Dict[str, Any]] = {}@@ -4559,6 +4563,34 @@ def _tail_lines(path: Path, n: int) -> List[str]:return lines[-n:]+def _durable_completed_update_action_id(lines: List[str]) -> Optional[str]:+ """Recover the latest successful update identity from ``update.log``.++ The dashboard action process can restart the dashboard that spawned it.+ That loses the in-memory ``Popen``/result registries while the durable+ update log survives. Only accept a completion marker that occurs after+ the latest update-start marker, so a stale success cannot mask a newer+ failed attempt.+ """+ last_start = -1+ last_completed = -1+ completed_action_id: Optional[str] = None++ for index, line in enumerate(lines):+ if line.startswith("=== hermes update started "):+ last_start = index++ match = _UPDATE_ACTION_COMPLETED_RE.fullmatch(line.strip())+ if match:+ last_completed = index+ completed_action_id = match.group(1)++ if completed_action_id and last_completed > last_start:+ return completed_action_id++ return None++def _gateway_subcommand(profile: Optional[str], verb: str) -> List[str]:return _profile_cli_args(profile) + ["gateway", verb]@@ -5494,7 +5526,17 @@ async def get_action_status(name: str, lines: int = 200):raise HTTPException(status_code=404, detail=f"Unknown action: {name}")log_path = _ACTION_LOG_DIR / log_file_name- tail = _tail_lines(log_path, min(max(lines, 1), 2000))+ requested_lines = min(max(lines, 1), 2000)+ tail = _tail_lines(log_path, requested_lines)++ durable_update_action_id = None+ if name == "hermes-update":+ durable_lines = _tail_lines(_ACTION_LOG_DIR / "update.log", 2000)+ durable_update_action_id = _durable_completed_update_action_id(durable_lines)+ if durable_update_action_id:+ marker = f"=== hermes-update completed {durable_update_action_id} ==="+ if marker not in tail:+ tail = [*tail, marker][-requested_lines:]proc = _ACTION_PROCS.get(name)if proc is None:@@ -5502,6 +5544,8 @@ async def get_action_status(name: str, lines: int = 200):running = Falseexit_code = result.get("exit_code") if result else Nonepid = result.get("pid") if result else None+ if result is None and durable_update_action_id:+ exit_code = 0else:exit_code = proc.poll()running = exit_code is None@@ -5516,13 +5560,16 @@ async def get_action_status(name: str, lines: int = 200):_ACTION_COMMANDS.pop(name, None)_ACTION_IDS.pop(name, None)- return {+ response = {"name": name,"running": running,"exit_code": exit_code,"pid": pid,"lines": tail,}+ if durable_update_action_id:+ response["action_id"] = durable_update_action_id+ return response# Per-row fields that no session LIST consumer reads but that dominate thediff --git a/tests/hermes_cli/test_web_server.py b/tests/hermes_cli/test_web_server.pyindex b28bc6a8fa5..38e64d6236e 100644--- a/tests/hermes_cli/test_web_server.py+++ b/tests/hermes_cli/test_web_server.py@@ -1231,6 +1231,36 @@ class TestWebServerEndpoints:assert check_data["update_command"] == "pkg upgrade hermes-agent"assert "Termux APT" in check_data["message"]+ def test_update_status_recovers_completed_result_after_dashboard_restart(self, monkeypatch, tmp_path):+ import hermes_cli.web_server as web_server++ action_id = "c" * 32+ (tmp_path / "hermes-update.log").write_text(+ "=== hermes-update started 2026-08-17 11:19:34 ===\n"+ "pulling updates...\n",+ encoding="utf-8",+ )+ (tmp_path / "update.log").write_text(+ "=== hermes update started 2026-08-17T11:19:35 ===\n"+ "✓ Update complete!\n"+ f"=== hermes-update completed {action_id} ===\n",+ encoding="utf-8",+ )+ monkeypatch.setattr(web_server, "_ACTION_LOG_DIR", tmp_path)+ monkeypatch.setattr(web_server, "_ACTION_PROCS", {})+ monkeypatch.setattr(web_server, "_ACTION_RESULTS", {})+ monkeypatch.setattr(web_server, "_ACTION_COMMANDS", {})+ monkeypatch.setattr(web_server, "_ACTION_IDS", {})++ status = self.client.get("/api/actions/hermes-update/status?lines=2000")++ assert status.status_code == 200+ data = status.json()+ assert data["running"] is False+ assert data["exit_code"] == 0+ assert data["action_id"] == action_id+ assert f"=== hermes-update completed {action_id} ===" in data["lines"]+def test_update_hermes_spawns_with_action_id(self, monkeypatch):import hermes_cli.web_server as web_server