Skip to content

Record a bolus cut short by a pod fault when the fault is read after the bolus's scheduled end - #211

Merged
ps2 merged 12 commits into
devfrom
fix/fault-bolus-not-delivered
Nov 8, 2026
Merged

ps2 merged 12 commits into
devfrom
fix/fault-bolus-not-delivered

Conversation

@ps2

@ps2 ps2 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

If a pod faults partway through a bolus (for example 0x18, reservoir empty), the fault status reports how much of the bolus was not delivered. handlePodFault applied that only if the bolus was still scheduled to be running when Loop read the fault. When the fault is read after the bolus's scheduled end, the undelivered amount was ignored and the full bolus was recorded.

The cancel now uses the pod's fault time (deliveryStoppedAt, computed from faultEventTimeSinceActivation just above) instead of the time Loop read the fault. An interrupted temp basal or suspend at the fault also ends at the fault time.

Reported in LoopKit/Loop#2648: a DASH pod ran dry about 2.2 U into a 4 U bolus and reported 1.8 U not delivered, but Loop recorded 4 U.

New test testFaultSeenAfterScheduledBolusEndRecordsUndeliveredBolus records 4 U without this change and 2.2 U with it.

OmniTests: 190 run, 3 skipped, 0 failures.

…fter 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.
@itsmojo

itsmojo commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Looking at the code, I see that handleCancelDosing() won't call unfinalizedBolus?.cancel to adjust the bolus dose when finishTime <= now even when it has a non-zero bolusNotDelivered that needs to be applied. This is why the at argument needs to be set to deliveryStoppedAt (if available) in handlePodFault() for the fault to have the bolus amount adjusted back correctly. But setting this at value to the fault time is also needed for the other cancelled dosing as well. Sorry that I didn't notice this issue with handleCancelDosing() calling handleCancelDosing() with the incorrect at value that seems to have always existed when a fault status is read after a bolus would have normally finished. Fortunately in OmnipodKit, the deliveryStoppedAt value is more careful set (or not set) for a number of cases than in the past.

Another bulletproofing improvement for these PR's would be to change thefinishTime > now test for the bolus dose to finishTime > now || bolusNotDelivered != 0 in case there might be some other path calling handleCancelDosing() with a non-zero bolusNotDelivered value that might not be applied to the unfinalizedBolus dose because of timing issues.

@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.

Looks good, but could also consider adding additional bulletproofing to have handleCancelDosing() with a non-zero bolusNotDelivered always adjust any unfinalizedBolus independent of the timing.

@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.

Should also update handleCancelDosing() for the bolus case to test finishTime > now || bolusNotDelivered > 0 to properly handle reset pod faults that occur mid bolus as they won't have a faultTime to properly for set deliveryStoppedAt.

@itsmojo

itsmojo commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

From inspection the latest commit should better handle cases like a reset fault with non-zero bolusNotDelivered and an incorrect now time in handleCancelDosing() by using a better at argument for the actual dose UnfinalizedDose cancel. With a non-zero bolusNowDelivered value, there is actually should be no need to use the given now parameter in handleCancelDosing() for the bolus dose as a calculated stopped at time using the bolus.finishTime & bolusNotDelivered should always be the correct at argument to use for the unfinalizedBolus?.cancel call. But I don't think it's worth making this type of change at this time and so I'm good with the updated code at is. Unfortunately I won't have time to test this by properly simulating a reset type fault during an in-progress bolus where the fault is noticed after the scheduled bolus finish time.

Since bolusNotDelivered for pods includes the undelivered amounts for any extended boluses (which currently is not used by the apps), the stoppedAt calculation assumes this canceled bolus was not for a combo bolus, although interestingly enough it should work correctly if the pod's extended bolus facilities were ever used to try to implement an alternate bolus delivery rate.

itsmojo
itsmojo previously approved these changes Nov 3, 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.

Latest commit seems to properly handle even reset faults during a bolus being read late. Nice work Pete!

@marionbarker

Copy link
Copy Markdown
Contributor

Claude Opus 5.5 Medium review:

Review: OmnipodKit PR #211

Verdict: Fixes the reported case (scenario 1) and reset faults (scenario 2). One regression to fix before merge.

Critical: double subtraction of bolusNotDelivered after an unacknowledged cancel

Path: user cancels a bolus (or suspends) → BLE response lost → unacknowledgedCommand stays set → next getStatus returns the fault → handlePodFault.

  1. recoverUnacknowledgedCommand runs first. It intends to skip bolusNotDelivered when faulted (podState.isFaulted ? 0 : …), but podState.fault is only set at the end of handlePodFault, so isFaulted is false. It calls unfinalizedBolus.cancel(at: commandDate, withRemaining: r). The bolus stays unfinalized with finishTime = commandDate.
  2. handleCancelDosing then subtracts r again:
    • fault after the cancel: the new bolusNotDelivered > 0 clause fires (finishTime ≤ faultTime).
    • fault before the cancel: at is now the fault time, so finishTime (commandDate) > at fires.

Before this PR, at = currentDate was later than commandDate, so step 2 was skipped. Example: 4 U bolus, cancel after 3 U → recorded 2 U. Under-reports insulin, the unsafe direction. cancel() only guards against a negative result.

Suggested fix (either): skip the bolus cancel in handleCancelDosing when the bolus was already interrupted (bolus.scheduledUnits != nil), or have recovery check the fault on the status rather than podState.isFaulted. Add a test: unacknowledged bolus cancel, then fault (fault time both before and after the cancel).

Scenarios

Scenario Result
1. Fault mid-bolus, read after scheduled end Fixed. Bolus ends at fault time; temp basal and suspend also end at fault time.
2. Reset fault (fault time 0/$FFFF → nil) Late read: correct, via finishTime − r/rate. Read before scheduled end: units correct, end time is read time (existing behaviour, minor).
3. Discard Unchanged. After scheduled end, progress = 1, so r = 0 and the full bolus is recorded (existing limitation).

Tests already reported — no need to repeat

  • ps2: OmniTests 190 run, 3 skipped, 0 failures (reported with the first commit).
  • ps2: new testFaultSeenAfterScheduledBolusEndRecordsUndeliveredBolus gives 4 U before the fix and 2.2 U after.
  • Second commit adds testCancelAfterScheduledEndAppliesBolusNotDelivered. No rerun count is posted after it.
  • itsmojo: approved from code inspection only; no reset-fault simulation run.

I did not build or run the tests (Linux environment).

@marionbarker

Copy link
Copy Markdown
Contributor

Comment

We fixed the double subtraction error before. Look at the history for when.

OmnipodKit PR 9: Fixes to handle unacknowledged command with pod faults correctly
Also OmniBLE PR 144, OmniKit PR 52
The testing was in OmniBLE:

LoopKit/OmniBLE#144 (comment)
I should be able to repeat that test to demonstrate the error if it exists in this code.

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).
@marionbarker

marionbarker commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Test

✅ Able to reproduce the problem, but not able to test the solution using the rPi with its current code

Reproduce the problem

After reviewing the tests from OmniBLE PR 144, I remembered that the rPi pod simulator was updated to provide details for an interrupted bolus based on time.

Configuration:

  • iPhone SE 2nd gen running iOS 18.7.8
  • rPi simulator (using mode DASH)

Reproduce the Issue

(Note - I did a test last night where I had the phone communicate with the rPi during the time the bolus was "still in progress" and an interrupted bolus was reported. This issue only happens when the communication happens after the bolus should have completed.)

This test was done on 2026-11-04

