Skip to content

fix(notify): keep the minutes of startOfDay - #427

Open
TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/notify-start-of-day-minutes-v2
Open

TimeToBuildBob wants to merge 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/notify-start-of-day-minutes-v2

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Item 3 of #409.

NotifyWorker kept only the hour of startOfDay, so 04:30 became 04:00. Between 04:00 and 04:30, alerts queried the new day and used its date for notification dedup, while the widget and web UI were still on the previous day.

The worker now parses a full LocalTime and uses one logical date for both the query and the dedup key. Legacy integer hours and the 04:00 fallback still work. It keeps its own parser because the widget's doesn't accept integer hours.

A new NotifyWorkerExecutionTest case runs the worker with a fake backend set to 04:30 and checks both query endpoints. The two logicalDayDate tests are removed with that wrapper; LogicalDayTest covers the shared helper.

Tested locally on 48711405: the NotifyWorker, LogicalDay and widget updater tests (55) pass, and dropping the minutes again makes tests fail. Not run on a device.

Git-Session-Id: 04989cff-efe2-4235-a5a7-899fd0b1c4ba
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

What changed: 3 files, +43/-38 in mobile/src/test/java/net/activitywatch/android/workers/, mobile/src/main/java/net/activitywatch/android/workers/
Riskiest file: mobile/src/main/java/net/activitywatch/android/workers/NotifyWorker.kt (+17/-18)
Test: Run the repo's usual CI-equivalent checks locally

Review guide

Key files

  • mobile/src/main/java/net/activitywatch/android/workers/NotifyWorker.kt (+17/-18, Δ35)
  • mobile/src/test/java/net/activitywatch/android/workers/NotifyWorkerTest.kt (+11/-19, Δ30)
  • mobile/src/test/java/net/activitywatch/android/workers/NotifyWorkerExecutionTest.kt (+15/-1, Δ16)

Suggested verification

  • Run the repo's usual CI-equivalent checks locally

Auto-posted by scripts/github/pr-warmup-review-guide.py for #427.

@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge, with the previous test-coverage finding addressed.

Summary

NotifyWorker preserves the minutes in startOfDay and uses the same logical date for activity queries and saved alert keys.

  • Notification alerts now follow the full start-of-day boundary.

Reviews (2) · Last reviewed commit: "test(notify): pin query and dedup to the..." · Reviewed by Greptile

Comment on lines +143 to +145
assertEquals(ListenableWorker.Result.success(), runWorker(backend))
val endpoints = org.json.JSONArray(backend.queriedTimeperiod!!).getString(0).split('/')
assertEquals(listOf(30, 30), endpoints.map { org.threeten.bp.OffsetDateTime.parse(it).minute })

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Wrong dates can pass

The new test checks only the minutes on the query endpoints. It would still pass if the worker selected today's date at 04:15 with startOfDay set to "04:30", or saved the fired threshold under the wrong date. Freeze the clock inside that interval and assert the full query window and saved triggered_ key. This would protect the query and duplicate-alert behavior this PR fixes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5ff88c1. The worker test now injects 2026-12-03 04:15 local time with startOfDay=04:30, asserts the complete Dec 2 04:30 → Dec 3 04:30 query window and the Dec 2 triggered_ preference, then dismisses the notification and reruns the worker to verify no duplicate alert. I independently mutated the query date and the dedup date to the calendar date; each mutation failed the corresponding assertion. All 55 NotifyWorker, LogicalDay and widget updater tests pass locally. The production time source remains ZonedDateTime.now(zone).

@TimeToBuildBob

TimeToBuildBob commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

The PR replaces parseStartOfDayHour (which returned an Int hour) with parseStartOfDay, which returns a LocalTime holding both hour and minute. The parser accepts quoted "HH:MM" strings and legacy unquoted integer hours, and falls back to DEFAULT_START_OF_DAY (04:00). NotifyWorker.doWork now computes one logical date and passes it to both getCategorySecondsToday and checkAndNotify. The logicalDayDate wrapper is removed, and NotifyWorker gains an injectable now: (ZoneId) -> ZonedDateTime constructor parameter for tests.

Safe to merge — no P0/P1 findings

Confidence 5/5

✅ No findings. The diff looks correct to me on this pass.

Files changed (3) — the diff as I read it
  • mobile/src/main/java/net/activitywatch/android/workers/NotifyWorker.kt — Replaces DEFAULT_START_OF_DAY_HOUR/parseStartOfDayHour with a LocalTime DEFAULT_START_OF_DAY/parseStartOfDay, removes logicalDayDate, adds a now clock parameter, and computes logicalDate once before querying and dedup.
  • mobile/src/test/java/net/activitywatch/android/workers/NotifyWorkerExecutionTest.kt — Adds a startOfDay parameter and a queriedTimeperiod capture to FakeBackend, a now parameter to runWorker, and a test that freezes the clock at 04:15 with startOfDay "04:30" and checks the query window, the pref key and re-run dedup.
  • mobile/src/test/java/net/activitywatch/android/workers/NotifyWorkerTest.kt — Replaces the parseStartOfDayHour test with parseStartOfDay tests for minutes, the legacy integer hour and invalid fallbacks, and deletes the two logicalDayDate tests.
Previous review passes
commit score findings engine when
96d876c2820f 4/5 1 subscription 2026-12-03 10:24 UTC

Reviewed 5ff88c174e4a · panel: claude-code:claude-opus-5-5 + codex:gpt-6.1-sol + claude-code:claude-opus-5-5#2 · subscription engine · 27s · about this reviewer

Maintainer commands

@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.

Git-Session-Id: 62faa06d-13ed-5e7f-a04b-26b92672b1af
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Adjudication deferred by the review-freshness check: current head is 5ff88c174e4a, and Greptile's 5/5 summary covers that head, but the latest bob-ai-review marker still covers 96d876c2820f (before the test follow-up). Awaiting the automatic AI-review sweep on the current head before final disposition of the open threads. Both threads already have inline replies; no duplicate replies, thread resolutions, code changes, or additional Greptile requests made in this pass. Current CI checks pass (release-only jobs skipped). This is not a new merge recommendation; maintainer judgment remains unchanged.

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