Repository navigation
Python: fix(python): preserve non-adjacent tool pairs during history truncation - #14658
Draft
hylin (linhongyu510) wants to merge 1 commit into
Draft
hylin (linhongyu510) wants to merge 1 commit into
hylin (linhongyu510) wants to merge 1 commit into
Conversation
Preserve matched FunctionCallContent and FunctionResultContent pairs when ChatHistoryTruncationReducer cuts between a call and its result. Co-authored-by: AI assistance was used and reviewed. Signed-off-by: hylin <linhongyu510@gmail.com>
hylin (linhongyu510)
deployed
to
github-app-auth
October 24, 2026 07:04 — with
GitHub Actions
Active
This branch was successfully deployed
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.
Title
fix(python): preserve non-adjacent tool pairs during history truncation
Motivation and Context
ChatHistoryTruncationReducercould retain aFunctionResultContentwhile dropping its matchingFunctionCallContentwhen the two were separated by non-function messages.Description
locate_safe_reduction_indexnow builds an O(n) suffix minimum-call map fromget_call_result_pairs(history). After the existing adjacency and threshold-window candidate selection, it moves the cut back only when a retained result requires an earlier matched call. Chained non-adjacent pairs are closed transitively. If the required call is beforeoffset_count, reduction returnsNonerather than crossing offset/summary territory.Offset, threshold, system/developer preservation, unknown/unpaired content, and existing user-boundary search semantics are otherwise unchanged.
Local verification
483ffb487a33a1644886992d56599feae3b69b76.4 failed, 4 passed.8 passed.1, restore green exit0.105 passed.0.9.10; check and format check pass.Contribution Checklist