Build using LoopWorkspace main v3.14.11, commit 5efba88, with no changes to OmnipodKit

  • 07:25:09 Issue a 3 U bolus
  • Lock the phone (as one would do if a manual bolus was actually delivered
  • 07:25:25 Use the front end to trigger an 0x18 fault during the bolus
  • Wait > 2 min for the bolus to finish delivery if it were not interrupted
    • (3 U/ 0.05 U/pulse) * 2 sec/pulse = 120 sec
  • 07:31 When the next rPi response is seen in the rPi terminal, unlock the phone, see the Pod Expired modal
    • ❌ Full bolus amount of 3 U is recorded
  • Examine the 0x202 fault response from the pod
    • Unfortunately, the pod response does not consider the time when the fault was triggered in determining what the response should be
07:30:08
pkg response 0x2; HEX, 17e8a5361c180216020d00000006007a1c001203ff00170000080000000082e2

Use the parser to report what that HEX means:

  pulses_not_delivered =   0
  insulin_not_delivered =   0.00

We will not be able to use the rPi in its current version to demonstrate the solution.

Test when expected bolus duration has not finished

This test demonstrates the rPi bases the interrupted bolus on the timing of the next pod communication, not when the fault was report to the rPi

I started the rPi with -q flag so the time the fault was entered did not show up in terminal output. (I actually sent it twice.)

  • 07:49:13 Issue a 4 U bolus
  • 07:50 Use the front end to trigger an 0x18 fault during the bolus, bolus in progress shows about 0.5 U
  • 07:50:35 Tap on pod icon on phone to stimulate communication between phone and pod
  • See the Pod Expired modal
    • Interrupted bolus is recorded, with amount of 2.05 U
  • Examine the 0x202 fault response from the pod
    • Unfortunately, the pod response does not consider the time when the fault was triggered in determining what the response should be
07:50:35
pkg response 0x2; HEX, 17e8a53720180216020d00002705008e1c000903ff00090000180000000001c3

Use the parser to report what that HEX means:

  pulses_not_delivered =   39
  insulin_not_delivered =   1.95

…e 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.
…e 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.
@ps2

ps2 commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Test with the pod simulator

The pod simulator now stops a bolus at a fault and keeps reporting what it left undelivered, however late the fault is read (LoopKit/pod#30). That makes the case this PR fixes testable, which the rPi couldn't do before.

Setup

Steps

  1. Bolus 2 U (80 s of delivery).
  2. Close Loop as soon as the pod is bolusing, so it can't read the fault early.
  3. 20 s in, trigger an 0x18 fault from the pod simulator.
    • The pod reports 1.5 U not delivered and 3.6 U delivered in total.
    • It still reports the same 1.5 U after the bolus's scheduled end.
  4. Reopen Loop after the bolus's scheduled end. Loop reads the fault.

Results

Build Recorded bolus
Without this PR ❌ 2 U, the full bolus (the LoopKit/Loop#2648 bug)
With this PR ✅ 0.5 U of 2 U

New commit: eeae371

The run showed a timing problem. A pod reports its fault time in whole minutes, so the fault time Loop works out can be up to a minute early. Here the fault was at 17:00:30 and the bolus started at 17:00:10, but the fault time came out as 17:00:05. Loop recorded the suspend at 17:00:05 and a zero-length bolus. The units were right; only the times were wrong.

A bolus runs at a fixed rate, so the pulses not delivered say when it stopped. When that time falls within the fault's minute, eeae371 uses it as the fault time for the bolus, the suspend and any temp basal.

New test: testBolusStartedInTheFaultMinuteEndsWhenItsPulsesStopped.

  • Without the fix it fails on all three times. With it, it passes.
  • Two existing tests had a 4 U bolus start 30 s before the fault but deliver 2.2 U by it, which takes 88 s. They now start it 90 s before.

OmniTests on dev: 195 run, 3 skipped, 0 failures.

Earlier commit dd97054 (Joe's review):

  • Removes the stale comment in handlePodFault and the podState.isFaulted checks in the unacknowledged-command recovery.
  • Adds Joe's cancel-answered-with-fault test.
  • Ends a bolus canceled after the fault at the fault time.

@marionbarker

marionbarker commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

EDITED - I was testing at the same time as Pete and this version did not use the final commit for this PR.

Test

✅ Updated pod code provides the support we need to be able to test the solution
✅ Demonstrated the solution was successful under 2 scenarios

  • User does not open phone until after the bolus duration is exceeded
  • User attempts to cancel the bolus after hearing the pod fault

Configuration

The pod simulator was updated to trigger proper timing on interrupted bolus when fault is injected.
Pull the updates to the rPi, commit 544103a
New commits:

544103a Stop a bolus at a fault and keep reporting what it left undelivered (#30)
e8ae25d Add failNextConnects: leave service discovery unanswered, then hang up (#31)
0656c68 Add ignoreNextMessages: stay connected but leave messages unanswered (#28)

Do a fresh build of this go code.

The 2nd gen SE is still configured for PR 209.
So it will work to demonstrate the problem.

Demonstrate the problem (with updated pod code)

This test was done on 2026-11-04

14:42 Pair, prime and insert rPi DASH pod

  • 14:46:10 Issue a 3 U bolus
  • 14:46:34 Use the front end to trigger an 0x1C fault during the bolus, progress is at about 0.65 U of 3.00 U
  • Lock phone
  • 14:50:20 When the next rPi response is seen in the rPi terminal, unlock the phone, see the Pod Expired modal
    • ❌ Full bolus amount of 3 U is recorded
  • Examine the 0x202 fault response from the pod
    • ✅ Excellent - the updated pod code provides the correct interrupted bolus information
14:50:20
pkg response 0x2; HEX, 17e8a5361c180216020d00003006004a1c000403ff0008000008000000008211

Use the parser to report what that HEX means:

  pulses_not_delivered =	48
  insulin_not_delivered =	2.4

This is consistent with an interrupted bolus of 0.6 U; which is not what is recorded with the v3.14.11 released code. In other words, this demonstrates the problem.

✅ Updated pod code provides the support we need to be able to test the solution

Demonstrate the solution, part 1

This test case is where a fault happens but the phone is not able to communicate with the pod until after enough time passed for the bolus to have completed.

Modify the configuration
LoopWorkspace, main, v3.14.11

  • OmnipodKit fix/fault-bolus-not-delivered, commit dd97054

Deactivate pod from previous test

15:50 Pair, prime and insert rPi DASH pod

  • 15:02:58 Issue a 5 U bolus
  • Use the front end to trigger an 0x1C fault during the bolus, progress is at about 0.35 U of 5.00 U
  • Lock phone
  • 15:05:06 When the next rPi response is seen in the rPi terminal, unlock the phone, see the Pod Expired modal
    • ✅ Interrupted bolus amount of 0.35 U is recorded
  • Examine the 0x202 fault response from the pod
15:07:02
pkg response 0x2; HEX, 17e8a53720180216020d00005d0500451c000303ff0007000008000000008134

Use the parser to report what that HEX means:

  pulses_not_delivered =	93
  insulin_not_delivered =	4.65

✅ This is consistent with an interrupted bolus of 0.35 U from the original 5 U requested

✅ Successful test where there are no communications with the phone and Pod until after sufficient time passes for both to finish

Demonstrate the solution, part 2

The original double subtraction error happened with this scenario:

User hears fault
User opens phone and taps cancel bolus as first action
The subtraction of the interrupted bolus was subtracted twice before OmniBLE PR 144 was implemented

See if we can reproduce this scenario

Deactivate pod, pair, prime and insert a new rPi one

  • 15:16:32 Issue a 4 U bolus
  • Use the front end to trigger an 0x1C fault during the bolus, progress is at about 0.25 U of 4.00 U
  • Wait a few seconds and then cancel the bolus (progress is at 0.4 of 4 U)
  • Get 2 modals, the one on top is Pod Expired. The one underneath is Error Canceling Bolus.
  • ✅ Interrupted bolus amount of 0.3 U is recorded
  • Examine the 0x202 fault response from the pod
15:16:51
pkg response 0x2; HEX, 17e8a5352c180216020d00004a0a00441c000203ff0002000008000000000311

Use the parser to report what that HEX means:

  pulses_not_delivered =	74
  insulin_not_delivered =	3.7

✅ This is consistent with an interrupted bolus of 0.3 U from the original 4 U requested
✅ Interrupted bolus report is not affected by the attempt to cancel the bolus
✅ Consistent with when the trigger was issued

Pod check

The pod continues to return the 0x202 fault response until pod is deactivated

  • Check value at 15:22:49, still reports the expected pulses not delivered

This latest update to the rPi code is very helpful. Thanks @ps2.

Note for testers

If you don't have a parser handy, you can use the phone, simply tap on Pod Diagnostics and choose Read Pod Status. All the information you need is reported on the screen.

@marionbarker

Copy link
Copy Markdown
Contributor

I'm willing to approve by test but want to give Joe another chance to review the final code.

I asked Claude for another review with the updated commits and the successful tests.
Verdict: No critical code issues remain.

Claude pointed out my test did not include the most recent commit. But says:

You tested dd97054, and the PR head is now eeae371. The newer commit only fine-tunes the bolus end time within the fault minute; recorded units don’t change. A rerun isn’t needed for the amounts. It also wouldn’t reliably exercise that commit, because the simulator rounds the fault minute.

And Pete tested the final version.

@itsmojo

itsmojo commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

The comment in PodState.handleCancelDosing() on the new bolus.scheduledUnits == nil test saying // already canceled, … seems backwards since we are verifying that the bolus was not already canceled, right? Or am I misunderstanding &/or misreading this?

If a bolusStoppedAt is computed in refineDeliveryStoppedAt(), it should be a pretty accurate value for the pod’s fault time for all cases that I can think of. I don’t understand why the podState.deliveryStoppedAt update is limited to only when the calculated bolusStoppedAt value is within a minute before it. In the case of a reset fault, podState.deliveryStoppedAt will be initialized to the current time (in setDeliveryStoppedAt() when called from handlePodFault()) which can easily be (much) later than the time of the [calculated] mid-bolus fault occurrence. Should we just always set podState.deliveryStoppedAt to bolusStopped if we have it or is this if statement enforcing the one minute earlier checking needed for some case?

Whatever happens with refineDeliveryStoppedAt(), I think its comment could be impoved with something like this.

/// podState.deliveryStoppedAt has a one minute resolution while
/// using a non-reset pod fault status (reset pod faults are worse).
/// If a bolus was interrupted at the time of the pod fault, try to use its
/// calculated finish time to improve the deliveryStoppedAt resolution.

ps2 added 2 commits November 5, 2026 01:01
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.
@marionbarker

Copy link
Copy Markdown
Contributor

Test

✅ bolus interrupted by reset fault properly reports delivered amount

  • scenario: fault detected after expected duration ends
  • rPi does seem to handle reset faults

Configuration

LoopWorkspace main, v3.14.11

  • OmnipodKit fix/fault-bolus-not-delivered, commit 9c63f43

Test Details

Use a Reset Fault for this test - more details below

08:47 start a 3 U manual bolus

  • Issue an 0x10 fault (Reset due to SAWCOP Safety Check) when the bolus progress is reading ~0.25 or 3.0
  • wait for the phone to notice the fault: modal: Critical Pod Fault 016 (decimal)

✅ interrupted amount reported under pump events was 0.25 U

Comment / nit

This is probably a nit, but shouldn't the Reset Fault used in line 203 of OmnipodKit/OmniTests/PodCommsSessionTests.swift be a reset fault instead of an 0x18, which is not a reset fault?

faultEventCode: Fault Event Code 0x18: Reservoir empty or exceeded maximum pulse delivery

Actual reset faults include: 0x0D, 0x0E, 0x0F, 0x10, 0x12, 0x34, 0xD6 and 0xD7 from Fault-Event-Codes

Data returned from rPi reset fault

I wanted to find out if rPi does handle reset faults differently.
I think the answer is yes - would need @itsmojo to look at this.

08:47 start a 3 U manual bolus

  • Issue an 0x10 fault (Reset due to SAWCOP Safety Check) when the bolus progress is reading ~0.25 or 3.0
  • wait for the phone to notice the fault: modal: Critical Pod Fault 016 (decimal)
08:49:29
pkg response 0x2; HEX, 002a05fd00180216020d0000370d005910001203ff00150000080000000002aa 

Parser says:

  msgType =	0x0202
  msgMeaning =	FaultEvent
  type_of_0x02_message =	0x02
  recvGain =	0
  rssiValue =	0
  pod_progress =	13
  extended_bolus_active =	False
  immediate_bolus_active =	False
  temp_basal_active =	False
  basal_active =	False
  pulses_not_delivered =	nan
  insulin_not_delivered =	2.75
  seq_byte_M =	13
  total_pulses_delivered =	89
  insulinDelivered =	4.45
  logged_fault =	0x10
  decimal_fault_string =	016
  fault_time_minutes_since_pod_activation =	nan
  reservoir =	>50 U
  podOnTime =	nan
  alerts_bit_mask =	0
  table_fault =	False
  word_R =	1023
  byte_V =	8
  byte_W =	0
  pod_progress_at_fault =	0
  word_Y =	0
  checkSum =	0
  pulsesTotal =	nan
  mlen =	22
  msg_body =	0216020d0000370d005910001203ff001500000800000000
  seqNum =	0
  rawHex =	002a05fd00180216020d0000370d005910001203ff00150000080000000002aa
  CRC =	0x02aa

✅ 3 U - 2.75 U = 0.25 U reported as interrupted bolus

ps2 added 3 commits November 5, 2026 11:06
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.
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.
@itsmojo

itsmojo commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

When the pod fault time is known (i.e., a non-reset fault) without an in-progress bolus (the most typical case), the current placeFaultTime() logic will add up to 2 minutes to podState.deliveryStoppedAt from the reported fault time depending on the time when the fault is read by the pod. The reported fault time is already adjusted for pod clock drift mechanism. This adjustment has always worked very well as shown by pod’s 80 hour fault time always being the adjusted No Delivery value and that the Faulted value in both the pump and Pod Details views. No adjustment should be made to this value in this case as it will create inconsistencies and it really doesn’t make any sense. With the current code a pod fault with in-progress bolus that is not read for 2 or more minutes after the fault occurs, the displayed No Delivery value would suddenly jump by 2 minutes when converted to a Faulted time after an 80 hour pod fault.

Getting rid of this else clause in placeFaultTime() reverts back to more of its previous semantics of just refining the delivery stopped at time when there was an interrupted bolus. Here’s my rewrite for placeFaultTime() including renaming it back to its previous name of refineDeliveryStoppedAt() along with the updated commenting.

    /// Try to refine the deliveryStoppedAt value if there was an interrupted bolus.
    private func refineDeliveryStoppedAt(bolusNotDelivered: Double) {
        guard let faultMinute = podState.deliveryStoppedAt else {
            return
        }
        if bolusNotDelivered > 0,
           let bolus = podState.unfinalizedBolus,
           bolus.scheduledUnits == nil,
           bolusNotDelivered <= bolus.units,
           let finishTime = bolus.finishTime,
           bolus.rate > 0
        {
            /// Calculate the bolus stopped at time which has more accuracy than faultMinute and use it
            /// (capped to between faultMinute and currentDate) as the new deliveryStoppedAt value.
            let bolusStoppedAt = finishTime - .hours(bolusNotDelivered / bolus.rate)
            podState.deliveryStoppedAt = min(currentDate, max(bolusStoppedAt, faultMinute))
        }
    }

The let bolusNotDelivered = faultTimeKnown ? derivedStatusResponse.bolusNotDelivered : 0 line in handlePodFault() shouldn’t really be needed as we now believe that a reset fault interrupting a bolus leaves the bolus not delivered value as 0 anyways, right? But if the bolus not delivered might ever be non-zero for some reset fault, then this assignment actually would unnecessarily prevent this value from being used to refine the deliveryStoppedAt time if the unneeded subsequent if faultTimeKnown test is also removed.

I’d suggest replacing this line and the subsequent 3 lines of if faultTimeKnown { placeFaultTime(bolusNotDelivered: bolusNotDelivered) } with following simpler and more beneficial 2 lines (assuming the func name reverts as shown above):

		let bolusNotDelivered = derivedStatusResponse.bolusNotDelivered /// typically zero if faultTimeKnown
		refineDeliveryStoppedAt(bolusNotDelivered: bolusNotDelivered)

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.
@marionbarker

Copy link
Copy Markdown
Contributor

Test

✅ Demonstrated the solution was successful under 3 scenarios

  • Fault that does not reset registers
    • User attempts to cancel the bolus after hearing the pod fault
    • User does not open phone until after the bolus duration is exceeded
  • Fault that does reset registers

Configuration

LoopWorkspace main branch, v3.14.11, commit 5efba88

  • OmnipodKit commit ee04a10, brancg fix/fault-bolus-not-delivered

Build onto SE 3rd gen running iOS 27.2

Test Case 1

  • Fault that does not reset registers
    • User attempts to cancel the bolus after hearing the pod fault

09:44 Pair, prime and insert rPi DASH pod

  • 09:49 Issue a 5 U bolus
  • Use the web server to trigger an 0x18 fault during the bolus, progress is at about 0.45 U of 5.00 U
  • Tap Cancel bolus
  • Examine the 0x202 fault response from the pod
pkg response 0x2; HEX, 179bbca91c180216020d00005b06004718000503ff00050000080000000001eb

Use the parser to report what that HEX means:

  pulses_not_delivered =	91
  insulin_not_delivered =	4.55

✅ This is consistent with an interrupted bolus of 0.45 U from the original 5 U requested
✅ Interrupted bolus report is not affected by the attempt to cancel the bolus
✅ pump event says 0.45 U delivered of 5 requested

Test Case 2

  • Fault that does not reset registers
    • User does not open phone until after the bolus duration is exceeded

09:56 Pair, prime and insert rPi DASH pod

  • 09:59 Issue a 1 U bolus
  • Use the web server to trigger an 0x18 fault during the bolus, progress is at about 0.3 U of 1.00 U
  • wait for bolus progress to complete and then tap on Pod icon
  • Got Empty Reservoir Modal, say OK
    • Because I tapped on the pod reservoir, I was on the pod screen when I got the empty reservoir
    • When I acknowledge it the screen did not update showing the fault
    • had to return to main screen and back to see the fault
    • not related to this PR - might want to look at later
pkg response 0x2; HEX, 179bbcaa1c180216020d00000d04004518000303ff000400000800000000836e
  pulses_not_delivered =	13
  insulin_not_delivered =	0.65
  seq_byte_M =	4
  total_pulses_delivered =	69
  insulinDelivered =	3.45
  logged_fault =	0x18

✅ This is consistent with an interrupted bolus of 0.35 U from the original 1 U requested
✅ Successful test where there are no communications with the phone and Pod until after sufficient time passes for both to finish
✅ pump event says 0.35 U delivered of 1 requested

Test Case 3

  • Fault that does reset registers

The Hex pattern returned by the pod code does not zero out the pulses not delivered register properly.
So for the reset fault, make sure the bolus delivery completes before triggering the fault.
This way all appropriate registers will be zeroed.

10:07 Pair, prime and insert pod

  • 10:09 Start a 1 U bolus, wait for bolus progress to complete before triggering fault
  • 10:10 Trigger an 0x10 Reset due to SAWCOP Safety Check
  • tap on pod icon to force read from rPi
  • see Critical pod fault 016 (decimal)
  • The UI screen updated immediately
pkg response 0x2; HEX, 179bbcab1c180216020d00000005005210000303ff00040000080000000080e0 

subset of output:

  pulses_not_delivered =	nan
  insulin_not_delivered =	0.0

  logged_fault =	0x10
  decimal_fault_string =	016
  fault_time_minutes_since_pod_activation =	nan

  podOnTime =	nan

✅ Pump Event History shows full bolus delivered - best we can do with a reset fault when the delivery would have completed before we contacted the pod.

@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

@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.

Thanks Pete and Marion for all your work on this one!

@ps2
ps2 merged commit adf8773 into dev Nov 8, 2026
@ps2 ps2 mentioned this pull request Nov 9, 2026
kristinkand added a commit to kristinkand/OmnipodKit that referenced this pull request Nov 10, 2026
…ce SQNs as Int64 for 32-bit watches), loopandlearn#211 (a bolus cut short by a pod fault, read after its scheduled end)

loopandlearn#205 replaces this branch's own fix for the same problem (613a882, throw instead of trapping
when a resync SQN does not fit in Int) with the reviewed one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BZnRiHc1U968YXyW3z6Jm

# Conflicts:
#	OmniTests/PodCommsSessionTests.swift
#	OmniTests/PodStateTests.swift
#	OmnipodKit/Bluetooth/BlePodComms.swift
#	OmnipodKit/PumpManager/PodCommsSession.swift
kristinkand added a commit to kristinkand/OmnipodKit that referenced this pull request Nov 11, 2026
…EAP and nonce SQNs as Int64 for 32-bit watches), loopandlearn#211 (a bolus cut short by a pod fault, read after its scheduled end)

As tested on untethered-kk (Trio build 745, 11.11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UUzqfqfsM8BQYJ2yoRaLz8

# Conflicts:
#	OmniTests/Driver/Comm/endecrypt/SqnEncodingTests.swift
#	OmniTests/PodCommsSessionTests.swift
#	OmnipodKit/Bluetooth/BlePodComms.swift
#	OmnipodKit/Bluetooth/Session/EapSqn.swift
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