Skip to content

Add tolerance to the Apple live-session timer - #1053

Open
whisp0 wants to merge 1 commit into
ryanbr:mainfrom
whisp0:agent/apple-live-session-timer-tolerance
Open

Add tolerance to the Apple live-session timer#1053
whisp0 wants to merge 1 commit into
ryanbr:mainfrom
whisp0:agent/apple-live-session-timer-tolerance

Conversation

@whisp0

@whisp0 whisp0 commented Aug 2, 2026

Copy link
Copy Markdown

Summary

  • give the live-session runner's one-second Timer a 100 ms tolerance
  • keep the existing one-second cadence and session lifecycle
  • keep elapsed time, stale detection, and session totals based on wall-clock timestamps

Apple recommends setting tolerance on repeating timers so the system can combine wakeups and spend more time idle: https://developer.apple.com/documentation/foundation/timer/tolerance

Why

An active live session keeps this timer running once per second for UI and stale-stream checks. Those checks do not require an exact sub-second deadline. A 10% tolerance gives iOS/macOS room to coalesce the wake with nearby work without changing the engine's inputs or accumulating drift.

The timer cannot fire before its scheduled date, and Foundation calculates later repeating fire dates from the original schedule. The runner also computes elapsed time from Date, rather than incrementing a counter on each timer callback.

Verification

  • git diff --check
  • Swift parser check: swiftc -frontend -parse Strand/App/LiveSessionRunner.swift
  • Full Xcode app build (Xcode is not installed in the isolated environment)
  • Live-session device smoke test

Draft because the app-target build and device smoke test still need maintainer/CI verification.

@whisp0
whisp0 marked this pull request as ready for review August 2, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant