Skip to content

Commit 204d314

Browse files
Novice LeeNovice Lee
Novice Lee
authored and
Novice Lee
committed
fix: remove the unused retry index field
1 parent dacd457 commit 204d314

File tree

14 files changed

+88
-124
lines changed

14 files changed

+88
-124
lines changed

api/controllers/console/app/workflow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from core.app.entities.app_invoke_entities import InvokeFrom
1616
from factories import variable_factory
1717
from fields.workflow_fields import workflow_fields
18-
from fields.workflow_run_fields import workflow_run_node_execution_fields
18+
from fields.workflow_run_fields import single_step_node_execution_fields
1919
from libs import helper
2020
from libs.helper import TimestampField, uuid_value
2121
from libs.login import current_user, login_required
@@ -285,7 +285,7 @@ class DraftWorkflowNodeRunApi(Resource):
285285
@login_required
286286
@account_initialization_required
287287
@get_app_model(mode=[AppMode.ADVANCED_CHAT, AppMode.WORKFLOW])
288-
@marshal_with(workflow_run_node_execution_fields)
288+
@marshal_with(single_step_node_execution_fields)
289289
def post(self, app_model: App, node_id: str):
290290
"""
291291
Run draft workflow node

api/core/app/apps/advanced_chat/generate_task_pipeline.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,22 @@ def _process_stream_response(
291291
yield self._workflow_start_to_stream_response(
292292
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run
293293
)
294+
elif isinstance(
295+
event,
296+
QueueNodeRetryEvent,
297+
):
298+
workflow_node_execution = self._handle_workflow_node_execution_retried(
299+
workflow_run=workflow_run, event=event
300+
)
301+
302+
response = self._workflow_node_retry_to_stream_response(
303+
event=event,
304+
task_id=self._application_generate_entity.task_id,
305+
workflow_node_execution=workflow_node_execution,
306+
)
307+
308+
if response:
309+
yield response
294310
elif isinstance(event, QueueNodeStartedEvent):
295311
if not workflow_run:
296312
raise Exception("Workflow run not initialized.")
@@ -331,22 +347,7 @@ def _process_stream_response(
331347

332348
if response:
333349
yield response
334-
elif isinstance(
335-
event,
336-
QueueNodeRetryEvent,
337-
):
338-
workflow_node_execution = self._handle_workflow_node_execution_retried(
339-
workflow_run=workflow_run, event=event
340-
)
341350

342-
response = self._workflow_node_retry_to_stream_response(
343-
event=event,
344-
task_id=self._application_generate_entity.task_id,
345-
workflow_node_execution=workflow_node_execution,
346-
)
347-
348-
if response:
349-
yield response
350351
elif isinstance(event, QueueParallelBranchRunStartedEvent):
351352
if not workflow_run:
352353
raise Exception("Workflow run not initialized.")

api/core/app/apps/workflow/generate_task_pipeline.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,22 @@ def _process_stream_response(
254254
yield self._workflow_start_to_stream_response(
255255
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run
256256
)
257+
elif isinstance(
258+
event,
259+
QueueNodeRetryEvent,
260+
):
261+
workflow_node_execution = self._handle_workflow_node_execution_retried(
262+
workflow_run=workflow_run, event=event
263+
)
264+
265+
response = self._workflow_node_retry_to_stream_response(
266+
event=event,
267+
task_id=self._application_generate_entity.task_id,
268+
workflow_node_execution=workflow_node_execution,
269+
)
270+
271+
if response:
272+
yield response
257273
elif isinstance(event, QueueNodeStartedEvent):
258274
if not workflow_run:
259275
raise Exception("Workflow run not initialized.")
@@ -289,22 +305,6 @@ def _process_stream_response(
289305
)
290306
if node_failed_response:
291307
yield node_failed_response
292-
elif isinstance(
293-
event,
294-
QueueNodeRetryEvent,
295-
):
296-
workflow_node_execution = self._handle_workflow_node_execution_retried(
297-
workflow_run=workflow_run, event=event
298-
)
299-
300-
response = self._workflow_node_retry_to_stream_response(
301-
event=event,
302-
task_id=self._application_generate_entity.task_id,
303-
workflow_node_execution=workflow_node_execution,
304-
)
305-
306-
if response:
307-
yield response
308308

309309
elif isinstance(event, QueueParallelBranchRunStartedEvent):
310310
if not workflow_run:

api/core/app/apps/workflow_app_runner.py

+32-30
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,38 @@ def _handle_event(self, workflow_entry: WorkflowEntry, event: GraphEngineEvent)
188188
)
189189
elif isinstance(event, GraphRunFailedEvent):
190190
self._publish_event(QueueWorkflowFailedEvent(error=event.error, exceptions_count=event.exceptions_count))
191+
elif isinstance(event, NodeRunRetryEvent):
192+
self._publish_event(
193+
QueueNodeRetryEvent(
194+
node_execution_id=event.id,
195+
node_id=event.node_id,
196+
node_type=event.node_type,
197+
node_data=event.node_data,
198+
parallel_id=event.parallel_id,
199+
parallel_start_node_id=event.parallel_start_node_id,
200+
parent_parallel_id=event.parent_parallel_id,
201+
parent_parallel_start_node_id=event.parent_parallel_start_node_id,
202+
start_at=event.start_at,
203+
node_run_index=event.node_run_index,
204+
predecessor_node_id=event.predecessor_node_id,
205+
in_iteration_id=event.in_iteration_id,
206+
parallel_mode_run_id=event.parallel_mode_run_id,
207+
inputs=event.route_node_state.node_run_result.inputs
208+
if event.route_node_state.node_run_result
209+
else {},
210+
process_data=event.route_node_state.node_run_result.process_data
211+
if event.route_node_state.node_run_result
212+
else {},
213+
outputs=event.route_node_state.node_run_result.outputs
214+
if event.route_node_state.node_run_result
215+
else {},
216+
error=event.error,
217+
execution_metadata=event.route_node_state.node_run_result.metadata
218+
if event.route_node_state.node_run_result
219+
else {},
220+
retry_index=event.retry_index,
221+
)
222+
)
191223
elif isinstance(event, NodeRunStartedEvent):
192224
self._publish_event(
193225
QueueNodeStartedEvent(
@@ -422,36 +454,6 @@ def _handle_event(self, workflow_entry: WorkflowEntry, event: GraphEngineEvent)
422454
error=event.error if isinstance(event, IterationRunFailedEvent) else None,
423455
)
424456
)
425-
elif isinstance(event, NodeRunRetryEvent):
426-
self._publish_event(
427-
QueueNodeRetryEvent(
428-
node_execution_id=event.id,
429-
node_id=event.node_id,
430-
node_type=event.node_type,
431-
node_data=event.node_data,
432-
parallel_id=event.parallel_id,
433-
parallel_start_node_id=event.parallel_start_node_id,
434-
parent_parallel_id=event.parent_parallel_id,
435-
parent_parallel_start_node_id=event.parent_parallel_start_node_id,
436-
start_at=event.start_at,
437-
inputs=event.route_node_state.node_run_result.inputs
438-
if event.route_node_state.node_run_result
439-
else {},
440-
process_data=event.route_node_state.node_run_result.process_data
441-
if event.route_node_state.node_run_result
442-
else {},
443-
outputs=event.route_node_state.node_run_result.outputs
444-
if event.route_node_state.node_run_result
445-
else {},
446-
error=event.error,
447-
execution_metadata=event.route_node_state.node_run_result.metadata
448-
if event.route_node_state.node_run_result
449-
else {},
450-
in_iteration_id=event.in_iteration_id,
451-
retry_index=event.retry_index,
452-
start_index=event.start_index,
453-
)
454-
)
455457

456458
def get_workflow(self, app_model: App, workflow_id: str) -> Optional[Workflow]:
457459
"""

