Skip to content

Python: Account for intercepted messages when stopping the runtime - #14656

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
KevinAndrewDong:fix/runtime-intervention-idle
Oct 26, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
KevinAndrewDong:fix/runtime-intervention-idle

Conversation

@KevinAndrewDong

Copy link
Copy Markdown
Contributor

Motivation and Context

Dropping a message or raising from an intervention handler can leave InProcessRuntime.stop_when_idle() waiting indefinitely. The runtime has removed the envelope from the queue, but its unfinished-task count is never decremented on those early-return paths.

Description

Call task_done() before returning from the six send, publish, and response interception branches that drop a message or handle an exception. Normal dispatch retains its existing completion accounting.

Add 12 parameterized regression cases covering those three stages with a drop marker class, a drop marker instance, a raised exception, and normal pass-through.

Validation

Baseline: 483ffb487a33a1644886992d56599feae3b69b76.

  • Before the fix, runtime/serialization plus the new regression: 9 failed, 23 passed on both Python 3.12.14 and 3.13.15. Each failure reaches the idle-stop deadline.
  • After the fix, runtime, orchestration, and group-chat suites: 175 passed, 1 skipped on each interpreter. The skip is an existing upstream timing-related skip.
  • These tests use normal complete-package imports and upstream tests/conftest.py. No namespace bootstrap, model API, or external service is involved.
  • Ruff 0.13.1 lint/format, Python AST, whitespace checks, and clean patch application pass.
  • The entire repository suite, type checking, and pinned pre-commit hooks have not run. Local command-line network access is blocked, so the repository's Ruff 0.9.6 hook and other missing hook dependencies could not be installed.

Command, from python/:
python -m pytest tests/unit/agents/runtime tests/unit/agents/orchestration tests/unit/agents/test_group_chat -rs

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines and the complete pre-submission checks pass
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone 😄

AI assistance

OpenAI Codex assisted with source inspection, the regression tests, the six-line fix, and local verification.

Mark send, publish, and response envelopes done when interception drops them or raises, so stop_when_idle can complete.
Cover send, publish, and response interception with both drop marker forms, exceptions, and normal pass-through using the real runtime.
@KevinAndrewDong
Kevin Dong (KevinAndrewDong) requested a review from a team as a code owner October 24, 2026 00:36
Copilot AI balanced review requested due to automatic review settings October 24, 2026 00:36
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 24, 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.

🟢 Approval recommended

The six targeted completion calls preserve normal dispatch accounting, and the regression cases cover every affected stage and outcome with no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes queue completion accounting in the Python in-process agent runtime so intercepted messages do not leave stop_when_idle() waiting indefinitely.

Changes:

  • Marks dequeued messages complete on all six drop and exception paths across send, publish, and response interception.
  • Adds 12 parameterized regression cases covering both drop marker forms, exceptions, and normal pass-through.
File Description
python/​tests/​unit/​agents/​runtime/​test_intervention_queue.py Adds regression coverage for idle shutdown after interception.
python/​semantic_kernel/​agents/​runtime/​in_process/​in_process_runtime.py Completes queue accounting on terminal interception paths.

Review effort: Balanced

@KevinAndrewDong

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Merged via the queue into microsoft:main with commit 84d4027 Oct 26, 2026
34 checks passed

This branch was successfully deployed

1 active deployment
github-app-auth — 42e593bb Deployed Oct 24, 2026 by KevinAndrewDong via add_label #29433
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.

3 participants