Guest agent time sync counts host-to-guest RPC latency as clock drift and steps the guest clock backwards under host load
Description
GuestServer.SyncTime (pkg/guestagent/api/server/server.go, v2.1.2) computes drift := now.Sub(hostTime) where hostTime is the timestamp the host put in the request, and calls timesync.SetSystemTime(hostTime) when |drift| > 100ms. The host's stamp is already latency old when the guest reads it, so the measured "drift" is the guest's real drift plus the host-to-guest transport latency, and the correction sets the guest clock to a time that is latency in the past. Whenever the RPC takes more than 100 ms (a loaded host), every 10-second sync steps the guest clock backwards by the latency, even if the guest clock was correct.
On a busy macOS host we see this at every sync for minutes at a time. Log excerpt from ~/.colima/_lima/colima/ha.stderr.log (11,226 guest clock adjusted entries since 2026-09-19 on this machine):
{"level":"info","msg":"Time sync: guest clock adjusted (was 113ms off)","time":"2026-09-25T15:08:48+08:00"}
{"level":"info","msg":"Time sync: guest clock adjusted (was 100ms off)","time":"2026-09-25T15:11:48+08:00"}
{"level":"info","msg":"Time sync: guest clock adjusted (was 102ms off)","time":"2026-09-25T15:13:29+08:00"}
{"level":"info","msg":"Time sync: guest clock adjusted (was 102ms off)","time":"2026-09-25T15:15:58+08:00"}The largest adjustments logged that day were 1388 ms, 4102 ms and 9577 ms. A probe inside a container that read CLOCK_REALTIME every 10 ms recorded the guest clock jumping back by 47 ms to 853 ms at the sync instants, and the guest journal shows matching "Time jumped backwards" entries. The sign is always the same: the drift is positive (guest ahead of the stale host stamp), so the clock only ever moves back.
Impact
Anything in the guest that orders events by wall-clock time breaks. Our case: GHDL records each design file's analysis time in its library file and reports "X is obsoleted by Y" when a dependency's stamp is newer, so a file analysed just after a step looks older than its dependencies and the whole build fails at random under host load. We had to add a wrapper that waits until the clock passes the newest stamp before each analysis.
Environment
- Lima 2.1.2 (via Colima 0.10.1, vz driver), macOS 26.5.1, Apple silicon (arm64 guest)
- Reproduces whenever the host's load average exceeds roughly the core count; no reproduction on an idle host.
Suggested fix
Measure the round trip on the guest side and treat half of it as transport, i.e. compare now with hostTime + rtt/2 (or have the host send both a send stamp and the guest reply with its receive stamp, NTP-style), and never step the clock backwards by less than the measured latency. Alternatively only adjust when the same-signed drift persists across several samples, which a latency spike does not.
Workaround we use
A ghdl wrapper that keeps analysis stamps monotonic (waits past the newest library stamp, re-analyses when its own stamp comes out older). Happy to share it or test a fix.
Source: lima-vm/lima