Skip to content

fix(iteration): pass host variable writes to the parent frame - #353

Merged
laipz8200 merged 6 commits into
mainfrom
claude/investigate-issue-43312-39339a
Oct 27, 2026
Merged

laipz8200 merged 6 commits into
mainfrom
claude/investigate-issue-43312-39339a

Conversation

@laipz8200

Copy link
Copy Markdown
Member

Important

  1. Make sure you have read our contribution guidelines
  2. Search existing issues and pull requests to confirm this change is not a duplicate
  3. Open or identify the issue this pull request resolves or advances
  4. Use a Conventional Commits title for this pull request, and mark breaking changes with !
  5. Remember that the pull request title will become the squash merge commit message
  6. If CLA Assistant prompts you, sign CLA.md in the pull request conversation

Related Issue

Closes #350

Summary

An Iteration round worked on a deep copy of its parent's variable pool and never wrote variable updates back. A conversation variable assigned inside an Iteration therefore reverted when the round finished, and nodes after the Iteration read the stale value (reported downstream in langgenius/dify#43312).

IterationContainerHandler.prepare_frame_event now passes a round's NodeRunVariableUpdatedEvent to the round's parent frame when the variable's namespace is not the ID of any node and the parent already holds the variable. No namespace is hard-coded: conversation, env, sys, or any other namespace a host adds behave the same. Node-owned variables (node outputs, Loop variables, Iteration item/index) written in a round stay private, as before.

  • Node IDs come from the graph configs of every registered frame. A child frame's config holds only its container's subtree, and a downstream container may run a separate workflow graph in its own frame (Dify's workflow-tool container does this), so the root config alone is not enough.
  • The handler uses the same identity check as the Loop handler, so a write passes through nested Loops and Iterations up to the root.
  • Writes are passed on per update event, not copied from a pool snapshot when the round completes, so a round never restores stale values for variables it did not write (the problem found in fix(workflow): sync conversation variables after iteration frames dify#43329).

Behavior notes:

  • Parallel rounds copy the pool when they start, so they do not see each other's writes. The last write to a variable wins, and concurrent read-modify-write operations such as append can lose updates. The handler docstring records this; shared-write semantics are still open in Clarify the semantics for variable assignment #24.
  • Writes to env.* and sys.* inside an Iteration now reach the parent too, under the same rule.
  • Hosts that keep the built-in Iteration handler need no code change. Dify wraps it and forwards prepare_frame_event, so a Graphon upgrade is enough for the downstream report.

Docs: corrected the ContainerHandler.prepare_frame_event docstring (an outer frame holds an update only if inner containers passed it on), a Loop handler comment, and two ARCHITECTURE.md evidence links.

Tests:

  • tests/workflows/test_full_engine_events.py:
    • Serial rounds accumulate an append, for conversation and an arbitrary host namespace.
    • The write reaches the root through an Iteration in a Loop, a Loop in an Iteration, and an Iteration in an Iteration.
    • Parallel rounds that write different variables keep both writes.
    • The nested isolation test also checks that a root Start node output written inside a nested Iteration stays private.
  • tests/engine/test_dispatch_patterns.py: an Iteration inside a Loop of a workflow that a custom container runs in its own frame keeps writes to that workflow's node variables private, while a conversation write passes up through the Loop round.
  • Every new case failed before the fix. Context-free reviewers checked the tests before the implementation, as CONTRIBUTING.md requires.

Validation: just test (1001 passed) and just check pass locally.

Checklist

  • This pull request links the issue it resolves or advances
  • This pull request title follows Conventional Commits, and any breaking change is marked with !
  • If CLA Assistant prompted me, I signed CLA.md in the pull request conversation

🤖 Generated with Claude Code

laipz8200 and others added 2 commits October 22, 2026 15:40
An Iteration round worked on a deep copy of its parent's variable pool
and never wrote updates back, so a conversation variable assigned
inside an Iteration reverted once the round finished, and nodes after
the Iteration read the stale value.

Pass a round's write to its parent frame when the variable's namespace
is not the ID of any workflow node, such as conversation, environment,
system, or any other host namespace. The same identity check as the
Loop handler carries the write through nested containers to the root.
Node-owned variables written in a round stay private.

Closes #350

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A downstream container may run a separate workflow graph in its own
frame, so the root graph config does not list that graph's nodes. An
Iteration inside such a graph treated the graph's node variables as
host variables and passed their writes out of the round.

Collect node IDs from the graph configs of every registered frame.
Enclosing frames stay registered while their child frames run, so the
graphs that own a round's outer values are always included.

Refs #350

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@laipz8200
laipz8200 enabled auto-merge (squash) October 23, 2026 04:57
@laipz8200
laipz8200 requested a review from WH-2099 October 27, 2026 05:43
@WH-2099 WH-2099 self-assigned this Oct 27, 2026
@laipz8200
laipz8200 merged commit f9c7ef1 into main Oct 27, 2026
9 checks passed
@laipz8200
laipz8200 deleted the claude/investigate-issue-43312-39339a branch October 27, 2026 09:46
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.

Conversation variable writes inside an Iteration never reach the parent frame

2 participants