restAfterMarked reads a failed try's held header, which keepRetry
fills from the upstream's reply. keepRetry kept Retry-After and the
rate-limit reset headers but not X-Magpie-Limit-Reset
(remoteKeyLimitHeader), so a remote magpie's gateway key over its own
limit read as that one model's rate limit (remoteModelRest): the model
rested alone and the remote's other models were asked into the same
refusal.
Patch by ggbdpq (#2791): their test and the cause are theirs. Changed
from it: the patch whitelisted the raw marker into the held header,
and holdWriter passes that header on to the client, so the marker
reached the agent and, in a chain, a magpie asking this one, which
would rest all of this magpie for one key there. keepRetry now sets
an internal note (keyLimitThereHeader) that remoteModelRest reads and
holdWriter drops, with answeredThereHeader. The two keepRetry sites
that write to the client directly (count_tokens, decide_group) go
through keepRetryOut, which drops both notes; answeredThereHeader
leaked there before too. Doc sentence in gateway-routing.md.
Run (rebased on origin/main):
- TestRemoteMagpieKeyLimitRestsTheRemote (theirs): red with the note
taken out of keepRetry by hand (rested office/glm/glm-5 and kimi, not
office), green now.
- TestRemoteMagpieKeyLimitMarkerStaysHere (new): red with the patch's
raw marker copy ("the agent's reply carries X-Magpie-Limit-Reset"),
and red with keyLimitThereHeader taken out of pass()'s strip list
("carries X-Magpie-Key-Limit-There"), green now.
- RemoteMagpie|AnotherMagpie|KeyLimit ok; the whole internal/gateway
package (-tags nogui -count=1 -timeout 45m) ok in 476s at fc860f2e6.
- gofmt -l clean; go vet ./internal/gateway for darwin, GOOS=windows,
GOOS=linux -tags nogui clean.
Not tried: two real magpies over a network with a key limit hit.