mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-23 15:26:33 +01:00
Latch the ring's sick/free stand-down
On 2026-11-11 the ring stood down for a sick day, the mark was cleared at 11:38, and the 19:31 stick check judged a miss and sent a lockdown for a day whose alarm never rang. AlarmReceiver now latches the skip and StickCheck honours it after a later clear. Docs: the 11-01/10-26 PC no_session rings were correct (no session started before A+15); the focus-owner on-device check is still open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9250db4cc1
commit
78c41bd167
@ -23,7 +23,7 @@ screen, and every log line and event says `sick_day`.
|
||||
| Per-locker sheet | `phone_app/lib/screens/sick_day_sheet.dart` (+ the dot in `day_cell.dart`) |
|
||||
| Sync | `phone_app/lib/services/sick_day_sync.dart` (shared tick: `day_pool_sync.dart`), Firebase only |
|
||||
| Ring path | `android/.../SickDays.kt` (+ `DayCache.kt`), read in `AlarmReceiver` through `RingDecision.kt` |
|
||||
| Stick | `StickCheck.kt`: verdict `sick_day`; the streak skips sick days like free days |
|
||||
| Stick | `StickCheck.kt`: verdict `sick_day`; the streak skips sick days like free days; a ring skipped for a sick day stays `sick_day` after a later clear (`RingWatch.markSkipped`) |
|
||||
| Pre-alarm sync | `PoolSyncAlarm.kt`, `PoolSyncSchedule.kt`, `PoolSyncEngine.kt` → `poolSyncMain` → `day_pool_refresh.dart` |
|
||||
|
||||
## The picker
|
||||
|
||||
@ -35,6 +35,19 @@ unreachable counts as "no ping, no session" (fail toward ringing) and is
|
||||
logged as `firebase_unreachable`. While ringing, stop conditions are polled
|
||||
every 20 s.
|
||||
|
||||
**A `no_session` ring after a phone ring is correct, not a missed read
|
||||
(traced 2026-11-16).** On 2026-10-26 and 2026-11-01 the PC went
|
||||
`waiting` → `no_session` at A+15. It never logged `phone_silent`, so it did
|
||||
see `ring_started`. What it never saw was a session for today: the
|
||||
session tick logged "Newest morning is 2026-10-25" and "2026-10-29" all
|
||||
morning. Firebase agrees. On 11-01 the phone fired, opened the ring screen
|
||||
at 07:43 and then logged nothing until a boot at 11:27: no `dismissed`
|
||||
event, no session. On 10-26 the session started at 11:01. So the PC was
|
||||
right on both days. A ringing phone that nobody dismisses is the case the
|
||||
`no_session` row exists for. `test_fallback_policy.py`
|
||||
(`test_ring_started_waits_for_the_session_grace`) pins it. Why the phone
|
||||
went quiet after 07:43 on 11-01 is a separate phone question.
|
||||
|
||||
**Sound.** 100 %, unmuted, a tone that rises over the first 60 s.
|
||||
- Active graphical session on seat0 → user PipeWire (`wpctl` + `pw-play`).
|
||||
- Otherwise (night lockdown: lightdm masked, nobody logged in; kuhy is not in
|
||||
@ -129,6 +142,22 @@ retracted) and audit behave exactly as on a normal stick day.
|
||||
`data.reason = "sick_day"` (by analogy with `free_day`); the audit treats
|
||||
it as not the morning's ring.
|
||||
|
||||
**A stand-down latches at ring time (fixed 2026-11-16).** On 2026-11-11 the
|
||||
07:40 ring stood down for a sick day (`alarm_fired reason=sick_day`), the
|
||||
phone cleared the mark at 11:38, and the 19:31 stick check re-read the cache,
|
||||
found a normal Wednesday with no dismissal and sent a lockdown. That punished
|
||||
a day whose alarm never rang, so no dismiss was possible. `AlarmReceiver` now
|
||||
records the skip (`RingWatch.markSkipped`, a `DateHistory` per reason), and
|
||||
`StickCheck.decideDay` returns `sick_day`/`free_day` for a latched day even
|
||||
after a clear. The streak look-back skips it too. A phone that was off at A
|
||||
latches nothing, so a clear still makes that day a stick day (hole 1).
|
||||
Tests: `StickCheckSickTest`.
|
||||
|
||||
**Still open: on-device check.** At the next real miss (Tue/Wed/Thu), right
|
||||
after 09:30 run `adb -s 23181JEGR08034 logcat -d | grep -E
|
||||
"LOCKDOWN_ACTIVATED|WORKDAY_LOCKDOWN"` (read-only) and confirm
|
||||
`LOCKDOWN_ACTIVATED` is followed by `WORKDAY_LOCKDOWN`.
|
||||
|
||||
### Escape hatch (until 2026-10-15 inclusive)
|
||||
|
||||
Bug-glyph button on the stakes card (spoken label "That was a bug"; the
|
||||
|
||||
@ -27,13 +27,15 @@ class AlarmReceiver : BroadcastReceiver() {
|
||||
}
|
||||
// A shared free or sick day means the alarm does not ring -- not
|
||||
// later, not quieter, not at all -- and nothing ring-related is
|
||||
// recorded: no markFired (the stick's own check skips the day too)
|
||||
// and no ring_started for the PC. Re-arm for tomorrow (the armed
|
||||
// recorded: no markFired and no ring_started for the PC. Only the
|
||||
// skip itself is latched, so the stick still stands the day down if
|
||||
// the mark is cleared after the ring time. Re-arm for tomorrow (the armed
|
||||
// instant has passed, so it rolls over) so the day after is normal.
|
||||
// Both caches fail closed: unreadable means ring.
|
||||
val skip = RingDecision.skip(FreeDays.isToday(context), SickDays.isToday(context))
|
||||
if (skip != null) {
|
||||
Log.i(TAG, "${skip.label}: not ringing; re-armed for tomorrow")
|
||||
RingWatch.markSkipped(context, skip)
|
||||
EventLog.append(context, "alarm_fired", mapOf("reason" to skip.wire))
|
||||
AlarmScheduler.rearmFromStorage(context)
|
||||
return
|
||||
|
||||
@ -32,6 +32,7 @@ object RingWatch {
|
||||
private const val KEY_FIRED_DATE = "fired_date"
|
||||
private const val KEY_DISMISSED_DATE = "dismissed_date"
|
||||
private const val KEY_DISMISSED_DATES = "dismissed_dates"
|
||||
private const val KEY_SKIPPED_PREFIX = "skipped_dates_"
|
||||
|
||||
fun markFired(context: Context) {
|
||||
prefs(context).edit().putString(KEY_FIRED_DATE, today()).apply()
|
||||
@ -42,6 +43,21 @@ object RingWatch {
|
||||
DateHistory.add(prefs(context), KEY_DISMISSED_DATES, LocalDate.now())
|
||||
}
|
||||
|
||||
/**
|
||||
* Latches that today's ring stood down for [skip]; called from
|
||||
* [AlarmReceiver]. The stick reads it back via [skippedOn], so clearing
|
||||
* the mark later that day cannot make the silenced day a miss.
|
||||
*/
|
||||
fun markSkipped(context: Context, skip: RingSkip) {
|
||||
DateHistory.add(prefs(context), KEY_SKIPPED_PREFIX + skip.wire, LocalDate.now())
|
||||
}
|
||||
|
||||
/** Why the ring stood down on [day], or null when it was not skipped. */
|
||||
fun skippedOn(context: Context, day: LocalDate): RingSkip? =
|
||||
RingSkip.entries.firstOrNull {
|
||||
DateHistory.contains(prefs(context), KEY_SKIPPED_PREFIX + it.wire, day)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the dismiss gate completed on [day]; read by [StickRunner],
|
||||
* which judges past days too. The single [KEY_DISMISSED_DATE] predates
|
||||
|
||||
@ -38,6 +38,14 @@ data class StickInputs(
|
||||
val state: StickState,
|
||||
/** The last day whose verdict was final, or null before the first run. */
|
||||
val checkedThrough: LocalDate?,
|
||||
/**
|
||||
* Why the daily ring stood down on a day, latched by [AlarmReceiver] at
|
||||
* ring time, or null when it rang (or the phone was off). Outlives a
|
||||
* later clear of the mark: the ring was silenced, so no dismiss was
|
||||
* possible, and a clear at 11:38 must not turn the day into a miss
|
||||
* (2026-11-11).
|
||||
*/
|
||||
val ringSkippedOn: (LocalDate) -> RingSkip? = { null },
|
||||
)
|
||||
|
||||
/** One day's verdict within a run. */
|
||||
@ -60,7 +68,7 @@ data class StickRun(
|
||||
* so every rule here is checkable in isolation.
|
||||
*
|
||||
* A **miss** is a stick day (Tue/Wed/Thu, [WorkdayStick.STICK_DAYS]) that is
|
||||
* neither a free day nor a sick day, whose alarm passed by at least [Stakes.STICK_GRACE_MINUTES]
|
||||
* neither a free day nor a sick day (now, or when its ring stood down), whose alarm passed by at least [Stakes.STICK_GRACE_MINUTES]
|
||||
* with no dismiss and no escape, and that has not already been penalised.
|
||||
* Nothing here needs the ring to have *fired*: a phone switched off before
|
||||
* the alarm misses exactly like one left ringing (hole 1 of the contract).
|
||||
@ -121,6 +129,11 @@ object StickCheck {
|
||||
// A sick day stands the stick down like a free day: no miss, no
|
||||
// streak change, no lockdown -- and nothing carried to tomorrow.
|
||||
if (inputs.isSick(day)) return StickVerdict.SICK_DAY to state
|
||||
when (inputs.ringSkippedOn(day)) {
|
||||
RingSkip.FREE_DAY -> return StickVerdict.FREE_DAY to state
|
||||
RingSkip.SICK_DAY -> return StickVerdict.SICK_DAY to state
|
||||
null -> Unit
|
||||
}
|
||||
// A dismissed or escaped stick day breaks the chain: the streak
|
||||
// shown and synced drops to 0 (a lockdown already sent stays).
|
||||
if (inputs.escapedOn(day)) return StickVerdict.ESCAPED to state.copy(streak = 0)
|
||||
@ -173,6 +186,6 @@ object StickCheck {
|
||||
fun isStickDay(day: LocalDate): Boolean = day.dayOfWeek in WorkdayStick.STICK_DAYS
|
||||
}
|
||||
|
||||
/** A day the stick skips entirely: free or sick. */
|
||||
/** A day the stick skips entirely: free or sick, now or at ring time. */
|
||||
val StickInputs.standsDown: (LocalDate) -> Boolean
|
||||
get() = { isFree(it) || isSick(it) }
|
||||
get() = { isFree(it) || isSick(it) || ringSkippedOn(it) != null }
|
||||
|
||||
@ -35,6 +35,7 @@ object StickRunner {
|
||||
isSick = { SickDays.isSick(context, it) },
|
||||
state = before,
|
||||
checkedThrough = StickStore.checkedThrough(context),
|
||||
ringSkippedOn = { RingWatch.skippedOn(context, it) },
|
||||
),
|
||||
)
|
||||
for ((day, verdict) in run.verdicts) {
|
||||
@ -69,7 +70,7 @@ object StickRunner {
|
||||
fun onDismissed(context: Context) {
|
||||
val today = LocalDate.now()
|
||||
if (!StickCheck.isStickDay(today) || FreeDays.isFree(context, today) ||
|
||||
SickDays.isSick(context, today)
|
||||
SickDays.isSick(context, today) || RingWatch.skippedOn(context, today) != null
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ class StickCheckSickTest {
|
||||
free: Set<LocalDate> = emptySet(),
|
||||
state: StickState = StickState(),
|
||||
checkedThrough: LocalDate? = null,
|
||||
skipped: Map<LocalDate, RingSkip> = emptyMap(),
|
||||
) = StickInputs(
|
||||
now = now,
|
||||
alarm = LocalTime.of(7, 30),
|
||||
@ -29,6 +30,7 @@ class StickCheckSickTest {
|
||||
isSick = { it in sick },
|
||||
state = state,
|
||||
checkedThrough = checkedThrough,
|
||||
ringSkippedOn = { skipped[it] },
|
||||
)
|
||||
|
||||
@Test
|
||||
@ -73,6 +75,40 @@ class StickCheckSickTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSickMarkClearedAfterTheSkippedRingIsStillSick() {
|
||||
// 2026-11-11: the ring stood down for a sick day at A, the mark was
|
||||
// cleared at 11:38, and the 19:31 run must not call the day a miss.
|
||||
val run = StickCheck.run(
|
||||
inputs(wed.atTime(19, 31), skipped = mapOf(wed to RingSkip.SICK_DAY)),
|
||||
)
|
||||
assertEquals(StickVerdict.SICK_DAY, run.verdicts.single().verdict)
|
||||
assertEquals(StickState(), run.state)
|
||||
assertNull(run.signalUntil)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFreeMarkClearedAfterTheSkippedRingIsStillFree() {
|
||||
val run = StickCheck.run(
|
||||
inputs(wed.atTime(19, 31), skipped = mapOf(wed to RingSkip.FREE_DAY)),
|
||||
)
|
||||
assertEquals(StickVerdict.FREE_DAY, run.verdicts.single().verdict)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSkippedRingDayIsSkippedWhenTheStreakLooksBack() {
|
||||
val before = StickState(streak = 1, lockedThrough = wed, lastMiss = tue)
|
||||
val run = StickCheck.run(
|
||||
inputs(
|
||||
thu.atTime(9, 0),
|
||||
state = before,
|
||||
checkedThrough = tue,
|
||||
skipped = mapOf(wed to RingSkip.SICK_DAY),
|
||||
),
|
||||
)
|
||||
assertEquals(2, run.state.streak)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFreeDayIsStillNamedFree() {
|
||||
val run = StickCheck.run(inputs(wed.atTime(9, 0), free = setOf(wed)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user