Repository navigation
Merge dev into next-dev - #215
Merged
Merged
Conversation
…the bolus's scheduled end (#211) * Record a bolus cut short by a pod fault even when the fault is read after the bolus's scheduled end The fault's bolusNotDelivered was only applied if the bolus was still scheduled to be running when Loop read the fault, so a pod that ran dry mid-bolus but was read later kept the full amount. Cancel at the pod's fault time instead. * Apply bolus not delivered when the cancel is seen after the bolus's scheduled end * Don't subtract bolus not delivered again for a bolus that was already canceled * Test a pod fault after an unacknowledged bolus cancel The recovered cancel subtracts the fault's bolus not delivered, then handlePodFault's handleCancelDosing used to subtract it again (4 U bolus, 1.8 U not delivered: 0.4 U recorded instead of 2.2 U). * End a bolus canceled after a pod fault at the fault time, and drop the stale faulted-pod checks When a recovered unacknowledged cancel comes after the fault, the bolus now ends at the fault time instead of the cancel time. The podState.isFaulted checks in unacknowledgedCommandWasReceived and checkCommandAgainstStatus no longer did anything: handlePodFault sets podState.fault only after the recovery, and the recovery is what applies bolus not delivered now. The comment in handlePodFault saying otherwise is removed. New test: a cancel sent before the bolus's scheduled end that the pod answers with the fault records 2.2 U ending at the fault time. * Place a pod fault within its minute using a bolus still running at the fault A pod reports its fault time in whole minutes, so the fault time can be up to a minute early. A bolus that started in that minute ended before it started: a zero-length bolus, with the suspend recorded before it. A bolus runs at a fixed rate, so its pulses not delivered say when it stopped. When that falls within the fault's minute, use it as the fault time, for the bolus, the suspend and any temp basal. The two tests that started a 4 U bolus 30 s before the fault, yet had 2.2 U delivered by it, now start it 90 s before, which is consistent. * Fix the comment on the not-yet-canceled bolus check * Place a reset fault with no fault time using the interrupted bolus A reset fault reports no fault time, so deliveryStoppedAt falls back to now, which can be long after the bolus was cut short. Accept the time the bolus's pulses not delivered give anywhere from its start to now; with a fault time, keep it within the fault's minute, since the pod's time is the better source when the phone's bolus start is off. * Use a real reset fault code (0x10) in the reset fault test * Assume more delivery for a bolus interrupted by a reset fault A reset fault has no fault time and its bolus not delivered can't be trusted: Eros reset faults seen mid-bolus all report zero, and O5 0x22 faults report the $3FF sigil. So when the fault time is unknown, ignore bolus not delivered. If the fault is seen before the bolus's scheduled end, assume every pulse up to now was delivered, rounded up to a whole pulse; if after, assume the full bolus. * Place a pod fault by the interrupted bolus, or late in its minute A pod's fault time is the start of its minute, and expiresAt can lag a slow pod clock by up to a minute, so the computed fault time can be up to about two minutes early. Comparing a bolus's stop time against that minute rejected good stop times on slow pods and fell back to the early minute, which undercounts insulin and could put the suspend before a bolus that started in the fault minute. An interrupted bolus's stop time comes from the phone's clock: its start plus the pulses delivered. Use it whenever bolus not delivered is valid (no more than the bolus), but not earlier than the fault minute. With no interrupted bolus, use the end of the fault minute plus a minute for clock lag. Either way, not later than now. * Keep the fault minute when no bolus was interrupted (Joe's rewrites) refineDeliveryStoppedAt() again only refines deliveryStoppedAt from an interrupted bolus; otherwise the drift-adjusted fault minute is kept, so the Faulted time matches the No Delivery time shown for an 80 hour fault. The fault minute can be up to ~2 min early (the pod truncates it to the minute, and the start estimate can lag a slow pod by up to a minute), so basal delivered up to the fault can be undercounted by up to that long. bolusNotDelivered is now always passed through: reset faults report 0 (or the 0x3FF sigil, which the bolus.units checks reject), so it changes nothing for them.
…v-211 # Conflicts: # OmniTests/PodStateTests.swift
next-dev's UnfinalizedDose bolus and temp basal inits take a decisionId.
marionbarker
approved these changes
Nov 9, 2026
marionbarker
left a comment
Contributor
There was a problem hiding this comment.
Approve by test.
Spot check of bolus interrupted by a fault.
marionbarker
approved these changes
Nov 9, 2026
marionbarker
left a comment
Contributor
There was a problem hiding this comment.
I did a Claude review and got an approval.
Merged
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.
Brings #211 to next-dev. It was the only dev commit not yet on next-dev.
OmniTests/PodStateTests.swift, where both branches added tests at the same spot. Both sets are kept. The source changes are identical to Record a bolus cut short by a pod fault when the fault is read after the bolus's scheduled end #211, so nothing on next-dev is reverted.UnfinalizedDoseinitializers take adecisionId. The tests from Record a bolus cut short by a pod fault when the fault is read after the bolus's scheduled end #211 now passdecisionId: nil.OmniTests on a next-dev LoopWorkspace with this branch: 205 run, 3 skipped, 0 failures.
Please merge with Create a merge commit, not squash, so the next dev → next-dev merge doesn't hit these conflicts again.