captureRequestBody wrote the body's first 256 KiB into a bytes.Buffer
and then copied the buffer into a string: 512 KiB allocated for every
request of 256 KiB or more. It is now one string conversion of the same
bytes, and the same truncated flag.
BenchmarkLargeRequest, ~2 MB conversation, B/op before → after:
anthropic 45.84 → 45.58 MB
anthropic-group 57.30 → 57.03 MB
chat 36.61 → 36.35 MB
responses 46.04 → 45.78 MB
In the 60-min soak before (dee5c9d75), Buffer.String was 1.08 GB
allocated.
TestCaptureRequestBodyLimit now also checks exact sizes (0, 5 and
callBodyLimit bytes are not truncated), that a capture allocates at most
1.25× callBodyLimit, and that the capture is a copy, not the body's
memory. Broken by hand (the buffer put back): red, "capturing 262144
bytes allocated 524288".
Run (darwin arm64, go1.26.8, sandbox HOME, load 40 to 90 from other
sessions' suites):
- go test ./... -count=1 -timeout 45m on the series' final tree at
ba319a758: exit 0, all 68 packages ok (gateway 1498s, agent 1633s).
- After the rebase onto b855cfee9 (two redact commits): go test
./internal/redact ./internal/gateway -count=1 -timeout 45m, both ok
(gateway 917s).
- go test -race -count=3 on the Held, ReadersOfAHeldBody, RecentRing,
RequestBody, CaptureRequest, folder, WorkPlace, WorkDir and Turn
tests: ok, after
TestReadersOfAHeldBodyParseItOnce's byte bound was skipped under
-race (the third commit says why); that test and
TestHeldFactsGoWithTheirBody then passed -count=30 with and without
-race.
- Each commit alone: go vet ./internal/gateway and gofmt -l clean.
- Final tree: gofmt -l clean; go vet ./... for darwin, GOOS=windows and
GOOS=linux -tags nogui, all exit 0.
Not tried: a second 60-minute soak after the series (the one before is
the "before" here; the "after" numbers are the benchmark's), the GUI
suite (nothing in it changed), Windows and Linux test runs (vet only).