The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(acp): an overlay HERMES_HOME attaches with the mirrored profile's identity
Tekniumfc49050f940e
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.pyindex c5c45a725f0..88d1e196ce2 100644--- a/acp_adapter/gateway_server.py+++ b/acp_adapter/gateway_server.py@@ -67,7 +67,9 @@ class GatewayACPAgent(GatewayReplyMixin, acp.Agent):self._gateway = Noneself._connection = Noneself._connect_lock = asyncio.Lock()- self._home = get_hermes_home().resolve()+ # A per-task overlay HERMES_HOME attaches to the profile its symlinked lock names (#138949).+ from hermes_cli.gateway_runtime import gateway_profile_home+ self._home = gateway_profile_home(get_hermes_home())self._snapshots = {}self._event_task = Noneself._terminals = {}diff --git a/hermes_cli/gateway_client.py b/hermes_cli/gateway_client.pyindex 9c1964fc5aa..f369f2cfe51 100644--- a/hermes_cli/gateway_client.py+++ b/hermes_cli/gateway_client.py@@ -193,13 +193,13 @@ async def connect_gateway(endpoint=None, subject=None):rather than the socket identity; only a peer the owner already trusts may name one."""from websockets.asyncio.client import connectfrom hermes_constants import get_hermes_home- from hermes_cli.gateway_runtime import attachable, ensure_gateway_runtime+ from hermes_cli.gateway_runtime import attachable, ensure_gateway_runtime, gateway_profile_homefrom urllib.parse import urlsplitremote = "" if endpoint is not None else os.environ.get("HERMES_TUI_GATEWAY_URL", "").strip()protocols = Noneif endpoint is not None:- ticket = await asyncio.to_thread(_session_ticket, get_hermes_home().resolve(), endpoint,+ ticket = await asyncio.to_thread(_session_ticket, gateway_profile_home(get_hermes_home()), endpoint,subject=subject)url, protocols = gateway_ws_target(endpoint, ticket)elif remote:@@ -208,7 +208,8 @@ async def connect_gateway(endpoint=None, subject=None):raise GatewayClientError("Invalid explicit gateway WebSocket URL; no local fallback")url = remoteelse:- home = get_hermes_home().resolve()+ # A per-task overlay home is served by the profile its symlinked lock names (#138949).+ home = gateway_profile_home(get_hermes_home())# A client's own start: the daemon it may launch ends itself once idle (no client, adapter,# cron/kanban work or admission), and the next client starts a fresh one.result = await asyncio.to_thread(ensure_gateway_runtime, home, idle_exit=True)diff --git a/hermes_cli/gateway_runtime.py b/hermes_cli/gateway_runtime.pyindex 10c01aaec29..c2b602944ac 100644--- a/hermes_cli/gateway_runtime.py+++ b/hermes_cli/gateway_runtime.py@@ -65,6 +65,14 @@ def _canonical_home(home: str | Path) -> str:return os.path.normcase(str(Path(home).expanduser().resolve()))+def gateway_profile_home(home: str | Path) -> Path:+ """The profile home whose gateway serves *home*: the home itself, or for a private overlay home+ (a task dir mirroring a profile through symlinks, its ``gateway.lock`` among them) the profile its+ lock names. A client compares the owner's ``profile_id`` with this, never the overlay path.+ Not normcased: ``profile_id`` keeps the owner's own spelling (Windows)."""+ return _overlay_owner_home(Path(home).expanduser().resolve())++def _overlay_owner_home(home: Path) -> Path:"""Return the owner named by a private overlay's gateway lock, if it has one."""if os.name == "nt":diff --git a/tests/acp_adapter/test_gateway_overlay_home.py b/tests/acp_adapter/test_gateway_overlay_home.pynew file mode 100644index 00000000000..c40f5ca1726--- /dev/null+++ b/tests/acp_adapter/test_gateway_overlay_home.py@@ -0,0 +1,41 @@+"""``hermes acp`` with a per-task overlay ``HERMES_HOME`` (#138949, #134889 ACP-18).++A Multica task home is a private real directory mirroring a served profile through symlinks, its+``gateway.lock`` among them. The symlinked lock names the owner that serves the mirrored profile:+the editor attaches to that owner (no second owner on the shared ``state.db``), over the real ACP+stdio wire and a real gateway. (A home others can write never selects an owner: covered in+tests/hermes_cli/test_gateway_runtime_discovery.py; ``hermes acp`` startup narrows its own home to+0700 first, so that case is not reachable through the entry.)+"""+import json++import pytest++from tests.acp_adapter.test_gateway_sessions import editor, viewer+++def _overlay(daemon, tmp_path):+ home, descriptor, env, root = daemon+ overlay = tmp_path / 'task-home'+ overlay.mkdir(mode=0o700)+ for name in ('gateway.lock', 'state.db', 'config.yaml'):+ (overlay / name).symlink_to(home / name)+ return overlay, descriptor, {**env, 'HERMES_HOME': str(overlay)}, root++[email protected]('linux')+async def test_overlay_home_attaches_to_the_owner_its_lock_names(daemon, tmp_path, model_peer):+ overlay = _overlay(daemon, tmp_path)+ async with editor(overlay, tmp_path) as acp:+ await acp.rpc('initialize', protocolVersion=1, clientCapabilities={})+ created = await acp.rpc('session/new', cwd=str(tmp_path), mcpServers=[])+ assert 'result' in created, (created, (tmp_path / 'acp.log').read_text()[-2000:])+ sid = created['result']['sessionId']+ turn = await acp.rpc('session/prompt', sessionId=sid, prompt=[{'type': 'text', 'text': 'WS_SHARED overlay'}])+ assert turn['result']['stopReason'] == 'end_turn', turn+ assert 'result' in await acp.rpc('session/load', cwd=str(tmp_path), sessionId=sid, mcpServers=[])+ async with viewer(daemon) as ws: # one owner: the mirrored profile's gateway holds the session+ saved = await ws.rpc('session.resume', session_id=sid)+ assert 'WS_SHARED overlay' in json.dumps(saved['messages'])+ assert not (overlay[0] / 'gateway.sock').exists() and not (overlay[0] / 'gateway.pid').exists()