Skip to content

Commit

Permalink
Fix: if multiple flows end in a chain, now they are resumed correctly…
Browse files Browse the repository at this point in the history
… (A->B->C->D).
  • Loading branch information
drazvan committed Oct 9, 2023
1 parent 48e7d5c commit eef01fe
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions nemoguardrails/flows/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,28 +453,34 @@ def compute_next_state(state: State, event: dict) -> State:
flow_state.interrupted_by = new_state.next_step_by_flow_uid

# If there are flows that were waiting on completed flows, we reactivate them
for flow_state in new_state.flow_states:
if flow_state.status == FlowStatus.INTERRUPTED:
# TODO: optimize this with a dict of statuses
# If already there are no more flows to interrupt, we should resume
should_resume = flow_state.interrupted_by is None

# Check if it was waiting on a completed flow
if not should_resume:
for _flow_state in new_state.flow_states:
if _flow_state.uid == flow_state.interrupted_by:
if _flow_state.status == FlowStatus.COMPLETED:
should_resume = True
break

if should_resume:
flow_state.status = FlowStatus.ACTIVE
flow_state.interrupted_by = None
changes = True
while changes:
changes = False

for flow_state in new_state.flow_states:
if flow_state.status == FlowStatus.INTERRUPTED:
# TODO: optimize this with a dict of statuses
# If already there are no more flows to interrupt, we should resume
should_resume = flow_state.interrupted_by is None

# Check if it was waiting on a completed flow
if not should_resume:
for _flow_state in new_state.flow_states:
if _flow_state.uid == flow_state.interrupted_by:
if _flow_state.status == FlowStatus.COMPLETED:
should_resume = True
break

if should_resume:
flow_state.status = FlowStatus.ACTIVE
flow_state.interrupted_by = None

_slide_with_subflows(new_state, flow_state)

_slide_with_subflows(new_state, flow_state)
if flow_state.head < 0:
flow_state.status = FlowStatus.COMPLETED

if flow_state.head < 0:
flow_state.status = FlowStatus.COMPLETED
changes = True

return new_state

Expand Down

0 comments on commit eef01fe

Please sign in to comment.