Repository navigation
Use LoopKit's value types and bridge to LoopAlgorithm - #2635
Merged
Merged
Conversation
LoopKit no longer depends on LoopAlgorithm, and LoopAlgorithm takes plain numbers in fixed units (LoopKit/LoopAlgorithm#17). Loop is now the one place that converts between the two. - AlgorithmBridge.swift: StoredGlucoseSample and StoredCarbEntry conform to the algorithm's protocols; LoopKit insulin models are wrapped for the algorithm; schedules convert to mg/dL; algorithm results convert back to LoopKit values for storage, display and the watch. - LoopKitTypeAliases.swift makes the unqualified value-type names mean LoopKit's in each target; algorithm types are written LoopAlgorithm.X. - LoopAlgorithm is linked once, in LoopCore; the widget, watch app and LoopCore's own code no longer import it. - LoopCore gets the two constants the UI used from LoopAlgorithm. - Name the new slow retrospective correction experiment in Current Setup. - Tests: an end-to-end test that mmol/L settings dose the same as mg/dL, and the dose annotation, IOB and override tests moved from LoopKit.
- The automatic dose direction maps by switch instead of rawValue, so a case added on either side fails to compile instead of crashing the loop. - Test that mmol/L settings give the same manual bolus recommendation and bolus preview as mg/dL with a pending carb entry. - Test that LoopCore's copies of the input recency interval and maximum carb absorption time match LoopAlgorithm's. - Fix the indentation of a predictGlucose call.
ps2
added a commit
to LoopKit/LoopAlgorithm
that referenced
this pull request
Nov 1, 2026
These test this package's dose annotation and insulin on board, so they belong here rather than in LoopKit/Loop#2635. They read LoopKit's pump event dose fixtures through a small test-only loader, with LoopKit's Walsh curve and daily basal schedule expansion ported for the tests.
They test LoopAlgorithm's dose annotation and insulin on board, so they now live there with their fixtures (LoopKit/LoopAlgorithm#17). The override tests stay here because they cross from LoopKit's override schedules into the algorithm.
This was referenced Nov 1, 2026
ps2
added a commit
to LoopKit/LoopAlgorithm
that referenced
this pull request
Nov 1, 2026
* Move the dose history annotation and IOB tests from Loop These test this package's dose annotation and insulin on board, so they belong here rather than in LoopKit/Loop#2635. They read LoopKit's pump event dose fixtures through a small test-only loader, with LoopKit's Walsh curve and daily basal schedule expansion ported for the tests. * Note the limits of the test basal schedule expansion
# Conflicts: # Loop/Managers/LoopDataManager.swift
This was referenced Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of decoupling LoopKit and LoopAlgorithm (so Trio can use LoopKit without the algorithm). It depends on:
With those, Loop is the one place that converts between LoopKit's types and the algorithm's.
What changes
Loop/Models/AlgorithmBridge.swift:StoredGlucoseSampleandStoredCarbEntryconform to the algorithm's protocols.sensitivityMgdlPerUnit,targetMgdlandsuspendThresholdMgdl.Common/LoopKitTypeAliases.swift: makes unqualified names likeGlucoseEffectmean LoopKit's in each target. Algorithm types are writtenLoopAlgorithm.X. The struct is nowAlgorithm, so calls areAlgorithm.run(input:).Testing
testMmolSettingsDoseTheSameAsMgdl). With ISF, targets, suspend threshold and glucose all in mmol/L, the algorithm receives mg/dL values and Loop doses exactly as in the mg/dL test.