forked from qodo-benchmark/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(api): defer streaming response until referenced variables are updated #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hila-f-qodo
wants to merge
3
commits into
devin_pr_code_review_bench_100_devin2_base_fixapi_defer_streaming_response_until_referenced_variables_are_updated_pr423
Choose a base branch
from
devin_pr_code_review_bench_100_devin2_head_fixapi_defer_streaming_response_until_referenced_variables_are_updated_pr423
base: devin_pr_code_review_bench_100_devin2_base_fixapi_defer_streaming_response_until_referenced_variables_are_updated_pr423
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
api/tests/fixtures/workflow/test_streaming_conversation_variables_v1_overwrite.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| app: | ||
| description: Validate v1 Variable Assigner blocks streaming until conversation variable is updated. | ||
| icon: 🤖 | ||
| icon_background: '#FFEAD5' | ||
| mode: advanced-chat | ||
| name: test_streaming_conversation_variables_v1_overwrite | ||
| use_icon_as_answer_icon: false | ||
| dependencies: [] | ||
| kind: app | ||
| version: 0.5.0 | ||
| workflow: | ||
| conversation_variables: | ||
| - description: '' | ||
| id: 6ddf2d7f-3d1b-4bb0-9a5e-9b0c87c7b5e6 | ||
| name: conv_var | ||
| selector: | ||
| - conversation | ||
| - conv_var | ||
| value: default | ||
| value_type: string | ||
| environment_variables: [] | ||
| features: | ||
| file_upload: | ||
| allowed_file_extensions: | ||
| - .JPG | ||
| - .JPEG | ||
| - .PNG | ||
| - .GIF | ||
| - .WEBP | ||
| - .SVG | ||
| allowed_file_types: | ||
| - image | ||
| allowed_file_upload_methods: | ||
| - local_file | ||
| - remote_url | ||
| enabled: false | ||
| fileUploadConfig: | ||
| audio_file_size_limit: 50 | ||
| batch_count_limit: 5 | ||
| file_size_limit: 15 | ||
| image_file_size_limit: 10 | ||
| video_file_size_limit: 100 | ||
| workflow_file_upload_limit: 10 | ||
| image: | ||
| enabled: false | ||
| number_limits: 3 | ||
| transfer_methods: | ||
| - local_file | ||
| - remote_url | ||
| number_limits: 3 | ||
| opening_statement: '' | ||
| retriever_resource: | ||
| enabled: true | ||
| sensitive_word_avoidance: | ||
| enabled: false | ||
| speech_to_text: | ||
| enabled: false | ||
| suggested_questions: [] | ||
| suggested_questions_after_answer: | ||
| enabled: false | ||
| text_to_speech: | ||
| enabled: false | ||
| language: '' | ||
| voice: '' | ||
| graph: | ||
| edges: | ||
| - data: | ||
| isInIteration: false | ||
| isInLoop: false | ||
| sourceType: start | ||
| targetType: assigner | ||
| id: start-source-assigner-target | ||
| source: start | ||
| sourceHandle: source | ||
| target: assigner | ||
| targetHandle: target | ||
| type: custom | ||
| zIndex: 0 | ||
| - data: | ||
| isInLoop: false | ||
| sourceType: assigner | ||
| targetType: answer | ||
| id: assigner-source-answer-target | ||
| source: assigner | ||
| sourceHandle: source | ||
| target: answer | ||
| targetHandle: target | ||
| type: custom | ||
| zIndex: 0 | ||
| nodes: | ||
| - data: | ||
| desc: '' | ||
| selected: false | ||
| title: Start | ||
| type: start | ||
| variables: [] | ||
| height: 54 | ||
| id: start | ||
| position: | ||
| x: 30 | ||
| y: 253 | ||
| positionAbsolute: | ||
| x: 30 | ||
| y: 253 | ||
| selected: false | ||
| sourcePosition: right | ||
| targetPosition: left | ||
| type: custom | ||
| width: 244 | ||
| - data: | ||
| answer: 'Current Value Of `conv_var` is:{{#conversation.conv_var#}}' | ||
| desc: '' | ||
| selected: false | ||
| title: Answer | ||
| type: answer | ||
| variables: [] | ||
| height: 106 | ||
| id: answer | ||
| position: | ||
| x: 638 | ||
| y: 253 | ||
| positionAbsolute: | ||
| x: 638 | ||
| y: 253 | ||
| selected: true | ||
| sourcePosition: right | ||
| targetPosition: left | ||
| type: custom | ||
| width: 244 | ||
| - data: | ||
| assigned_variable_selector: | ||
| - conversation | ||
| - conv_var | ||
| desc: '' | ||
| input_variable_selector: | ||
| - sys | ||
| - query | ||
| selected: false | ||
| title: Variable Assigner | ||
| type: assigner | ||
| write_mode: over-write | ||
| height: 84 | ||
| id: assigner | ||
| position: | ||
| x: 334 | ||
| y: 253 | ||
| positionAbsolute: | ||
| x: 334 | ||
| y: 253 | ||
| selected: false | ||
| sourcePosition: right | ||
| targetPosition: left | ||
| type: custom | ||
| width: 244 | ||
| viewport: | ||
| x: 0 | ||
| y: 0 | ||
| zoom: 0.7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Type mismatch in blocks_variable_output causes comparison to always return False
The
blocks_variable_outputmethod in v1 VariableAssignerNode compares aSequence[str](list) directly with aset[tuple[str, ...]], which will always returnFalsebecause a list is never equal to a tuple.Click to expand
Bug Mechanism
The
assigned_variable_selectoris of typeSequence[str](typically alist[str]from Pydantic parsing atnode_data.py:14). Thevariable_selectorsparameter is aset[tuple[str, ...]](as defined in the base class atnode.py:435and populated incoordinator.py:172-175).When checking
assigned_selector in variable_selectorsat line 43, Python compares a list with tuples in the set. Since['conversation', 'conv_var'] != ('conversation', 'conv_var'), the comparison always returnsFalse.Comparison with v2 Implementation
The v2 implementation correctly handles this at
v2/node.py:79:Impact
The streaming response coordinator uses
blocks_variable_outputto determine if a node must complete before streaming can proceed. Because this method always returnsFalse, the v1 Variable Assigner node will never block streaming output, potentially causing the Answer node to stream the old/default value of a conversation variable before the Variable Assigner has updated it.Recommendation: Convert the assigned_selector to a tuple before comparison:
Was this helpful? React with 👍 or 👎 to provide feedback.