The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(acp): /discard keeps replies the editor has not shown yet
Tekniume1d69de34d1c
diff --git a/acp_adapter/gateway_commands.py b/acp_adapter/gateway_commands.pyindex fbcde2592b3..355dff307fd 100644--- a/acp_adapter/gateway_commands.py+++ b/acp_adapter/gateway_commands.py@@ -73,16 +73,17 @@ async def _discard_unknown(agent, session_id, _command, admission_id):"""Acknowledge one exact lost turn and refresh its FIFO snapshot."""if not admission_id:return 'Usage: /discard <lost admission id>', None- client = await agent._client()- snapshot = await client.rpc('session.resume', session_id=session_id)- agent._snapshots[session_id] = snapshot- lost = next((row for row in snapshot.get('pending', [])+ # Pending-only refreshes: adopting the whole snapshot would advance its reply cursor past+ # messages and approvals the editor's event pump has not projected yet.+ await agent._refresh_unknown(session_id)+ lost = next((row for row in agent._snapshots[session_id].get('pending', [])if row.get('admission_id') == admission_id and row.get('status') == 'unknown'), None)if lost is None:return (f'No unknown (lost) admission with id {admission_id}; refresh the session and try again.', None)+ client = await agent._client()await client.rpc('prompt.resolve_unknown', session_id=session_id, admission_id=admission_id,execution_generation=lost['execution_generation'])- agent._snapshots[session_id] = await client.rpc('session.resume', session_id=session_id)+ await agent._refresh_unknown(session_id)return 'Discarded the lost turn. Queued messages can continue.', Nonediff --git a/tests/acp_adapter/test_acp_discard_review.py b/tests/acp_adapter/test_acp_discard_review.pynew file mode 100644index 00000000000..4f2bf8ce2c1--- /dev/null+++ b/tests/acp_adapter/test_acp_discard_review.py@@ -0,0 +1,67 @@+"""ACP ``/discard`` while a lost turn pauses the session (review #141357, GW-10).++Discard must not consume reply/approval sequence numbers the editor has not projected yet (the+pending-only refresh, not whole-snapshot adoption), and a paused prompt that is not ``/discard``+is refused before any media is staged or the retained retry identity is retired. Deterministic+protocol peers, real staging I/O."""+import asyncio++import acp+import pytest++from acp_adapter.gateway_commands import run_command+from acp_adapter.gateway_server import GatewayACPAgent+++class Peer:+ def __init__(self, snapshots):+ self.snapshots = iter(snapshots)+ self.events = asyncio.Queue()+ self.calls = []++ async def rpc(self, method, **params):+ self.calls.append(method)+ if method == 'session.resume':+ return next(self.snapshots)+ if method == 'prompt.resolve_unknown':+ return {'status': 'terminal', 'outcome': 'interrupted'}+ raise AssertionError((method, params))+++class Editor:+ def __init__(self):+ self.messages = []+ self.marker = asyncio.Event()++ async def session_update(self, *, session_id, update):+ text = getattr(getattr(update, 'content', None), 'text', '')+ self.messages.append(text)+ if text == 'MARKER':+ self.marker.set()++[email protected]('route', ['existing_pending_refresh', 'new_discard'])+async def test_discard_preserves_buffered_reply(route):+ agent = GatewayACPAgent()+ old = {'pending': [{'admission_id': 'lost', 'status': 'unknown', 'execution_generation': 1}],+ 'replay_epoch': 'owner', 'last_sequence': 1}+ fresh = {'pending': [], 'replay_epoch': 'owner', 'last_sequence': 4}+ agent._snapshots['s'] = dict(old)+ agent._gateway = Peer([dict(old), dict(fresh)] if route == 'new_discard' else [dict(fresh)])+ editor = agent._conn = Editor()+ if route == 'new_discard':+ await run_command(agent, 's', 'discard', 'lost')+ else:+ await agent._refresh_unknown('s')+ for seq, text in [(3, 'BUFFERED FOLLOWER ANSWER'), (5, 'MARKER')]:+ await agent._gateway.events.put({'params': {+ 'session_id': 's', 'replay_epoch': 'owner', 'seq': seq,+ 'type': 'message.delta', 'admission_id': 'follower', 'payload': {'text': text}}})+ pump = asyncio.create_task(agent._events())+ try:+ await asyncio.wait_for(editor.marker.wait(), 5)+ assert 'BUFFERED FOLLOWER ANSWER' in editor.messages, editor.messages+ finally:+ pump.cancel()+ await asyncio.gather(pump, return_exceptions=True)