From 5001f2b092b2df89660f37b02a56ede10b49d154 Mon Sep 17 00:00:00 2001 From: Shalabh Gupta Date: Tue, 10 Mar 2026 14:27:53 +0530 Subject: [PATCH] Fix history provider isolation bypass in Responses-style continuation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #4577 **Problem**: When using InMemoryHistoryProvider(load_messages=False), Responses-style clients (OpenAI, Anthropic) still remember conversation history while Chat-style clients correctly forget it. **Root Cause**: The _prepare_run_context method always forwards session.service_session_id to conversation_id regardless of history provider settings (lines 1095-1097). **Fix**: Only forward service_session_id when: 1. No explicit conversation_id provided in runtime options 2. No history provider has load_messages=False 3. Active session with service_session_id exists This ensures Responses-style clients respect history provider isolation settings the same way Chat-style clients do. **Impact**: Enables proper conversation isolation for Responses-style clients when using history providers with load_messages=False. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../packages/core/agent_framework/_agents.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/python/packages/core/agent_framework/_agents.py b/python/packages/core/agent_framework/_agents.py index 3aaf9f1419..3141c4ab21 100644 --- a/python/packages/core/agent_framework/_agents.py +++ b/python/packages/core/agent_framework/_agents.py @@ -1090,11 +1090,30 @@ async def _prepare_run_context( additional_function_arguments["session"] = active_session # Build options dict from run() options merged with provided options + # Determine conversation_id: honor explicit runtime option first, then conditionally forward service_session_id + explicit_conversation_id = opts.pop("conversation_id", None) + + # Check if any history provider has load_messages=False (meaning it wants to manage history itself) + has_history_provider_disabling_load = any( + isinstance(p, BaseHistoryProvider) and not p.load_messages + for p in self.context_providers + ) + + # Only auto-forward service_session_id if: + # 1. No explicit conversation_id provided in runtime options + # 2. No history provider is explicitly disabling message loading + should_forward_service_session = ( + active_session + and active_session.service_session_id + and not explicit_conversation_id + and not has_history_provider_disabling_load + ) + run_opts: dict[str, Any] = { "model_id": opts.pop("model_id", None), - "conversation_id": active_session.service_session_id - if active_session - else opts.pop("conversation_id", None), + "conversation_id": explicit_conversation_id if explicit_conversation_id else ( + active_session.service_session_id if should_forward_service_session else None + ), "allow_multiple_tool_calls": opts.pop("allow_multiple_tool_calls", None), "additional_function_arguments": additional_function_arguments or None, "frequency_penalty": opts.pop("frequency_penalty", None),