Python: Prevent compaction from emitting empty projections#7219
Merged
eavanvalkenburg merged 3 commits intoJul 21, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a Python compaction edge case where truncation and token-budget fallback paths could exclude every model-visible message (or every non-system message), producing an empty projection that providers reject. It introduces a shared “minimum retained group” floor so the newest included non-system group (or the last system group if no non-system group exists) is always kept.
Changes:
- Add
_minimum_retained_group_ids(...)and apply it toTruncationStrategyprotection logic. - Apply the same floor to
TokenBudgetComposedStrategyfallback and strict-fallback exclusion loops. - Add/adjust regression tests in
test_compaction.pyto cover oversized-latest-group and system-only scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_compaction.py | Adds and applies a minimum-retained-group floor to prevent empty projections during truncation and token-budget fallback paths. |
| python/packages/core/tests/core/test_compaction.py | Updates token-budget thresholds and adds regression tests for “keep latest group” / system-only behaviors. |
ronronner02
force-pushed
the
codex/7213-compaction-context-floor
branch
from
July 21, 2026 03:38
f7ed863 to
0044f11
Compare
Contributor
Author
|
@microsoft-github-policy-service agree |
eavanvalkenburg
approved these changes
Jul 21, 2026
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
eavanvalkenburg
enabled auto-merge
July 21, 2026 12:08
chetantoshniwal
approved these changes
Jul 21, 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 & Context
Fixes #7213.
Compaction must not return an empty model-visible projection when the newest message group alone exceeds the target budget. An empty projection causes providers to reject an otherwise healthy agent run.
Description & Review Guide
TruncationStrategyand both fallback paths inTokenBudgetComposedStrategy.The patch was developed with AI assistance and manually reviewed against the existing compaction annotations and test conventions.
Related Issue
Fixes #7213
Contribution Checklist
_workflows/_viz.pyandobservability.py).packages/core/testssuite pass; regression tests were added.