forked from qodo-benchmark/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: workflow incorrectly marked as completed while nodes are still executing #83
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
tomerqodo
wants to merge
5
commits into
qodo_combined_100_qodo_grep_sentry_1_base_fix_workflow_incorrectly_marked_as_completed_while_nodes_are_still_executing_pr133
Choose a base branch
from
qodo_combined_100_qodo_grep_sentry_1_head_fix_workflow_incorrectly_marked_as_completed_while_nodes_are_still_executing_pr133
base: qodo_combined_100_qodo_grep_sentry_1_base_fix_workflow_incorrectly_marked_as_completed_while_nodes_are_still_executing_pr133
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb834b8
Fix lost `start_execution` after `enqueue_node` when the last previou…
79c6e98
Add unit test
8a735f9
[autofix.ci] apply automated fixes
autofix-ci[bot] 6b9dd40
Merge branch 'langgenius:main' into bugfix_workflow_skip
Chenyl-Sai dfedfef
Apply changes for benchmark PR
tomerqodo 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
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
1 change: 1 addition & 0 deletions
1
api/tests/unit_tests/core/workflow/graph_engine/graph_traversal/__init__.py
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 @@ | ||
| """Tests for graph traversal components.""" |
308 changes: 308 additions & 0 deletions
308
api/tests/unit_tests/core/workflow/graph_engine/graph_traversal/test_skip_propagator.py
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,308 @@ | ||
| """Unit tests for skip propagator.""" | ||
|
|
||
| from typing import Any | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. • The new unit test introduces typing.Any and uses it in annotations for get_incoming_edges_side_effect, weakening static typing and making refactors/type-checking less effective. • This conflicts with the requirement to use strong typing and avoid overly-permissive types unless strictly necessary. • It may also mask incorrect mock usage/signatures that stronger types would catch earlier. Agent Prompt
|
||
| from unittest.mock import MagicMock, create_autospec | ||
|
|
||
| from core.workflow.graph import Edge, Graph | ||
| from core.workflow.graph_engine.graph_state_manager import GraphStateManager | ||
| from core.workflow.graph_engine.graph_traversal.skip_propagator import SkipPropagator | ||
|
|
||
|
|
||
| class TestSkipPropagator: | ||
| """Test suite for SkipPropagator.""" | ||
|
|
||
| def test_propagate_skip_from_edge_with_unknown_edges_stops_processing(self) -> None: | ||
| """When there are unknown incoming edges, propagation should stop.""" | ||
| # Arrange | ||
| mock_graph = create_autospec(Graph) | ||
| mock_state_manager = create_autospec(GraphStateManager) | ||
|
|
||
| # Create a mock edge | ||
| mock_edge = MagicMock(spec=Edge) | ||
| mock_edge.id = "edge_1" | ||
| mock_edge.head = "node_2" | ||
|
|
||
| # Setup graph edges dict | ||
| mock_graph.edges = {"edge_1": mock_edge} | ||
|
|
||
| # Setup incoming edges | ||
| incoming_edges = [MagicMock(spec=Edge), MagicMock(spec=Edge)] | ||
| mock_graph.get_incoming_edges.return_value = incoming_edges | ||
|
|
||
| # Setup state manager to return has_unknown=True | ||
| mock_state_manager.analyze_edge_states.return_value = { | ||
| "has_unknown": True, | ||
| "has_taken": False, | ||
| "all_skipped": False, | ||
| } | ||
|
|
||
| propagator = SkipPropagator(mock_graph, mock_state_manager) | ||
|
|
||
| # Act | ||
| propagator.propagate_skip_from_edge("edge_1") | ||
|
|
||
| # Assert | ||
| mock_graph.get_incoming_edges.assert_called_once_with("node_2") | ||
| mock_state_manager.analyze_edge_states.assert_called_once_with(incoming_edges) | ||
| # Should not call any other state manager methods | ||
| mock_state_manager.enqueue_node.assert_not_called() | ||
| mock_state_manager.start_execution.assert_not_called() | ||
| mock_state_manager.mark_node_skipped.assert_not_called() | ||
|
|
||
| def test_propagate_skip_from_edge_with_taken_edge_enqueues_node(self) -> None: | ||
| """When there is at least one taken edge, node should be enqueued.""" | ||
| # Arrange | ||
| mock_graph = create_autospec(Graph) | ||
| mock_state_manager = create_autospec(GraphStateManager) | ||
|
|
||
| # Create a mock edge | ||
| mock_edge = MagicMock(spec=Edge) | ||
| mock_edge.id = "edge_1" | ||
| mock_edge.head = "node_2" | ||
|
|
||
| mock_graph.edges = {"edge_1": mock_edge} | ||
| incoming_edges = [MagicMock(spec=Edge)] | ||
| mock_graph.get_incoming_edges.return_value = incoming_edges | ||
|
|
||
| # Setup state manager to return has_taken=True | ||
| mock_state_manager.analyze_edge_states.return_value = { | ||
| "has_unknown": False, | ||
| "has_taken": True, | ||
| "all_skipped": False, | ||
| } | ||
|
|
||
| propagator = SkipPropagator(mock_graph, mock_state_manager) | ||
|
|
||
| # Act | ||
| propagator.propagate_skip_from_edge("edge_1") | ||
|
|
||
| # Assert | ||
| mock_state_manager.start_execution.assert_called_once_with("node_2") | ||
| mock_state_manager.enqueue_node.assert_called_once_with("node_2") | ||
| mock_state_manager.mark_node_skipped.assert_not_called() | ||
|
|
||
| def test_propagate_skip_from_edge_with_all_skipped_propagates_to_node(self) -> None: | ||
| """When all incoming edges are skipped, should propagate skip to node.""" | ||
| # Arrange | ||
| mock_graph = create_autospec(Graph) | ||
| mock_state_manager = create_autospec(GraphStateManager) | ||
|
|
||
| # Create a mock edge | ||
| mock_edge = MagicMock(spec=Edge) | ||
| mock_edge.id = "edge_1" | ||
| mock_edge.head = "node_2" | ||
|
|
||
| mock_graph.edges = {"edge_1": mock_edge} | ||
| incoming_edges = [MagicMock(spec=Edge)] | ||
| mock_graph.get_incoming_edges.return_value = incoming_edges | ||
|
|
||
| # Setup state manager to return all_skipped=True | ||
| mock_state_manager.analyze_edge_states.return_value = { | ||
| "has_unknown": False, | ||
| "has_taken": False, | ||
| "all_skipped": True, | ||
| } | ||
|
|
||
| propagator = SkipPropagator(mock_graph, mock_state_manager) | ||
|
|
||
| # Act | ||
| propagator.propagate_skip_from_edge("edge_1") | ||
|
|
||
| # Assert | ||
| mock_state_manager.mark_node_skipped.assert_called_once_with("node_2") | ||
| mock_state_manager.enqueue_node.assert_not_called() | ||
| mock_state_manager.start_execution.assert_not_called() | ||
|
|
||
| def test_propagate_skip_to_node_marks_node_and_outgoing_edges_skipped(self) -> None: | ||
| """_propagate_skip_to_node should mark node and all outgoing edges as skipped.""" | ||
| # Arrange | ||
| mock_graph = create_autospec(Graph) | ||
| mock_state_manager = create_autospec(GraphStateManager) | ||
|
|
||
| # Create outgoing edges | ||
| edge1 = MagicMock(spec=Edge) | ||
| edge1.id = "edge_2" | ||
| edge1.head = "node_downstream_1" # Set head for propagate_skip_from_edge | ||
|
|
||
| edge2 = MagicMock(spec=Edge) | ||
| edge2.id = "edge_3" | ||
| edge2.head = "node_downstream_2" | ||
|
|
||
| # Setup graph edges dict for propagate_skip_from_edge | ||
| mock_graph.edges = {"edge_2": edge1, "edge_3": edge2} | ||
| mock_graph.get_outgoing_edges.return_value = [edge1, edge2] | ||
|
|
||
| # Setup get_incoming_edges to return empty list to stop recursion | ||
| mock_graph.get_incoming_edges.return_value = [] | ||
|
|
||
| propagator = SkipPropagator(mock_graph, mock_state_manager) | ||
|
|
||
| # Use mock to call private method | ||
| # Act | ||
| propagator._propagate_skip_to_node("node_1") | ||
|
|
||
| # Assert | ||
| mock_state_manager.mark_node_skipped.assert_called_once_with("node_1") | ||
| mock_state_manager.mark_edge_skipped.assert_any_call("edge_2") | ||
| mock_state_manager.mark_edge_skipped.assert_any_call("edge_3") | ||
| assert mock_state_manager.mark_edge_skipped.call_count == 2 | ||
| # Should recursively propagate from each edge | ||
| # Since propagate_skip_from_edge is called, we need to verify it was called | ||
| # But we can't directly verify due to recursion. We'll trust the logic. | ||
|
|
||
| def test_skip_branch_paths_marks_unselected_edges_and_propagates(self) -> None: | ||
| """skip_branch_paths should mark all unselected edges as skipped and propagate.""" | ||
| # Arrange | ||
| mock_graph = create_autospec(Graph) | ||
| mock_state_manager = create_autospec(GraphStateManager) | ||
|
|
||
| # Create unselected edges | ||
| edge1 = MagicMock(spec=Edge) | ||
| edge1.id = "edge_1" | ||
| edge1.head = "node_downstream_1" | ||
|
|
||
| edge2 = MagicMock(spec=Edge) | ||
| edge2.id = "edge_2" | ||
| edge2.head = "node_downstream_2" | ||
|
|
||
| unselected_edges = [edge1, edge2] | ||
|
|
||
| # Setup graph edges dict | ||
| mock_graph.edges = {"edge_1": edge1, "edge_2": edge2} | ||
| # Setup get_incoming_edges to return empty list to stop recursion | ||
| mock_graph.get_incoming_edges.return_value = [] | ||
|
|
||
| propagator = SkipPropagator(mock_graph, mock_state_manager) | ||
|
|
||
| # Act | ||
| propagator.skip_branch_paths(unselected_edges) | ||
|
|
||
| # Assert | ||
| mock_state_manager.mark_edge_skipped.assert_any_call("edge_1") | ||
| mock_state_manager.mark_edge_skipped.assert_any_call("edge_2") | ||
| assert mock_state_manager.mark_edge_skipped.call_count == 2 | ||
| # propagate_skip_from_edge should be called for each edge | ||
| # We can't directly verify due to the mock, but the logic is covered | ||
|
|
||
| def test_propagate_skip_from_edge_recursively_propagates_through_graph(self) -> None: | ||
| """Skip propagation should recursively propagate through the graph.""" | ||
| # Arrange | ||
| mock_graph = create_autospec(Graph) | ||
| mock_state_manager = create_autospec(GraphStateManager) | ||
|
|
||
| # Create edge chain: edge_1 -> node_2 -> edge_3 -> node_4 | ||
| edge1 = MagicMock(spec=Edge) | ||
| edge1.id = "edge_1" | ||
| edge1.head = "node_2" | ||
|
|
||
| edge3 = MagicMock(spec=Edge) | ||
| edge3.id = "edge_3" | ||
| edge3.head = "node_4" | ||
|
|
||
| mock_graph.edges = {"edge_1": edge1, "edge_3": edge3} | ||
|
|
||
| # Setup get_incoming_edges to return different values based on node | ||
| def get_incoming_edges_side_effect(node_id: Any) -> Any: | ||
| if node_id == "node_2": | ||
| return [edge1] | ||
| elif node_id == "node_4": | ||
| return [edge3] | ||
| return [] | ||
|
|
||
| mock_graph.get_incoming_edges.side_effect = get_incoming_edges_side_effect | ||
|
|
||
| # Setup get_outgoing_edges to return different values based on node | ||
| def get_outgoing_edges_side_effect(node_id): | ||
| if node_id == "node_2": | ||
| return [edge3] | ||
| elif node_id == "node_4": | ||
| return [] # No outgoing edges, stops recursion | ||
| return [] | ||
|
|
||
| mock_graph.get_outgoing_edges.side_effect = get_outgoing_edges_side_effect | ||
|
|
||
| # Setup state manager to return all_skipped for both nodes | ||
| mock_state_manager.analyze_edge_states.return_value = { | ||
| "has_unknown": False, | ||
| "has_taken": False, | ||
| "all_skipped": True, | ||
| } | ||
|
|
||
| propagator = SkipPropagator(mock_graph, mock_state_manager) | ||
|
|
||
| # Act | ||
| propagator.propagate_skip_from_edge("edge_1") | ||
|
|
||
| # Assert | ||
| # Should mark node_2 as skipped | ||
| mock_state_manager.mark_node_skipped.assert_any_call("node_2") | ||
| # Should mark edge_3 as skipped | ||
| mock_state_manager.mark_edge_skipped.assert_any_call("edge_3") | ||
| # Should propagate to node_4 | ||
| mock_state_manager.mark_node_skipped.assert_any_call("node_4") | ||
| assert mock_state_manager.mark_node_skipped.call_count == 2 | ||
|
|
||
| def test_propagate_skip_from_edge_with_mixed_edge_states_handles_correctly(self) -> None: | ||
| """Test with mixed edge states (some unknown, some taken, some skipped).""" | ||
| # Arrange | ||
| mock_graph = create_autospec(Graph) | ||
| mock_state_manager = create_autospec(GraphStateManager) | ||
|
|
||
| mock_edge = MagicMock(spec=Edge) | ||
| mock_edge.id = "edge_1" | ||
| mock_edge.head = "node_2" | ||
|
|
||
| mock_graph.edges = {"edge_1": mock_edge} | ||
| incoming_edges = [MagicMock(spec=Edge), MagicMock(spec=Edge), MagicMock(spec=Edge)] | ||
| mock_graph.get_incoming_edges.return_value = incoming_edges | ||
|
|
||
| # Test 1: has_unknown=True, has_taken=False, all_skipped=False | ||
| mock_state_manager.analyze_edge_states.return_value = { | ||
| "has_unknown": True, | ||
| "has_taken": False, | ||
| "all_skipped": False, | ||
| } | ||
|
|
||
| propagator = SkipPropagator(mock_graph, mock_state_manager) | ||
|
|
||
| # Act | ||
| propagator.propagate_skip_from_edge("edge_1") | ||
|
|
||
| # Assert - should stop processing | ||
| mock_state_manager.enqueue_node.assert_not_called() | ||
| mock_state_manager.mark_node_skipped.assert_not_called() | ||
|
|
||
| # Reset mocks for next test | ||
| mock_state_manager.reset_mock() | ||
| mock_graph.reset_mock() | ||
|
|
||
| # Test 2: has_unknown=False, has_taken=True, all_skipped=False | ||
| mock_state_manager.analyze_edge_states.return_value = { | ||
| "has_unknown": False, | ||
| "has_taken": True, | ||
| "all_skipped": False, | ||
| } | ||
|
|
||
| # Act | ||
| propagator.propagate_skip_from_edge("edge_1") | ||
|
|
||
| # Assert - should enqueue node | ||
| mock_state_manager.start_execution.assert_called_once_with("node_2") | ||
| mock_state_manager.enqueue_node.assert_called_once_with("node_2") | ||
|
|
||
| # Reset mocks for next test | ||
| mock_state_manager.reset_mock() | ||
| mock_graph.reset_mock() | ||
|
|
||
| # Test 3: has_unknown=False, has_taken=False, all_skipped=True | ||
| mock_state_manager.analyze_edge_states.return_value = { | ||
| "has_unknown": False, | ||
| "has_taken": False, | ||
| "all_skipped": True, | ||
| } | ||
|
|
||
| # Act | ||
| propagator.propagate_skip_from_edge("edge_1") | ||
|
|
||
| # Assert - should propagate skip | ||
| mock_state_manager.mark_node_skipped.assert_called_once_with("node_2") | ||
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.
2. Invalid node ids queued
🐞 BugAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools