Skip to content

Fixes failed reconnection after a SystemMemoryReset - #100

Merged
ps2 merged 1 commit into
LoopKit:next-devfrom
kingst:fix-reconnect-issue-on-restart
Oct 22, 2026
Merged

ps2 merged 1 commit into
LoopKit:next-devfrom
kingst:fix-reconnect-issue-on-restart

Conversation

@kingst

@kingst kingst commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

When iOS had a SystemMemoryReset, the sensor failed to reconnect. A
session relaunched by Bluetooth state restoration knows its sensor
only through the bluetooth manager, which records the identifier when
the restored peripheral is made active. resumeScanning() then replaced
that identifier with the persisted one, and in Dexcom-app mode the
persisted one was always nil: the manager wrote it from the sensor's
credentials inside the didDiscoverNewSensor callback, before the
sensor had updated them. The rescan after the next disconnect had
nothing to retrieve and, with the peripheral still active, nothing to
scan for, so bluetoothd had no reason to wake the app again. A phone
reboot reproduces it: the first disconnect after the relaunch is
followed by no connect request, while other apps on the same sensor
reconnect within seconds, and the stall lasts until the next relaunch.

The discovery callback now carries the identifier the sensor was found
under, so the manager persists a real value. resumeScanning() no longer
touches the identifier at all; every write to the credentials already
reaches the bluetooth manager through init, reconfigure and discovery.
Installs that have already persisted nil are protected by the second
change, and pick up a real identifier at their next sensor.

When iOS had a SystemMemoryReset, the sensor failed to reconnect.  A
session relaunched by Bluetooth state restoration knows its sensor
only through the bluetooth manager, which records the identifier when
the restored peripheral is made active. resumeScanning() then replaced
that identifier with the persisted one, and in Dexcom-app mode the
persisted one was always nil: the manager wrote it from the sensor's
credentials inside the didDiscoverNewSensor callback, before the
sensor had updated them. The rescan after the next disconnect had
nothing to retrieve and, with the peripheral still active, nothing to
scan for, so bluetoothd had no reason to wake the app again. A phone
reboot reproduces it: the first disconnect after the relaunch is
followed by no connect request, while other apps on the same sensor
reconnect within seconds, and the stall lasts until the next relaunch.

The discovery callback now carries the identifier the sensor was found
under, so the manager persists a real value. resumeScanning() no longer
touches the identifier at all; every write to the credentials already
reaches the bluetooth manager through init, reconfigure and discovery.
Installs that have already persisted nil are protected by the second
change, and pick up a real identifier at their next sensor.
@ps2

ps2 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@ps2
ps2 merged commit 512cd78 into LoopKit:next-dev Oct 22, 2026
@kingst
kingst deleted the fix-reconnect-issue-on-restart branch October 22, 2026 21:42
ps2 added a commit to LoopKit/LoopWorkspace that referenced this pull request Oct 22, 2026
- G7SensorKit: calibration reply decoding and stale calibration expiry (LoopKit/G7SensorKit#98), reconnect after a SystemMemoryReset (LoopKit/G7SensorKit#100), temporary sensor issue in settings (LoopKit/G7SensorKit#99)
- LoopSupport: view the diagnostic report before sharing or sending it (LoopKit/LoopSupport#42)
- OmnipodKit: pump view signal loss uses the last response time (loopandlearn/OmnipodKit#196)
- EversenseKit: retry GetTxCertificate with tx_flags inverted on the 365 (LoopKit/EversenseKit#8)
dnzxy pushed a commit to loopandlearn/G7SensorKit that referenced this pull request Oct 23, 2026
When iOS had a SystemMemoryReset, the sensor failed to reconnect.  A
session relaunched by Bluetooth state restoration knows its sensor
only through the bluetooth manager, which records the identifier when
the restored peripheral is made active. resumeScanning() then replaced
that identifier with the persisted one, and in Dexcom-app mode the
persisted one was always nil: the manager wrote it from the sensor's
credentials inside the didDiscoverNewSensor callback, before the
sensor had updated them. The rescan after the next disconnect had
nothing to retrieve and, with the peripheral still active, nothing to
scan for, so bluetoothd had no reason to wake the app again. A phone
reboot reproduces it: the first disconnect after the relaunch is
followed by no connect request, while other apps on the same sensor
reconnect within seconds, and the stall lasts until the next relaunch.

The discovery callback now carries the identifier the sensor was found
under, so the manager persists a real value. resumeScanning() no longer
touches the identifier at all; every write to the credentials already
reaches the bluetooth manager through init, reconfigure and discovery.
Installs that have already persisted nil are protected by the second
change, and pick up a real identifier at their next sensor.

(cherry picked from commit 512cd78)
kristinkand added a commit to kristinkand/G7SensorKit that referenced this pull request Oct 23, 2026
…yReset (LoopKit#100, Sam King)

# Conflicts:
#	G7SensorKitTests/G7CGMManagerTests.swift
kristinkand added a commit to kristinkand/G7SensorKit that referenced this pull request Oct 23, 2026
…yReset (LoopKit#100, Sam King)

# Conflicts:
#	G7SensorKitTests/G7CGMManagerTests.swift
kristinkand added a commit to kristinkand/G7SensorKit that referenced this pull request Oct 23, 2026
…yReset (LoopKit#100, Sam King)

# Conflicts:
#	G7SensorKitTests/G7CGMManagerTests.swift
kristinkand added a commit to kristinkand/G7SensorKit that referenced this pull request Oct 24, 2026
…yReset (LoopKit#100, Sam King)

# Conflicts:
#	G7SensorKitTests/G7CGMManagerTests.swift
kristinkand added a commit to kristinkand/G7SensorKit that referenced this pull request Oct 24, 2026
…yReset (LoopKit#100, Sam King)

# Conflicts:
#	G7SensorKitTests/G7CGMManagerTests.swift
EJM0 pushed a commit to EJM0/G7SensorKit that referenced this pull request Oct 24, 2026
…yReset (LoopKit#100, Sam King)

# Conflicts:
#	G7SensorKitTests/G7CGMManagerTests.swift
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