Repository navigation
Python: preserve idle shutdown after cancelled sends - #14853
Open
A_Zhe (1137423918) wants to merge 1 commit into
Open
A_Zhe (1137423918) wants to merge 1 commit into
A_Zhe (1137423918) wants to merge 1 commit into
Conversation
A_Zhe (1137423918)
temporarily deployed
to
github-app-auth
November 21, 2026 17:25 — with
GitHub Actions
Inactive
A_Zhe (1137423918)
marked this pull request as ready for review
November 22, 2026 06:44
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the idle-shutdown cancellation fix.
No open issues 🎉
What changed in this PR
Fixes InProcessRuntime idle shutdown when a cancelled sender’s agent handler or asynchronous factory later raises an exception.
Changes:
- Avoids setting an exception on a cancelled response future, allowing queue completion and exception logging to continue.
- Adds four parameterized regression cases covering handler and factory failures, with cancelled and still-waiting callers.
| File | Description |
|---|---|
python/tests/unit/agents/runtime/test_runtime.py |
Adds event-coordinated tests for late failures, cancellation, and idle shutdown. |
python/semantic_kernel/agents/runtime/in_process/in_process_runtime.py |
Guards exception delivery when the response future is cancelled. |
Review effort: Balanced
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Cancelling the task awaiting
InProcessRuntime.send_message()cancels its response future. If the agent handler or asynchronous agent factory subsequently raises an ordinary exception,_process_send()callsset_exception()on that cancelled future. The resultingInvalidStateErrorpreventstask_done()from running, sostop_when_idle()can wait indefinitely.The regression uses the public runtime API and events to establish this ordering. It covers both an agent handler and an asynchronous factory, with a still-waiting caller as a control for each path. No model or external service is needed.
Description
Check
future.cancelled()before setting the exception, following the existingCancelledErrorand response paths. Queue completion and exception logging continue for the cancelled caller. A still-waiting caller receives the original agent error.One production guard changes; the four parameterized tests use the same test-file bytes before and after the fix. The branch is based on main
aa46eddff989c13fba70c15e0ae8715b75f3fe8dand does not depend on the separate cancellation-callback PR #14845. The earlier merged intervention-accounting fix #14656 addresses a different path.Server validation: Linux, Python 3.11.4, the same dedicated test environment for both checkouts.
The scopes overlap and are not additive. The 12 broader orchestration failures remain on the unchanged base; this does not claim that the full SDK suite or upstream CI is green. The initial build invocation found no build frontend in the test environment. Packaging then passed in a separate locked build environment (
build==1.3.0,flit-core==3.12.0, within the declared backend range). The original test environment and tested source bytes remained unchanged; successful tests were not rerun for that tooling correction.Focused reproduction after applying only the new test file to the base checkout:
AI assistance: Codex produced the implementation, tests and server validation. Human author review and upstream review remain pending; this PR is a draft.
Contribution Checklist