Skip to content

The agent that grows with you

fix(acp): slash work retires an un-acked prompt's retained identity

Teknium75580099e0a6
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.py
index a61a58e815f..0df66be25c2 100644
--- a/acp_adapter/gateway_server.py
+++ b/acp_adapter/gateway_server.py
@@ -417,6 +417,9 @@ class GatewayACPAgent(acp.Agent):
raise GatewayClientError(self._unknown_recovery(session_id, submitted=False))
from acp_adapter.content import _content_blocks_to_openai_user_content
text, attachments = _stage_user_content(_content_blocks_to_openai_user_content(prompt))
+ # Only this session's very next prompt may be the editor's retry of an un-acked submit; any
+ # prompt (slash work included) retires the retained identity, so a later repeat is new work.
+ retained = self._unacked.pop(session_id, None)
command = _slash_command(text) if not attachments else None
if command is not None:
from hermes_cli.gateway_mutations import slash_mutation
@@ -445,9 +448,6 @@ class GatewayACPAgent(acp.Agent):
if attachments:
submit['attachments'] = attachments
retry_key = await asyncio.to_thread(_submit_fingerprint, session_id, text, attachments)
- # Only this session's very next prompt may be the editor's retry of an un-acked submit; any
- # prompt retires the retained identity, so a deliberately repeated prompt later is new work.
- retained = self._unacked.pop(session_id, None)
input_id = retained[1] if retained is not None and retained[0] == retry_key else uuid.uuid4().hex
self._submitting.add(session_id)
try:
diff --git a/tests/acp_adapter/test_gateway_unacked_slash.py b/tests/acp_adapter/test_gateway_unacked_slash.py
new file mode 100644
index 00000000000..331af2a8605
--- /dev/null
+++ b/tests/acp_adapter/test_gateway_unacked_slash.py
@@ -0,0 +1,72 @@
+"""Slash work retires an un-acked prompt's retained identity: a later identical prompt is new work."""
+import asyncio
+from types import SimpleNamespace
+
+import acp
+import pytest
+
+from acp_adapter.gateway_server import GatewayACPAgent
+from gateway.config import GatewayConfig
+from gateway.session import SessionStore
+from gateway.session_authority import initialize_session_authority
+from gateway.session_controls import AuthorityConnection
+from hermes_cli.gateway_client import GatewayClientError
+from hermes_state_runtime import list_session_admissions
+from tests.acp_adapter.test_gateway_submit_retry import Wire
+
+
+class SlashWire(Wire):
+ async def rpc(self, method, _timeout=None, **params): # the client budget is never on the wire
+ return await super().rpc(method, **params)
+
+
+async def test_repeated_prompt_after_slash_command_is_new_work(tmp_path, monkeypatch):
+ monkeypatch.setenv('HERMES_HOME', str(tmp_path))
+ store = SessionStore(tmp_path / 'sessions', GatewayConfig())
+ executed = []
+
+ async def answer(event):
+ from gateway.session_results import execution_result
+ executed.append(event.text)
+ execution_result.get()['result'] = {'final_response': 'ACK_' + event.text, 'completed': True, 'messages': []}
+ return 'ACK_' + event.text
+
+ from gateway import run
+ from gateway.session_local import create_local_session
+ monkeypatch.setattr(run, '_load_gateway_config', lambda: {'platform_toolsets': {'acp': []}})
+ runner = SimpleNamespace(_session_db=store._db, session_store=store, _draining=False, adapters={},
+ _handle_message=answer, _adapter_for_source=lambda source: None,
+ _cached_agent_for=lambda route: None,
+ _resolve_session_agent_runtime=lambda **kwargs: ('frozen', {}))
+ authority = await initialize_session_authority(runner, profile_id='p', instance_id='owner')
+ wire = SlashWire(asyncio.get_running_loop())
+ wire.viewer = AuthorityConnection(authority, wire, {'user_id': 'editor', 'profile_id': 'p'})
+ s = create_local_session(authority, wire.viewer.actor, {'request_id': 'editor', 'source': 'acp',
+ 'cwd': str(tmp_path), 'model': 'frozen',
+ 'toolsets': []}).session_id
+ agent = GatewayACPAgent()
+ agent._gateway = wire
+ updates = []
+
+ async def session_update(session_id, update):
+ updates.append(update.content.text)
+ agent._conn = SimpleNamespace(session_update=session_update)
+ agent._snapshots[s] = await wire.rpc('session.resume', session_id=s)
+ agent._event_task = asyncio.create_task(agent._events())
+ try:
+ with pytest.raises(GatewayClientError, match='outcome is unknown'):
+ await agent.prompt([acp.text_block('yes')], s)
+ async with asyncio.timeout(5):
+ while 'ACK_yes' not in updates:
+ await asyncio.sleep(0.01)
+ # Read-only slash work between the lost-ack prompt and the deliberate repeat.
+ await asyncio.wait_for(agent.prompt([acp.text_block('/compress --preview')], s), 5)
+ response = await asyncio.wait_for(agent.prompt([acp.text_block('yes')], s), 5)
+ assert response.stop_reason == 'end_turn'
+ assert executed == ['yes', 'yes']
+ assert len(list_session_admissions(authority.db, session_id=s, pending_only=False)) == 2
+ finally:
+ agent._event_task.cancel()
+ await wire.viewer.close()
+ store.close_all_db_handles()