Skip to content

Count notification retention in calendar days, not 336 hours - #687

Merged
abdulsaheel merged 4 commits into
OpenStrap:mainfrom
kurexw:fix/notify-retention-calendar-days
Nov 14, 2026
Merged

abdulsaheel merged 4 commits into
OpenStrap:mainfrom
kurexw:fix/notify-retention-calendar-days

Conversation

@kurexw

@kurexw kurexw commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Why

FiredKeyStore._cutoffLabel() and NotificationIds._prune each computed the 14-day retention cutoff as dayLabelOf(DateTime.now().subtract(const Duration(days: 14))). That is 336 hours, not 14 calendar days: across a DST change one of those days is 23 or 25 h, so in the hour either side of local midnight the cutoff lands one label early or late. AGENTS.md §3.7 calls this out ("Day-length arithmetic must not assume 86400 s"), and day_label.dart already has dayLabelBefore for exactly this.

Impact is small, to be upfront: twice a year, dated fired-key / slot bookkeeping is kept a day longer or shorter. The dedupe only needs today's keys. The other reason to fix it is that the same cutoff was written out twice and could drift.

What changes

  • FiredKeyStore.cutoffLabel([DateTime? now]) (was private _cutoffLabel()): dayLabelBefore(todayLabel(now), retentionDays)!. Both of its callers (the DB prune and the prefs-mirror prune) use it.
  • NotificationIds._prune uses FiredKeyStore.cutoffLabel() instead of its own copy (NotificationIds.retentionDays is already defined as FiredKeyStore.retentionDays). Its now-unused day_label.dart import is dropped.

Tests

  • New test/notify_retention_dst_test.dart moves the process timezone to America/New_York (libc setenv/tzset, as day_window_dst_test does) and checks the cutoff at 00:30 the day after the 23 h day (2026-02-23, the old code gave 2026-02-22), at 23:30 the day after the 25 h day (2026-10-19, old: 2026-10-20), and on an ordinary day. A first test asserts the zone really has DST, so the others can't pass vacuously. With the old formula, the two DST cases fail.
  • All 9 test files that touch FiredKeyStore / NotificationIds: 86 passed.
  • flutter analyze: no issues.
  • Full suite not re-run for this change: it only touches the two prune paths, all of whose tests are above.

🤖 Generated with Claude Code

Summary by Sourcery

Use calendar-day retention cutoffs consistently for fired-key and notification-slot pruning.

Bug Fixes:

  • Correct notification retention cutoffs to use 14 calendar days across daylight-saving transitions instead of a fixed 336-hour interval.

Enhancements:

  • Centralize the retention cutoff calculation for fired keys and notification slots.

Tests:

  • Add DST-aware retention tests covering 23-hour days, 25-hour days, and ordinary days.

Summary by CodeRabbit

  • Bug Fixes
    • Notification history and notification IDs now use the same calendar-day cutoff for retention. This keeps pruning consistent across stored records and IDs and avoids differences caused by calculating the retention period as elapsed hours, including when the current time of day varies.

FiredKeyStore and NotificationIds each computed the retention cutoff as
dayLabelOf(now.subtract(Duration(days: 14))). That is 14 x 24 h: across
a DST change one day is 23 or 25 h, so in the hour either side of local
midnight the cutoff landed one label early or late (AGENTS.md: day
arithmetic must not assume 86400 s).

One shared FiredKeyStore.cutoffLabel([now]) now does it with the
existing calendar helpers, dayLabelBefore(todayLabel(now), 14), and
NotificationIds uses it instead of its own copy. The effect was only a
day more or less of notification bookkeeping kept twice a year, but the
two copies could also have drifted apart.
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Notification pruning uses a shared calendar-day cutoff helper. The helper accepts an optional date. Database, SharedPreferences, and notification ID pruning use it.

Changes: Notification retention

Layer / File(s) Summary
Shared calendar-day cutoff
lib/notify/fired_keys.dart, lib/notify/notification_ids.dart
FiredKeyStore.cutoffLabel([DateTime? now]) calculates the cutoff using calendar-day labels. Database and SharedPreferences pruning use the helper. Notification ID pruning also uses it and removes its day_label.dart import.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: abdulsaheel

Merge Risk: Minimal · up to fa996

This change makes notification retention count calendar days, so the cutoff no longer shifts around daylight saving transitions. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Count notification retention in calendar days, not 336 hours" matches the main change. The PR replaces the 14×24-hour retention cutoff with a calendar-day cutoff via FiredKeyStore.cutoffLab…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Count notification retention in calendar days, not 336 hours" matches the main change. The PR replaces the 14×24-hour retention cutoff with a calendar-day cutoff via FiredKeyStore.cutoffLabel, used by fired-key and notification-slot pruning. The title is specific, concise, and does not include file lists or vague terms.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: OpenStrap/edge
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: e10dcaf
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e8f0e221-8022-4aec-a7a7-b2c5ca463609
Commits

Reviewing files that changed from the base of the PR and between e10dcaf and fa9963d.

Files ignored due to path filters: 1

  • test/notify_retention_dst_test.dart is excluded by !test/**
Files selected for processing: 2

  • lib/notify/fired_keys.dart
  • lib/notify/notification_ids.dart

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Expose a shared cutoff-label function that uses calendar-day arithmetic, keeping the retention rule consistent for callers.

  • lib/notify/fired_keys.dart L179-184

Uses of the API

Use the shared calendar-day cutoff when pruning fired-key records and notification slots.

  • lib/notify/fired_keys.dart L140, L222
  • lib/notify/notification_ids.dart L40 (removed lines), L206

Tests

Verify the retention cutoff across daylight-saving transitions and on an ordinary day.

  • test/notify_retention_dst_test.dart L1-67

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@kurexw
kurexw marked this pull request as ready for review November 10, 2026 17:45

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="test/notify_retention_dst_test.dart" line_range="30" />
<code_context>
+      lib.lookupFunction<_UnsetenvNative, _UnsetenvDart>('unsetenv')(key);
+    } else {
+      final value = tz.toNativeUtf8();
+      lib.lookupFunction<_SetenvNative, _SetenvDart>('setenv')(key, value, 1);
+      calloc.free(value);
+    }
</code_context>
<issue_to_address>
**Windows test setup fails**

When the Flutter test suite runs on Windows, `_setProcessTz` looks up POSIX `setenv`/`tzset` symbols that Windows does not provide, so `setUpAll` throws before assertions run and the test file fails.

Use a Windows-compatible way to set and restore the process time zone, or skip this setup on Windows.

Also at `test/notify_retention_dst_test.dart:42`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and the new calendar-day cutoff is used to prune both fired-key and notification-slot claims. If it removes a claim too soon, a later event can send a duplicate notification; reverting does not restore claims already deleted.

Blocking findings: test/notify_retention_dst_test.dart:30


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread test/notify_retention_dst_test.dart Resolved
@kurexw

kurexw commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Closing this myself: the change is correct but its practical effect is tiny, and I'd rather keep the review queue short.

@abdulsaheel

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@abdulsaheel

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Full review finished.

@abdulsaheel

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@abdulsaheel

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
Action not completed

Review rate limited.

@abdulsaheel

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Full review finished.

@abdulsaheel
abdulsaheel merged commit 364cb61 into OpenStrap:main Nov 14, 2026
10 checks passed
mikenrafter pushed a commit to mikenrafter/edge that referenced this pull request Nov 14, 2026
…endar-days

Count notification retention in calendar days, not 336 hours
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.

2 participants