Repository navigation
cleanup(ios): make elapsedRealtimeMillis count through device sleep - #1328
Conversation
NSProcessInfo.systemUptime pauses while the phone is asleep, so rest deadlines armed on that clock under-counted until the process was restored. Use Darwin CLOCK_MONOTONIC_RAW, which follows mach_continuous_time and keeps counting through sleep. Co-authored-by: Devil <9thLevelSoftware@users.noreply.github.com>
Code Review SummaryStatus: 2 Issues Found | Recommendation: Merge (already merged) — one follow-up verification outstanding Overview
Issue Details (click to expand)WARNING
Files Reviewed (3 files)
Fix these issues in Kilo Cloud VerdictComment only — the incremental commit resolves both prior findings in the direction the review asked for, and no new defect appears in the changed lines; the one open item is a physical-device measurement that cannot be produced in this environment. Correctness / Safety Findingsimportant: shared/src/iosMain/kotlin/com/devil/phoenixproject/domain/model/PlatformUtils.ios.kt:L19: the previous finding is now half-closed — the KDoc cites Apple Libc No new correctness, safety, or regression issues in the changed lines of this pass. The trimmed test no longer imports Ponytail Reviewshared/src/iosTest/kotlin/com/devil/phoenixproject/domain/model/ElapsedRealtimeIosTest.kt:L27: test-shrink — 31 lines and three assertions that also hold for the pre-fix shared/src/iosMain/kotlin/com/devil/phoenixproject/domain/model/PlatformUtils.ios.kt:L24: shrink — Ponytail net: -6 lines. Suggested Minimal Patch
No new dependencies, no other files touched. Final Merge GuidanceAlready merged as Previous Review Summary (commit 849f3e1)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 849f3e1)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (3 files)
Fix these issues in Kilo Cloud VerdictRequest changes — the change is small and the intent is right, but the platform-clock behavior it depends on is uncited and the only new test passes with the code it replaces. Correctness / Safety Findingsimportant: shared/src/iosMain/kotlin/com/devil/phoenixproject/domain/model/PlatformUtils.ios.kt:L20: the fix hinges on important: shared/src/iosTest/kotlin/com/devil/phoenixproject/domain/model/ElapsedRealtimeIosTest.kt:L27: No other correctness, safety, or regression issues found: the clock is only used for in-memory deadlines ( Ponytail Reviewshared/src/iosTest/kotlin/com/devil/phoenixproject/domain/model/ElapsedRealtimeIosTest.kt:L13: test-shrink — 37 lines and four assertions that also pass with the pre-fix implementation. Replace with one smoke assertion on the iOS actual (or delete the file if the device-only sleep check lands elsewhere). shared/src/iosMain/kotlin/com/devil/phoenixproject/domain/model/PlatformUtils.ios.kt:L20: shrink — Ponytail net: -25 lines. Suggested Minimal Patch
Final Merge GuidanceCan merge once the Darwin clock mapping is cited and the new test either covers the sleep-inclusive clock or is trimmed — the implementation itself is sound and small. Reviewed by minimax-m3 · Input: 202.9K · Output: 163.1K · Cached: 2M Review guidance: REVIEW.md from base branch |
…st a smoke check The KDoc now cites Apple Libc gen/clock_gettime.c: CLOCK_MONOTONIC_RAW reads mach_continuous_time() (counts through sleep), CLOCK_UPTIME_RAW reads mach_absolute_time() (stops while asleep). The "at least the awake uptime" assertion also held for the old NSProcessInfo.systemUptime implementation, so it could not catch a regression. Drop it and say plainly that the simulator test is a smoke check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015tsDJ6LzV6FwGD3VQwfNEn
Problem
iOS
elapsedRealtimeMillisusedNSProcessInfo.systemUptime, which stops while the device sleeps. Android usesSystemClock.elapsedRealtime(), which keeps counting. Live rest deadlines (including Just Lift) are armed on this clock, so a locked iPhone under-counted rest until the process was killed and restored from the wall-clock deadline.Fix
The iOS actual now reads Darwin
CLOCK_MONOTONIC_RAWviaclock_gettime_nsec_np. Apple Libcgen/clock_gettime.creads that clock id frommach_continuous_time(), which includes time spent asleep (CLOCK_UPTIME_RAWis themach_absolute_time()one that stops). The KDoc cites this. Units stay milliseconds and the expect signature is unchanged. The common KDoc now says the clock includes sleep, matching Android.Verification
./gradlew :shared:compileKotlinIosSimulatorArm64 :shared:compileTestKotlinIosSimulatorArm64 :shared:compileAndroidHostTest :androidApp:compileDebugKotlin -Pskip.supabase.check=trueThe new iosTest is a smoke check only: the reading is boot-relative, does not go backwards, and is not wall-clock time. The simulator cannot be put to sleep in that test, so it does not distinguish the sleep-inclusive clock from the awake-only one. A before/after-sleep reading on a physical iPhone is still unverified.