Skip to content

fix(workflow): sync conversation variables after iteration frames - #43329

Closed
Souravrajvi0 wants to merge 3 commits into
langgenius:mainfrom
Souravrajvi0:feat/iteration-conversation-variable-sync-0f01
Closed

Souravrajvi0 wants to merge 3 commits into
langgenius:mainfrom
Souravrajvi0:feat/iteration-conversation-variable-sync-0f01

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #43312 (regression of #26367).

When workflow execution moved into the Graphon package, iteration subgraphs stopped propagating conversation.* variable updates back to the parent variable pool. Conversation variables written inside an iteration were visible during the iteration but reverted after it finished, breaking downstream Answer nodes.

This PR registers a Dify IterationContainerHandler subclass that syncs conversation-scoped variables from each completed iteration frame to the parent pool before scheduling the next frame. The table-driven regression test from #26368 is restored.

Screenshots

Before After
n/a n/a

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 verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

@github-actions github-actions Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 1, 2026
@ghfind-review ghfind-review Bot added the review: high ghfind author score; see https://ghfind.com label Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-10-11 03:36:53.975535590 +0000
+++ /tmp/pyrefly_pr.txt	2026-10-11 03:36:45.907497421 +0000
@@ -4913,15 +4913,11 @@
 ERROR Argument `core.workflow.nodes.human_input.entities.HumanInputNodeData` is not assignable to parameter `data` with type `graphon.nodes.human_input.entities.HumanInputNodeData` in function `graphon.nodes.human_input.human_input_node.HumanInputNode.__init__` [bad-argument-type]
    --> tests/unit_tests/core/workflow/graph_engine/test_parallel_human_input_join_resume.py:222:14
 ERROR Argument `Sequence[type[GraphEngineEvent]]` is not assignable to parameter `expected_sequence` with type `list[type[GraphEngineEvent]]` in function `TableTestRunner._validate_event_sequence` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:352:21
+   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:354:21
 ERROR `graph` is uninitialized [unbound-name]
-   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:405:23
+   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:407:23
 ERROR `graph_runtime_state` is uninitialized [unbound-name]
-   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:406:37
-ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:634:23
-ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:635:23
+   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:408:37
 ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
    --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:636:23
 ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
@@ -4929,15 +4925,19 @@
 ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
    --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:638:23
 ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:646:31
+   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:639:23
 ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:648:35
+   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:640:23
+ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
+   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:648:31
 ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
    --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:650:35
 ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
    --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:652:35
 ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:661:27
+   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:654:35
+ERROR Argument `str` is not assignable to parameter `object` with type `LiteralString` in function `list.append` [bad-argument-type]
+   --> tests/unit_tests/core/workflow/graph_engine/test_table_runner.py:663:27
 ERROR Class member `FakeBindingResolver.resolve` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:146:9
 ERROR Argument `tuple[WorkflowAgentSessionScope, str, SessionSnapshot | None]` is not assignable to parameter `object` with type `tuple[WorkflowAgentSessionScope, str, SessionSnapshot | None, str | None, str | None]` in function `list.append` [bad-argument-type]
@@ -5745,19 +5745,19 @@
 ERROR Object of class `object` has no attribute `tool` [missing-attribute]
    --> tests/unit_tests/core/workflow/test_node_runtime.py:887:12
 ERROR Argument `SimpleNamespace` is not assignable to parameter `graph_runtime_state` with type `GraphRuntimeState` in function `core.workflow.workflow_entry.WorkflowEntry.__init__` [bad-argument-type]
-  --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:62:29
+  --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:63:29
 ERROR Argument `SimpleNamespace` is not assignable to parameter `graph_runtime_state` with type `GraphRuntimeState` in function `core.workflow.workflow_entry.WorkflowEntry.__init__` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:119:37
+   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:120:37
 ERROR Class member `EmptySplitKey.split` overrides parent class `UserString` in an inconsistent manner [bad-override]
-   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:708:17
+   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:710:17
 ERROR Class member `EmptySplitKey.split` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:708:17
+   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:710:17
 ERROR `TestMappingUserInputsBranches.test_rejects_invalid_node_variable_key.EmptySplitKey` is not assignable to dict key type `str` [bad-assignment]
-   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:713:35
+   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:715:35
 ERROR Argument `TestWorkflowEntryNodeLayers.test_run_node_with_layers_reports_success.FakeNode` is not assignable to parameter `node` with type `Node[Unknown]` in function `core.workflow.workflow_entry.WorkflowEntry._run_node_with_layers` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:782:78
+   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:784:78
 ERROR Argument `TestWorkflowEntryNodeLayers.test_run_node_with_layers_reports_errors.FakeNode` is not assignable to parameter `node` with type `Node[Unknown]` in function `core.workflow.workflow_entry.WorkflowEntry._run_node_with_layers` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:816:73
+   --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:818:73
 ERROR Missing argument `case` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]
    --> tests/unit_tests/enterprise/telemetry/test_contracts.py:110:30
 ERROR Missing argument `tenant_id` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 72.00% 72.01% +0.01%
Strict coverage 71.66% 71.67% +0.01%
Typed symbols 58,109 58,131 +22
Untyped symbols 22,705 22,705 0
Modules 3738 3740 +2

@Stream29

Copy link
Copy Markdown
Contributor

@Souravrajvi0 Please fix the CI checks and we can process this PR.

@Stream29
Stream29 self-requested a review October 10, 2026 13:27
Reintroduce propagation of conversation-scoped variable updates from
iteration subgraphs to the parent variable pool, which was lost when
workflow execution moved into Graphon. Wire a Dify iteration container
handler into GraphEngine and restore the table-driven regression test.

Fixes langgenius#43312
Replace subclassing the final Graphon IterationContainerHandler with a
delegating container handler, update WorkflowEntry test expectations,
and add the missing test return annotation for pyrefly.
@Souravrajvi0
Souravrajvi0 force-pushed the feat/iteration-conversation-variable-sync-0f01 branch from 1e40d99 to cff2b47 Compare October 10, 2026 13:37
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.88525% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.82%. Comparing base (bde3a87) to head (c9b7a68).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...w/graph_engine/iteration_conversation_variables.py 86.66% 5 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #43329   +/-   ##
=======================================
  Coverage   88.81%   88.82%           
=======================================
  Files        5319     5320    +1     
  Lines      329341   329402   +61     
  Branches    66005    66010    +5     
=======================================
+ Hits       292520   292578   +58     
  Misses      31592    31592           
- Partials     5229     5232    +3     
Flag Coverage Δ
api 88.42% <86.88%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Stream29

Copy link
Copy Markdown
Contributor

Closing in favor of the planned Graphon fix in #43312. The issue remains open until Dify integrates and verifies the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: high ghfind author score; see https://ghfind.com size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conversation variables updated in iteration do not persist in main flow

2 participants