From a952008e49f285b1e039abb7307aed88d84aea8a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 29 Sep 2026 14:22:59 +0000 Subject: [PATCH 1/3] Initial plan From 5e53b7b7bc0e3ad40c9626f89139ff82bda79d8b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 29 Sep 2026 14:27:07 +0000 Subject: [PATCH 2/3] Fix compaction for per-service-call local chat history Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> --- .../Compaction/CompactionProvider.cs | 3 +- .../Compaction/CompactionProviderTests.cs | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs b/dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs index 2d919f709cf..0673b67d3ea 100644 --- a/dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs @@ -132,7 +132,8 @@ protected override async ValueTask InvokingCoreAsync(InvokingContext ChatClientAgentSession? chatClientSession = session.GetService(); if (chatClientSession is not null && - !string.IsNullOrWhiteSpace(chatClientSession.ConversationId)) + !string.IsNullOrWhiteSpace(chatClientSession.ConversationId) && + chatClientSession.ConversationId != PerServiceCallChatHistoryPersistingChatClient.LocalHistoryConversationId) { logger.LogCompactionProviderSkipped("session managed by remote service"); return context.AIContext; diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/Compaction/CompactionProviderTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/Compaction/CompactionProviderTests.cs index e4d4fa23780..c4e6dd4f73c 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/Compaction/CompactionProviderTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/Compaction/CompactionProviderTests.cs @@ -131,6 +131,46 @@ public async Task InvokingAsyncAppliesCompactionWhenTriggeredAsync() Assert.True(resultList.Count < messages.Count); } + [Theory] + [InlineData(null, true)] + [InlineData("", true)] + [InlineData(" ", true)] + [InlineData(PerServiceCallChatHistoryPersistingChatClient.LocalHistoryConversationId, true)] + [InlineData("remote-conversation-id", false)] + public async Task InvokingAsyncCompactsOnlyLocallyManagedHistoryAsync(string? conversationId, bool shouldCompact) + { + // Arrange + TruncationCompactionStrategy strategy = new(CompactionTriggers.Always, minimumPreservedGroups: 1); + CompactionProvider provider = new(strategy); + Mock mockAgent = new() { CallBase = true }; + ChatClientAgentSession session = new(conversationId); + List messages = + [ + new ChatMessage(ChatRole.User, "Q1"), + new ChatMessage(ChatRole.Assistant, "A1"), + new ChatMessage(ChatRole.User, "Q2"), + ]; + AIContextProvider.InvokingContext context = new( + mockAgent.Object, + session, + new AIContext { Messages = messages }); + + // Act + AIContext result = await provider.InvokingAsync(context); + + // Assert + Assert.NotNull(result.Messages); + if (shouldCompact) + { + Assert.Same(messages[2], Assert.Single(result.Messages)); + } + else + { + Assert.Same(context.AIContext, result); + Assert.Same(messages, result.Messages); + } + } + [Fact] public async Task InvokingAsyncNoCompactionNeededReturnsOriginalMessagesAsync() { From 25fc330f27c2455957b10e5b782c1fad45de5b40 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 29 Sep 2026 16:08:20 +0000 Subject: [PATCH 3/3] Use explicit ordinal equality for compaction conversation ID Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> --- dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs b/dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs index 0673b67d3ea..a8e3948a7ce 100644 --- a/dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs +++ b/dotnet/src/Microsoft.Agents.AI/Compaction/CompactionProvider.cs @@ -133,7 +133,7 @@ protected override async ValueTask InvokingCoreAsync(InvokingContext ChatClientAgentSession? chatClientSession = session.GetService(); if (chatClientSession is not null && !string.IsNullOrWhiteSpace(chatClientSession.ConversationId) && - chatClientSession.ConversationId != PerServiceCallChatHistoryPersistingChatClient.LocalHistoryConversationId) + !string.Equals(chatClientSession.ConversationId, PerServiceCallChatHistoryPersistingChatClient.LocalHistoryConversationId, StringComparison.Ordinal)) { logger.LogCompactionProviderSkipped("session managed by remote service"); return context.AIContext;