Skip to content

Diagnose and skip rogue Nightscout profile records#635

Open
bjorkert wants to merge 1 commit intodevfrom
feature/remote-diagnostics-warnings
Open

Diagnose and skip rogue Nightscout profile records#635
bjorkert wants to merge 1 commit intodevfrom
feature/remote-diagnostics-warnings

Conversation

@bjorkert
Copy link
Copy Markdown
Member

@bjorkert bjorkert commented May 4, 2026

Summary

  • Switches the Nightscout profile fetch from /profile/current to /api/v1/profiles?count=1&find[startDate][$lte]=now, so future-dated records can no longer hide the active profile. /profile/current only sorts by startDate desc and ignores whether that date is in the past or future, which makes a single rogue upload (e.g. a phone with the wrong system clock) keep winning indefinitely. The find[] filter is the same query syntax already used for treatments, sage/iage/cage, BG data, and stats.
  • Adds a "Run diagnostics" button in the Remote Settings → Debug section. It fetches 14 days of profile history and surfaces three known failure modes for remote commands:
    • Profile uploaded by a different app — when Loop and Trio share a Nightscout, profile uploads overwrite each other. Detected by checking which key path carries bundleIdentifier (Loop populates loopSettings.bundleIdentifier, Trio populates the top-level field) against Storage.shared.device.value.
    • Multiple devices uploading profiles — multiple installs (spare/old phones) each push their own deviceToken, causing APNS commands to fail intermittently. Detected by compressing consecutive same-token runs and warning when a token reappears (true alternation), not when tokens simply rotate (a→b→c stays silent).
    • Future-dated profile record found — informational only, since the new fetch already skips them; flagged because the rogue record still corrupts what Nightscout's own dashboard considers current and signals a broken phone clock somewhere.
  • Results auto-scroll into view when the run completes (ScrollViewReader anchored to the diagnostics block).
  • Reuses existing helpers — NightscoutUtils.executeRequest/parseDate, the find[] parameter convention, dateTimeUtils.formattedDate(from:), the orange exclamationmark.triangle warning idiom from ImportExportSettingsView. No new abstractions.

Profile fetch now uses /api/v1/profiles?count=1 with find[startDate][$lte]=now,
so future-dated records can no longer block the active profile. Adds a
"Run diagnostics" button in the Remote Settings Debug section that fetches
14 days of profile history and surfaces three failure modes:

- Bundle ID mismatch when Loop and Trio share a Nightscout
- Alternating device tokens from multiple installations
- Future-dated profile records left over from a wrong-clock uploader

The bouncing-tokens check compresses consecutive same-token runs and only
warns on actual token alternation, not normal token rotation.
@bjorkert
Copy link
Copy Markdown
Member Author

bjorkert commented May 4, 2026

Image

@bjorkert
Copy link
Copy Markdown
Member Author

bjorkert commented May 4, 2026

6DA3B5E9-4D3A-46F2-80F3-A05700E672CA

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