Skip to content

.NET: Fix compaction updates with repeated todo messages - #8838

Draft
JS (Punisheroot) wants to merge 4 commits into
microsoft:mainfrom
Punisheroot:fix/compaction-repeated-todo-message
Draft

JS (Punisheroot) wants to merge 4 commits into
microsoft:mainfrom
Punisheroot:fix/compaction-repeated-todo-message

Conversation

@Punisheroot

@Punisheroot JS (Punisheroot) commented Sep 29, 2026 •

Copy link
Copy Markdown

Motivation & Context

When CompactionProvider and TodoProvider are used together, TodoProvider can append the same empty todo-list message on consecutive turns. CompactionMessageIndex.Update() treated a matching final message as evidence that nothing had changed, so new user messages could be omitted from the context sent to the model.

Description & Review Guide

  • What are the major changes? Persist the number of consumed input messages separately from RawMessageCount and record which summary groups came from input history. Before appending, compare the represented input prefix while skipping only summaries inserted by compaction strategies; rebuild when the prefix changes even if the saved boundary still contains the same todo message. Older state without summary provenance is rebuilt once when summaries make the prefix ambiguous. Add index and provider regression tests for repeated todo messages, summary provenance, replaced or shifted history, legacy state, and serialized sessions.
  • What is the impact of these changes? New messages are indexed, existing exclusions are preserved when input history is unchanged, and stale groups are discarded when its prefix changes. Prefix validation scans the represented history on each update; the session stores one group index per input summary. There are no public API changes.
  • What do you want reviewers to focus on? For human reviewers: input summary positions after strategies insert generated groups, preservation after session serialization, and rebuilding when a changed input summary matches a generated summary.

Related Issue

Fixes #7395

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible. All 293 Compaction tests pass. In the full unit-test project, 3,345 pass, 2 are skipped, and 1 unrelated AgentSkills test fails while deleting a temporary symlink on Windows.
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after a language prefix) - a workflow keeps the label and title prefix in sync automatically.

Copilot AI balanced review requested due to automatic review settings September 29, 2026 13:22
@agent-framework-automation agent-framework-automation Bot added the .NET Usage: [Issues, PRs], Target: .Net label Sep 29, 2026
@Punisheroot

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Input summary messages are excluded from RawMessageCount, allowing the reported message-loss behavior to persist.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes repeated todo messages causing new user messages to be omitted during compaction updates.

Changes:

  • Uses the previously indexed message count as the append boundary.
  • Adds regression coverage for repeated todo messages and generated summaries.
File Description
CompactionMessageIndex.cs Updates incremental append detection.
CompactionMessageIndexTests.cs Adds index regression tests.
CompactionProviderTests.cs Adds provider-level regression coverage.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread dotnet/src/Microsoft.Agents.AI/Compaction/CompactionMessageIndex.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The append path can preserve stale groups when a changed prefix has duplicate content at the saved boundary.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Comment thread dotnet/src/Microsoft.Agents.AI/Compaction/CompactionMessageIndex.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Summary matching can accept a changed input prefix and preserve stale compaction state.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread dotnet/src/Microsoft.Agents.AI/Compaction/CompactionMessageIndex.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Chat-reducer group replacement leaves the new persisted prefix metadata inconsistent, causing reduced history to be rebuilt on subsequent turns.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

Comment on lines 184 to +187
state.MessageGroups.Clear();
state.MessageGroups.AddRange(messageIndex.Groups);
state.ProcessedInputMessageCount = messageIndex.ProcessedInputMessageCount;
state.InputSummaryGroupIndices = messageIndex.InputSummaryGroupIndices;

This branch was successfully deployed

1 active deployment
github-app-auth — 3728049f Deployed Sep 29, 2026 by Punisheroot via add_label #24017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: CompactionMessageIndex.Update() drops new user messages when TodoProvider is configured

2 participants