Skip to content

.NET: fix: skip local history after service conversation ids#6128

Closed
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/service-conversation-history
Closed

.NET: fix: skip local history after service conversation ids#6128
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/service-conversation-history

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

  • skip ChatHistoryProvider resolution once a real service-managed ConversationId is on the session
  • keep the per-service-call local-history sentinel using the local provider path
  • strengthen the default InMemory regression test for service-returned ConversationId

Fixes #6120

To verify

  • dotnet test --project tests\Microsoft.Agents.AI.UnitTests\Microsoft.Agents.AI.UnitTests.csproj -f net10.0 -c Debug -v Normal --filter-class Microsoft.Agents.AI.UnitTests.ChatClientAgent_ChatHistoryManagementTests --report-xunit-trx --ignore-exit-code 8
  • dotnet test --project tests\Microsoft.Agents.AI.UnitTests\Microsoft.Agents.AI.UnitTests.csproj -f net472 -c Debug -v Normal --filter-class Microsoft.Agents.AI.UnitTests.ChatClientAgent_ChatHistoryManagementTests --report-xunit-trx --ignore-exit-code 8
  • git diff --check

Copilot AI review requested due to automatic review settings May 28, 2026 01:43
@moonbox3 moonbox3 added the .NET label May 28, 2026
@github-actions github-actions Bot changed the title fix: skip local history after service conversation ids .NET: fix: skip local history after service conversation ids May 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors ResolveChatHistoryProvider in ChatClientAgent to consider the session's ConversationId (in addition to ChatOptions.ConversationId) when deciding whether to use the local ChatHistoryProvider. A new helper IsServiceManagedConversationId centralizes detection of server-side conversations, treating the sentinel LocalHistoryConversationId as local.

Changes:

  • Pass the ChatClientAgentSession to ResolveChatHistoryProvider from all three call sites (notify-new-messages, notify-failure, load-history).
  • Introduce IsServiceManagedConversationId to distinguish service-managed conversation ids from the local sentinel and use it for both provider resolution and the conflict-throw check.
  • Update unit test name and assertions to verify the default InMemoryChatHistoryProvider is not populated when the service returns a conversation id.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Resolves history provider using session conversation id and the new service-managed id check.
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs Renames test and asserts the default in-memory provider remains empty when a conversation id is returned.

Comment on lines +985 to 988
if (this._agentOptions?.ThrowOnChatHistoryProviderConflict is true && IsServiceManagedConversationId(conversationId))
{
throw new InvalidOperationException(
$"Only {nameof(ChatClientAgentSession.ConversationId)} or {nameof(this.ChatHistoryProvider)} may be used, but not both. The current {nameof(ChatClientAgentSession)} has a {nameof(ChatClientAgentSession.ConversationId)} indicating server-side chat history management, but an override {nameof(this.ChatHistoryProvider)} was provided via {nameof(AgentRunOptions.AdditionalProperties)}.");

private ChatHistoryProvider? ResolveChatHistoryProvider(ChatOptions? chatOptions)
private ChatHistoryProvider? ResolveChatHistoryProvider(ChatOptions? chatOptions, ChatClientAgentSession? session = null)
{
@he-yufeng
Copy link
Copy Markdown
Contributor Author

Closing this in favor of #6141. The newer PR carries the current version of the same service-managed conversation id history handling fix, so keeping both open just splits review attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: InMemoryChatHistoryProvider used even when service stores history (OpenAI Responses)

3 participants