Skip to content

The agent that grows with you

fix: ACP names the existing recovery for a session blocked by a lost turn

Tekniumabddc31aaef8
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.py
index 5dc9b9d2cd8..b19a4404f66 100644
--- a/acp_adapter/gateway_server.py
+++ b/acp_adapter/gateway_server.py
@@ -270,6 +270,10 @@ class GatewayACPAgent(acp.Agent):
await self._conn.session_update(session_id=held_id, update=update)
for pending in snapshot.get("prompts", []):
self._permission(session_id, pending)
+ if self._has_unknown(session_id) and self._conn:
+ # The classic chat's resume notice: say why the next prompt will be refused and how to recover.
+ await self._conn.session_update(session_id=held_id, update=acp.update_agent_message_text(
+ self._unknown_recovery(session_id, submitted=False).removeprefix("unknown_execution: ") + "\n"))
return snapshot
async def load_session(self, cwd, session_id, mcp_servers=None, **kwargs):
@@ -363,7 +367,7 @@ class GatewayACPAgent(acp.Agent):
if session_id not in self._snapshots:
raise GatewayClientError("not_found")
if self._has_unknown(session_id):
- raise GatewayClientError("unknown_execution")
+ 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))
command = _slash_command(text) if not attachments else None
@@ -415,8 +419,7 @@ class GatewayACPAgent(acp.Agent):
raise self._lost_failure
if self._failure:
raise self._failure
- raise GatewayClientError("unknown_execution: do not resend accepted input; "
- "resolve the lost turn before continuing")
+ raise GatewayClientError(self._unknown_recovery(session_id, admission_id))
terminal = self._terminals.pop(admission_id)
finally:
# Do not let one prompt tear down a newer mapping if the session has
@@ -426,12 +429,27 @@ class GatewayACPAgent(acp.Agent):
outcome = terminal.get("outcome")
if outcome == "unknown":
# Our own lost turn: the same refusal whether session.info or this completion woke us.
- raise GatewayClientError("unknown_execution: do not resend accepted input; "
- "resolve the lost turn before continuing")
+ raise GatewayClientError(self._unknown_recovery(session_id, admission_id))
if outcome == "failed":
raise GatewayClientError("admitted_turn_failed")
return PromptResponse(stop_reason="cancelled" if outcome == "cancelled" else "end_turn")
+ def _unknown_recovery(self, session_id, admission_id=None, *, submitted=True):
+ """The refusal for a FIFO blocked by a lost turn, naming the existing recovery control.
+
+ ACP has no discard affordance; the classic chat's fenced ``/discard`` (``prompt.resolve_unknown``)
+ acknowledges the exact lost admission without replaying it, and the queue then continues."""
+ from hermes_constants import profile_name_for_home
+ lost = [row["admission_id"] for row in self._snapshots.get(session_id, {}).get("pending", [])
+ if row.get("status") == "unknown"] or [admission_id]
+ profile = profile_name_for_home(self._home)
+ command = "hermes" + (f" -p {profile}" if profile not in (None, "default") else "")
+ state = ("your input is accepted and kept" if submitted else "nothing was submitted")
+ return (f"unknown_execution: do not resend accepted input; a turn in this session was lost when the "
+ f"gateway restarted and its outcome is unknown ({state}). Resolve it in a terminal with "
+ f"`{command} chat --cli --resume {session_id}` then "
+ + " and ".join(f"`/discard {lost_id}`" for lost_id in lost) + ", then continue here.")
+
def _has_unknown(self, session_id):
return any(row.get("status") == "unknown"
for row in self._snapshots[session_id].get("pending", []))
diff --git a/tests/acp_adapter/test_gateway_queued_unknown.py b/tests/acp_adapter/test_gateway_queued_unknown.py
index 750616dcee1..105498443e0 100644
--- a/tests/acp_adapter/test_gateway_queued_unknown.py
+++ b/tests/acp_adapter/test_gateway_queued_unknown.py
@@ -51,6 +51,30 @@ async def test_editor_refuses_new_prompt_until_lost_turn_is_resolved():
agent._gateway.rpc.assert_not_awaited()
+async def test_resumed_unknown_turn_names_the_existing_discard_recovery():
+ # ACP has no discard affordance: the resume notice and the refusal must name the exact
+ # admission and the classic chat control (``/discard`` -> prompt.resolve_unknown) that clears it.
+ agent = GatewayACPAgent()
+ agent._gateway = AsyncMock()
+ agent._conn = AsyncMock()
+ lost = 'admission-lost-0123456789abcdef'
+ agent._gateway.rpc.side_effect = lambda method, **params: {
+ 'session.info': {}, 'session.resume': {
+ 'session_id': 's', 'messages': [], 'prompts': [],
+ 'pending': [{'admission_id': lost, 'status': 'unknown', 'execution_generation': 4}]},
+ }[method]
+ await agent.load_session(cwd='/', session_id='s')
+ notice = agent._conn.session_update.await_args.kwargs['update'].content.text
+ with pytest.raises(GatewayClientError) as refused:
+ await agent.prompt([acp.text_block('new input')], 's')
+ for text in (notice, str(refused.value)):
+ assert 'chat --cli --resume s' in text and f'/discard {lost}' in text, text
+ assert 'do not resend' in text
+ assert 'nothing was submitted' in str(refused.value)
+ assert [call.args[0] for call in agent._gateway.rpc.await_args_list] == ['session.info', 'session.resume']
+
+
@pytest.mark.asyncio
@pytest.mark.parametrize('yield_between', [False, True])
async def test_editor_own_lost_turn_reports_unknown_not_end_turn(yield_between):