Each plugin request was copied several times before it reached the
plugin:
- pluginFetch read the body with io.ReadAll, which grows from 512
bytes, so a 1 MB body was some 3 MB read. It now reads into a buffer
of the request's Content-Length.
- Fetch marshalled a map holding the FetchRequest and the body as
[]byte, so encoding/json base64'd the body into its own buffer and
then copied it into the line, and enqueueOwned appended the newline
in another copy. fetchLine now marshals the request without the body
(FetchRequest.Body is json:"-") and appends the base64 body and
window into one slice sized for the whole line; enqueueLine sends it
as is.
The frame is byte for byte what it was: TestFetchBodyWireIsUnchanged
compares it with the old json.Marshal of the map, field order
included (request fields, body, window).
BenchmarkFetchBodyProd B/op, before -> after:
1 MiB 1,516,234 -> 1,411,609
8 MiB 14.4 MB -> 11.2 MB
16 MiB 29.7 MB -> 22.4 MB
Through the gateway with the previous commit (probe, 60 requests of
~938 KB, per request including the test's client and fake vendor):
/v1/chat/completions 21.2 MB -> 17.3 MB (24.4 MB before both, -29%)
/v1/messages 33.7 MB -> 29.3 MB (39.8 MB before both, -26%)
Server.serve's own share on /v1/messages: 29.1 -> 19.0 MB (-35%).
What is left on top is buildChat's json.Marshal of the outgoing body,
which the upstream byte fixtures pin; not changed here.
Run at this head (base origin/main 1bb8143b3):
- go test ./internal/plugin ./internal/provider -skip
'^TestUnreadLoginsWriteErrorsKeepCredentials$' (#3632) -count=1
-timeout 45m: ok (plugin 109s, provider 105s)
- go test ./internal/gateway -skip '^TestZZ' -count=1 -timeout 45m: ok
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui for
internal/plugin, internal/provider, internal/gateway: clean
- Real account in a sandbox HOME: the Command Code plugin
(commandcode-plan/claude-haiku-5-5) answered /v1/messages and
/v1/chat/completions with a ~54 KB history, a tool call and a UTF-8
tool result: 200 both, the tool's text quoted back exactly.
Not tried: an OAuth plugin (their tokens rotate; not copied into a
sandbox), Windows.
Rebased onto origin/main 6e6aba51c (a providers key change) and run again at the pushed head: go build -tags nogui ./... ok; go test ./internal/provider (same skip) ok 115s, ./internal/plugin ok 110s, ./internal/gateway -run 'Facts|Parse|Plugin|WorkPlace|Fetch' ok 50s. The full gateway run above was at 1bb8143b3.