Skip to content

Python: fix stop_process so processes actually stop - #14731

Open
KVR Vishnu (VISHNU0906) wants to merge 2 commits into
microsoft:mainfrom
VISHNU0906:fix/14730-stop-process-never-stops
Open

KVR Vishnu (VISHNU0906) wants to merge 2 commits into
microsoft:mainfrom
VISHNU0906:fix/14730-stop-process-never-stops

Conversation

@VISHNU0906

Copy link
Copy Markdown

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:

  1. ProcessStepEdgeBuilder.stop_process — link the edge under self.event_id (same pattern as send_event_to), not the literal "END". No step ever emits END, so the edge never fired.
  2. EndStep — after super().__init__, set self.id = self.END_STEP_ID (== END_PROCESS_ID). Runtimes (local + Dapr) look for that fixed id; the class already had the constant unused.
  3. LocalProcess.internal_execute — remember that an end message was seen, finish the rest of the current superstep, then break the outer loop. The old break only left the inner message loop.

Also updates test_stop_process, which was asserting the wrong link key, and adds real ProcessBuilder → start() regression tests in test_local_process_stop.py (looping process with stop ends after one run/work; without a matching stop edge it still hits max_supersteps).

Contribution Checklist

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>
@VISHNU0906
KVR Vishnu (VISHNU0906) requested a review from a team as a code owner November 6, 2026 21:36
Copilot AI balanced review requested due to automatic review settings November 6, 2026 21:36
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Nov 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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

Comment on lines +222 to +224
if end_message_sent:
# A step asked to stop the process: finish this superstep, then stop.
break

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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>

This branch was previously deployed

1 inactive deployment
github-app-auth — d61d7898 Deployed Nov 6, 2026 by VISHNU0906 via add_label #29614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: stop_process() never stops a process, the edge is linked under the wrong key and the end step id is random

2 participants