From d6cb404754a68bfdfedff322dbd17eeab5e8d3d4 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 14 Nov 2026 10:18:03 +0800 Subject: [PATCH] gateway: the live reasoning fixture allows the time its first event really took TestLiveVisibleReasoningFixture set start to now minus the event's at_ms and then called see, which reads the clock again. Any time between the two lands in the measured start, so on macOS CI (run 43530452364, e730a14dc) it read 6790 where the fixture says 6789. The test now records the time before setting start, and accepts the fixture's at_ms up to the milliseconds that really passed during the first see. Run on mica, at this change on f1f34d624: - The test -count=20: ok. go vet -tags nogui ./internal/gateway: ok. -run 'Reasoning|TTFT|FirstToken' ./internal/gateway: ok. gofmt clean. - Broken by hand: - The old test with a 3ms sleep before see: red, 6792/6789. The new one with the same sleep: ok. - ttft.go setting reasoning on every event, so the first is lost: the new test is red (0/6789). - Not run: the whole gateway package or the full suite; this changes one test's bound only. --- internal/gateway/reasoning_speed_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/gateway/reasoning_speed_test.go b/internal/gateway/reasoning_speed_test.go index d509bf33b..0d97ff601 100644 --- a/internal/gateway/reasoning_speed_test.go +++ b/internal/gateway/reasoning_speed_test.go @@ -366,14 +366,22 @@ func TestLiveVisibleReasoningFixture(t *testing.T) { if err = json.Unmarshal(b, &sample); err != nil { t.Fatal(err) } + // see reads the wall clock after start is set, so the first event lands + // at its at_ms plus however long that took: a millisecond more on a busy + // machine (6790/6789 on macOS CI), so the bound is what really passed. f := firstToken{} - for _, e := range sample.Events { + var slack int64 + for i, e := range sample.Events { delta, _ := json.Marshal(e.Delta) - f.start = time.Now().Add(-time.Duration(e.At) * time.Millisecond) + set := time.Now() + f.start = set.Add(-time.Duration(e.At) * time.Millisecond) f.see([]byte(`data: {"choices":[{"delta":{"reasoning_content":` + string(delta) + `}}]}` + "\n\n")) + if i == 0 { + slack = time.Since(set).Milliseconds() + 1 + } } - if f.reasoningMs(provider.Chat) != sample.Events[0].At { - t.Fatalf("live reasoning fixture lost its start: %d/%d", f.reasoningMs(provider.Chat), sample.Events[0].At) + if got, at := f.reasoningMs(provider.Chat), sample.Events[0].At; got < at || got > at+slack { + t.Fatalf("live reasoning fixture lost its start: %d/%d (+%d ms passing)", got, at, slack) } // its 731 ms came after a 6.8 s wait, which tells no speed: under a // second after a wait over four times longer reads as a reply let go