Repository navigation
fix(goals): bucket goal-history documents by the user's local day, not UTC's - #15209
Conversation
|
The 3 failing `Backend unit` shards are pre-existing breaks on `main`, unrelated to this PR's diff (only `database/goals.py` and one new test file):
Shard 2/4 (which happens to contain this PR's own new test file, `test_goal_history_local_day.py`) passed cleanly. Happy to rebase once `main` is green again. |
|
Thanks @Abhist17 — verified end to end, and this checks out cleanly. Notes below. The fix ( Tests ( CI: your triage is confirmed — the three failing files ( Two non-blocking notes, fine to address whenever:
Since this changes goal-history persistence semantics (which document a day's progress lands in), leaving the merge call to a human maintainer — everything technical verifies clean. 🤖 Automated review on behalf of the maintainers. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…n retry loop Addressed review note from Git-on-my-level on PR BasedHardware#15209: _history_date_str did a Firestore read of the user's timezone inside the @firestore.transactional callback, repeating on every contention retry. now doesn't change across retries, so resolve it once before entering the transaction.
|
Thanks for the thorough review!
@Git-on-my-level — this is ready whenever a human has a moment to merge. This was proposed as a $50 bounty (#15206); glad to take it whenever that's convenient, no rush. |
…nt seam
_history_date_str called database.notifications.resolve_user_timezone(), which
has no firestore_client injection point of its own and always hit the real
Firestore client. Invisible in this module's own tests (they inject a fake
client throughout), but it broke tests/unit/test_workstream_core.py's
hermetic goal tests, which exercise goals.py through their own fake_db and
have no reason to know this module reached into another one's unmocked
client -- CI failed with BlockedNetworkError against the GCP metadata IP
(ADC credential resolution) once resolve_user_timezone tried to read the
real users/{uid} doc.
Reads time_zone directly through _get_db(firestore_client) instead -- the
same seam every other read in this module already goes through -- and
removes the need for the database.notifications import entirely.
|
Found and fixed a real regression from my last push — this one was actually mine, not a pre-existing Root cause: Fix: Verified: reproduced both previously-failing |
kodjima33
left a comment
There was a problem hiding this comment.
Fixes #15206: goal-history documents were keyed by UTC calendar day, causing progress to land on the wrong day for non-UTC users. Now buckets via resolve_user_timezone (same pattern as the shipped notification-cap fix), with lazy import to avoid breaking existing test stubbing. New regression tests cover west/east of UTC and the fallback. CI green.
|
Following up on payment for this one — merged 2026-09-21. I've emailed [email protected] with the full list of my merged bounty PRs, as the contribution guide asks under Paid Bounties ("claiming payment"). Leaving a note here too so it's on the thread rather than only in a mailbox. Bounty: $50 — proposal #15206. Payout — crypto is easiest for me, USDC/USDT on either chain:
Happy to use whatever method is simplest on your side. Thanks! |
Description
_append_goal_progress_eventandsave_goal_progress_historyindatabase/goals.pykeygoal_historydocuments bydatetime.now(timezone.utc).strftime('%Y-%m-%d'). A user west of UTC (e.g. US Pacific) whose local evening hasn't yet crossed UTC midnight has their progress written into tomorrow's UTC-dated document; a user east of UTC can have it land in yesterday's.GET /v1/goals/{id}/history(database.goals.get_goal_history, ordered by thedatefield,days=30default) returns a chart whose day boundaries don't match the user's own calendar.Same bug class as the already-shipped fix for the proactive-notification daily cap (
_proactive_daily_cap_reached), which bucketed byresolve_user_timezone(uid)instead of raw UTC.The fix
Added
_history_date_str(uid, now), which resolves the user's IANA timezone viaresolve_user_timezone(imported locally inside the function —database.goalsis intentionally import-light for its test suite's minimal Firestore stubbing, so a module-level import ofdatabase.notificationswould breaktests/unit/test_goals_id_fallback.py/test_goals_sort_missing_created_at.py) and buckets by the local calendar day, falling back to UTC if the zone is missing or unresolvable. Both write sites now go through it.Testing performed
tests/unit/test_goal_history_local_day.py: local-day bucketing west and east of UTC, the unresolvable-zone fallback, and thatsave_goal_progress_historywrites both the document id and the storeddatefield as the local day.tests/unit/test_goal_history_local_day.py,test_goal_progress_events_skip_malformed.py,test_goal_get_by_id.py,test_goals_advice_arg_and_clear_metric.py,test_goals_id_fallback.py,test_goal_source_compatibility.py,test_goal_context_null_message_text.py,test_goal_extraction_batch.py,test_goals_response_int_guard.py,test_goals_sort_missing_created_at.py,test_goal_storage_coerce_guard.py,test_dev_goals_limit_include_inactive.py— each run in its own process (matching this repo's own per-file isolation for pollution-prone suites); all green. Confirmedtest_goals_id_fallback.py/test_goals_sort_missing_created_at.pybroke whenresolve_user_timezonewas imported at module scope, which is why the import is local to the function instead.python3 -c "import database.goals"— clean, no circular import.scripts/backend-python-format --check— clean.Type of Change
Product invariants affected
none
Failure class (fixes)
Failure-Class: none
The closest existing class,
FC-day-bucket-key-recomputed, is scoped to the Flutter app'sconversationLocalDayKeycomparison (app/lib/providers/**) — a different domain and mechanism (client-side day-key comparison vs. this backend'sresolve_user_timezone-based Firestore document keying). Given how many backend UTC-vs-local-day bugs have surfaced recently (the notification cap fix referenced above, plus several open bounty proposals on the same pattern), a backend-scoped class may be worth declaring separately — leaving that call to a maintainer rather than declaringnewwithout surveying the full recent history myself.Fixes #15206