Python: Fix history provider isolation bypass in Responses-style continuation#4579
Open
coding-shalabh wants to merge 1 commit intomicrosoft:mainfrom
Open
Conversation
Fixes microsoft#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 <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4577
Resolves conversation history leakage when using
InMemoryHistoryProvider(load_messages=False)with Responses-style clients (OpenAI, Anthropic).Problem
When using a history provider with
load_messages=Falseto isolate conversations, Responses-style clients still remember previous conversation history, while Chat-style clients correctly forget it.Expected behavior: Both client types should respect history provider isolation settings.
Root Cause
In _agents.py:1095-1097, the
_prepare_run_contextmethod always forwardssession.service_session_idtoconversation_id:This bypasses history provider settings and causes Responses-style clients to continue previous conversations even when history providers explicitly disable message loading.
Solution
Modified
_prepare_run_contextto conditionally forwardservice_session_idbased on history provider settings:Now
service_session_idis forwarded ONLY when:conversation_idprovided in runtime optionsload_messages=Falseservice_session_idexistsTesting
Before fix (reproducing issue #4577):
After fix:
Impact
load_messagessettingsconversation_idstill takes precedenceRelated Issues
Closes #4577
🤖 Generated with Claude Code