Skip to content

Offer slow retrospective correction; show Guard + Runway v2 and its guard - #2643

Merged
ps2 merged 1 commit into
next-devfrom
slow-rc-experiment
Nov 2, 2026
Merged

ps2 merged 1 commit into
next-devfrom
slow-rc-experiment

Conversation

@ps2

@ps2 ps2 commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Depends on LoopKit/LoopKit#683 for the chart's guard line. LoopKit/LoopAlgorithm#16 (Guard + Runway v2 and slow retrospective correction) is already in LoopAlgorithm main; the LoopWorkspace bump, LoopKit/LoopWorkspace#568, brings it in.

Slow retrospective correction

A new row under Settings → Algorithm Experiments, with its own description and toggle, off by default.

Algorithm Experiments

Slow Retrospective Correction

  • History. The experiment keeps no state, so when it's on fetchData reads:

    • 72 h of glucose instead of 12 h
    • carbs from 72 h plus the longest absorption time (10 h)
    • doses from 72 h plus the insulin activity duration

    Carb ratio, ISF, basal and override history follow those windows, since they are derived from them. That satisfies the algorithm's new carbRatioOrSensitivityStartsAfterCarbEntry check. With the experiment off, nothing changes.

  • Recorded. The dosing decision's slowRetrospectiveCorrection experiment carries level and multiplier.

  • Matching forecasts. The bolus screen, the manual dose screen and forecast details draw their own forecasts with predictGlucose. It now takes the ISF multiplier from the algorithm's last run, so those forecasts match the algorithm's.

  • Forecast details. A Slow Retrospective Correction row shows the ISF multiplier and the level. Deselecting it draws the comparison forecast at the scheduled ISF.

  • Analytics. An on/off user property and an experiment-change event, as for the other experiments.

Guard + Runway v2

  • Labels. Labeled "Guard + Runway v2" in settings and on forecast details.
  • Description. Rewritten for v2: the volatility band lowers only the forecast the low guard checks, not the displayed forecast or the size of corrections, and the runway fades out as carbs rise to 20 g instead of stopping at any carbs.
  • Recorded. The dosing decision's guardAndRunway experiment carries version: 2, so v1 and v2 data can be told apart.

Guard + Runway v2

The guard on forecast details

While Guard + Runway is on and its row is selected, forecast details draws the forecast the low guard checks as a dotted line. That's GuardAndRunwayOutput.guarded(predictedGlucose), shown when the band applied, and the row says so. Deselecting the row hides it.

The comparison forecast is no longer lowered by the band, because in v2 the displayed forecast isn't.

Forecast details with the guard's forecast

Testing

  • All 426 LoopTests pass, including 2 new ones:
    • testSlowRetrospectiveCorrectionReadsThreeDaysOfHistory: with the experiment on, glucose from 71 h ago and a carb entry from 80 h ago are read, and the carb ratio and ISF timelines reach back past that entry. With it off, neither is read.
    • testSlowRetrospectiveCorrectionIsRecordedOnTheDosingDecision: three days of an unexplained slow rise give a positive level and a multiplier below 1, and the multiplier is recorded on the loop's dosing decision.
  • In the iOS Simulator with the CGM simulator:
    • both experiment screens
    • the guard's dotted line, and hiding it with the row
    • the slow RC row

…uard

Slow retrospective correction (LoopKit/LoopAlgorithm#16) becomes an algorithm
experiment. When it is on, Loop reads 72 hours of glucose, carbs from 72 hours
plus the longest absorption time, and doses from 72 hours plus the insulin
activity duration, with schedule history covering them, since the experiment
keeps no state. Its level and ISF multiplier are recorded on the dosing
decision, and the bolus screen and forecast details forecasts use the
multiplier so they match the algorithm's.

Guard + Runway is labeled v2, its description says what changed, and its
recorded parameters carry version 2. The forecast details screen draws the
forecast the low guard checks as a dotted line while Guard + Runway is selected,
and no longer lowers the comparison forecast by the band, since the second
version no longer lowers the displayed forecast.
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