education: committing after a clock rollback no longer destroys a live streak
- Commit
6075215c145c008a7ec1ae3cfaf523045d6d3d61- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 09:41 UTC (5 days ago)
- Parents
1f5536e
The landed read fix made effectiveStreak treat a future lastActivityEpochDay as still alive (clock rollback via timezone travel or manual date correction), but the commit path nextStreak only special-cased last == today / today-1 and fell through to 1 for any future date. Learner with streak 5, last activity day 200, clock back to day 198: the home showed 5 suns, then any completed quiz committed streak 1 and regressed the streak-badge progress with it. nextStreak now treats lastEpochDay >= today with same-day semantics (maxOf(current, 1)), so read and commit agree; no other behaviour changed. New test pins future-dated runs staying alive and read/commit agreement. Quiz scoring, progress math, content indexing and profile handling were audited and cleared. Verified: :education:testDevUnitTest 77 tests pass; lint errors are pre-existing on untouched files.
Diff
education/src/main/java/com/vayunmathur/education/platform/EducationViewModel.kt
diff --git a/education/src/main/java/com/vayunmathur/education/platform/EducationViewModel.kt b/education/src/main/java/com/vayunmathur/education/platform/EducationViewModel.ktindex d8e63cfc5d..1de676aac8 100644--- a/education/src/main/java/com/vayunmathur/education/platform/EducationViewModel.kt+++ b/education/src/main/java/com/vayunmathur/education/platform/EducationViewModel.kt@@ -241,7 +241,9 @@ class EducationViewModel( /** Consecutive-day streak update given last activity day and today. */ fun nextStreak(current: Int, lastEpochDay: Long, today: Long): Int = when {- lastEpochDay == today -> maxOf(current, 1)+ // Same day, or a future last day after the clock moved backwards:+ // the run is still alive (as effectiveStreak reads it), so keep it.+ lastEpochDay >= today -> maxOf(current, 1) lastEpochDay == today - 1 -> current + 1 else -> 1 }
education/src/test/java/com/vayunmathur/education/util/EducationViewModelTest.kt
diff --git a/education/src/test/java/com/vayunmathur/education/util/EducationViewModelTest.kt b/education/src/test/java/com/vayunmathur/education/util/EducationViewModelTest.ktindex f6b8a2a0d3..18b14551fd 100644--- a/education/src/test/java/com/vayunmathur/education/util/EducationViewModelTest.kt+++ b/education/src/test/java/com/vayunmathur/education/util/EducationViewModelTest.kt@@ -203,6 +203,20 @@ class EducationViewModelTest { assertEquals(3, EducationViewModel.effectiveStreak(3, 6, 5)) } + @Test fun nextStreakKeepsFutureDatedRunAlive() {+ // Regression: effectiveStreak reads a future last-activity day (clock+ // moved backwards) as still alive, but nextStreak used to fall through+ // to 1 and destroy that run on the next committed quiz.+ assertEquals(5, EducationViewModel.nextStreak(5, 6, 5))+ assertEquals(5, EducationViewModel.nextStreak(5, 10, 5))+ assertEquals(1, EducationViewModel.nextStreak(0, 6, 5))+ // Commit and read agree for every future-dated state.+ assertEquals(+ EducationViewModel.effectiveStreak(4, 7, 5),+ EducationViewModel.nextStreak(4, 7, 5),+ )+ }+ @Test fun currentStreakReadsExpiredLearnerAsZero() { // Epoch day 100 is far in the past for any real "today", so a stored // streak from then has certainly missed a day since.