Skip to content

fix: cancel in-flight initialize when context changes - #263

Open
fabriziodemaria wants to merge 2 commits into
mainfrom
fix/lifecycle-cancel-and-supersede
Open

fix: cancel in-flight initialize when context changes#263
fabriziodemaria wants to merge 2 commits into
mainfrom
fix/lifecycle-cancel-and-supersede

Conversation

@fabriziodemaria

Copy link
Copy Markdown
Member

Summary

  • Route initialize and onContextSet through the same TaskManager generation so a later context change cancels in-flight init/prefetch instead of racing it.
  • Emit .ready / .contextChanged / .stale only if that call is still current; a superseded fetch cannot overwrite flags or status.
  • Add overlap tests for fetchAndActivate init, activateAndFetchAsync prefetch, and stacked onContextSet calls.

Why not FIFO

OpenFeature 0.6 serializes lifecycle call starts, not Future completion. #261 queues the work so initialize always finishes first. This PR follows the SDK's existing cancel-and-supersede model (and OpenFeature's guidance) so the app does not wait on a resolve for a context it already replaced.

Stacked on #259.

Test plan

  • swift test --skip ConfidenceIntegrationTest --skip MixedTypesFlagIntegrationTest
  • swiftlint lint --strict on touched files
  • CI (Unit-Tests, Integration-Tests, API-diff, SwiftLint)

Made with Cursor

@nicklasl

Copy link
Copy Markdown
Member

closes #262

@fabriziodemaria
fabriziodemaria changed the base branch from openfeature-0.6-migration to main August 19, 2026 06:27
OpenFeature 0.6 can start onContextSet before initialize's Future
resolves. Route both through TaskManager so the latest context owns
the cache and superseded calls do not emit stale status events.

Co-authored-by: Cursor <cursoragent@cursor.com>
@fabriziodemaria
fabriziodemaria force-pushed the fix/lifecycle-cancel-and-supersede branch from 0bb3857 to a97c21d Compare August 19, 2026 06:28
Co-Authored-By: Codex <noreply@openai.com>
@nicklasl

Copy link
Copy Markdown
Member

Could we make committing the resolution conditional on the task still owning the current generation? I guess cancellation can land after the check but before storage.save, which lets a superseded request overwrite newer persisted flags; I pushed eda89fd with a deterministic failing test that reloads 3 instead of 7.

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.

2 participants