The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: offload dashboard log reads from event loop
Xipongfe9a5ccafae1
diff --git a/hermes_cli/web_routers/status.py b/hermes_cli/web_routers/status.pyindex 9b85f5768c0..99fcf9a1393 100644--- a/hermes_cli/web_routers/status.py+++ b/hermes_cli/web_routers/status.py@@ -824,13 +824,17 @@ async def get_logs(if comp_prefixes is None:raise HTTPException(status_code=400, detail=f"Unknown component: {component}. "f"Available: {', '.join(sorted(COMPONENT_PREFIXES))}")- result = _read_tail(- log_path, min(lines, 500) if not search else 2000,- has_filters=bool(min_level or comp_prefixes or search),- min_level=min_level, component_prefixes=comp_prefixes)- # _read_tail doesn't support free-text search, so post-filter (case-insensitive- # substring) here and trim to the requested line count afterward.- if search:- needle = search.lower()- result = [l for l in result if needle in l.lower()][-min(lines, 500):]+ def _load_logs():+ result = _read_tail(+ log_path, min(lines, 500) if not search else 2000,+ has_filters=bool(min_level or comp_prefixes or search),+ min_level=min_level, component_prefixes=comp_prefixes)+ # _read_tail doesn't support free-text search, so post-filter (case-insensitive+ # substring) here and trim to the requested line count afterward.+ if search:+ needle = search.lower()+ result = [line for line in result if needle in line.lower()][-min(lines, 500):]+ return result++ result = await asyncio.to_thread(_load_logs)return {"file": file, "lines": result}diff --git a/tests/hermes_cli/test_web_logs_async.py b/tests/hermes_cli/test_web_logs_async.pynew file mode 100644index 00000000000..3936971d944--- /dev/null+++ b/tests/hermes_cli/test_web_logs_async.py@@ -0,0 +1,26 @@+import asyncio+import threading++from hermes_cli.web_routers import status+++def test_get_logs_yields_while_reading_and_filtering(tmp_path, monkeypatch):+ logs_dir = tmp_path / "logs"+ logs_dir.mkdir()+ (logs_dir / "agent.log").write_text("fixture\n", encoding="utf-8")+ monkeypatch.setattr(status, "get_hermes_home", lambda: tmp_path)++ loop_ran = threading.Event()++ def blocking_read(*args, **kwargs):+ assert loop_ran.wait(2), "log reading blocked the event loop"+ return ["fixture"]++ import hermes_cli.logs+ monkeypatch.setattr(hermes_cli.logs, "_read_tail", blocking_read)++ async def exercise():+ asyncio.get_running_loop().call_soon(loop_ran.set)+ return await status.get_logs(file="agent", lines=100)++ assert asyncio.run(exercise()) == {"file": "agent", "lines": ["fixture"]}