Deep Review: 20261004-001957-pr-5565
| Date | 2026-10-04 00:19 |
| Repo | lima-vm/lima |
| Round | 1 (of pr-5565) |
| Author | @mvanhorn |
| PR | #5565 — fix: stop guest time sync from stepping the clock back by RPC latency |
| Branch | fix/5543-guest-timesync-latency |
| Commits | 3a5e97c3 fix: stop guest time sync from stepping the clock back by RPC latency |
| Review SHA | 3a5e97c378f31ff1b5a2bac866fac3778be9d01a |
| Reviewers | Claude Opus 5.5 (effort: high), Codex GPT 6 Astra (effort: high), Gemini 3.1 Pro (effort: default), Gemini 3.5 Flash (effort: default) |
| Verdict | Merge with fixes — the approach helps under steady load, but its stale estimate can now set the guest ahead of the host and step it back later |
| Wall-clock time | 55 min 29 s |
Executive Summary ¶
The PR sends host_time ahead by half the smaller of the last two round trips, so steady RPC latency no longer steps the guest clock back each tick. When that estimate, one or two ticks old, exceeds the current request delay (after a slow first sync, when load ends, or when replies run slow), the guest is set ahead of the host and a later tick steps it back. Two small patches fix this, at some cost to the gain.
Critical Issues ¶
None.
Important Issues ¶
}
// oneWayDelay estimates host-to-guest delay as half the lesser of the two most
// recent round trips. It is 0 when the latest sample is not positive, so the
// first send is uncompensated and a single stall cannot aim the next tick ahead.
func oneWayDelay(prev, last time.Duration) time.Duration {
if last <= 0 {
return 0
}
if prev > 0 && prev < last {
return prev / 2
}
return last / 2
}
// compensatedHostTime is the predicted guest receipt time sent as host_time.
func compensatedHostTime(sentAt time.Time, delay time.Duration) time.Time {
return sentAt.Add(delay)
On tick 2 prev is still 0, so line 101 returns half the only sample. The doc comment's claim that a single stall cannot aim the next tick ahead holds only from tick 3. The first sync runs while the guest is still booting. After a slow first round trip, tick 2 aims host_time ahead and the guest steps forward; with no guest NTP, tick 3 steps it back. An 8 s stall on the first reply gives +3.995 s, then −3.995 s, where the merge-base does not step. Below the threshold the guest stays ahead. Round trips of 220 ms then 40 ms leave it 90 ms ahead, against 110 ms behind at the merge-base and on time with the fix.
Reproducer
// Save as pkg/hostagent/timesync_probe_test.go; run: go test ./pkg/hostagent/ -run TestProbeTimeSync -v
package hostagent
import (
"context"
"io"
"testing"
"time"
"github.com/sirupsen/logrus"
guestagentapi "github.com/lima-vm/lima/v2/pkg/guestagent/api"
)
type trip struct{ out, back time.Duration }
// simulateTicks runs syncGuestClock once per trip against a guest that applies
// GuestServer.SyncTime's 100ms rule, and returns each step the guest clock
// took (negative is backward). ntp returns the guest to true time between
// ticks; compensate=false sends the send time itself, as the merge-base did.
func simulateTicks(trips []trip, ntp, compensate bool) []time.Duration {
var steps []time.Duration
var offset, prev, last time.Duration
start := time.Date(2026, time.October, 3, 0, 0, 0, 0, time.UTC)
for i, tr := range trips {
if ntp {
offset = 0
}
sentAt := start.Add(time.Duration(i) * timeSyncInterval)
doSync := func(_ context.Context, hostTime time.Time) (*guestagentapi.TimeSyncResponse, error) {
if !compensate {
hostTime = sentAt
}
receipt := sentAt.Add(tr.out)
drift := receipt.Add(offset).Sub(hostTime)
if drift > 100*time.Millisecond || drift < -100*time.Millisecond {
steps = append(steps, -drift)
offset = hostTime.Sub(receipt)
}
return &guestagentapi.TimeSyncResponse{}, nil
}
prev, last = syncGuestClock(context.Background(), doSync, prev, last, scriptedNow(sentAt, sentAt.Add(tr.out+tr.back)))
}
return steps
}
func TestProbeTimeSync(t *testing.T) {
logrus.SetOutput(io.Discard)
ms := time.Millisecond
steady := trip{250 * ms, 250 * ms}
fast := trip{5 * ms, 5 * ms}
for _, tc := range []struct {
name string
trips []trip
ntp bool
}{
{"steady 250ms each way, guest NTP", []trip{steady, steady, steady, steady}, true},
{"first reply stalls 8s, no guest NTP", []trip{{10 * ms, 7990 * ms}, fast, fast}, false},
{"first sync 250ms each way, no guest NTP", []trip{steady, fast, fast}, false},
} {
t.Run(tc.name, func(t *testing.T) {
base := simulateTicks(tc.trips, tc.ntp, false)
pr := simulateTicks(tc.trips, tc.ntp, true)
t.Logf("merge-base steps: %v", base)
t.Logf("reviewed steps: %v", pr)
if len(pr) > len(base) {
t.Errorf("reviewed code steps the guest clock %d times, merge-base %d", len(pr), len(base))
}
})
}
}
$ go test ./pkg/hostagent/ -run TestProbeTimeSync -v
=== RUN TestProbeTimeSync
=== RUN TestProbeTimeSync/steady_250ms_each_way,_guest_NTP
timesync_probe_test.go:64: merge-base steps: [-250ms -250ms -250ms -250ms]
timesync_probe_test.go:65: reviewed steps: [-250ms]
=== RUN TestProbeTimeSync/first_reply_stalls_8s,_no_guest_NTP
timesync_probe_test.go:64: merge-base steps: []
timesync_probe_test.go:65: reviewed steps: [3.995s -3.995s]
timesync_probe_test.go:67: reviewed code steps the guest clock 2 times, merge-base 0
=== RUN TestProbeTimeSync/first_sync_250ms_each_way,_no_guest_NTP
timesync_probe_test.go:64: merge-base steps: [-250ms 245ms]
timesync_probe_test.go:65: reviewed steps: [-250ms 495ms -245ms]
timesync_probe_test.go:67: reviewed code steps the guest clock 3 times, merge-base 2
--- FAIL: TestProbeTimeSync (0.00s)
--- PASS: TestProbeTimeSync/steady_250ms_each_way,_guest_NTP (0.00s)
--- FAIL: TestProbeTimeSync/first_reply_stalls_8s,_no_guest_NTP (0.00s)
--- FAIL: TestProbeTimeSync/first_sync_250ms_each_way,_no_guest_NTP (0.00s)
FAIL
FAIL github.com/lima-vm/lima/v2/pkg/hostagent 0.482s
FAIL
Fix: compensate only from two positive samples, and update the two assertions that pinned single-sample compensation. The probe and the shipped tests pass with it.
Patch
diff --git a/pkg/hostagent/timesync.go b/pkg/hostagent/timesync.go
index 3f63c309..365ead64 100644
--- a/pkg/hostagent/timesync.go
+++ b/pkg/hostagent/timesync.go
@@ -89,16 +89,13 @@ func syncGuestClock(ctx context.Context, doSync func(context.Context, time.Time)
}
// oneWayDelay estimates host-to-guest delay as half the lesser of the two most
-// recent round trips. It is 0 when the latest sample is not positive, so the
-// first send is uncompensated and a single stall cannot aim the next tick ahead.
+// recent round trips. It is 0 until both samples are positive, so a single
+// slow round trip, the first one included, cannot aim the next tick ahead.
func oneWayDelay(prev, last time.Duration) time.Duration {
- if last <= 0 {
+ if prev <= 0 || last <= 0 {
return 0
}
- if prev > 0 && prev < last {
- return prev / 2
- }
- return last / 2
+ return min(prev, last) / 2
}
// compensatedHostTime is the predicted guest receipt time sent as host_time.
diff --git a/pkg/hostagent/timesync_test.go b/pkg/hostagent/timesync_test.go
index 814d56cf..8d510f83 100644
--- a/pkg/hostagent/timesync_test.go
+++ b/pkg/hostagent/timesync_test.go
@@ -52,7 +52,7 @@ func TestOneWayDelay(t *testing.T) {
t.Run("startup and empty window", func(t *testing.T) {
assert.Equal(t, oneWayDelay(0, 0), time.Duration(0))
assert.Equal(t, compensatedHostTime(sentAt, 0), sentAt)
- assert.Equal(t, oneWayDelay(0, 300*time.Millisecond), 150*time.Millisecond)
+ assert.Equal(t, oneWayDelay(0, 300*time.Millisecond), time.Duration(0))
})
t.Run("non-positive latest sample", func(t *testing.T) {
@@ -74,7 +74,7 @@ func TestSyncGuestClock(t *testing.T) {
assert.Equal(t, got, sentAt)
assert.Equal(t, prev, time.Duration(0))
assert.Equal(t, last, 300*time.Millisecond)
- assert.Equal(t, oneWayDelay(prev, last), 150*time.Millisecond)
+ assert.Equal(t, oneWayDelay(prev, last), time.Duration(0))
})
t.Run("third stable sample keeps the one-way delay", func(t *testing.T) {
// syncGuestClock sends the predicted guest receipt time and shifts the RTT window
// after SyncTime returns a nil error. An RPC error leaves the window unchanged.
func syncGuestClock(ctx context.Context, doSync func(context.Context, time.Time) (*guestagentapi.TimeSyncResponse, error), prevIn, lastIn time.Duration, now func() time.Time) (prev, last time.Duration) {
prev, last = prevIn, lastIn
sentAt := now()
// host_time is the predicted receipt time (issue 5543).
hostTime := compensatedHostTime(sentAt, oneWayDelay(prev, last))
resp, err := doSync(ctx, hostTime)
if err != nil {
logrus.WithError(err).Debug("Time sync: RPC failed")
return prev, last
}
The delay comes from round trips 10 and 20 s old. When it exceeds the current request leg by more than 100 ms, the guest (pkg/guestagent/api/server/server.go:128-130) sets its clock to a host_time ahead of the host's own clock. The merge-base never could, because its host_time was never later than the guest's receipt. Load ending triggers this, and so do replies slower than requests, since rtt/2 charges half the reply leg to the request. Without guest NTP, a later tick steps it back. Which model Lima guests follow is open (Design Observations).
resp := &api.TimeSyncResponse{
Adjusted: false,
DriftMs: drift.Milliseconds(),
}
const driftThreshold = 100 * time.Millisecond
if drift > driftThreshold || drift < -driftThreshold {
if err := timesync.SetSystemTime(hostTime); err != nil {
logrus.WithError(err).Warn("SyncTime: failed to set system time")
resp.Error = err.Error()
return resp, nil
}
resp.Adjusted = true
Reproducer
// Save as pkg/hostagent/timesync_overshoot_probe_test.go; run: go test ./pkg/hostagent/ -run TestProbeOvershoot -v
package hostagent
import (
"context"
"io"
"testing"
"time"
"github.com/sirupsen/logrus"
guestagentapi "github.com/lima-vm/lima/v2/pkg/guestagent/api"
)
type leg struct{ out, back time.Duration }
// guestSteps runs syncGuestClock once per entry against a guest that applies
// GuestServer.SyncTime's 100ms rule, and returns each step the guest clock
// took (negative is backward). ntp returns the guest to true time between
// ticks; compensate=false sends the send time itself, as the merge-base did.
func guestSteps(legs []leg, ntp, compensate bool) []time.Duration {
var steps []time.Duration
var offset, prev, last time.Duration
start := time.Date(2026, time.October, 3, 0, 0, 0, 0, time.UTC)
for i, l := range legs {
if ntp {
offset = 0
}
sentAt := start.Add(time.Duration(i) * timeSyncInterval)
doSync := func(_ context.Context, hostTime time.Time) (*guestagentapi.TimeSyncResponse, error) {
if !compensate {
hostTime = sentAt
}
receipt := sentAt.Add(l.out)
drift := receipt.Add(offset).Sub(hostTime)
if drift > 100*time.Millisecond || drift < -100*time.Millisecond {
steps = append(steps, -drift)
offset = hostTime.Sub(receipt)
}
return &guestagentapi.TimeSyncResponse{}, nil
}
prev, last = syncGuestClock(context.Background(), doSync, prev, last, scriptedNow(sentAt, sentAt.Add(l.out+l.back)))
}
return steps
}
func TestProbeOvershoot(t *testing.T) {
logrus.SetOutput(io.Discard)
ms := time.Millisecond
slow, fast, slowReply := leg{250 * ms, 250 * ms}, leg{5 * ms, 5 * ms}, leg{10 * ms, 790 * ms}
for _, tc := range []struct {
name string
legs []leg
ntp bool
}{
{"steady 250ms each way, guest NTP", []leg{slow, slow, slow, slow}, true},
{"load ends, no guest NTP", []leg{fast, fast, slow, slow, slow, fast, fast}, false},
{"slow replies end, no guest NTP", []leg{fast, fast, slowReply, slowReply, slowReply, fast, fast}, false},
} {
t.Run(tc.name, func(t *testing.T) {
base := guestSteps(tc.legs, tc.ntp, false)
pr := guestSteps(tc.legs, tc.ntp, true)
t.Logf("merge-base steps: %v", base)
t.Logf("reviewed steps: %v", pr)
if len(pr) > len(base) {
t.Errorf("reviewed code steps the guest clock %d times, merge-base %d", len(pr), len(base))
}
})
}
}
$ go test ./pkg/hostagent/ -run TestProbeOvershoot -v
=== RUN TestProbeOvershoot
=== RUN TestProbeOvershoot/steady_250ms_each_way,_guest_NTP
timesync_overshoot_probe_test.go:63: merge-base steps: [-250ms -250ms -250ms -250ms]
timesync_overshoot_probe_test.go:64: reviewed steps: [-250ms]
=== RUN TestProbeOvershoot/load_ends,_no_guest_NTP
timesync_overshoot_probe_test.go:63: merge-base steps: [-250ms 245ms]
timesync_overshoot_probe_test.go:64: reviewed steps: [-245ms 245ms 245ms -245ms]
timesync_overshoot_probe_test.go:66: reviewed code steps the guest clock 4 times, merge-base 2
=== RUN TestProbeOvershoot/slow_replies_end,_no_guest_NTP
timesync_overshoot_probe_test.go:63: merge-base steps: []
timesync_overshoot_probe_test.go:64: reviewed steps: [390ms -390ms]
timesync_overshoot_probe_test.go:66: reviewed code steps the guest clock 2 times, merge-base 0
--- FAIL: TestProbeOvershoot (0.00s)
--- PASS: TestProbeOvershoot/steady_250ms_each_way,_guest_NTP (0.00s)
--- FAIL: TestProbeOvershoot/load_ends,_no_guest_NTP (0.00s)
--- FAIL: TestProbeOvershoot/slow_replies_end,_no_guest_NTP (0.00s)
FAIL
FAIL github.com/lima-vm/lima/v2/pkg/hostagent 0.447s
FAIL
Fix: cap the delay at the guest's drift threshold, shared as a constant in pkg/guestagent/api, so an overestimate alone cannot cross it. In the steady case, 250 ms each way then steps back 150 ms per tick instead of once. The patch is independent of I1's; with both applied, both probes and the package tests pass.
Patch
diff --git a/pkg/guestagent/api/server/server.go b/pkg/guestagent/api/server/server.go
index 60478d97..00e4a460 100644
--- a/pkg/guestagent/api/server/server.go
+++ b/pkg/guestagent/api/server/server.go
@@ -125,8 +125,7 @@ func (s *GuestServer) SyncTime(_ context.Context, req *api.TimeSyncRequest) (*ap
DriftMs: drift.Milliseconds(),
}
- const driftThreshold = 100 * time.Millisecond
- if drift > driftThreshold || drift < -driftThreshold {
+ if drift > api.TimeSyncDriftThreshold || drift < -api.TimeSyncDriftThreshold {
if err := timesync.SetSystemTime(hostTime); err != nil {
logrus.WithError(err).Warn("SyncTime: failed to set system time")
resp.Error = err.Error()
diff --git a/pkg/guestagent/api/timesync.go b/pkg/guestagent/api/timesync.go
new file mode 100644
index 00000000..b2fbe9a8
--- /dev/null
+++ b/pkg/guestagent/api/timesync.go
@@ -0,0 +1,10 @@
+// SPDX-FileCopyrightText: Copyright The Lima Authors
+// SPDX-License-Identifier: Apache-2.0
+
+package api
+
+import "time"
+
+// TimeSyncDriftThreshold is how far the guest clock may be from a SyncTime
+// request's host_time before the guest agent sets its clock to host_time.
+const TimeSyncDriftThreshold = 100 * time.Millisecond
diff --git a/pkg/hostagent/timesync.go b/pkg/hostagent/timesync.go
index 3f63c309..c27ffb03 100644
--- a/pkg/hostagent/timesync.go
+++ b/pkg/hostagent/timesync.go
@@ -65,7 +65,10 @@ func syncGuestClock(ctx context.Context, doSync func(context.Context, time.Time)
prev, last = prevIn, lastIn
sentAt := now()
// host_time is the predicted receipt time (issue 5543).
- hostTime := compensatedHostTime(sentAt, oneWayDelay(prev, last))
+ // The delay comes from earlier round trips. Capping it at the guest's
+ // threshold stops an overestimate from stepping the guest ahead of the host.
+ delay := min(oneWayDelay(prev, last), guestagentapi.TimeSyncDriftThreshold)
+ hostTime := compensatedHostTime(sentAt, delay)
resp, err := doSync(ctx, hostTime)
if err != nil {
logrus.WithError(err).Debug("Time sync: RPC failed")
diff --git a/pkg/hostagent/timesync_test.go b/pkg/hostagent/timesync_test.go
index 814d56cf..a46f2f96 100644
--- a/pkg/hostagent/timesync_test.go
+++ b/pkg/hostagent/timesync_test.go
@@ -84,7 +84,7 @@ func TestSyncGuestClock(t *testing.T) {
got = hostTime
return &guestagentapi.TimeSyncResponse{}, nil
}, prev, last, scriptedNow(sentAt, sentAt.Add(360*time.Millisecond)))
- assert.Equal(t, got, compensatedHostTime(sentAt, 180*time.Millisecond))
+ assert.Equal(t, got, compensatedHostTime(sentAt, guestagentapi.TimeSyncDriftThreshold))
assert.Equal(t, prev, 360*time.Millisecond)
assert.Equal(t, last, 360*time.Millisecond)
assert.Equal(t, oneWayDelay(prev, last), 180*time.Millisecond)
Suggestions ¶
Fixes #5543 closes the issue while a single latency spike still steps the guest back by almost its full delay Claude Opus 5.5¶
The estimate predicts each RPC from earlier ones, so it cannot see a spike in the current one. In Claude's executed simulation, a 4 s round trip between 10 ms ticks steps the guest back 1.995 s, against 2 s at the merge-base. The issue's largest adjustments (1388, 4102 and 9577 ms) look like that, and the issue proposes two guards for them (persistent same-signed drift, or never stepping back by less than the measured latency) that this PR does not add. Merging with Fixes #5543 closes the issue on those cases.
Fix: write Refs #5543 in the commit and the PR body, or keep the issue open for the spike case.
t.Run("stable link", func(t *testing.T) {
delay := oneWayDelay(360*time.Millisecond, 360*time.Millisecond)
assert.Equal(t, delay, 180*time.Millisecond)
hostTime := compensatedHostTime(sentAt, delay)
assert.Equal(t, hostTime, sentAt.Add(180*time.Millisecond))
// Receipt at sentAt+180ms has drift 0, inside the guest's 100ms threshold.
assert.Equal(t, sentAt.Add(180*time.Millisecond).Sub(hostTime), time.Duration(0))
})
t.Run("sustained latency increase", func(t *testing.T) {
assert.Equal(t, oneWayDelay(80*time.Millisecond, 360*time.Millisecond), 40*time.Millisecond)
delay := oneWayDelay(360*time.Millisecond, 360*time.Millisecond)
Once line 24 passes, line 26 cannot fail. Lines 34-38 build guestNow 140 ms behind and then assert the drift is −140 ms, without noting that −140 ms crosses the threshold and makes the guest step. Every TestSyncGuestClock subtest is a single call with a hand-set window, so nothing feeds one tick's output into the next or applies GuestServer.SyncTime's threshold-and-set rule. That is why I1 and I2 pass the suite.
Fix: replace the identity assertions with a multi-tick test that models the guest's rule, like the probes in I1 and I2, and assert on the guest's step sequence.
client, err := a.getOrCreateClient(ctx)
if err != nil {
logrus.WithError(err).Debug("Time sync: failed to get client")
return prev, last
}
prevRTT, lastRTT = syncGuestClock(ctx, client.SyncTime, prev, last, time.Now)
return prevRTT, lastRTT
}
// syncGuestClock sends the predicted guest receipt time and shifts the RTT window
// after SyncTime returns a nil error. An RPC error leaves the window unchanged.
func syncGuestClock(ctx context.Context, doSync func(context.Context, time.Time) (*guestagentapi.TimeSyncResponse, error), prevIn, lastIn time.Duration, now func() time.Time) (prev, last time.Duration) {
Fix: return syncGuestClock(ctx, client.SyncTime, prev, last, time.Now).
if err != nil {
logrus.WithError(err).Debug("Time sync: RPC failed")
return prev, last
}
// A response Error string still counts: the round trip completed.
prev, last = last, max(now().Sub(sentAt), 0)
if resp.Error != "" {
logrus.Warnf("Time sync: guest failed to set time: %#q (drift was %dms)", resp.Error, resp.DriftMs)
return prev, last
}
time.Now() contains a monotonic reading, and Sub between two such values uses it, so the elapsed time cannot go negative in production. Only the injected clock in the negative sample is stored as zero subtest reaches the clamp, yet the commit body spends a sentence on it.
Fix: drop the clamp, the subtest and the commit-body sentence.
Design Observations ¶
Concerns ¶
- (in-scope) Whether the PR reduces backward steps depends on what moves the guest clock between ticks, and nobody has measured that. Claude Opus 5.5 Claude ran 2000 simulated ticks per latency distribution with symmetric legs. If the guest is restored to true time before each tick, the PR cuts backward steps from 1343 to 694 (uniform 0 to 600 ms RTT) and from 2000 to 1 (200 to 400 ms). If the guest keeps whatever offset the last step left, the PR raises them, from 439 to 571, 1 to 47, and 313 to 374 for 10 ms RTT with 20% of ticks at 400 ms. With I2's cap the free-running counts are 478, 1 and 313, and the restored ones 894, 1 and 383. The reporter's log, with positive drift on tick after tick, fits the restored model better, but I don't know what restores the guest that fast. A loaded-host VM run counting guest steps before and after the PR would settle it.
- (future) Measuring the offset inside one exchange would cover spikes, drops and asymmetric legs. Claude Opus 5.5 Codex GPT 6 Astra The guest would report its clock without stepping, and the host would compute
offset = guest_now − (sentAt + rtt/2)from that same call and order a step only when the offset exceeds the threshold plus rtt/2. That needs a proto field and a guest agent change. The guest agent ships in the cidata that the samelimactlbuild generates, so version skew is limited to instances not restarted since an upgrade. - (in-scope) The
Infocall before everySyncTimeis not a clean fresh sample. Claude Opus 5.5 Claude suggested timing it, sincegetOrCreateClientcallsclient.Info(pkg/hostagent/hostagent.go:915) just before each sync. But the guest'sInforunsLocalPorts(pkg/guestagent/guestagent_linux.go:205), so its round trip includes guest work and overstates transport, the direction I2 warns about.
Strengths ¶
- (in-scope) Injecting
doSyncandnowmakessyncGuestClocktestable without a VM, and both probes in this review depend on it. Codex GPT 6 Astra Claude Opus 5.5 - (in-scope) The change stays on the host: no proto field and no guest agent change. Gemini 3.5 Flash
- (in-scope) The RTT window is a local of the time-sync goroutine, so it does not need locking. Codex GPT 6 Astra
- (in-scope) In steady state the min-of-two filter does stop one stall from aiming the following tick ahead. Claude Opus 5.5 Gemini 3.5 Flash
Testing Assessment ¶
- Required (I1, I2, S2): a multi-tick test that applies the guest's threshold-and-set rule and asserts the guest's step sequence, covering the slow first sync, load ending, and slow replies. The change exists to alter what the guest clock does, and no current assertion can fail on over-compensation.
- Optional, kept: a spike case asserting the step on the spike tick itself (S1), which records what the change does not fix.
- What I ran:
go test -count=1on./pkg/hostagent/...and./pkg/guestagent/...at the review SHA passed, as didgofmt -landgo vet ./pkg/hostagent/. CI shows 36 checks passing and 2 skipped. - Mutations: I1's patch breaks
timesync_test.go:55and:77, which pinned single-sample compensation; I2's cap breaks:87. Each patch updates those lines. - Test output: the
guest error string still records the samplesubtest prints a logrus warning to stderr.
Documentation Assessment ¶
The oneWayDelay doc comment (pkg/hostagent/timesync.go:91-93) is false for the second tick; I1's patch rewrites it. No page under website/content or docs mentions time sync, so no user documentation needs a change.
Commit Structure ¶
One commit, signed off, which settles the DCO comment. The body names functions and walks through the mechanism, which the diff already shows, while the bug itself appears only in the PR body. Since the PR lands as a squashed commit, the PR body's second paragraph (a loaded host steps the guest clock back by the RPC latency) belongs in the commit body. The body also repeats I1's single-stall claim and S4's negative-sample sentence.
Acknowledged Limitations ¶
- PR comment (@mvanhorn, replying to @AkihiroSuda): the author ran the branch on an idle vz VM with a Debian 13 guest and could not reproduce the loaded-host case, so only unit tests cover it. This review's probes are models too. They apply
GuestServer.SyncTime's rule to scripted delays and say nothing about a real guest's NTP.
Unresolved Feedback ¶
- @AkihiroSuda, "Did you test it with an actual VM?": answered for an idle host only. Given the model dependence in Design Observations, a loaded-host run is the evidence still missing.
Agent Performance Retro ¶
Claude Opus 5.5 ¶
Claude did the most to frame the question this PR raises. Besides I1, it alone filed the latency-drop overshoot as a finding (I2) and the spike gap (S1), and its 2000-tick simulation across two guest models showed that the PR's net effect flips with whatever moves the guest clock between ticks. That simulation really ran; the session log has its output. It rated the spike gap Important, although the PR does not make spikes worse. Its I2 patch used a shared guestagentapi.DriftThreshold constant that its own fix text asked for but did not write, and its idea of timing the Info call missed that Info runs a guest port scan.
Codex GPT 6 Astra ¶
Codex found I1 with the sharpest reproducer. Its first reply stalls for 8 s and the merge-base does not step at all, which separates the defect from any question about guest NTP. It also modeled slow replies followed by recovery and got the forward-then-back pair that became I2's third case, but it filed that under Design Observations instead of as a finding. It could not run go test (empty module cache, GOPROXY=off) and said so instead of claiming a pass; its Python and Go models did run.
Gemini 3.1 Pro ¶
The first attempt hung after ten tool calls, about three minutes in, and the relaunch finished. Its one finding traced a real I1 case, a slow first sync followed by a fast one that leaves the guest 90 ms ahead below the threshold, and its arithmetic matches the simulator. But it blamed the uncompensated first sync instead of the single-sample second one, and its fix primes the window with Info calls, whose round trip includes the guest's port scan. It also praised the negative-RTT clamp and called the tests comprehensive; S4 and S2 show otherwise.
Gemini 3.5 Flash ¶
Flash found I1 and the two small simplifications (the built-in min, folded into I1's patch, and S3), and it raised the latency-drop overshoot as a design concern. Its I1 repro block quotes a failure at timesync_test.go:130, but its session log does not show a write to that file, so no run produced that output. The assertion would fail as quoted, which my probe confirms. The two Gemini models did not converge on anything beyond I1, and there they reached it by different routes.
Summary ¶
| Claude Opus 5.5 | Codex GPT 6 Astra | Gemini 3.1 Pro | Gemini 3.5 Flash | |
|---|---|---|---|---|
| Duration | 5m 58s | 5m 06s | 7m 25s | 8m 00s |
| Findings | 2I 3S | 2I 1S | 1I | 2I 2S |
| Tool calls | 17 (Bash 14, Read 3) | 7 (shell 7) | 12 (runshellcommand 12) | 27 (readfile 9, grepsearch 8, runshellcommand 7) |
| Design observations | 5 | 3 | 2 | 3 |
| False positives | 0 | 0 | 0 | 0 |
| Unique insights | 4 | 1 | 0 | 1 |
| Files reviewed | 2 | 2 | 2 | 2 |
| Coverage misses | 0 | 0 | 0 | 0 |
| Totals | 2I 3S | 2I 1S | 1I | 2I 2S |
| Downgraded | 1 | 0 | 0 | 0 |
| Dropped | 0 | 0 | 0 | 0 |
Reconciliation: Claude pass 1, spike gap (its I3): important → suggestion S1, because the PR neither introduces nor worsens the spike step. Codex pass 1, slow replies then recovery (a design concern): → part of I2, important. Gemini 3.5 Flash pass 1, overshoot on latency collapse (a design concern): → part of I2, important. Gemini 3.1 Pro pass 1, permanent skew from the first sync (its I1): merged into I1, with its first-sync diagnosis and its Info priming fix rejected. Gemini 3.5 Flash pass 1, built-in min (its S1): folded into I1's patch.
Review Process Notes ¶
Skill improvements ¶
- When a change feeds measurements from earlier iterations into a decision a downstream consumer acts on (a predicted delay, a rate estimate, a backoff), evaluate the consumer's actions over a sequence of iterations that includes the cold start and a regime change in each direction. An estimator that is right in steady state overshoots or undershoots at each transition, and the consumer's action there can be worse than the uncompensated behavior.
Repo context updates ¶
- [repo] Guest time sync is a closed loop.
GuestServer.SyncTimesteps the guest clock to the request'shost_timewhenever the drift exceeds 100 ms, and the hostagent sends a request every 10 s. Judge any change to a request'shost_timeby the guest's sequence of steps across ticks, including the first ticks and a latency change in each direction. A guest left ahead of the host is corrected by a backward step on a later tick, which is the symptom time sync exists to avoid.
Notes on this report ¶
- S1 is about the commit message, so it cites the short SHA, and the citation lint's warning on it is deliberate.