fix: VariableTruncator._truncate_array under-reports truncated flag#37543
Open
ifer47 wants to merge 1 commit into
Open
fix: VariableTruncator._truncate_array under-reports truncated flag#37543ifer47 wants to merge 1 commit into
ifer47 wants to merge 1 commit into
Conversation
The `_truncate_array` method had two bugs causing the `truncated` flag to be incorrectly reported as `False` when data was actually truncated: 1. When the size-limit `break` was hit, the loop exited without setting `truncated = True`, so dropped tail elements went unreported. 2. On each iteration, `truncated = part_result.truncated` overwrote the flag instead of accumulating it (`truncated = truncated or ...`), so a later non-truncated element could erase an earlier truncation signal. Both fixes align `_truncate_array` with its sibling methods `_truncate_object` and `truncate_variable_mapping`, which already accumulate the flag correctly. Closes langgenius#37192 Co-Authored-By: zhipu/glm-5 <zai-org@claude-code-best.win>
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.
Summary
_truncate_arraysize-limitbreaknot settingtruncated = Truebefore exiting the loop, causing dropped tail elements to go unreported_truncate_arrayoverwriting thetruncatedflag on each iteration instead of accumulating it (truncated = truncated or part_result.truncated), so a later non-truncated element could erase an earlier truncation signalContext
Closes #37192
The
_truncate_objectandtruncate_variable_mappingsibling methods already accumulate the flag correctly. This PR brings_truncate_arrayin line with them.Bug 1 — size-limit break: When
used_size > target_size, the loop breaks but leavestruncated = False, so dropped array elements are not reported:Bug 2 — flag overwrite:
truncated = part_result.truncatedreplaces the flag on each iteration instead of OR-accumulating:Test plan
test_array_size_limit_break_sets_truncated_flagverifies bug 1test_array_truncated_flag_accumulates_across_elementsverifies bug 2TestArrayTruncationtests continue to pass (no behavior change for non-buggy paths)🤖 Generated with Claude Code Best