From 9e1431084f61e5bb60294dd7ea4dcf1edecfb841 Mon Sep 17 00:00:00 2001 From: mlsmaycon Date: Sun, 23 Aug 2026 06:20:55 +0000 Subject: [PATCH] [misc] End the access-log lookup when its window ends The poll interval was not bounded by the window: a page that came back without the row just before the deadline still slept a full two seconds before the loop noticed it was out of budget, so the caller waited longer than the window it asked for to be told nothing arrived. Cap the wait at whatever is left of the window. --- e2e/agentnetwork/custom_pricing_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/e2e/agentnetwork/custom_pricing_test.go b/e2e/agentnetwork/custom_pricing_test.go index fded58304..253a3d7ed 100644 --- a/e2e/agentnetwork/custom_pricing_test.go +++ b/e2e/agentnetwork/custom_pricing_test.go @@ -174,6 +174,11 @@ func chatOnce(t *testing.T, ctx context.Context, env pricedEnv, model, sessionID // to appear before the caller gives up on it. const accessLogIngestWindow = 30 * time.Second +// accessLogPollInterval is how long the lookup waits between pages. Ingest is +// asynchronous, so the row lands somewhere inside the window rather than on +// any particular poll. +const accessLogPollInterval = 2 * time.Second + // lookupAccessLogBySession polls the access-log page for the row carrying // sessionID and reports whether it arrived within the window. It never fails // the test: callers that can recover — by firing a fresh request under a new @@ -192,10 +197,23 @@ func lookupAccessLogBySession(ctx context.Context, sessionID string, within time } } } + // The wait is bounded by the window as well, so the answer arrives when + // the caller's budget runs out rather than a poll interval later: a + // full interval slept past the deadline reports "no row" up to two + // seconds late, which reads as a slower lookup than the one asked for. + wait := time.Until(deadline) + if wait > accessLogPollInterval { + wait = accessLogPollInterval + } + if wait <= 0 { + return api.AgentNetworkAccessLog{}, false + } + timer := time.NewTimer(wait) select { case <-ctx.Done(): + timer.Stop() return api.AgentNetworkAccessLog{}, false - case <-time.After(2 * time.Second): + case <-timer.C: } // Checked after the wait rather than before the request: a poll issued // past the deadline carries no budget and would fail on arrival.