Skip to content

fix: _truncate_array under-reports truncated flag after dropping/shortening elements#37242

Open
1795771535y-cell wants to merge 1 commit into
langgenius:mainfrom
1795771535y-cell:fix/variable-truncator-array-flag-37192
Open

fix: _truncate_array under-reports truncated flag after dropping/shortening elements#37242
1795771535y-cell wants to merge 1 commit into
langgenius:mainfrom
1795771535y-cell:fix/variable-truncator-array-flag-37192

Conversation

@1795771535y-cell

Copy link
Copy Markdown
Contributor

Summary

Fixes #37192

_truncate_array\ has two bugs causing the \ runcated\ flag to be under-reported:

  1. Size-limit break doesn't set flag: When \used_size > target_size, the loop breaks but \ runcated\ stays \False, so dropped tail elements go unreported.
  2. Flag gets overwritten instead of accumulated: \ runcated = part_result.truncated\ replaces the flag, so a later element that fits resets the flag from an earlier truncated one.

Changes

  • Set \ runcated = True\ before the size-limit \�reak\
  • Use \ runcated = truncated or part_result.truncated\ to accumulate

Testing

Verified with the reproduction cases from #37192:

\\python
t = VariableTruncator(array_element_limit=20, max_size_bytes=1000)
r = t._truncate_array([10, 20, 30, 40, 50], 12)

Before: r.truncated == False, r.value == [10, 20, 30, 40]

After: r.truncated == True ✅

t2 = VariableTruncator(array_element_limit=20, max_size_bytes=1000, string_length_limit=10)
r2 = t2._truncate_array(['x'*60, 'a'], 60)

Before: r2.truncated == False

After: r2.truncated == True ✅

\\

Also verified element-count-limit path and no-truncation path are unaffected.

…tening elements

When _truncate_array breaks due to size limit exceeding target_size, the
truncated flag was not set to True, causing dropped tail elements to go
unreported. Additionally, the flag was overwritten (truncated =
part_result.truncated) instead of accumulated, so a later fitting element
could reset a previously-set flag to False.

Fix by setting truncated = True before the size-limit break, and using
logical OR to accumulate (truncated = truncated or part_result.truncated).

Fixes langgenius#37192

Signed-off-by: C4P-T <cap@teamos.dev>
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 47.25% 47.25% 0.00%
Strict coverage 46.75% 46.75% 0.00%
Typed symbols 26,553 26,553 0
Untyped symbols 29,962 29,962 0
Modules 2853 2853 0

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