Skip to content

fix: preserve cancellation during async flag evaluation - #693

Draft
frajberrima wants to merge 1 commit into
open-feature:mainfrom
frajberrima:fix/async-evaluation-cancellation
Draft

frajberrima wants to merge 1 commit into
open-feature:mainfrom
frajberrima:fix/async-evaluation-cancellation

Conversation

@frajberrima

@frajberrima frajberrima commented Dec 2, 2026 •

Copy link
Copy Markdown

Cancelling an in-progress async flag evaluation raises UnboundLocalError from final-hook dispatch because the provider await exits before flag_evaluation is assigned. Since asyncio.CancelledError derives from BaseException, the ordinary exception handlers do not initialize those details. The same failure prevents asyncio.wait_for from 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 0 because 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.ERROR and ErrorCode.GENERAL, but does not call ordinary error hooks 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.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Prepared with AI assistance; reviewed and DCO attestation confirmed by the submitting author.

Signed-off-by: frajberrima <frajberrima98@gmail.com>
@frajberrima
frajberrima force-pushed the fix/async-evaluation-cancellation branch from d6bc3f6 to a625c31 Compare December 2, 2026 21:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant