Skip to content

[dotnet-code] Consolidate truncation removable count #379

Description

@github-actions

Summary

Reuse the existing message index helper when truncation calculates removable non-system groups. This keeps the Go truncation internals aligned around the same included/non-system group concept used elsewhere, which should make future .NET-to-Go compaction ports easier to compare. Added a narrow preservation test for system and pre-excluded groups.

.NET Reference

  • dotnet/src/Microsoft.Agents.AI/Compaction/TruncationCompactionStrategy.cs - counts removable non-system, non-excluded groups before applying the truncation floor.
  • dotnet/tests/Microsoft.Agents.AI.UnitTests/Compaction/TruncationCompactionStrategyTests.cs - covers skipping pre-excluded and system groups during truncation.

Public API and Behavior

No public Go API changed. No intentional behavior change was made.

Tests

  • go test ./agent/compaction
  • go test ./agent/compaction ./agent/harness/loop ./agent/hosting/workflowhosting

Added TestTruncationStrategy_SkipsPreExcludedAndSystemGroups.

Notes

Rejected dotnet/src/Microsoft.Agents.AI.Workflows/Specialized/AggregateTurnMessagesExecutor.cs because the Go aggregate-turn workflow binding is already structurally close and changing it would be churn. Rejected dotnet/src/Microsoft.Agents.AI.Workflows/FanInEdgeData.cs because Go intentionally uses a unified Edge/EdgeConnection shape and introducing a separate fan-in data type would risk public/internal churn. Rejected dotnet/src/Microsoft.Agents.AI/Harness/Loop/LoopContext.cs because matching the .NET context shape would require public Go API changes.

Generated by .NET-to-Go Code Portability Refactoring Agent · 408 AIC · ⌖ 17.6 AIC · ⊞ 20.8K ·


Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch dotnet-code/truncation-removable-count-2305220f28c523ce.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (80 of 80 lines)
From d261ae63e97e2f6b4b4464b13ef2f1d2244fdb5f Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Sat, 27 Jun 2026 22:43:23 +0000
Subject: [PATCH] Consolidate truncation removable count

Reuse the message index helper for counting included non-system groups before truncation and add a preservation test for skipped system and pre-excluded groups.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 agent/compaction/compaction_test.go | 34 +++++++++++++++++++++++++++++
 agent/compaction/truncation.go      |  7 +-----
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/agent/compaction/compaction_test.go b/agent/compaction/compaction_test.go
index 3aa44fea2..08026b43e 100644
--- a/agent/compaction/compaction_test.go
+++ b/agent/compaction/compaction_test.go
@@ -85,6 +85,40 @@ func TestTruncationStrategy_ExcludesOldestGroups(t *testing.T) {
 	}
 }
 
+func TestTruncationStrategy_SkipsPreExcludedAndSystemGroups(t *testing.T) {
+	index := compaction.CreateMessageIndex([]*message.Message{
+		textMessage(message.RoleSystem, "system"),
+		textMessage(message.RoleUser, "u1"),
+		textMessage(message.RoleAssistant, "a1"),
+		textMessage(message.RoleUser, "u2"),
+	}, nil)
+	index.Groups[1].IsExcluded = true
+	strategy := &compaction.TruncationStrategy{
+		MinimumPreservedGroups: 1,
+	}
+
+	compacted, err := strategy.Compact(t.Context(), index)
+	if err != nil {
+		t.Fatalf("unexpected error: %v", err)
+	}
+	if !compacted {
+		t.Fatal("expected compaction")
+	}
+
+	if index.Groups[0].IsExcluded {
+		t.Fatal("expected system group to be preserved")
+	}
+	if !index.Groups[1].IsExcluded {
+		t.Fatal("expected pre-excluded group to remain excluded")
+	}
+	if !index.Groups[2].IsExcluded {
+		t.Fatal("expected oldest removable group to be excluded")
+	}
+	if index.Groups[3].IsExcluded {
+		t.Fatal("expected minimum preserved group to remain included")
+	}
+}
+
 func TestTruncationStrategy_ZeroValueU
... (truncated)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions