Commit Graph
1 Commits
Author SHA1 Message Date
yetone 4391ff0f56 provider: asking a plugin for its model id replaces just the model (#4004)
When a plugin's model has an API id other than the one asked for,
withModel decoded the whole request into a map and marshalled it again,
which allocated 469 MiB for a 45 MiB body, about ten times the body.
Now a body with one top-level "model" string gets just that string
replaced, in one buffer of the body's size. Every other byte goes as it
came. A body that isn't JSON, has no string model, or names "model"
twice takes the old path. A body of null goes as it came; it was a
panic, writing into a nil map.

The gateway's own withModel (Codex backend) and rewriteModel are left
as they are. TestCodexRewritesAsBefore pins the Codex backend's sorted
bytes, and TestUpstreamBodiesUnchanged pins rewriteModel's handling of a
duplicate model. Both went red when the splice was tried there.

Run on mote at 3aa36bbea (since rebased onto main, which changed nothing in
internal/provider or internal/gateway):
- TestWithModelAsksForTheModel: a nested "model" is kept, spacing is
  kept, an escaped model is replaced, and a missing, numeric or
  duplicate model, a cut-off body and null are covered.
- TestWithModelCopiesOnce: a 45 MiB body is copied once (45 MiB
  allocated). Against the old withModel, the test is red: 469 MiB
  allocated, and the body's < was escaped.
- go vet ./internal/provider for darwin, linux and windows: ok.
- go test ./internal/provider ./internal/gateway -timeout 45m: ok
  (106s, 495s), the plugin parity tests included.

Not tried with a real account: none of the plugins signed in here
(WorkBuddy, Devin, Cursor and others) has a model whose API id differs,
so this path isn't reached by them today.
2026-10-28 18:11:21 +08:00