api/core/app/entities/queue_entities.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -314,35 +314,18 @@ class QueueNodeSucceededEvent(AppQueueEvent):
314314
iteration_duration_map: Optional[dict[str, float]] = None
315315

316316

317-
class QueueNodeRetryEvent(AppQueueEvent):
317+
class QueueNodeRetryEvent(QueueNodeStartedEvent):
318318
"""QueueNodeRetryEvent entity"""
319319

320320
event: QueueEvent = QueueEvent.RETRY
321321

322-
node_execution_id: str
323-
node_id: str
324-
node_type: NodeType
325-
node_data: BaseNodeData
326-
parallel_id: Optional[str] = None
327-
"""parallel id if node is in parallel"""
328-
parallel_start_node_id: Optional[str] = None
329-
"""parallel start node id if node is in parallel"""
330-
parent_parallel_id: Optional[str] = None
331-
"""parent parallel id if node is in parallel"""
332-
parent_parallel_start_node_id: Optional[str] = None
333-
"""parent parallel start node id if node is in parallel"""
334-
in_iteration_id: Optional[str] = None
335-
"""iteration id if node is in iteration"""
336-
start_at: datetime
337-
338322
inputs: Optional[dict[str, Any]] = None
339323
process_data: Optional[dict[str, Any]] = None
340324
outputs: Optional[dict[str, Any]] = None
341325
execution_metadata: Optional[dict[NodeRunMetadataKey, Any]] = None
342326

343327
error: str
344328
retry_index: int # retry index
345-
start_index: int # start index
346329

347330

348331
class QueueNodeInIterationFailedEvent(AppQueueEvent):

