Repository navigation
Python: fix stop_process so processes actually stop - #14731
KVR Vishnu (VISHNU0906) wants to merge 2 commits into
Conversation
stop_process linked the edge under the literal key "END" and EndStep used a random id, so the local runtime never saw END_PROCESS_ID. The inner-loop break also left the outer superstep loop running. Link under the event id, pin EndStep.id to END_STEP_ID, and leave the outer loop after finishing the current superstep. Fixes microsoft#14730 Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The loop exits before draining final-superstep public events, preventing nested processes from forwarding result or completion events to their parent.
1 open issue
What changed in this PR
This PR addresses #14730 by repairing stop-event routing and termination in the Python process framework, so looping processes can stop before reaching the superstep limit.
Changes:
- Register stop edges under the triggering event and give the end step the runtime’s fixed identifier.
- Finish the current local-runtime superstep before stopping the execution loop.
- Correct the edge-builder assertion and add regression tests for stopping and superstep-limit behavior.
| File | Description |
|---|---|
python/tests/unit/processes/test_process_step_edge_builder.py |
Assert registration under the triggering event ID. |
python/tests/unit/processes/local_runtime/test_local_process_stop.py |
Add stop-routing, termination, and loop-limit tests. |
python/semantic_kernel/processes/process_step_edge_builder.py |
Link stop edges to their triggering events. |
python/semantic_kernel/processes/process_end_step.py |
Assign the fixed end-process identifier. |
python/semantic_kernel/processes/local_runtime/local_process.py |
Exit after completing the superstep containing a stop message. |
Review effort: Balanced
| if end_message_sent: | ||
| # A step asked to stop the process: finish this superstep, then stop. | ||
| break |
There was a problem hiding this comment.
Good catch, thanks. Confirmed: breaking after the final superstep skipped the next enqueue_step_messages() pass, so public events emitted by handlers in that superstep stayed in the steps' outgoing queues and a nested parent never saw them.
Before breaking we now drain each step once (forward public events / enqueue edges) and still do not run another superstep. Added test_stop_process_forwards_nested_public_events_from_final_superstep for the nested case.
When end_message_sent breaks the local process loop, handlers in that superstep may still have outgoing events. Drain them so public events reach a parent nested process, without running another superstep. Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>

Motivation and Context
stop_process()currently does nothing in the Python process framework — a process with a stop edge keeps running until it hits the superstep limit. Caught in #14730 by PRABHU KIRAN VANDRANKI (@VANDRANKI) (thanks for the clear repro and root-cause write-up).Fixes #14730
Description
Three small root-cause fixes that have to land together:
ProcessStepEdgeBuilder.stop_process— link the edge underself.event_id(same pattern assend_event_to), not the literal"END". No step ever emitsEND, so the edge never fired.EndStep— aftersuper().__init__, setself.id = self.END_STEP_ID(== END_PROCESS_ID). Runtimes (local + Dapr) look for that fixed id; the class already had the constant unused.LocalProcess.internal_execute— remember that an end message was seen, finish the rest of the current superstep, then break the outer loop. The oldbreakonly left the inner message loop.Also updates
test_stop_process, which was asserting the wrong link key, and adds realProcessBuilder→start()regression tests intest_local_process_stop.py(looping process with stop ends after onerun/work; without a matching stop edge it still hitsmax_supersteps).Contribution Checklist