Skip to content

Merge dev into next-dev - #215

Merged
ps2 merged 3 commits into
next-devfrom
merge-dev-into-next-dev-211
Nov 9, 2026
Merged

ps2 merged 3 commits into
next-devfrom
merge-dev-into-next-dev-211

Conversation

@ps2

@ps2 ps2 commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Brings #211 to next-dev. It was the only dev commit not yet on next-dev.

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.

ps2 and others added 3 commits November 8, 2026 14:24
…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 marionbarker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve by test.
Spot check of bolus interrupted by a fault.

@marionbarker marionbarker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did a Claude review and got an approval.

@ps2
ps2 merged commit 8eac8fa into next-dev Nov 9, 2026
@ps2 ps2 mentioned this pull request Nov 10, 2026

@itsmojo itsmojo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

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