Skip to content

fix(notify): drop alert-trigger keys from previous days - #350

Open
0xbrayo wants to merge 2 commits into
ActivityWatch:masterfrom
0xbrayo:fix/notify-prune-stale-prefs
Open

0xbrayo wants to merge 2 commits into
ActivityWatch:masterfrom
0xbrayo:fix/notify-prune-stale-prefs

Conversation

@0xbrayo

@0xbrayo 0xbrayo commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Part of #333.

NotifyWorker remembers which thresholds already fired with a triggered_<category>_<configHash>_<logicalDate> key per alert per day. Keys from earlier days were never removed, so aw_notify_prefs kept growing, by one key per alert per day plus one for every reconfiguration. SharedPreferences parses the whole file into memory on first access and rewrites all of it on each apply(), so that cost grows with every day the app is installed.

Change

  • Before checking thresholds, remove `triggered_*` keys more than two logical days older than the current one (`staleTriggeredKeys`).
  • Recent days are kept on purpose: moving `startOfDay` later (e.g. 04:00 → 06:00) can move the logical day back by one, and that day's fired thresholds must still be recorded so alerts don't fire twice.
  • Keys whose date can't be parsed are left alone.

Testing

  • New NotifyWorkerTest cases: keys outside the window are dropped (including the null/"All" category), recent days and unrelated or unparseable keys are kept, and yesterday's keys survive when the logical day moves back.
  • ./gradlew :mobile:testStandardDebugUnitTest passes.

@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

This PR removes old alert-trigger keys from aw_notify_prefs.

  • Notification alert keys older than two logical days are cleared.

The previous unnumbered finding is fixed: changing startOfDay can move the logical day back by one without losing that day’s fired thresholds.

Reviews (3) · Last reviewed commit: "fix(notify): keep two recent days of ale..." · Reviewed by Greptile

@0xbrayo
0xbrayo force-pushed the fix/notify-prune-stale-prefs branch from 66cc587 to 392a14c Compare October 8, 2026 19:37
@0xbrayo

0xbrayo commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

NotifyWorker wrote a triggered_<category>_<hash>_<date> key per alert
per logical day and never removed any, so the preferences file grew
every day and SharedPreferences loads it whole on each access. Only the
current day's keys are read, so remove the rest before checking.
Pruning everything but the current logical day could re-fire alerts:
moving startOfDay later (04:00 -> 06:00) before the new boundary moves
the logical day back to yesterday, whose keys had just been deleted.
Keep keys for the current day and the two before it.
@0xbrayo
0xbrayo force-pushed the fix/notify-prune-stale-prefs branch from 143cfaa to 4972dfa Compare October 19, 2026 17:18
@0xbrayo

0xbrayo commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

🤖 Claude, on behalf of @0xbrayo

@greptile review

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