Repository navigation
fix: preserve cancellation during async flag evaluation - #693
Open
frajberrima wants to merge 1 commit into
Open
frajberrima wants to merge 1 commit into
frajberrima wants to merge 1 commit into
Conversation
Prepared with AI assistance; reviewed and DCO attestation confirmed by the submitting author. Signed-off-by: frajberrima <frajberrima98@gmail.com>
frajberrima
force-pushed
the
fix/async-evaluation-cancellation
branch
from
December 2, 2026 21:11
d6bc3f6 to
a625c31
Compare
frajberrima
marked this pull request as ready for review
December 3, 2026 07:52
EmiRZx
approved these changes
Dec 3, 2026
EmiRZx
left a comment
There was a problem hiding this comment.
tested with asyncio.wait_for and a provider that sleeps. on main the timeout surfaces as UnboundLocalError and no finally hook runs. here it raises TimeoutError. the finally hook gets the default value with GENERAL. a provider that raises CancelledError itself behaves the same. the new tests fail on main and the suite passes. it merges cleanly with #691.
a KeyboardInterrupt from the provider still ends as UnboundLocalError. the sync path does the same. setting flag_evaluation before the try would cover every BaseException. that could be a follow-up.
This branch has not been 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.
Cancelling an in-progress async flag evaluation raises
UnboundLocalErrorfrom final-hook dispatch because the provider await exits beforeflag_evaluationis assigned. Sinceasyncio.CancelledErrorderives fromBaseException, the ordinary exception handlers do not initialize those details. The same failure preventsasyncio.wait_forfrom reporting its expected timeout.Handle cancellation explicitly, construct default-valued error details for final hooks, and re-raise the original cancellation. The application still receives cancellation; the default is only cleanup metadata. Ordinary provider-error handling is unchanged.
Eight regression cases cover all supported value shapes, the exact provider-raised cancellation object without hooks, and actual task timeout behavior. They fail before the patch and pass afterward. Events synchronize provider startup without sleep-based races.
Validation on Windows: all 234 pytest tests and all 21 Gherkin scenarios pass on Python 3.10.22, 3.11.18, 3.12.16, 3.13.18, 3.14.10 and 3.15.2. Ruff, formatting, repository text/configuration hooks, wheel and sdist builds pass. Strict mypy passes with
--num-workers 0because parallel workers encounter a Windows IPC limitation. Gherkin uses the pinned specification fixtures; live flagd integration and hosted Linux CI have not been run.The proposed cancellation policy calls final hooks with
Reason.ERRORandErrorCode.GENERAL, but does not call ordinaryerrorhooks for cancellation. The specification does not separately define Python cancellation semantics, so this policy needs maintainer review.This contribution was prepared with AI assistance. The submitting author has reviewed the contribution and confirmed the DCO attestation; the commit includes their Signed-off-by line. Hosted build, lint, and test workflows currently await repository approval.