From 7dd1ddcca471ff6c6348c9a4248f801b7dd25c6a Mon Sep 17 00:00:00 2001 From: Aslaaen Date: Tue, 21 Apr 2026 18:00:10 +0300 Subject: [PATCH] fix(acp): preserve assistant reasoning metadata in session persistence --- acp_adapter/session.py | 3 +++ tests/acp/test_session.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/acp_adapter/session.py b/acp_adapter/session.py index 3f5f78f9a1d85..451d1e19a4d69 100644 --- a/acp_adapter/session.py +++ b/acp_adapter/session.py @@ -419,6 +419,9 @@ def _persist(self, state: SessionState) -> None: tool_name=msg.get("tool_name") or msg.get("name"), tool_calls=msg.get("tool_calls"), tool_call_id=msg.get("tool_call_id"), + reasoning=msg.get("reasoning"), + reasoning_details=msg.get("reasoning_details"), + codex_reasoning_items=msg.get("codex_reasoning_items"), ) except Exception: logger.warning("Failed to persist ACP session %s", state.session_id, exc_info=True) diff --git a/tests/acp/test_session.py b/tests/acp/test_session.py index 50d04b1a913bf..19d91af4fdd7f 100644 --- a/tests/acp/test_session.py +++ b/tests/acp/test_session.py @@ -343,6 +343,39 @@ def test_tool_calls_persisted(self, manager): assert restored.history[0].get("tool_calls") is not None assert restored.history[1].get("tool_call_id") == "tc_1" + def test_assistant_reasoning_fields_persisted(self, manager): + """ACP session restore should preserve assistant reasoning context.""" + state = manager.create_session() + state.history.append({ + "role": "assistant", + "content": "hello", + "reasoning": "step-by-step", + "reasoning_details": [ + {"type": "thinking", "thinking": "first thought"}, + ], + "codex_reasoning_items": [ + {"type": "reasoning", "id": "rs_123", "encrypted_content": "enc_blob"}, + ], + }) + manager.save_session(state.session_id) + + with manager._lock: + del manager._sessions[state.session_id] + + restored = manager.get_session(state.session_id) + assert restored is not None + assert restored.history == [{ + "role": "assistant", + "content": "hello", + "reasoning": "step-by-step", + "reasoning_details": [ + {"type": "thinking", "thinking": "first thought"}, + ], + "codex_reasoning_items": [ + {"type": "reasoning", "id": "rs_123", "encrypted_content": "enc_blob"}, + ], + }] + def test_restore_preserves_persisted_provider_snapshot(self, tmp_path, monkeypatch): """Restored ACP sessions should keep their original runtime provider.""" runtime_choice = {"provider": "anthropic"}