The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(acp): refuse a paused prompt before staging its media
Tekniumed4cefebb449
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.pyindex d70cb2bb5f9..327f5c2a77f 100644--- a/acp_adapter/gateway_server.py+++ b/acp_adapter/gateway_server.py@@ -579,13 +579,18 @@ class GatewayACPAgent(GatewayReplyMixin, acp.Agent):raise GatewayClientError("not_found")if self._has_unknown(session_id) and await self._refresh_unknown_for_prompt(session_id):return PromptResponse(stop_reason='cancelled')+ if self._has_unknown(session_id):+ # Only a text-only /discard passes a lost turn, recognised BEFORE staging: a refused+ # prompt must not write its media or retire the editor's retained retry identity.+ from acp_adapter.content import _content_blocks_to_openai_user_content+ content = _content_blocks_to_openai_user_content(prompt)+ if not isinstance(content, str) or _slash_command(content) != 'discard':+ raise GatewayClientError(self._unknown_recovery(session_id, submitted=False))prepared = await self._prepare_submit(session_id, prompt)if prepared is None:return PromptResponse(stop_reason='cancelled')retry_key, input_id, staged = preparedtext, attachments = staged- if self._has_unknown(session_id) and (attachments or _slash_command(text) != 'discard'):- raise GatewayClientError(self._unknown_recovery(session_id, submitted=False))answered, text = await self._run_slash(held_id, session_id, text) if not attachments else (False, text)if answered:return PromptResponse(stop_reason='end_turn')diff --git a/tests/acp_adapter/test_acp_discard_review.py b/tests/acp_adapter/test_acp_discard_review.pyindex 4f2bf8ce2c1..b84425c8e3d 100644--- a/tests/acp_adapter/test_acp_discard_review.py+++ b/tests/acp_adapter/test_acp_discard_review.py@@ -5,12 +5,16 @@ pending-only refresh, not whole-snapshot adoption), and a paused prompt that isis refused before any media is staged or the retained retry identity is retired. Deterministicprotocol peers, real staging I/O."""import asyncio+import base64import acpimport pytest+from acp.schema import ImageContentBlockfrom acp_adapter.gateway_commands import run_commandfrom acp_adapter.gateway_server import GatewayACPAgent+from hermes_cli.gateway_client import GatewayClientError+from tests.acp_adapter.test_acp_image_staging_boundary import PNGclass Peer:@@ -65,3 +69,21 @@ async def test_discard_preserves_buffered_reply(route):finally:pump.cancel()await asyncio.gather(pump, return_exceptions=True)+++async def test_paused_image_refusal_does_not_stage_image(tmp_path):+ agent = GatewayACPAgent()+ agent._home = tmp_path+ unknown = {'pending': [{'admission_id': 'lost', 'status': 'unknown'}],+ 'replay_epoch': 'owner', 'last_sequence': 1}+ agent._snapshots['s'] = dict(unknown)+ agent._gateway = Peer([dict(unknown)])+ agent._unacked['s'] = ('prior-retry', 'prior-id', ('prior-content', []))+ prompt = [acp.text_block('explain image'), ImageContentBlock(type='image',+ data=base64.b64encode(PNG).decode(), mime_type='image/png')]+ with pytest.raises(GatewayClientError, match='unknown_execution'):+ await agent.prompt(prompt, 's')+ staged = [str(p.relative_to(tmp_path)) for p in tmp_path.rglob('*.png')]+ assert not staged, staged+ assert 's' in agent._unacked