api/core/app/task_pipeline/workflow_cycle_manage.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ def _handle_workflow_node_execution_retried(
445445
workflow_node_execution.workflow_id = workflow_run.workflow_id
446446
workflow_node_execution.triggered_from = WorkflowNodeExecutionTriggeredFrom.WORKFLOW_RUN.value
447447
workflow_node_execution.workflow_run_id = workflow_run.id
448+
workflow_node_execution.predecessor_node_id = event.predecessor_node_id
448449
workflow_node_execution.node_execution_id = event.node_execution_id
449450
workflow_node_execution.node_id = event.node_id
450451
workflow_node_execution.node_type = event.node_type.value
@@ -461,9 +462,11 @@ def _handle_workflow_node_execution_retried(
461462
workflow_node_execution.execution_metadata = json.dumps(
462463
{
463464
NodeRunMetadataKey.ITERATION_ID: event.in_iteration_id,
465+
NodeRunMetadataKey.PARALLEL_MODE_RUN_ID: event.parallel_mode_run_id,
466+
NodeRunMetadataKey.ITERATION_ID: event.in_iteration_id,
464467
}
465468
)
466-
workflow_node_execution.index = event.start_index
469+
workflow_node_execution.index = event.node_run_index
467470

468471
db.session.add(workflow_node_execution)
469472
db.session.commit()

api/core/helper/ssrf_proxy.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ def make_request(method, url, max_retries=SSRF_DEFAULT_MAX_RETRIES, **kwargs):
6363
logging.warning(f"Received status code {response.status_code} for URL {url} which is in the force list")
6464

6565
except httpx.RequestError as e:
66+
if max_retries == 0:
67+
raise
6668
logging.warning(f"Request to URL {url} failed on attempt {retries + 1}: {e}")
6769

6870
retries += 1
6971
if retries <= max_retries:
7072
time.sleep(BACKOFF_FACTOR * (2 ** (retries - 1)))
71-
72-
raise MaxRetriesExceededError(f"Reached maximum retries ({max_retries}) for URL {url}")
73+
if max_retries != 0:
74+
raise MaxRetriesExceededError(f"Reached maximum retries ({max_retries}) for URL {url}")
7375

7476

7577
def get(url, max_retries=SSRF_DEFAULT_MAX_RETRIES, **kwargs):

api/core/workflow/graph_engine/entities/event.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ class NodeInIterationFailedEvent(BaseNodeEvent):
9797
error: str = Field(..., description="error")
9898

9999

100-
class NodeRunRetryEvent(BaseNodeEvent):
100+
class NodeRunRetryEvent(NodeRunStartedEvent):
101101
error: str = Field(..., description="error")
102102
retry_index: int = Field(..., description="which retry attempt is about to be performed")
103103
start_at: datetime = Field(..., description="retry start time")
104-
start_index: int = Field(..., description="retry start index")
104+
node_run_index: int = Field(..., description="retry run index")
105105

106106

107107
###########################################

api/core/workflow/graph_engine/graph_engine.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,15 @@ def _run_node(
649649
node_type=node_instance.node_type,
650650
node_data=node_instance.node_data,
651651
route_node_state=route_node_state,
652-
error=run_result.error,
653-
retry_index=retries,
652+
predecessor_node_id=node_instance.previous_node_id,
654653
parallel_id=parallel_id,
655654
parallel_start_node_id=parallel_start_node_id,
656655
parent_parallel_id=parent_parallel_id,
657656
parent_parallel_start_node_id=parent_parallel_start_node_id,
657+
error=run_result.error,
658+
retry_index=retries,
658659
start_at=retry_start_at,
659-
start_index=self.graph_runtime_state.node_run_steps,
660+
node_run_index=self.graph_runtime_state.node_run_steps,
660661
)
661662
time.sleep(retry_interval)
662663
continue

api/core/workflow/nodes/event/event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SingleStepRetryEvent(BaseModel):
4646

4747
inputs: dict | None = Field(..., description="input")
4848
error: str = Field(..., description="error")
49-
outputs: dict = Field(..., description="output")
49+
outputs: dict | None = Field(..., description="output")
5050
retry_index: int = Field(..., description="Retry attempt number")
5151
error: str = Field(..., description="error")
5252
elapsed_time: float = Field(..., description="elapsed time")

api/core/workflow/nodes/http_request/executor.py

+2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ def _do_http_request(self, headers: dict[str, Any]) -> httpx.Response:
251251
response = getattr(ssrf_proxy, self.method)(**request_args)
252252
except ssrf_proxy.MaxRetriesExceededError as e:
253253
raise HttpRequestNodeError(str(e))
254+
except httpx.RequestError as e:
255+
raise HttpRequestNodeError(str(e))
254256
return response
255257

256258
def invoke(self) -> Response:

api/fields/workflow_run_fields.py

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
"created_by_account": fields.Nested(simple_account_fields, attribute="created_by_account", allow_null=True),
113113
"created_by_end_user": fields.Nested(simple_end_user_fields, attribute="created_by_end_user", allow_null=True),
114114
"finished_at": TimestampField,
115+
}
116+
117+
single_step_node_execution_fields = {
118+
**workflow_run_node_execution_fields,
115119
"retry_events": fields.List(fields.Nested(retry_event_field)),
116120
}
117121

api/migrations/versions/2024_12_20_0628-e1944c35e15e_add_retry_index_field_to_node_execution_.py

-33
This file was deleted.

api/models/workflow.py

-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,6 @@ class WorkflowNodeExecution(db.Model):
640640
created_by_role = db.Column(db.String(255), nullable=False)
641641
created_by = db.Column(StringUUID, nullable=False)
642642
finished_at = db.Column(db.DateTime)
643-
retry_index = db.Column(db.Integer, server_default=db.text("0"))
644643

645644
@property
646645
def created_by_account(self):

0 commit comments

Comments
 (0)