Python: Keep call and result occurrences atomic in compaction - #7406
Merged
eavanvalkenburg merged 3 commits intoJul 30, 2026
Merged
Conversation
eavanvalkenburg
temporarily deployed
to
github-app-auth
July 29, 2026 20:11 — with
GitHub Actions
Inactive
eavanvalkenburg
temporarily deployed
to
github-app-auth
July 29, 2026 20:11 — with
GitHub Actions
Inactive
eavanvalkenburg
temporarily deployed
to
github-app-auth
July 29, 2026 20:11 — with
GitHub Actions
Inactive
eavanvalkenburg
marked this pull request as ready for review
July 29, 2026 20:12
eavanvalkenburg
temporarily deployed
to
github-app-auth
July 29, 2026 20:12 — with
GitHub Actions
Inactive
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Python message compaction correctness by ensuring function-call declarations and their tool results remain grouped atomically even when the result is non-adjacent (e.g., approval/resume traffic in between) and when call_id values are legitimately reused across completed rounds. It updates both the compaction implementation and its specification/tests to prevent provider-invalid transcripts caused by orphaned call/result halves.
Changes:
- Link non-adjacent
function_call/function_resultoccurrences by ordered, unambiguouscall_idmatching, including merging groups when a single tool message returns multiple results. - Expand incremental re-annotation boundaries when newly appended tool results complete earlier declarations, and ensure linked groups are kept/excluded atomically.
- Add comprehensive unit tests and update docs/spec text to cover non-adjacent pairing, reused ids, and ambiguity safeguards.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_compaction.py | Implements unambiguous non-adjacent pairing/linking for tool call/result spans and adjusts incremental group re-annotation to preserve atomicity. |
| python/packages/core/tests/core/test_compaction.py | Adds tests covering non-adjacent pairing, multiple results, reused call_id occurrences, ambiguity handling, incremental extension behavior, and sliding-window behavior. |
| python/packages/core/AGENTS.md | Documents the new “ordered unambiguous occurrence” rule for reused call_id pairing during compaction. |
| docs/specs/004-python-function-calling-loop.md | Updates the spec’s compaction integrity coverage references and tracking list to reflect the new behavior and tests. |
TaoChenOSU
approved these changes
Jul 29, 2026
eavanvalkenburg
temporarily deployed
to
github-app-auth
July 30, 2026 05:33 — with
GitHub Actions
Inactive
eavanvalkenburg
enabled auto-merge
July 30, 2026 05:37
eavanvalkenburg
force-pushed
the
python-compaction-call-result-occurrences
branch
from
July 30, 2026 06:59
cdf162d to
c86cfc2
Compare
eavanvalkenburg
temporarily deployed
to
github-app-auth
July 30, 2026 06:59 — with
GitHub Actions
Inactive
moonbox3
reviewed
Jul 30, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1ee1d250-d1e2-4c6f-8c36-aae0d94fe7a1
Document why incremental reannotation retains all prior duplicate candidates and strengthen the regression that keeps ambiguous results unpaired without changing existing groups. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1ee1d250-d1e2-4c6f-8c36-aae0d94fe7a1
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1ee1d250-d1e2-4c6f-8c36-aae0d94fe7a1
eavanvalkenburg
force-pushed
the
python-compaction-call-result-occurrences
branch
from
July 30, 2026 07:41
c86cfc2 to
9414007
Compare
eavanvalkenburg
temporarily deployed
to
github-app-auth
July 30, 2026 07:41 — with
GitHub Actions
Inactive
moonbox3
approved these changes
Jul 30, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jul 30, 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
Compaction can separate a function call from a non-adjacent result, especially when completed rounds reuse the
same
call_id. That can leave provider-invalid transcripts after sliding-window or incremental compaction.Description & Review Guide
Related Issue
Fixes #7212
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.