The plugin host holds streamBudget/streamWindow = 128 streaming calls'
windows. begin(true) failed the 129th at once with errTooManyCalls, before
anything reached the plugin child, and the gateway counted it as a 502
try and sent the request again. The reporter's 192 concurrent MiniMax
streams through one plugin all came back 200, but over 298 local 502
tries that never reached MiniMax (65 requests retried).
Fetch now takes its window through beginStream: when all 128 are held
it waits for one to come free, outside h.mu (the transition that frees
one takes it), while its request's context lives, the host is up, and
for streamWait (1 minute) at most, past which it is errTooManyCalls as
before. RPCs keep their reserve and still never wait; begin(false) and
begin(true) are unchanged for their other callers.
Tests:
- TestHostFetchWaitsForAStreamWindow (internal/plugin): one window;
a second fetch waits, runs once the first is released, gives up on
a cancelled context and after streamWait, and leaves no window taken.
- TestPluginStreamsPastTheBudgetWait (internal/gateway, new file): 192
concurrent streams through the real Bun plugin host to a local vendor
that holds each open until 128 are live. Every request is 200 on one
try, the vendor sees 192 requests and never more than 128 at once.
Run at this head (on ff7048dec):
- gofmt -l internal/plugin internal/gateway: clean
- go vet -tags nogui ./internal/plugin/ ./internal/gateway/ for GOOS
linux, windows, darwin: ok
- go test -timeout 45m ./internal/plugin/: ok (99.0s, before the rebase
over two usage/provider commits that don't touch plugin or gateway)
- go test -timeout 45m -run Plugin ./internal/gateway/: ok (52.0s, same)
- After the rebase: TestHostFetchWaitsForAStreamWindow,
TestHostAdmission*, TestPluginStreamsPastTheBudgetWait: ok
- Broken by hand (beginStream returning errTooManyCalls at once, as
begin did): TestHostFetchWaitsForAStreamWindow fails ("want it
waiting"); TestPluginStreamsPastTheBudgetWait fails with 960 lines
of "a try 502 too many plugin calls are in flight".
- Real account: a sandbox HOME with only the ZCode plugin and its
account, this head's build on 127.0.0.1:3581, 8 concurrent streaming
zcode/GLM-5.3-Flash requests: 8 of 8 200, each with its [DONE].
Not tried: 192 real concurrent streams against a vendor (the reporter's
MiniMax setup); the full gateway package (only its Plugin tests).