Files
magpie/docs
yetone ce1ecaa414 gateway: MaxRPM keeps a second's slack, so a first request's dial doesn't let the vendor see one over its minute
TestMaxRPMWaitsForRoomInTheMinute went red under CI load and b1396d23
reran it without a cause. The cause is real, not only in the test: a
request is counted when it starts to go, the vendor counts it when it
arrives, and the first on a new connection arrives later by its dial
and TLS handshake. With the bare 60s window, the limit+1-th request
could reach the vendor less than 60s after the first did.

- rpm.go: a counted request stays counted for rpmWindow + rpmSlack (1s),
  in prune and in reserve.
- rpm_test.go: minuteVendor can hold the first arrival (late); the two
  vendor-timing tests hold it 150ms with a window/6 slack and now ask
  that the vendor saw the gap of a whole window, not window-50ms.
  TestRPMReserveKeepsTheSlack checks the arithmetic. shortMinute zeroes
  the slack so the exact-minute tests are unchanged.
- docs/subsystems/gateway-routing.md: the Limits row says so.

Ran:
- With rpmSpan() returning the bare window: TestMaxRPMWaitsForRoomInTheMinute
  ("the vendor saw the third 1.346s after the first, inside the 1.5s window"),
  TestMaxRPMCountsRetriesAndCounts and TestRPMReserveKeepsTheSlack fail.
  With the slack all pass.
- go test -count=5 -run RPM ./internal/gateway; -race -count=3 -run RPM.
- go test -count=1 ./internal/gateway (581s, ok).
- gofmt -l clean; go vet on darwin, GOOS=linux, GOOS=windows for the package.
2026-10-11 02:25:05 +08:00
..