.NET: Fix bug with per-service-call persistence and approvals#4933
Merged
westey-m merged 2 commits intomicrosoft:mainfrom Mar 26, 2026
Merged
.NET: Fix bug with per-service-call persistence and approvals#4933westey-m merged 2 commits intomicrosoft:mainfrom
westey-m merged 2 commits intomicrosoft:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a bug in .NET ChatClientAgent approval flows when per-service-call persistence is enabled by introducing a local-history sentinel ConversationId to influence FunctionInvokingChatClient behavior (while stripping it before reaching the leaf client), and adds end-to-end unit tests to validate persistence + approvals behavior.
Changes:
- Add a sentinel
ChatOptions.ConversationId(LocalHistoryConversationId) for per-service-call persistence, and strip it before calling the leafIChatClient. - Expand unit tests to validate sentinel behavior (non-leakage), chat options merging expectations, persistence behavior, and approval flows.
- Introduce a shared test helper to run multi-call scenarios with history assertions.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs | Sets a local-history sentinel ConversationId for per-service-call persistence runs. |
| dotnet/src/Microsoft.Agents.AI/ChatClient/ChatHistoryPersistingChatClient.cs | Adds sentinel constant and strips it before forwarding options to the inner client. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatHistoryPersistingChatClientTests.cs | Adds tests ensuring sentinel is stripped and does not leak to session/inner client. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatOptionsMergingTests.cs | Updates expectations around null vs non-null ChatOptions due to sentinel behavior. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs | Updates tests to capture options and assert ConversationId is stripped. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatHistoryManagementTests.cs | Adds end-to-end persistence validation tests across modes and function loops. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ApprovalsTests.cs | New end-to-end approval flow tests across persistence modes and rejection scenarios. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTestHelper.cs | New helper for sequential mock service calls + persisted history assertions. |
...et/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ChatOptionsMergingTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatHistoryPersistingChatClient.cs
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_ApprovalsTests.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
TaoChenOSU
approved these changes
Mar 26, 2026
SergeyMenshykh
approved these changes
Mar 26, 2026
peibekwe
approved these changes
Mar 26, 2026
Merged
This was referenced Apr 3, 2026
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.
Motivation and Context
#2889
#4791
Description
Contribution Checklist