Skip to content

Refuse remote boluses and carbs that the sender did not know about - #594

Open
bjorkert wants to merge 1 commit into
LoopKit:next-devfrom
bjorkert:remote-guard
Open

bjorkert wants to merge 1 commit into
LoopKit:next-devfrom
bjorkert:remote-guard

Conversation

@bjorkert

@bjorkert bjorkert commented Nov 19, 2026 •

Copy link
Copy Markdown

A remote command can arrive minutes after it was sent. If someone gave a bolus or entered carbs on the phone in the meantime, the command can double the treatment. Today Loop only accepts a command for about a minute, which makes commands fail on a slow network.

With this change Loop refuses a remote bolus if insulin the sender could not have seen adds up to 20 % or more of the requested amount, and refuses carbs if any carb entry was added that the sender had not seen. The command is never changed: it runs as sent or is refused with a reason. LoopFollow sends the Nightscout id of the newest treatment it had, so Loop can tell what the sender had seen. Because of this, commands are now accepted for 12 minutes. The careportal keeps its 5 minutes. The same change is open for Trio in nightscout/Trio#1789.

Many people use the remote_window customization today to get a longer window. It reduces the bolus by every bolus from the last 10 minutes, also the ones the sender already saw, so the caregiver can get less insulin than they decided on. It also refuses carbs after any recent carb entry and has to be kept up to date with every Loop change. I look forward to retiring it.

Older LoopFollow versions keep working with this Loop. They send no Nightscout id and set a 5-minute expiration, so their commands are accepted for 5 minutes and only treatments dated after the send time count. A treatment added just before the command was sent, that LoopFollow had not fetched yet, is not caught. A new LoopFollow with an older Loop works as today, since older Loop ignores the new fields.

LoopCaregiver sends its commands through Nightscout, the same way as the careportal. Nightscout sets the send time and a 5-minute expiration, so LoopCaregiver keeps working without changes: its commands are accepted for 5 minutes and only treatments dated after the send time count. To get the full check, LoopCaregiver would need to send the newest Nightscout id it had, and Nightscout would need to pass it on to Loop. If there is interest, I'm happy to open PRs for that.

Tested on an iPhone with a simulated pump, LoopFollow on a second phone, real push notifications and a test Nightscout. All passed:

  • A bolus from LoopFollow with nothing new on the phone is delivered.
  • A bolus given on the phone after the command was sent refuses it.
  • 11 minutes old is accepted, 13 minutes old or ahead is refused.
  • A treatment the sender had not seen refuses the command, one it had seen does not.
  • 0.1 U unknown against 1 U is accepted, 0.2 U is refused.
  • Unseen carb entries refuse a carb command, also backdated ones.
  • Two commands at the same time: one is delivered, the other refused.
  • A bolus the pump refuses is reported as failed.
  • LoopFollow shows the reason for a refusal.

This branch builds the whole feature; the submodules point at the PR commits and need re-pinning once those are merged. PRs: LoopKit/LoopKit#704, LoopKit/NightscoutService#54 and LoopKit/NightscoutService#53, LoopKit/Loop#2692 and LoopKit/Loop#2691. LoopFollow: loopandlearn/LoopFollow#842.

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