Skip to content

A link that delivered a reading isn't a stopped session - #127

Merged
ps2 merged 2 commits into
next-devfrom
eavesdrop-reading-not-session-end
Nov 23, 2026
Merged

ps2 merged 2 commits into
next-devfrom
eavesdrop-reading-not-session-end

Conversation

@ps2

@ps2 ps2 commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

While eavesdropping, Loop reads a disconnect with pendingAuth still set as the Dexcom app having stopped the session. That starts the 15-minute suspected-session-end grace period, and when it runs out Loop scans for a new sensor. On a slow link the flag can still be set after a reading has already arrived on that same link.

On a test phone this happened three times in one night. Each time a link delivered a reading and was then flagged as a suspected session end a few seconds later. The next slots were lost to queue stalls, the grace period ran out, and Loop forgot the sensor. It then retried a different nearby G7 until the Dexcom app authenticated the right one again, 5 to 20 minutes later.

A reading on the current link shows the session is running, so peripheralDidDisconnect now checks manager.readingReceivedOnCurrentLink before setting suspectedEndOfSession.

This doesn't cover a link where Loop never subscribed in time and so got no reading. That case can still raise the suspicion falsely and needs a separate heuristic.

ps2 added 2 commits November 20, 2026 03:59
While eavesdropping, a disconnect with pendingAuth still set is read as
the Dexcom app having stopped the session, which starts a 15 minute
grace period and then a scan for a new sensor. On a slow link the flag
can still be set after a reading arrived: on a test phone a reading at
09:36:52 was followed by a session-end suspicion at 09:36:57, the next
three slots were lost to queue stalls, and when the grace period ran out
Loop forgot the sensor until the Dexcom app authenticated it again.

A reading on the current link is direct evidence that the session is
running, so it rules the suspicion out.
A reading on the link already clears the session-end suspicion, but a
link can lose the race for the reading and still carry other control
responses: overnight on a test phone, three links that saw only the end
of the Dexcom app's exchange (the final ea frame, or a 51 frame) were
each flagged as a possible session end. The sensor answers on the
control characteristic only within an authenticated session, so any
response there shows the session is still running.
@ps2
ps2 merged commit 86a8a97 into next-dev Nov 23, 2026
jeremybarnum pushed a commit to jeremybarnum/G7SensorKit that referenced this pull request Nov 26, 2026
…it#134), with the early bond record

Upstream's phone reconnect changes (a 2 s rescan and a connect when another app connects, the
connect reissued at power-on after a restore, a link with a reading is not a stopped session)
and the watch's in-place sensor change (LoopKit#128, the same as this branch's own). Also: a watch whose
bond was lost records it at the handshake's bond step, not only at its end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dnzxy pushed a commit to loopandlearn/G7SensorKit that referenced this pull request Dec 1, 2026
* A link that delivered a reading isn't a stopped session

While eavesdropping, a disconnect with pendingAuth still set is read as
the Dexcom app having stopped the session, which starts a 15 minute
grace period and then a scan for a new sensor. On a slow link the flag
can still be set after a reading arrived: on a test phone a reading at
09:36:52 was followed by a session-end suspicion at 09:36:57, the next
three slots were lost to queue stalls, and when the grace period ran out
Loop forgot the sensor until the Dexcom app authenticated it again.

A reading on the current link is direct evidence that the session is
running, so it rules the suspicion out.

* Any control response rules out a stopped session

A reading on the link already clears the session-end suspicion, but a
link can lose the race for the reading and still carry other control
responses: overnight on a test phone, three links that saw only the end
of the Dexcom app's exchange (the final ea frame, or a 51 frame) were
each flagged as a possible session end. The sensor answers on the
control characteristic only within an authenticated session, so any
response there shows the session is still running.

(cherry picked from commit 86a8a97)
@ps2
ps2 deleted the eavesdrop-reading-not-session-end branch December 3, 2026 06:48
kristinkand pushed a commit to kristinkand/G7SensorKit that referenced this pull request Dec 4, 2026
* A link that delivered a reading isn't a stopped session

While eavesdropping, a disconnect with pendingAuth still set is read as
the Dexcom app having stopped the session, which starts a 15 minute
grace period and then a scan for a new sensor. On a slow link the flag
can still be set after a reading arrived: on a test phone a reading at
09:36:52 was followed by a session-end suspicion at 09:36:57, the next
three slots were lost to queue stalls, and when the grace period ran out
Loop forgot the sensor until the Dexcom app authenticated it again.

A reading on the current link is direct evidence that the session is
running, so it rules the suspicion out.

* Any control response rules out a stopped session

A reading on the link already clears the session-end suspicion, but a
link can lose the race for the reading and still carry other control
responses: overnight on a test phone, three links that saw only the end
of the Dexcom app's exchange (the final ea frame, or a 51 frame) were
each flagged as a possible session end. The sensor answers on the
control characteristic only within an authenticated session, so any
response there shows the session is still running.

(cherry picked from commit 86a8a97)
(cherry picked from commit 46756a2)
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