Loop exit condition #16276

Closed
opened 2026-02-21 19:25:25 -05:00 by yindo · 2 comments
Owner

Originally created by @DavideDelbianco on GitHub (Aug 19, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.7.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Loop termination condition does not accept a variable that comes from a node inside the loop..

✔️ Expected Behavior

Should accept the value because the termination is enforced by the loop count..
This is considered ok (i copy the status_code value in a loop variable

Image

Actual Behavior

This is considered not ok:

Image
Originally created by @DavideDelbianco on GitHub (Aug 19, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/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.7.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Loop termination condition does not accept a variable that comes from a node inside the loop.. ### ✔️ Expected Behavior Should accept the value because the termination is enforced by the loop count.. This is considered ok (i copy the status_code value in a loop variable <img width="1887" height="719" alt="Image" src="https://github.com/user-attachments/assets/39e5671d-7682-4e80-b80c-b22b7cfec6ac" /> ### ❌ Actual Behavior This is considered not ok: <img width="1757" height="854" alt="Image" src="https://github.com/user-attachments/assets/619b11b6-2fee-4b08-bab5-d6cef3cbe76c" />
yindo added the 🐞 buggood first issue labels 2026-02-21 19:25:25 -05:00
yindo closed this issue 2026-02-21 19:25:25 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 19, 2025):

This limitation is due to how Dify handles variable scoping and validation for loop exit conditions. Variables created or updated by nodes inside the loop are considered iteration-scoped and are not directly available for use in the loop's termination condition. The loop exit condition can only reference variables known before the loop starts (global or workflow variables). This is enforced by both the backend runtime and the frontend UI logic, which restricts the available variables for condition selection.

The current workaround is to explicitly copy the value you want to check (such as a status code from an HTTP node) into a loop variable, and then use that loop variable in your termination condition. This approach aligns with how Dify collects and propagates variables during loop execution. There is no indication in the documentation or codebase that this is a bug; rather, it's a design choice based on variable scope handling in the workflow engine. For more on loop exit conditions and related documentation issues, see this discussion.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 19, 2025): <!-- Answer --> This limitation is due to how Dify handles variable scoping and validation for loop exit conditions. Variables created or updated by nodes inside the loop are considered iteration-scoped and are not directly available for use in the loop's termination condition. The loop exit condition can only reference variables known before the loop starts (global or workflow variables). This is enforced by both the backend runtime and the frontend UI logic, which restricts the available variables for condition selection. The current workaround is to explicitly copy the value you want to check (such as a status code from an HTTP node) into a loop variable, and then use that loop variable in your termination condition. This approach aligns with how Dify collects and propagates variables during loop execution. There is no indication in the documentation or codebase that this is a bug; rather, it's a design choice based on variable scope handling in the workflow engine. For more on loop exit conditions and related documentation issues, see [this discussion](https://github.com/langgenius/dify-docs/issues/276). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/2b367798-a803-4829-9db7-8d63d89eda6e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2b367798-a803-4829-9db7-8d63d89eda6e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2b367798-a803-4829-9db7-8d63d89eda6e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2b367798-a803-4829-9db7-8d63d89eda6e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2b367798-a803-4829-9db7-8d63d89eda6e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2b367798-a803-4829-9db7-8d63d89eda6e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2b367798-a803-4829-9db7-8d63d89eda6e?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/24183)
Author
Owner

@baonudesifeizhai commented on GitHub (Aug 20, 2025):

Image fixed Image
@baonudesifeizhai commented on GitHub (Aug 20, 2025): <img width="1680" height="726" alt="Image" src="https://github.com/user-attachments/assets/a180898d-8ac9-42cc-a3a8-145cac9ce340" /> fixed <img width="1619" height="765" alt="Image" src="https://github.com/user-attachments/assets/90728c04-5ee1-49da-84dc-ae248be436b0" />
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#16276