Skip to content

fix(workflow): preserve conversation array appends across Iteration rounds#34539

Open
Dexterity104 wants to merge 8 commits intolanggenius:mainfrom
Dexterity104:fix/iteration-conversation-variable-append
Open

fix(workflow): preserve conversation array appends across Iteration rounds#34539
Dexterity104 wants to merge 8 commits intolanggenius:mainfrom
Dexterity104:fix/iteration-conversation-variable-append

Conversation

@Dexterity104
Copy link
Copy Markdown

Fixes #34417

Summary

Sequential Iteration runs a separate child graph engine per item with a deep-copied variable pool. Variable Assigner updates (e.g. appending to a conversation array[...]) were still applied to the parent pool only when the parent engine's dispatcher handled NodeRunVariableUpdatedEvent. That could happen after the next iteration had already taken another deep copy of the parent pool, so one append could be missing, especially visible on a later chat turn when the array was non-empty.

This change adds an IterationVariableSyncLayer on child engines that use an isolated pool (the Iteration pattern). On each NodeRunVariableUpdatedEvent, the layer writes the same variable into the parent pool inside the child's EventManager.collect path, so the parent pool is up to date before the child run finishes and the next iteration copies it. Loop child engines are unchanged (they share the parent pool and never pass a custom variable_pool).

  • New layer: api/core/app/workflow/layers/iteration_variable_sync.py
  • Wired in: api/core/workflow/workflow_entry.py (_WorkflowChildEngineBuilder.build_child_engine)
  • Tests: api/tests/unit_tests/core/workflow/test_iteration_variable_sync_patch.py and updated expectations in test_workflow_entry_helpers.py

Checklist

  • This change requires a documentation update, included: Dify Document
  • Understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • Added tests for the change; kept the diff focused on this fix.
  • Updated product documentation (not applicable for this internal engine fix unless maintainers want a note in workflow docs).
  • Ran backend checks: uv run --project api pytest api/tests/unit_tests/core/workflow/ (and targeted tests for the new layer); run make lint / make type-check from api before merge if CI differs from local setup.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 3, 2026
@Dexterity104
Copy link
Copy Markdown
Author

Hi @QuantumGhost @laipz8200 @Yeuoly @crazywoola
Can you please review this PR when you have some time?

@Dexterity104
Copy link
Copy Markdown
Author

@Dexterity104
Copy link
Copy Markdown
Author

Hi @asukaminato0721 ,
I'm sorry to bother you. I just wanted to ask if there's a reason my PRs have been taking longer to review. I've noticed that PRs from @YB0y are being merged quite quickly, so I wanted to check if there's anything I should improve or adjust on my side.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Items are lost when appending to an array-type conversation variable in the Iteration node

1 participant