You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Apple: a press, native timer or page notice right after a sleep reads the date from before it, and a refused setTime is not told again #668
This follows 1353a1d ("On Apple the date an app reads follows a sleep and a clock change"). That commit makes followOffset tell the date again when it slipped by a second or more, before each advance and frame and on the clock-change, zone-change, wake and did-become-active notices. Two gaps remain on Apple hosts:
The first event after a sleep can still read the old date.followOffset does not run before a press, a native task timer or a page notice. A press, or a timer that fires before any frame or notice, reads time.epochAtZero + performanceNow() with the epoch from before the sleep, behind the real date by the length of the sleep.
A refused correction is lost.dateMoved() records toldEpoch and toldOffset before followOffset applies runtime.setTime(...). If the runner refuses that batch (busy or held), the session believes the date was told, and the correction is not sent again until the date moves by another second.
The slip itself was not reproduced. It needs a real iPhone that sleeps with the app suspended, because a simulator does not stop CACurrentMediaTime. Both gaps were found by reading the code.
presenter.onPress in Session.swift runs followOffset() (when clock == nil) before runtime.press.
deliverNativeTimer in NativeTaskTimers.swift runs followOffset() after its guard.
tellPage in PageFacts.swift runs followOffset() (when clock == nil).
In SessionTime.swift, followOffset keeps the batch from setTime, and if batch.busy || batch.held it clears toldEpoch and offsetHeld, so the next check tells the date again.
SessionClockTimerTests (including 1353a1d's sleep test, which moves ExactSession.machineDate ahead), HeadlessSessionTests, NativeTaskTimersTests, PageFactsMacTests, PageFactsSoonMacTests and PressFeedbackMacTests pass on macOS. No new test was added for these two gaps.
Host
iOS, macOS
Smallest app that shows it
Launch on a device, lock it for a few minutes with the app suspended, unlock, and press Stamp first, before anything else redraws.
shape Time
epochAtZero: number
utcOffset: number
component App
resource time = exactTime() as shape Time
state pressedAt = 0
action stamp
pressedAt = time.epochAtZero + performanceNow()
view
column padding=16 gap=12
button press=stamp testId="stamp"
text "Stamp"
text `${pressedAt}` testId="stamped"
This snippet compiles. Whether the press beats the did-become-active notice and the first frame depends on timing, so the stale stamp may not show every time.
Exact commit
f3a4ace, which includes 1353a1d. presenter.onPress, deliverNativeTimer and tellPage there do not call followOffset, and followOffset applies setTime without checking the batch.
Fixed in 7dcac1c, with the fork credited. On Apple the machine date is now checked at four points: before every person's input, before a native task timer fires, and in tellPage and tellPageSoon. tellPageSoon queues the date ahead of the page facts. If the runner refuses the date because it is busy or held, the date is forgotten, so the next check sends it again. This holds for direct and queued sends alike. The new SessionClockTimerTests case moves machineDate an hour ahead and presses in the same turn, then holds the runtime over a check. It fails on the old code and passes now. A simulator doesn't stop CACurrentMediaTime, so this test stands in for a real sleep on a device.
Activity
ccheever commentedon Nov 15, 2026
Fixed in 7dcac1c, with the fork credited. On Apple the machine date is now checked at four points: before every person's input, before a native task timer fires, and in
tellPageandtellPageSoon.tellPageSoonqueues the date ahead of the page facts. If the runner refuses the date because it is busy or held, the date is forgotten, so the next check sends it again. This holds for direct and queued sends alike. The newSessionClockTimerTestscase movesmachineDatean hour ahead and presses in the same turn, then holds the runtime over a check. It fails on the old code and passes now. A simulator doesn't stopCACurrentMediaTime, so this test stands in for a real sleep on a device.Posted by Claude Code on the maintainers' behalf.
On Apple an input after a sleep reads the date now, and a refused dat…