Files
magpie/internal
yetone fcbf618ebb gateway: a request's turns are looked through for images in place, before any copy (#3725)
walkImages decoded the whole request's top level (a copy of the body)
before it knew whether any turn held an image, and anyImageBlock read
every block whole, so a long agent conversation of text tool_results was
decoded block by block on every request. Now anyImageTurn walks the
turns array in place with eachMember/eachElement and decodes only when
an image is there. A tool_result's content (Anthropic) and a
functionResponse's parts (Gemini) are looked inside, so an image a tool
returned is still found.

Measured:
- hasImage on a 60-turn, 76KB body of text tool_results: 6863
  allocations before, at most 4 now (TestImageWalkReadsToolResultsInPlace,
  red on the old code with "took 6863 allocations").
- BenchmarkZZIO (12x20 catalog, ~31KB body, a local benchmark not
  committed): 620KB/1944 allocs per request before, 520KB/1544 after.

The test's table covers content before type, content given twice, a
tool_result inside a tool_result, an escaped "type" key, a text block
with content, string content, Gemini parts after name, nested fileData
and text-only parts. The existing image tests pass unchanged.

Run at this tree (base e1709ab42): gofmt -l clean; GOOS=linux and
GOOS=windows go vet -tags nogui ./internal/gateway ok; go test -count=1
-timeout 45m ./internal/gateway ok (446.961s).

Rebased onto 92cf0b68d (no internal/gateway change since
e1709ab42; pii, redact and settings changed): go vet -tags nogui
./internal/gateway ok and go test -count=1 -run Image ./internal/gateway
ok (12.011s) at the pushed head. The full gateway package ran at the
base above, not at this head.
2026-10-27 02:17:05 +08:00
..
…
…
…