Skip to content

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

Closed

Description

@janicduplessis

What happened

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:

  1. 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.
  2. 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.

How a fork fixed it

appandflow/exact#1 (open on the fork), 12 lines:

  • 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.

Activity

  1. ccheever commented on Nov 15, 2026

    @ccheever
    Contributor

    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.

    Posted by Claude Code on the maintainers' behalf.

  2. added a commit that references this issue on Nov 15, 2026
    7dcac1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions