Skip to content

Don't re-evaluate glucose alerts from a backfill older than the last reading - #2521

Closed
ps2 wants to merge 1 commit into
next-devfrom
fix/alert-evaluate-ignore-backfill
Closed

ps2 wants to merge 1 commit into
next-devfrom
fix/alert-evaluate-ignore-backfill

Conversation

@ps2

@ps2 ps2 commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

CGMs deliver the live reading and then backfill the gap behind it, each as its own .newData batch, and DeviceDataManager hands every batch to GlucoseAlertManager.evaluate(samples:). The backfill carries a sample no newer than the one just evaluated, and evaluate re-decided the alert from it.

Seen with a G7 on next-dev, from the AlertStore and DeviceLog:

22:58:59  didRead        glucose 86  timestamp 89595   → evaluate → urgent low issued
22:58:59  didReadBackfill glucose 86  timestamp 89591   → evaluate → urgent low retracted 22:59:00

Retraction goes through unscheduleAlertWithSchedulers, which also calls criticalAlertAudioPlayer.stop() — so on an un-entitled build the in-process alarm audio was cut off one second after it started, and the notification was pulled with it. The user saw a banner slide in and out and heard nothing.

Fix

Skip any batch whose newest sample is not newer than the last evaluated reading. Backfill still reaches the glucose store; it just cannot override an alert decision that was made on a newer reading.

Testing

Builds clean. The sequence above is reproducible with the "next reading as urgent low" test on a G7, which is how it was found; with the guard the backfill batch is logged and ignored.

…reading

CGMs deliver the live reading and then backfill the gap behind it, each as
its own batch. evaluate() re-ran on the backfill, which carries a sample no
newer than the one just evaluated, and re-decided the alert from it. Seen
with the G7: a live reading raised an urgent low at 22:58:59 and the
backfill of the same period retracted it at 22:59:00, which also stopped
the in-process alarm audio one second after it started.

Skip any batch whose newest sample is not newer than the last evaluated
reading. Backfill still reaches the glucose store; it just cannot override
an alert decision made on a newer reading.
@ps2

ps2 commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator Author

Folding this into #2520 — same fix set, one PR.

@ps2 ps2 closed this Sep 16, 2026
@ps2
ps2 deleted the fix/alert-evaluate-ignore-backfill branch September 16, 2026 04:17
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