The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(lsp): the LSP server's spawn-ledger write runs off the event loop
kshitijk4poor6d915fad08e8
diff --git a/agent/lsp/client.py b/agent/lsp/client.pyindex 93d584f6bbe..9fc5ae418d0 100644--- a/agent/lsp/client.py+++ b/agent/lsp/client.py@@ -285,7 +285,8 @@ class LSPClient:# SIGKILLed / OOM-killed Hermes forever. The owner-death supervisor kills the whole group# the moment this process dies, by any cause. No-op on Windows (job object instead).own_process_groups([self._proc.pid])- register_child(self._proc.pid, "lsp-server")+ # Off the event loop: the ledger write takes a cross-process lock (up to 2 s).+ await asyncio.to_thread(register_child, self._proc.pid, "lsp-server")# stderr must be drained or the pipe buffer fills and the server hangs.self._stderr_task = asyncio.create_task(self._drain_stderr())self._reader_task = asyncio.create_task(self._reader_loop())diff --git a/tests/agent/lsp/test_lsp_owned_server.py b/tests/agent/lsp/test_lsp_owned_server.pyindex 3cce57fcd0c..139d43e326b 100644--- a/tests/agent/lsp/test_lsp_owned_server.py+++ b/tests/agent/lsp/test_lsp_owned_server.py@@ -9,6 +9,7 @@ owner-death supervisor; teardown hands it back once the group is empty."""from __future__ import annotations+import asyncioimport osimport subprocessimport sys@@ -36,6 +37,14 @@ def _alive(pid: int) -> bool:return False+def _no_running_loop() -> bool:+ try:+ asyncio.get_running_loop()+ except RuntimeError:+ return True+ return False++def _client(workspace: Path, script: str, **extra_env: str) -> LSPClient:env = {"MOCK_LSP_SCRIPT": script, "PYTHONPATH": os.environ.get("PYTHONPATH", ""), **extra_env}return LSPClient(server_id=f"mock-{script}", workspace_root=str(workspace),@@ -47,7 +56,13 @@ def recorded(monkeypatch):calls: list = []monkeypatch.setattr(lsp_client, "own_process_groups", lambda pgids: calls.append(("own", list(pgids))))monkeypatch.setattr(process_identity, "release_process_groups", lambda pgids: calls.append(("release", list(pgids))))- monkeypatch.setattr(lsp_client, "register_child", lambda pid, purpose: calls.append(("ledger", pid, purpose)))++ def ledger(pid, purpose):+ # The ledger write can wait up to 2 s on another Hermes's lock: never on the event loop.+ assert _no_running_loop(), "the spawn-ledger write ran on the event loop"+ calls.append(("ledger", pid, purpose))++ monkeypatch.setattr(lsp_client, "register_child", ledger)return calls