Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/application/workflow/nodes/loop_node/loop_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,17 @@ def on_complete(wf_manage, error):
self.complete(Status.CANCELLED)
return

if wf_manage.signal == Signal.BREAK or wf_manage.signal == Signal.FORM:
if wf_manage.signal == Signal.BREAK:
self.data["run_time"] = time.time() - self.data.get("start_time", time.time())
self.complete(Status.SUCCESS)
return

# 循环体命中表单:向上传播中断,暂停父工作流,等用户提交后按 position 恢复到本轮
if wf_manage.signal == Signal.FORM:
self.data["run_time"] = time.time() - self.data.get("start_time", time.time())
self.complete(Status.SUCCESS, signal=Signal.FORM)
return

if wf_manage.signal == Signal.CONTINUE:
self._run_next()
return

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my review of the diff:

Issues / Observations

1. Behavior change may break existing callers

Previously, Signal.BREAK and Signal.FORM were handled identically (complete with Status.SUCCESS). Now FORM completes with an extra signal=Signal.FORM argument. Check that self.complete() actually accepts a signal keyword — if not defined or if it doesn't propagate the signal upstream correctly, this will raise TypeError or silently drop the signal. Confirm the signature and downstream handling of the propagated signal.

2. Duplicated run_time computation

The line:

self.data["run_time"] = time.time() - self.data.get("start_time", time.time())

is now duplicated in both branches. Consider factoring it out before the branch, or into a small helper, to reduce drift risk.

3. Signal.FORM propagation must be handled by parent

The comment says "propagate interrupt upward, pause parent workflow, resume at position after user submit." Verify:

  • The parent on_complete handler actually inspects the child's returned signal (e.g., wf_manage.result.signal or wherever complete(..., signal=...) stores it).
  • There is logic to persist the current position so resumption works. If no such resume mechanism exists yet, the new behavior will complete the loop body but not actually pause/resume — it could silently end the loop iteration instead.

4. Status.SUCCESS for a "paused/awaiting form" state is semantically questionable

Completing with Status.SUCCESS while emitting Signal.FORM conflates "finished successfully" with "interrupted awaiting input." Consider a distinct status (e.g., Status.PAUSED / Status.AWAITING_FORM) to make the state explicit and avoid mistaking it for a normal completion in metrics/logging.

5. Idempotency / repeated submission

If the parent re-invokes the loop body after form submission, ensure start_time and run_time are not double-counted (run_time is rewritten each time — likely fine, but confirm start_time isn't reset on resume).

6. Missing test coverage note

This is a control-flow change for interruptions. Ensure tests cover: BREAK path unchanged, FORM path sets the propagated signal, and the parent resumes via position.

7. Minor: readability

An elif chain would read more clearly than sequential if ... return blocks when all conditions are mutually exclusive signals:

if wf_manage.signal == Signal.BREAK:
    ...
elif wf_manage.signal == Signal.FORM:
    ...
elif wf_manage.signal == Signal.CONTINUE:
    ...

Summary

Main risks: (a) complete(signal=...) must exist and be consumed by the parent; (b) the resume-at-position machinery must actually exist, otherwise FORM interruption won't work as intended; (c) using SUCCESS for a paused state is misleading. Validate these before merging.

Expand Down
Loading