The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(acp): project the edit mode from every recovered snapshot
Teknium0ef1f91d6ae0
diff --git a/acp_adapter/gateway_server.py b/acp_adapter/gateway_server.pyindex b1ccab1ce26..b650ff9986e 100644--- a/acp_adapter/gateway_server.py+++ b/acp_adapter/gateway_server.py@@ -188,7 +188,7 @@ class GatewayACPAgent(GatewayReplyMixin, acp.Agent):logger.info("ACP session %s not re-attached after reconnect", session_id, exc_info=True)self._snapshots.pop(session_id, None)continue- self._snapshots[session_id] = snapshot+ await self._adopt(session_id, snapshot)# Before this session's cards are offered again: until ``_client`` returns, ``self._gateway`` is# not this connection, so a card answered while the request is out would lose its answer.await self._request_live_reasoning(gateway, session_id)@@ -196,6 +196,19 @@ class GatewayACPAgent(GatewayReplyMixin, acp.Agent):self._permission(session_id, pending)await self._notify_unknown(session_id)+ async def _adopt(self, session_id, snapshot, resumes=None):+ """Replace a session's projection with a fresh ``session.resume`` snapshot (reconnect, replay gap).++ Events before its watermark are skipped from here on, so the session state they would have carried+ is projected from the snapshot itself: the editor is never left showing Default while the owner+ enforces Accept Edits / Don't Ask (#141338 ACP-7)."""+ async with self._changed: # its pending rows and controls may settle or block a waiter+ self._snapshots[session_id] = snapshot+ if resumes is not None:+ self._adopted[session_id] = resumes+ self._changed.notify_all()+ await self._project_mode(session_id, self._editor_id(session_id), snapshot.get("info") or {})+async def _request_live_reasoning(self, client, session_id):"""Ask the owner to stream this session's reasoning (``show_reasoning``), as the CLI does.@@ -943,9 +956,7 @@ class GatewayACPAgent(GatewayReplyMixin, acp.Agent):params = {"editor": self._editor_mcp[sid]} if sid in self._editor_mcp else {}self._resumes[sid] = self._resumes.get(sid, 0) + 1snapshot = await self._gateway.rpc("session.resume", session_id=sid, **params)- async with self._changed: # its pending rows and controls may settle or block a waiter- self._snapshots[sid], self._adopted[sid] = snapshot, self._resumes[sid]- self._changed.notify_all()+ await self._adopt(sid, snapshot, self._resumes[sid])for prompt in snapshot.get("prompts", []):self._permission(sid, prompt)started = [row["admission_id"] for row in snapshot.get("pending", []) if row.get("status") == "started"]@@ -1003,7 +1014,9 @@ class GatewayACPAgent(GatewayReplyMixin, acp.Agent):returnself._modes[sid] = modeif self._conn:- await self._conn.session_update(session_id=editor_id, update=acp.update_current_mode(mode))+ from acp.schema import CurrentModeUpdate # ``acp`` does not re-export ``update_current_mode``+ await self._conn.session_update(session_id=editor_id, update=CurrentModeUpdate(+ session_update="current_mode_update", current_mode_id=mode))async def _project_usage(self, sid, editor_id, stats):"""The owner's usage dict: kept for the turn's ``PromptResponse.usage``, shown as ``usage_update``."""diff --git a/tests/acp_adapter/test_gateway_reconnect.py b/tests/acp_adapter/test_gateway_reconnect.pyindex 85769bd865f..68237011ecb 100644--- a/tests/acp_adapter/test_gateway_reconnect.py+++ b/tests/acp_adapter/test_gateway_reconnect.py@@ -93,3 +93,33 @@ async def test_editor_reconnects_to_a_restarted_gateway_without_resending(monkeyawait agent.aclose()for owner in owners:owner.server.close()++[email protected]("path", ["reconnect", "gap"])+async def test_a_recovered_snapshot_repaints_the_sessions_edit_mode(path):+ """ACP-7: a reconnect or replay gap adopts a fresh snapshot and skips the events before it, so the+ snapshot's own edit policy is what the editor is shown (owner Don't Ask is never left as Default)."""+ agent = GatewayACPAgent()+ agent._conn = AsyncMock()+ agent._snapshots["s"] = {"pending": [], "replay_epoch": "old", "last_sequence": 0}+ agent._modes["s"] = "default"+ snapshot = {"session_id": "s", "pending": [], "prompts": [], "replay_epoch": "new", "last_sequence": 99,+ "info": {"edit_approval_policy": "session"}}++ async def rpc(method, **kwargs):+ assert method in {"session.resume", "config.set"}, method+ return snapshot if method == "session.resume" else {}++ agent._gateway = type("Gateway", (), {"rpc": staticmethod(rpc)})()+ try:+ if path == "reconnect":+ await agent._reattach(agent._gateway)+ else:+ await agent._gap_guard("session.replay_gap", "s", None)+ modes = [call.kwargs["update"].current_mode_id for call in agent._conn.session_update.await_args_list+ if call.kwargs["update"].session_update == "current_mode_update"]+ assert agent._modes["s"] == "dont_ask" and modes == ["dont_ask"]+ finally:+ for task in agent._background:+ task.cancel()