Skip to content

The agent that grows with you

fix(acp): keep retained submission identities through their own retry

Tekniumf3c6349480c1
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.py
index 7e4bd3a3dfc..736f97f0cc3 100644
--- a/acp_adapter/gateway_server.py
+++ b/acp_adapter/gateway_server.py
@@ -422,7 +422,6 @@ class GatewayACPAgent(acp.Agent):
# 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)
- self._mutations.retire(session_id) # ... and every prepared control's (a slash re-keeps its own)
command = _slash_command(text) if not attachments else None
if command is not None:
from hermes_cli.gateway_mutations import slash_mutation
@@ -445,8 +444,8 @@ class GatewayACPAgent(acp.Agent):
self._snapshots[session_id] = await client.rpc('session.resume', session_id=session_id)
self._mutations.acknowledge(session_id, operation, payload)
return PromptResponse(stop_reason='end_turn')
- client = await self._client()
- link = self._link
+ # ... and every prepared control's (a slash keeps its own key: apply retires the rest).
+ self._mutations.retire(session_id)
submit = {'text': text}
if attachments:
submit['attachments'] = attachments
@@ -454,6 +453,9 @@ class GatewayACPAgent(acp.Agent):
input_id = retained[1] if retained is not None and retained[0] == retry_key else uuid.uuid4().hex
self._submitting.add(session_id)
try:
+ # Inside the try: a failed reconnect is as ambiguous for a retained identity as a lost ack.
+ client = await self._client()
+ link = self._link
receipt = await client.rpc("prompt.submit", session_id=session_id, input_id=input_id, **submit)
except BaseException as exc:
from hermes_cli.gateway_client import GatewayRPCError
diff --git a/tests/acp_adapter/test_acp_unacked_identity_retry.py b/tests/acp_adapter/test_acp_unacked_identity_retry.py
new file mode 100644
index 00000000000..16dd94a8c3f
--- /dev/null
+++ b/tests/acp_adapter/test_acp_unacked_identity_retry.py
@@ -0,0 +1,52 @@
+"""ACP keeps a retained submission identity through its own retry: a failed reconnect keeps an
+un-acked prompt's input_id, and a slash control's retry keeps its prepared request_id."""
+import asyncio
+
+import acp
+import pytest
+
+from hermes_cli.gateway_client import GatewayClientError
+from hermes_state_runtime import list_session_admissions
+from tests.acp_adapter import test_retained_identity_retirement as base
+from tests.acp_adapter.test_retained_identity_retirement import _acp, _model, _settled
+
+owner = base.owner # the shared real-authority fixture
+
+
+async def test_failed_reconnect_keeps_the_unacked_input_id(owner):
+ agent = await _acp(owner)
+ try:
+ owner.wire.lose = ('prompt.submit', lambda params: True, 'after')
+ with pytest.raises(GatewayClientError, match='outcome is unknown'):
+ await agent.prompt([acp.text_block('yes')], owner.sid)
+ await _settled(owner, 1)
+ reconnect = agent._client
+
+ async def unreachable():
+ agent._client = reconnect
+ raise GatewayClientError('gateway unreachable')
+ agent._client = unreachable
+ with pytest.raises(GatewayClientError, match='unreachable'):
+ await agent.prompt([acp.text_block('yes')], owner.sid)
+ await asyncio.wait_for(agent.prompt([acp.text_block('yes')], owner.sid), 5)
+ assert owner.executed == ['yes']
+ assert len(list_session_admissions(owner.authority.db, session_id=owner.sid, pending_only=False)) == 1
+ finally:
+ agent._event_task.cancel()
+
+
+async def test_slash_control_retry_after_lost_reply_is_one_mutation(owner):
+ agent = await _acp(owner)
+ try:
+ owner.wire.lose = ('session.mutate', _model, 'after')
+ with pytest.raises(GatewayClientError, match='outcome is unknown'):
+ await agent.prompt([acp.text_block('/model model-a')], owner.sid)
+ revision = owner.authority.db.get_session(owner.sid)['runtime_revision']
+ await asyncio.wait_for(agent.prompt([acp.text_block('/model model-a')], owner.sid), 5)
+ # The retry replays the committed receipt: no second mutation (a /compress would summarize twice).
+ assert owner.authority.db.get_session(owner.sid)['runtime_revision'] == revision
+ assert owner.authority.db.get_session(owner.sid)['model'] == 'model-a'
+ finally:
+ agent._event_task.cancel()