Files
magpie/internal
yetone 2a27fb8da8 gateway: a request's body is looked at for web search without a copy, and not parsed for a provider that searches by itself
attempt() asked searchAsked first, on every relayed request, and only
then whether the provider searches by itself. searchAsked looked for
three words with strings.Contains(string(body), …), each conversion a
copy of the whole body (a 211KB body: ~640KB and ms a request), and a
body offering web_search was then parsed whole: Codex offers it on
every turn, so each relayed Codex turn was parsed only to be told
"Codex searches by itself". searchedForIt now asks what is known of the
provider and model first, and searchAsked looks with bytes.Contains.
The same copy in the siblings that look at an error body
(fallback.passing, patience.busy, routing.failure's insufficient_quota)
goes too. lan.go's and the lower-cased look-ups in gateway.go need the
string they make and are left as they are.

Test: TestSearchAskedLooksCheaply. Broken by hand (string(body) and the
old order put back): red, "a 211KB body with no search in it: 3
allocations, want 0" and "a provider that searches by itself: 29
allocations, the body parsed".

BenchmarkSearchedForIt (211KB Responses body; load average ~450):
  codex-asks   old 2.55-5.02 ms/op  665KB/op  29-30 allocs/op
               new 0.1-1.9 us/op    0B/op     0 allocs/op
  other-plain  old 1.6-4.8 ms/op    663KB/op  3 allocs/op
               new 0.26-1.15 ms/op  0B/op     0 allocs/op

Run: go test ./internal/gateway -run
'TestSearchAskedLooksCheaply|TestWebSearchAskedOfEachAPI|Search|Busy|
Passing|Failure|Credit|Quota' -count 1: ok (140s).
2026-10-19 15:19:31 +08:00
..
…
…
…
…