fix(py-isolation-saga): document wait_for cancel semantics on timeout#2174
Merged
imran-siddique merged 1 commit intoMay 12, 2026
Conversation
`SagaOrchestrator.execute_step` and `.compensate` both wrap their
callable in `asyncio.wait_for(callable, timeout=step.timeout_seconds)`.
The standing audit question was whether wait_for *awaits* the
cancellation it issues, or just signals it and moves on.
CPython's `asyncio.wait_for` does in fact wait for the cancellation to
complete before raising `TimeoutError`. Cooperative executors with
`await` points get a chance to release resources. But:
- Executors with no `await` points (synchronous CPU work inside an
`async def`) are not cancellable by Python at all — the timeout
only fires once the executor next yields control.
- Callers needing hard-kill semantics must run such executors in a
process or thread pool and arrange external termination.
Document this contract on `execute_step`; cross-reference from
`compensate`. No behaviour change — pure docstring clarification.
🤖 AI Agent: code-reviewer — View detailsNo issues found. Clean change. |
🤖 AI Agent: test-generator — View detailsTest coverage looks good. No gaps identified. |
🤖 AI Agent: security-scanner — View detailsNo security issues found. |
🤖 AI Agent: docs-sync-checker — Docs SyncDocs Sync
|
🤖 AI Agent: breaking-change-detector — View detailsNo breaking changes detected. |
|
🟡 Contributor Check: MEDIUM
Automated check by AGT Contributor Check. |
PR Review Summary
Verdict: ✅ Ready for human review |
MohammadHaroonAbuomar
pushed a commit
to MohammadHaroonAbuomar/agt-acs
that referenced
this pull request
Jun 1, 2026
…microsoft#2174) `SagaOrchestrator.execute_step` and `.compensate` both wrap their callable in `asyncio.wait_for(callable, timeout=step.timeout_seconds)`. The standing audit question was whether wait_for *awaits* the cancellation it issues, or just signals it and moves on. CPython's `asyncio.wait_for` does in fact wait for the cancellation to complete before raising `TimeoutError`. Cooperative executors with `await` points get a chance to release resources. But: - Executors with no `await` points (synchronous CPU work inside an `async def`) are not cancellable by Python at all — the timeout only fires once the executor next yields control. - Callers needing hard-kill semantics must run such executors in a process or thread pool and arrange external termination. Document this contract on `execute_step`; cross-reference from `compensate`. No behaviour change — pure docstring clarification.
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.
Summary
saga/orchestrator.py'sSagaOrchestrator.execute_stepand.compensateboth wrap their callable inasyncio.wait_for(callable, timeout=step.timeout_seconds). The standing audit question was whetherwait_forawaits the cancellation it issues, or just signals it and moves on.CPython's
asyncio.wait_fordoes wait for the cancellation to complete before raisingTimeoutError(see Python docs). Cooperative executors withawaitpoints get a chance to release resources. But:awaitpoints (synchronous CPU work inside anasync def) are not cancellable by Python at all — the timeout only fires once the executor next yields control.The behaviour is correct as-is; what's missing is the contract being documented for callers writing executors.
Change
Add a
Cancellation semantics on timeout:block toexecute_step's docstring naming the cooperative-cancel contract and the two failure modes. Cross-reference fromcompensate's docstring.Pure documentation change — no behaviour delta.
Tests
No new tests needed (documentation change).
Test plan
Surfaced during independent audit conducted by @finnoybu (Ken Tannenbaum, AEGIS Initiative); [LOW, Python Isolation].