invalidate() cleared the cached status but did nothing about a probe already in
flight. That probe then completed and wrote its answer back — the answer from
before whatever prompted the invalidation.
The case that matters is the one invalidate() exists for: the user is told
Local Network is off, taps through to System Settings, grants it and comes back.
If a probe was in flight when they left, its stale "denied" lands afterwards and
becomes the cached truth, so the app still claims the permission is off.
Tag each probe with a generation, bump it in invalidate(), and only write the
cache when the generation is still current. Whoever is awaiting the stale probe
still gets its result — it just doesn't become the shared answer. invalidate()
also drops _inFlight now, so the next caller starts a fresh probe instead of
being handed the pre-invalidation one.
Found while chasing an intermittent test failure. That turned out to be an
unrelated ambient issue (a MissingPluginException on the app_links EventChannel
that attaches to whichever test is in flight, which already fails ten other
files), but the race it exposed here was real.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>