Skip to content

fix(workflow): fix answer node stream processing in conditional branches#12510

Merged
crazywoola merged 1 commit intolanggenius:mainfrom
Kevin9703:fix-workflow-if-else
Jan 13, 2025
Merged

fix(workflow): fix answer node stream processing in conditional branches#12510
crazywoola merged 1 commit intolanggenius:mainfrom
Kevin9703:fix-workflow-if-else

Conversation

@Kevin9703
Copy link
Contributor

@Kevin9703 Kevin9703 commented Jan 8, 2025

Summary

Previously, the _fetch_node_ids_in_reachable_branch method would collect all downstream
answer nodes regardless of branch conditions, causing incorrect stream processing.
This change ensures that only nodes in the current conditional branch are collected
by tracking and matching branch identifiers.

  • Add branch_identify parameter to track current branch context
  • Add condition check to only follow edges matching current branch
  • Skip edges with mismatched branch identifiers

Tip

Close issue syntax: Fixes #<issue number> or Resolves #<issue number>, see documentation for more details.

Fixes #11542
image

Fixes #9560
image

Fixes #10638
image

Fixes #10564
image

Also fixes #11985 (streaming output)

Screenshots

Before After
image image

Checklist

Important

Please review the checklist below before submitting your pull request.

  • 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 added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 8, 2025
@Kevin9703 Kevin9703 force-pushed the fix-workflow-if-else branch 2 times, most recently from 882bcbc to e74d523 Compare January 8, 2025 15:00
@crazywoola
Copy link
Member

Please open an issue or link an existing issue first.

@Kevin9703 Kevin9703 force-pushed the fix-workflow-if-else branch from 6dfc1cc to 070b232 Compare January 9, 2025 02:20
@Kevin9703
Copy link
Contributor Author

Please open an issue or link an existing issue first.

Issue linked

@yihong0618
Copy link
Contributor

Nice job, but these kind of workflow has many special case, you can follow the issue link to test them if this patch work well

@Kevin9703
Copy link
Contributor Author

Nice job, but these kind of workflow has many special case, you can follow the issue link to test them if this patch work well

Many thanks, will test all related issues

@crazywoola crazywoola requested a review from laipz8200 January 9, 2025 02:47
@Kevin9703 Kevin9703 force-pushed the fix-workflow-if-else branch from d654631 to c50f434 Compare January 12, 2025 16:31
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 13, 2025
@crazywoola crazywoola merged commit 54b5b80 into langgenius:main Jan 13, 2025
6 checks passed
Scorpion1221 added a commit to yybht155/dify that referenced this pull request Jan 14, 2025
* commit '6e0fb055d18969eb923e719ad92ecac3a5c5d534': (42 commits)
  chore: bump version to 0.15.1 (langgenius#12690)
  feat: add table of contents to Knowledge API doc (langgenius#12688)
  [fix] support feature restore (langgenius#12563)
  api tool support multiple env url (langgenius#12249)
  Add new integration with Opik Tracking tool (langgenius#11501)
  fix: add type hints for App model and improve error handling in audio services (langgenius#12677)
  fix: Update variable handling in VariableAssignerNode and clean up app_dsl_service (langgenius#12672)
  Revert "Feat/new saas billing" (langgenius#12673)
  fix(workflow): fix answer node stream processing in conditional branches (langgenius#12510)
  fix: ruff with statements (langgenius#12578)
  fix: ruff check for True if ... else (langgenius#12576)
  chore: Adjust translations to align with Taiwanese Mandarin conventions (langgenius#12633)
  Fix pandas indexing method for knowledge base imports (langgenius#12637) (langgenius#12638)
  Feat/new saas billing (langgenius#12591)
  improve the readability of the function generate_api_key (langgenius#12552)
  chore: translate i18n files (langgenius#12543)
  Feat/add knowledge include all filter (langgenius#12537)
  fix: Add datasets list access control and fix datasets config display issue (langgenius#12533)
  fix: sum costs return error value on overview page (langgenius#12534)
  feat: show workflow running status (langgenius#12531)
  ...

# Conflicts:
#	api/poetry.lock
@Kevin9703 Kevin9703 deleted the fix-workflow-if-else branch January 14, 2025 16:58
alexcodelf pushed a commit to alexcodelf/dify that referenced this pull request Jan 21, 2025
@Nov1c444
Copy link
Contributor

This approach resolves most of the issues, but it introduces a small problem: when conditional branches are nested, it causes the streaming output after the branches to fail. I’ve attempted to fix this issue, but could you kindly review if this fix might cause the previous bug to reappear?

PR: #14065
Issue: #13626

@Kevin9703
Copy link
Contributor Author

This approach resolves most of the issues, but it introduces a small problem: when conditional branches are nested, it causes the streaming output after the branches to fail. I’ve attempted to fix this issue, but could you kindly review if this fix might cause the previous bug to reappear?

PR: #14065 Issue: #13626

Thank you so much. I will proceed to test all the previously related issues.

@Kevin9703
Copy link
Contributor Author

Kevin9703 commented Feb 21, 2025

This approach resolves most of the issues, but it introduces a small problem: when conditional branches are nested, it causes the streaming output after the branches to fail. I’ve attempted to fix this issue, but could you kindly review if this fix might cause the previous bug to reappear?

PR: #14065 Issue: #13626

I've tested everything and it works perfectly. Furthermore, it also resolved the streaming output issue caused by exceptional branch configurations. Brilliant!
image

@yihong0618
Copy link
Contributor

nice work!

jsincorporated pushed a commit to jsincorporated/asaAi that referenced this pull request Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

5 participants