Skip to content

fix(workflow): report truncated=True when _truncate_array drops or shortens array elements#37193

Open
lalala223 wants to merge 1 commit into
langgenius:mainfrom
lalala223:fix/variable-truncator-array-truncated-flag
Open

fix(workflow): report truncated=True when _truncate_array drops or shortens array elements#37193
lalala223 wants to merge 1 commit into
langgenius:mainfrom
lalala223:fix/variable-truncator-array-truncated-flag

Conversation

@lalala223

Copy link
Copy Markdown

Fixes #37192

Summary

VariableTruncator._truncate_array could return truncated=False even though array data was actually dropped or shortened, in two cases:

  1. Size-limit break drops elements without flagging it — when the running size exceeds the budget the loop breaks and discards the remaining elements, but truncated was left unset. The element-count-limit branch a few lines above already returns True in the same situation.
  2. The per-element flag was overwritten instead of accumulated — so an element that fit after a truncated one reset an earlier True back to False.

The fix mirrors the existing correct pattern in the sibling methods truncate_variable_mapping and _truncate_object, which accumulate the flag.

The flag funnels into inputs_truncated/outputs_truncated on the streaming node events, so a false negative reports truncated node values as untruncated. Impact is minor/cosmetic — the final workflow_finished output is not truncated and no data is lost.

Screenshots

Same input ({"result": [10, 20, 30, 40, 50]}, small WORKFLOW_VARIABLE_TRUNCATION_MAX_SIZE), node_finished event:

Before After
"outputs":{"result":[10]}, "outputs_truncated":false "outputs":{"result":[10]}, "outputs_truncated":true

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

…ortens elements

VariableTruncator._truncate_array could return truncated=False even though
array data was actually dropped or shortened, in two cases:

1. When the running size exceeds the limit, the loop stops and skips all the
   remaining elements, but it did not set truncated=True. The element-count
   limit a few lines above already returns truncated=True when it drops
   elements, so the two drop paths were inconsistent.
2. The flag was reassigned on every element instead of OR-ed together, so an
   element that fit after a truncated one reset it back to False.

The two sibling methods, truncate_variable_mapping and _truncate_object,
already accumulate the flag correctly; this aligns _truncate_array with them.

The flag is exposed as inputs_truncated/outputs_truncated on the streaming
node events, so a false negative reports truncated node values as
untruncated. Added regression tests that fail before this change and pass
after.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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