Codex sends every turn's body zstd. decodedBody made a new zstd decoder
for each one, with the package's default concurrency: it started a
stream goroutine and allocated its window and block buffers on every
request. In the procmem profile (a sandbox `magpie web` on main, three
Codex-style sessions sending zstd /v1/responses every 2-4s plus Chat and
Messages traffic, ~1,000 requests in 10 minutes) that was 1.74 GB of the
9.8 GB allocated, all under zstd.(*Decoder).startStreamDecoder.
Now a sync.Pool keeps decoders (concurrency 1, the same 512 MB memory
bound), as sessions' packed reads do since 21c2ab6fa. A decoder decodes
in step with the body's reader, which reads it through to its end
anyway, and goes back to the pool at Close; a read after Close gets
net.ErrClosed. A body that isn't zstd fails at Reset with the same 400
as before.
Measured with TestZstdBodyDecoderKept (a 304 KB body, 20 reads): 1719 KB
allocated a read before (fails), 678 KB after, which is io.ReadAll
growing to the body's size. The test is skipped under -race, where
sync.Pool drops a quarter of what is put in it (raceOn, as in sessions).
Run: go test -tags nogui -run 'Zstd|Encod|Codex.*Backend|BodyLimit|
Title|Bound|Gzip' ./internal/gateway (ok), the same with -race (ok),
gofmt -l clean, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/gateway pass. The full suite is run before the push of this
batch.