Skip to content

Python: fix: preserve synthetic compaction summaries - #7944

Open
Patel Namraa (Namraa310806) wants to merge 1 commit into
microsoft:mainfrom
Namraa310806:fix/compaction-before-run-summary
Open

Python: fix: preserve synthetic compaction summaries#7944
Patel Namraa (Namraa310806) wants to merge 1 commit into
microsoft:mainfrom
Namraa310806:fix/compaction-before-run-summary

Conversation

@Namraa310806

Copy link
Copy Markdown
Contributor

Motivation & Context

CompactionProvider.before_run can lose synthetic summary messages created by replacement-based compaction strategies such as ToolResultCompactionStrategy and SummarizationStrategy.

These strategies create new Message objects to replace messages that are excluded during compaction. However, before_run was only filtering the existing messages in context.context_messages using object identity. Since the newly created summary messages were not part of those original source lists, they were silently discarded during reconciliation.

This could cause the original tool results or conversation history to be removed without retaining the summary that was supposed to replace them.

Fixes #7943.

Description & Review Guide

  • What are the major changes?

    • Updated CompactionProvider.before_run to track the source of existing messages before running the compaction strategy.
    • Rebuild the context.context_messages buckets from the projected message list after compaction instead of only filtering the original buckets.
    • This allows newly created synthetic summary messages to be preserved.
    • Added regression coverage for ToolResultCompactionStrategy and SummarizationStrategy.
  • What is the impact of these changes?

    • Synthetic summary messages created during before_strategy compaction are no longer silently dropped.
    • Compacted tool results and summarized conversation history are preserved in the session context.
    • This is a bug fix and does not change the public API.
  • What do you want reviewers to focus on?

    • The reconciliation logic in CompactionProvider.before_run, especially how existing messages and newly created synthetic messages are assigned back to context.context_messages.
    • The regression tests verifying that both tool-result summaries and summarization messages survive the before_run reconciliation.

Related Issue

Fixes #7943

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue.
  • This is not a breaking change.

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Aug 29, 2026
@github-actions github-actions Bot changed the title fix: preserve synthetic compaction summaries Python: fix: preserve synthetic compaction summaries Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: CompactionProvider.before_run drops synthetic summary messages created by compaction strategies

2 participants