Skip to content

Commit 5b08fc2

Browse files
committed
Python: Clear service_session_id in AgentExecutor on full-history replay (microsoft#3295)
Defense-in-depth follow-up to 31d126c. When a coordinator hands an AgentExecutor an AgentExecutorRequest carrying function-call or function-result items and the executor's session already has a service_session_id from a prior run, clear the id before invoking. This stops the chat client from pairing the supplied messages with a previous_response_id that points at a different conversation. The wire-level "Duplicate item" error was already closed by the chat-client strip in microsoft#3295. This change makes the executor wiring reflect intent: the executor is replaying a conversation it does not own, so it should not present continuation context from a prior response at all. Decisions: - Trigger only when the request carries function_call/function_result items. Plain text replays do not need the clear. - from_response handoff path is unchanged. The companion test test_from_response_preserves_service_session_id continues to lock the inverse case. - No new public API. A small helper _carries_tool_items keeps the run() body readable. Files: - python/packages/core/agent_framework/_workflows/_agent_executor.py: add _carries_tool_items helper and clear-on-replay branch in run(). - python/packages/core/tests/workflow/test_full_conversation.py: drop the strict xfail on test_run_request_with_full_history_clears_service_session_id; the test now passes for the reason its name describes (executor clears the id) rather than masked by the chat-client strip. Notes for next iteration: - pytest was not run in this iteration; uv-based pytest commands required interactive approval. Validation rests on careful reading and the existing strict-xfail contract. Next iteration should run the core test suite to confirm.
1 parent 3aa4a28 commit 5b08fc2

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎python/packages/core/agent_framework/_workflows/_agent_executor.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
logger = logging.getLogger(__name__)
3030

3131

32+
_TOOL_ITEM_TYPES = frozenset({"function_call", "function_result"})
33+
34+
35+
def _carries_tool_items(messages: list[Message]) -> bool:
36+
return any(content.type in _TOOL_ITEM_TYPES for message in messages for content in message.contents)
37+
38+
3239
@dataclass
3340
class AgentExecutorRequest:
3441
"""A request to an agent executor.
@@ -205,6 +212,13 @@ async def run(
205212
This is the standard path: extend cache with provided messages; if should_respond
206213
run the agent and emit an AgentExecutorResponse downstream.
207214
"""
215+
if self._session.service_session_id and _carries_tool_items(request.messages):
216+
# Coordinator is replaying a full prior conversation we did not own. Drop the
217+
# inherited service-side continuation token so the chat client treats the
218+
# supplied messages as the sole source of truth instead of pairing them with
219+
# a previous_response_id that points at a different run. See microsoft/agent-framework#3295.
220+
self._session.service_session_id = None
221+
208222
self._cache.extend(request.messages)
209223

210224
if request.should_respond:

‎python/packages/core/tests/workflow/test_full_conversation.py‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from collections.abc import AsyncIterable, Awaitable
44
from typing import Any, Literal, overload
55

6-
import pytest
76
from pydantic import PrivateAttr
87
from typing_extensions import Never
98

@@ -428,15 +427,6 @@ async def handle(
428427
)
429428

430429

431-
@pytest.mark.xfail(
432-
reason=(
433-
"Tracks the executor-layer half of #3295: AgentExecutor should clear service_session_id "
434-
"when handed a full prior conversation. The wire-level 'Duplicate item' API error is "
435-
"already closed by the chat-client strip in #3295; this xfail covers the defense-in-depth "
436-
"follow-up that makes the executor wiring reflect intent."
437-
),
438-
strict=True,
439-
)
440430
async def test_run_request_with_full_history_clears_service_session_id() -> None:
441431
"""Replaying a full conversation (including function calls) via AgentExecutorRequest must
442432
clear service_session_id so the API does not receive both previous_response_id and the

0 commit comments

Comments
 (0)