monotonic-clock-offset-sync

Installation
SKILL.md

Two clocks, one offset, estimated from round trips

Every device in a synchronised room runs its own clock with its own drift, so "resume at 1234" means nothing until both ends agree what time it is. A pong that carries back the client's send time plus the peer's own receive and send times has everything needed to estimate one-way latency, and from that the offset between the two clocks:

// adapted — names generalized; the lock, the sample-validity checks and the accessors are elided
val receivedAt = elapsedRealtime()                       // MONOTONIC, injected by the caller
val roundTrip = receivedAt - clientTime
val peerProcessing = peerSendTime - peerReceiveTime
// Time the peer spent thinking is not time on the wire, so it comes out before the halving.
val networkRoundTrip = max(0L, roundTrip - peerProcessing)
val sampleOffset = peerSendTime + networkRoundTrip / 2.0 - receivedAt
Installs
2
GitHub Stars
35
First Seen
5 days ago
monotonic-clock-offset-sync — maxrave-dev/kotlin-footguns