Skip to content

Conversation

@bjorkert
Copy link
Contributor

Summary

This PR fixes a race where Missed Reading and Not Looping alarms could fire while BG/Loop checks were still running.
We now mark the “last checked” timestamps after the data fetch has either succeeded (and been processed) or finally failed. That way, the alarm logic only validates once the attempt is actually finished.

What changed

  • BG

    • Added Storage.shared.lastBGChecked.
    • Set on success at the end of viewUpdateNSBG(...) (after observables/UI updates).
    • Set on final failure when NS is disabled or NS fetch fails and there’s no Dex fallback; also when a processor receives empty data.
    • MissedReadingCondition now requires a recent lastBGChecked (≤ 6 min) before evaluating staleness.
  • Loop

    • Moved Storage.shared.lastLoopingChecked from start of webLoadNSDeviceStatus() to the end of success handling (after updateDeviceStatusDisplay) and to the error path (final failure).
    • This mirrors the BG behavior to prevent “not looping” alarms from firing during in-flight device status checks.

Why

Previously, we stamped the “checked” moment at the start of network calls. If the alarm evaluator ran in parallel—while lastLoopTime or BG entries were still old—we could alarm prematurely.

Copy link
Collaborator

@codebymini codebymini left a comment

Choose a reason for hiding this comment

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

Approved based on codereview

Copy link
Collaborator

@marionbarker marionbarker left a comment

Choose a reason for hiding this comment

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

Approved from code review and test. LGTM

@marionbarker marionbarker merged commit 7f7530d into loopandlearn:dev Oct 23, 2025
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