dify icon indicating copy to clipboard operation
dify copied to clipboard

"Invalid variable" when referencing output variables inside loop node

Open smartding opened this issue 1 month ago • 6 comments

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.10.1, 1.10.1-fix.1, 2.0.0-beta2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Create a chatflow that contains a loop node
  2. Set the "max loop count" of the loop node to 2
  3. Create a code node that output a variable called "is_success", hard-code the value to be True
  4. Set the loop node to terminate when the "is_success" variable is True in loop termination condition.
  5. Run this chatflow
Image

✔️ Expected Behavior

The loop node should only run 1 iteration.

❌ Actual Behavior

In 1.10.1, 1.10.1-fix.1, 2.0.0-beta2, there's an "invalid variable" error in Checklist in the web console, as shown in the attached image.

Also, in 2.0.0-beta2, I get an error after running the chatflow: Run failed: Variable ['1765262890772', 'is_success'] not found

In 1.10.1 and 1.10.1-fix.1, the loop node ran 2 iterations without any error.

I found #25566 about a similar error. The answer in that issue said the error was a known issue in 1.8.0 and was already fixed in a PR in Sep. 2025. It's Dec. 2025 now, shouldn't the fix be included in 1.10.1, 1.10.1-fix.1, 2.0.0-beta2?

smartding avatar Dec 10 '25 02:12 smartding

Hi @smartding! I'm Dosu and I’m helping the dify team.

The fix for referencing output variables inside loop node termination conditions was merged in September 2025 (PR #24844, PR #26036), but the current codebase still filters out variable selectors from nodes inside the loop when validating break conditions. This means the "Invalid variable" error persists in versions 1.10.1, 1.10.1-fix.1, and 2.0.0-beta2, and the fix is not fully effective yet (source).

To avoid this error, make sure the variable used in the loop termination condition (like is_success) is always defined in every branch of your workflow, or use a variable that is guaranteed to exist in every iteration (docs issue). This is the most reliable workaround until the filtering logic is improved.

If you want to track progress or changes, keep an eye on future PRs that address loop node variable selector handling. Let me know if you need help structuring your workflow to avoid this issue.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

dosubot[bot] avatar Dec 10 '25 03:12 dosubot[bot]

I'm going to leave the issue open until it's fixed, in case someone ran into a similar situation.

smartding avatar Dec 10 '25 03:12 smartding

this is my dsl

test.yml

i have no errors

Image

fatelei avatar Dec 10 '25 08:12 fatelei

this is my dsl

test.yml

i have no errors

You had no error because you didn't set any "Loop Termination Condition" in the loop node. Please read the "Steps to reproduce" part in my original message

smartding avatar Dec 10 '25 08:12 smartding

I have the same issue, so I assigned the variables in the process as session variables, and now it works properly.

389703328 avatar Dec 10 '25 09:12 389703328

I have the same issue, so I assigned the variables in the process as session variables, and now it works properly.

I assigned the variables to some loop-scoped variables, which also works as a workaround.

smartding avatar Dec 10 '25 12:12 smartding