Skip to content

Leave manual glucose entries out of momentum, ICE and the RC smoothness gate - #14

Merged
ps2 merged 1 commit into
mainfrom
fix/ignore-manual-glucose-in-velocity
Oct 25, 2026
Merged

ps2 merged 1 commit into
mainfrom
fix/ignore-manual-glucose-in-velocity

Conversation

@ps2

@ps2 ps2 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What

linearMomentumEffect, counteractionEffects and hasGradualTransitions now ignore samples with wasUserEntered and run on the CGM samples alone. The latest glucose, manual or not, is still the forecast's starting point.

Why

Loop's GlucoseStore gives every sample the same provenance (Loop's bundle id), so the existing provenance checks never kept a manual entry apart from the CGM readings around it. A meter value is a different measurement, and a change between it and a CGM reading isn't glucose movement:

  • Momentum: a manual entry 30 mg/dL below the sensor between CGM readings more than doubled the projected fall (−41.6 instead of −18 mg/dL at 30 min in the test fixture).
  • ICE: a manual entry more than 4 min after the previous sample was paired with CGM readings on both sides. That produced two counteraction velocities from the meter/sensor offset, which feed carb absorption and RC.
  • RC gate: a manual entry 40+ mg/dL off the CGM turned RC off.

This matters more with LoopKit/G7SensorKit#102, which records every G7 calibration as a manual glucose entry. It also covers fingersticks from the bolus screen and Nightscout meter readings.

Tests

One test for each of the three paths: a manual entry inserted between CGM readings leaves the result unchanged. All three fail without the change. Full suite: 182 tests pass.

…ss gate

A manual entry (fingerstick, calibration value, Nightscout meter reading) is a
different measurement from the CGM, and Loop stores both with the same
provenance, so the existing provenance checks never separated them. A meter
value 30 mg/dL below the sensor was read as a sharp fall: in momentum it more
than doubled the projected drop, and in insulin counteraction it produced two
velocities from the meter/sensor offset that fed carb absorption and RC. A
manual value 40+ off also turned RC off through the gradual-transitions gate.

Each of these now runs on the CGM samples alone. The latest glucose, manual or
not, is still the forecast's starting point.
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