The shared pool (~/utils/freedays) was CLI-only: the gates on the PC stood down, but the phone kept ringing at 08:00 and there was nowhere to mark a day from bed. This is the one picker for every app. FreeDayPool is a Dart port of the Python rules with the identical record shape (id = ISO date; state/consumed/actor/reason on one tick; un-mark is a state flip, never a tombstone), verified by a real cross-language round trip: a log written here reads back through freedays.is_free_day and remaining() with the same verdicts and count, and the PC's live pool reads here as the same 27 of 35 that `freedays status` prints. The alarm fires from Kotlin with no engine running, so the pool is mirrored into a native SharedPreferences set after every mark, release and sync (channel method setFreeDays), and AlarmReceiver consults it before starting AlarmService. Fail closed: a missing or corrupt cache rings. All three branches exercised on the API 36 AVD by broadcasting the receiver. Firebase only for this namespace -- no GitHub mirror; the alarm record keeps its own because un-migrated installs depend on it. Known gap, documented rather than papered over: a day marked on the PC reaches the phone at the next app launch or picker open, not overnight. The ring path takes no background dependency by design, so mark on the phone, or open the app once after marking on the PC. Verified on the phone (release build, 23181JEGR08034): picker shows the budget, marks 2026-09-30 with a reason, pushes it to freedays-sync/devices/<uuid>, releases it with a full refund back to 35. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019pBgaXSJKyY3DarYpDatDF
3.5 KiB
Free days — the phone picker for the shared pool
The pool itself is ~/utils/freedays (Python): one global set of days on
which every gate app stands down, 35 per calendar year, declared for today or
later, never backdated, refunded only while still in the future. Read its
README for the rules. This file covers the phone half, which lives in this
repo because the alarm is the one gate where standing down is a physical
event — the phone stays silent — rather than an absent dialog.
Where things are
| Picker | phone_app/lib/screens/free_days_screen.dart (+ free_days_body.dart), the calendar icon on the home screen |
| Rules, Dart port | phone_app/lib/services/free_day_pool.dart — same record shape as the Python package, byte for byte |
| Sync | phone_app/lib/services/free_day_sync.dart — Firebase only, freedays-sync/devices/<uuid>/free_days.json |
| Ring path | android/.../FreeDays.kt + the check at the top of AlarmReceiver.onReceive |
Why there is a native cache
The alarm fires from Kotlin with no Flutter engine running, so at 08:00 the
Dart pool is unreadable. Dart hands the current free dates to
FreeDays.store (channel method setFreeDays) after every mark, release
and sync; AlarmReceiver reads that set before starting AlarmService. On a
free day it logs free day: not ringing; re-armed for tomorrow and returns —
nothing rings, nothing is shown, and the next morning is normal.
Fail closed. An unreadable or missing cache is "not a free day", matching
freedays.is_free_day() on the PC: a corrupt pool restores the normal rules,
it never silences the alarm. Verified on the wake_alarm_api36 AVD
(2026-09-11, adb root + am broadcast --include-stopped-packages -n …/.AlarmReceiver): today in the set → skip line, no service; a different
date → service start; a garbage XML file → service start.
What reaches the phone when
- Marked on the phone: immediate. The cache is rewritten before the sync even runs, so an offline phone still stands down on a day it marked itself.
- Marked on the PC (
freedays mark …): on the phone's next sync, which happens at app launch and whenever the picker opens. The ring path takes no background dependency by design (seeDOCS-phone-alarm.md), so a day marked on the PC overnight can miss the morning ring. Mark on the phone, or open the app once after marking on the PC.
Cross-language check
The Dart port is a second implementation of the rules, so it is verified
against the Python one rather than against itself: a log written by
FreeDayPool (mark, mark today, mark+release future, mark+release after
arrival) read back with freedays.is_free_day / remaining gives the same
verdicts and the same count (32 of 35), and the PC's live pool read by Dart
gives the same 27 of 35 that freedays status prints. Rerun that whenever
either side's policy changes — the shape test in free_day_pool_test.dart
only checks field names, not semantics.
Do NOT
- Don't give this namespace a GitHub mirror. The alarm record keeps its mirror because un-migrated installs depend on it; this pool never had one.
- Don't tombstone a date to un-mark it. crdt tombstones are monotonic; a
deleted date could never be marked again. Flip
statetocleared. - Don't write
consumedback tofalse. It is the sticky flag that stops two devices either side of midnight from refunding a day already used. - Don't add a warning, a notification or a ring-time prompt. The pool is consulted silently; the count is shown only when the picker is opened.