Skip to content

Handle inactive CGM sensor sessions#211

Merged
marionbarker merged 1 commit intoLoopKit:devfrom
AndyLow91:fix/no-active-session-start
May 3, 2026
Merged

Handle inactive CGM sensor sessions#211
marionbarker merged 1 commit intoLoopKit:devfrom
AndyLow91:fix/no-active-session-start

Conversation

@AndyLow91
Copy link
Copy Markdown
Contributor

This PR addresses the remaining part of #209 by handling Dexcom’s “no active sensor session” marker at the source.

CGMBLEKit currently receives 0xffffffff as the session start time when there is no active sensor session. Because that value was still being treated as a real elapsed-time offset, CGMBLEKit could derive a sensor start date far in the future. Downstream apps can then see that future date as a valid sessionStartDate, which can lead to incorrect Nightscout CGM state uploads such as future-dated Sensor Start treatments.

#191 added a useful safety check by filtering out future-dated sensor events before they are emitted. That helps one path, but it does not fully solve the issue because downstream consumers may still read latestReading.sessionStartDate directly before or outside that event filtering path.

This PR moves the handling earlier:

  • treats 0xffffffff as an explicit “no active session” value
  • exposes whether the transmitter time represents a valid sensor session
  • avoids deriving sessionStartDate / sessionExpDate when no session is active
  • keeps transmitter session state consistent with that invalid-session marker
  • adds tests for both valid-session and no-session transmitter time/glucose parsing

The intent is that CGMBLEKit should not manufacture a future sensor start date when the transmitter is actually reporting that no session is active. That should prevent the bad date from leaking into downstream apps, while #191 remains useful as an additional defensive filter for any future-dated events.

Treat Dexcom's no-active-session marker as an invalid sensor session instead of deriving a future session start date. Keep transmitter state consistent and add coverage for no-session transmitter time and glucose parsing.
@marionbarker
Copy link
Copy Markdown
Contributor

Test

✅ I tested that this built successfully but I'm a G7 user
❓ The behavior with and without this change when no G6 sensor or transmitter is available is not modified. It needs to be tested with real hardware

Configuration

I started with branch, update_dev_to_3.13.2, commit 076f608

  • I then set up CGMBLEKit to use commit 4daa9fe
  • build was successful on test phone, SE 2nd gen running iOS 18.7
  • this test phone is configured to upload to a test nightscout site

Test Narrative

  • Deleted the CGM used by Loop
  • Add G6 and entered a fake transmitter ID
    • Use a fake Transmitter ID of 81DEAD for both the Dexcom G6 app and the Loop code
  • Pair an rPi DASH pod

Observe the Nightscout display for SAGE and CAGE.

I see that CAGE resets to 0 days.
SAGE is unchanged at 38d6h.

restore CGMBLE to dev branch and build again
delete and add the G6 CGM

@itsmojo
Copy link
Copy Markdown

itsmojo commented May 3, 2026

Using a test G6 sensor harness with an Anubis (G6) transmitter and a fresh clone of Loop dev, I could see that Nightscout would reliably and repeatedly show a newly added "CGM Sensor Start" treatment with a future time of 9/20/2161, 9:47 AM every time I started a New Sensor session. After applying this PR, I found that no future treatments were being added to Nightscout when a New Sensor session was started.

Copy link
Copy Markdown
Contributor

@marionbarker marionbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by code review and test.
LTGM

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.

3 participants