Skip to content

Don't adopt a failed or ended sensor again - #115

Merged
ps2 merged 1 commit into
next-devfrom
fix/ended-sensor-rediscovery
Nov 7, 2026
Merged

ps2 merged 1 commit into
next-devfrom
fix/ended-sensor-rediscovery

Conversation

@ps2

@ps2 ps2 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #111. Supersedes #112, which keeps the alert marker but still re-adopts the sensor.

What happened

Seen on a phone eavesdropping on a G7 (DXCMgc, 14 days 17 hours into a 15-day session). The sensor reported state 25 (sensorFailed), and from then on every five minutes:

  1. Loop raised Sensor Failed, then forgot the sensor and scanned for a replacement. The forget cleared sensorFailedAlertIssuedFor and retracted the alert the moment it was issued.
  2. The scan connected to the only Dexcom sensor in range to identify it: the same failed one. Discovery adopts any sensor, so it became a "new sensor", with a new paired date, rescheduled expiry alerts and a sensor start event.
  3. Its next message was the same failed reading, so the alarm, the sensor end event and the forget repeated. The previous-sensor record was overwritten each time.

The user acknowledged three critical alarms in ten minutes, and they continue until the sensor is out of range.

Change

  • G7SensorRecord.EndReason gains failed and sessionEnded, and the Previous Sensor page shows them. The failure and session-ended paths forget the sensor with that reason; scanForNewSensor() (the user's Scan for New Sensor) still uses replaced.
  • Discovery declines a sensor whose previous record ended as failed or session ended, matched by name and activation time (within a minute). A sensor the user forgot can still be adopted again.
  • Sensor Failed stays up after a failure forget, and is retracted when a different sensor is adopted. sensorFailedAlertIssuedFor survives the forget, as in Suppress repeated G7 sensor failure alerts during replacement scans #112.

Tests

New in G7LifecycleAlertManagerTests:

  • a failed sensor rediscovered three times: one alert, not retracted, no further sensor start/end events, and the record keeps failed and its failure message
  • a different sensor retracts the failure alert and is adopted
  • a sensor whose session ended is not adopted again
  • a sensor forgotten with Scan for New Sensor can be adopted again

All 207 G7SensorKit tests pass on the iOS Simulator.

A G7 that fails or ends its session keeps advertising. While
eavesdropping, the scan for its replacement connects to any Dexcom
sensor in range to identify it, so it found the same sensor again five
minutes later, adopted it as a new sensor, read the same failed message
and raised Sensor Failed again: a critical alarm every five minutes
until the sensor was removed. Each pass also recorded a sensor start and
end, and overwrote the previous-sensor record, losing the failure.

The previous-sensor record now says why the sensor ended (failed,
session ended), and discovery declines that sensor, matched by name and
activation time. A sensor forgotten by the user can still be adopted
again. The Sensor Failed alert now stays up until a different sensor is
adopted, instead of being retracted as soon as it is issued, and its
issued marker survives the forget (as in #112).

Fixes #111.
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