Skip to content

fix: VariableTruncator._truncate_array under-reports truncated flag#37213

Open
functionkiller wants to merge 1 commit into
langgenius:mainfrom
functionkiller:fix/truncate-array-flag
Open

fix: VariableTruncator._truncate_array under-reports truncated flag#37213
functionkiller wants to merge 1 commit into
langgenius:mainfrom
functionkiller:fix/truncate-array-flag

Conversation

@functionkiller

Copy link
Copy Markdown

Summary

Fixes two bugs in VariableTruncator._truncate_array that caused the truncated flag to be under-reported:

  1. Size-limit break path: When used_size > target_size, the loop breaks without setting truncated = True, so dropped tail elements are not reflected in the flag.
  2. Overwrite instead of accumulation: truncated = part_result.truncated overwrites the flag on each iteration. If an earlier element was truncated but a later element fits, the flag is incorrectly reset to False.

Both sibling methods (truncate_variable_mapping and _truncate_object) correctly accumulate the flag with |= or or.

Changes

  • Added truncated = True before the size-limit break
  • Changed truncated = part_result.truncated to truncated = truncated or part_result.truncated

Test plan

  • Case 1: size-limit break — truncated=True when tail elements are dropped
  • Case 2: flag accumulation — truncated flag preserved when later element fits
  • Case 3: no truncation — truncated=False unchanged
  • Case 4: element limit — truncated=True unchanged

Fixes #37192

- Set truncated=True when size-limit break drops tail elements
- Use OR accumulation instead of assignment to preserve truncation state

fixes langgenius#37192
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VariableTruncator._truncate_array under-reports the truncated flag after dropping/shortening array elements

1 participant