Files
magpie/internal
ggbdpq 24d4425944 gateway: TestRequestBuildsProvidersOnce judges the build's ask, not the
request's start (#2965)

Cause: the test judged the second request by when it began, letting it
want 0 rebuilds only within 900ms of the first, while what decides a
rebuild is the hold and the stamp, not the clock from a request's
start. Two ways that guess goes red: on a loaded machine a request can
begin within the second and reach the build after the hold has let what
was built go — "request 2 built the providers 1 times, want 0", seen in
full runs at load ~280–400; and since 6a050eeb keeps the catalog for
the next requests, a request that begins past the 900ms builds none at
all — "request 2 built the providers 0 times, want 1", which an idle
machine now reproduces with a plain 1.2s pause between the requests.

Fix: allProviders notes when the build it counts was asked for
(AllBuiltAt, beside AllBuilt), and the test judges a rebuild by that,
not by the request's start: a rebuild asked a second or more after the
first build's ask is the hold letting go, rightly, and is allowed only
when it is exactly one; a rebuild asked within the second, or more than
one build in a request (the #2502 bug class), stays red. Nothing rests
on how fast the machine gets from a request's start to its build.

Red first (macOS arm64, idle, this tree): with a 1.2s pause put before
the second request, the old test failed "request 2 built the providers
0 times, want 1"; the new test passed the same pause (-count=3); the
old form failed it again with the hook in place (ablation: the test is
what guards). The loaded-machine shape is the issue's own run at load
~280–400 and the maintainer's "request 2 built the providers 1 times,
want 0" at c8c0985df; the "request 1 built 2 times" red at dee5c9d75 is
not the guess — two builds inside one request stays red here by design,
per #2502.

Run (macOS arm64, go1.26.8, load ~4–7):
- go test -tags nogui -count=5 -run 'TestRequestBuildsProvidersOnce$'
  ./internal/gateway/: ok.
- go test -tags nogui -race -count=4 -run
  'TestRequestBuildsProvidersOnce$' ./internal/gateway/: ok.
- go test -tags nogui -count=1 ./internal/gateway/: ok (634.7s).
- go test -tags nogui -count=1 ./internal/provider/: ok (127.8s).
- gofmt -l internal/gateway/ internal/provider/: clean.
- go vet -tags nogui ./internal/gateway/ ./internal/provider/ for
  darwin, linux, windows: ok.
- CGO_ENABLED=0 go build -tags nogui ./..., darwin/linux/windows: ok.

Fixes #2965

Generated-by: GLM-5.3-Flash (ZCode)

Review (mote, go1.26.8): go test -tags nogui -count=3 -run
'TestRequestBuildsProvidersOnce$' ./internal/gateway/ ok. A rebuild
happens only when the second ask is a second or more after the build's
end (h.at is set after the build), so a second or more between the asks
is necessary and the new allowance excuses no wrong rebuild.
Broken by hand: heldFor at 1ns makes it red ("request 1 built the
providers 2 times, want 1"); a 1.2s pause before request 2 passes, which
is the case the old test misjudged.
2026-11-06 05:53:50 +08:00
..
…
…
…
…
…
…