Agent V2 node inside an Iteration fails to publish with "references non-upstream previous node" when referencing iteration.item or outer upstream variables
Self Checks
- [x] I have read the Contributing Guide and Language Policy.
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
- [x] I confirm that I am using English to submit this report, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
Dify version
1.17.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
- Create a Workflow with a
Startnode and anIterationnode. - Inside the
Iterationnode, add a v2Agentnode (dify_agent/roster_agent). - Connect
iteration-start->Agentnode. - In the
Agentnode's prompt (workflow_prompt), reference either:- The iteration variable
{{#<iteration_node_id>.item#}}, OR - An outer upstream node variable (e.g.,
{{#<start_node_id>.input#}}).
- The iteration variable
- Click Publish.
✔️ Expected Behavior
The workflow should publish successfully, just like LLM, Code, or Template nodes inside an Iteration container can natively reference iteration.item and outer upstream variables.
❌ Actual Behavior
❌ Actual Behavior
Publishing fails with a toast error:
Workflow Agent node <agent_node_id> references non-upstream previous node <iteration_node_id / start_node_id>.
🔍 Root Cause Analysis (For Developers)
When validating agent_job.previous_node_output_refs on a v2 Agent node placed inside an Iteration (or Loop) subgraph:
- The validator only traverses
edgesbackward within the subgraph, stopping at<iteration_id>start(type: custom-iteration-start). - It fails to include the parent container node (
<iteration_id>) itself (for.item/.index) and fails to traverse across the parentIterationnode's incoming edges in the root graph. Current Workaround: Insert aCodeorTemplatenode right afteriteration-startto relayiteration.itemand outer variables into theAgentnode.
Hi @wazgii! I'm Dosu and I'm helping the Dify team.
Your diagnosis matches the validation path in the current checkout: WorkflowAgentNodeValidator.validate_node_job() raises this exact error when topology.is_upstream() returns false. The shared helper, WorkflowGraphTopology, builds ancestry only from explicit edges[].source/target links. It does not incorporate container membership, so the graph shape you described leaves the parent Iteration and its outer predecessors unreachable from the Agent's backward traversal. [1] [2]
Related PR #39192 relaxed checks for draft saves only. It deliberately retained strict publish validation, so it does not resolve this container-boundary case. [3]
For the relay workaround, make sure the Agent prompt references only the relay node's outputs, not the original iteration.item or Start selectors. That gives the validator an explicit upstream edge path to the referenced producer. This follows from the validator's logic; I haven't executed your workflow here. [1] [4]
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
test1349.yml
Here is the reproducible DSL (
test1349.yml) and the error screenshot when clicking Publish:
I'd like to take this one. I verified the defect is still present on current main, checked that no open PR covers it, and prepared a minimal patch with an offline check. Opening a focused PR from my fork now.
Confirmed on Dify 1.19.0, Self Hosted (Docker). This still blocks publishing a workflow that uses a New Agent inside a parallel Iteration.
The Agent task references the enclosing Iteration's current item, inserted through the / variable picker. The item is a small service object (namespace/deployment). Draft saving succeeds, but Publish fails with:
Workflow Agent node <agent_node_id> references non-upstream previous node <iteration_node_id>.
The referenced node is the Agent's parent Iteration. The error occurs during publication, before model/tool execution. Sequential iteration has not been tested in this environment.
Documentation supporting the expected behavior:
- Iteration documents that internal nodes can reference the current item and its index.
- New Agent node documents
/references in the Agent task. The item here is well below the documented 2,000-character limit.
1.19.0 source verification:
- Agent publish validator: publication validates previous-node references using
topology.is_upstream(...); draft validation skips the topology check. - Graph topology helper: ancestry is built from explicit
edges, without enclosing-container membership.
Using the actual 1.19.0 helper with a reduced parent Iteration / internal Start / Agent graph reproduces is_upstream(parent_iteration, internal_agent) == False. An internal Code -> Agent edge is recognized as upstream. The relay workaround has only been checked at the topology-helper level here; its full publication/execution has not yet been tested.
Adding this 1.19.0 confirmation to the existing issue for tracking alongside #45825.