ac4af582301a4e8a29245dbba767eba31334ddf9
7
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d56c14e953 |
gateway: a single provider's busy or briefly rate-limited reply is waited out, for its own Patience (zoecats)
zoecats on Discord: a request to one provider (not a group) got a local
relay's short 429 straight back in Claude Code once the few same-one
retries were spent. A group would have held the agent and asked again.
A plain provider now takes the group's replan path (patience.go: replan,
pauseAlive, the held writer) once passing's same-one retries are spent:
its accounts take turns as members do, each pause never shorter than the
Retry-After, and a streaming agent gets keepalives past keepHeldAfter.
- Zero-config: unset, it waits singlePatience, PatienceDefault (60s),
counted from when the agent would have had the error.
- The user's value wins: Provider.Patience, the same values as a group's
Patience, set with `magpie provider set <id> patience=2m|off|default`
(at most 4m). The provider editor has no row for it (no new UI), and its
save keeps it. A group the provider is in keeps the group's own.
- Not retried: a Retry-After past the budget, quota/credit/plan limits,
401/403, refusals, response protection, didNotStream, and an agent
that has gone (499, try marked Gone).
- The try is traced with Again alone, so the Routing page tells it as
"tried again in …".
- codexReset (ChatGPT's 503 for a large request) is left out of the
plain-provider replan, so Codex still gets its 503 with advice.
- Codex's own one-account relay (codexUpstreamOn) does not join. It is
relayed outside the candidate loop, and its backend 429 is always the
plan's usage limit (codexBusy never retries one), so the short rate
limit this waits out doesn't arise there. Its overloads keep
lastRetries and then fallbacks.
longestPause became a var so tests can scale it. Tests updated for the
new count (1 + retries + replanRounds when it never clears):
- TestLastOneLeftIsTriedAgain
- TestRateLimitIsWaitedOut
- TestQueuedStreamFailureIsTheStreamsError
- TestOverflowTheVendorDidntSay
New tests, through the server with a fake upstream and injected
durations, waiting on trace state, not a duration:
- TestSingleProviderWaitsOutAShortRateLimit (stream and whole: 200,
keepalive before the answer, asked twice)
- TestSingleProviderPassesALongLimitThrough (an hour, quota, 401)
- TestSingleProviderAgentGoneInTheWait
- TestSingleProviderOwnPatienceWins (off, shorter and longer than the
default)
- TestPatiencePair (cli)
- TestProviderSaveKeepsPatience (gui)
Broken by hand, each red, then restored:
- singlePatience fallback 0 for a plain provider: WaitsOut stream and
whole got 429, and AgentGone never paused.
- replan's budget check off: PassesALongLimitThrough/an_hour, "magpie
waits to ask again".
- pauseAlive's ctx.Done case removed: AgentGone, "route done false
status 0".
- The gateway ignoring Provider.Patience: OwnPatienceWins off, shorter
and longer all red.
- The GUI save not keeping Patience: TestProviderSaveKeepsPatience,
"patience 0 … want -1 kept".
Run in this tree, before the rebase:
- go test ./internal/gateway ./internal/cli ./internal/gui: ok.
- ./internal/provider: ok with -skip TestUnreadLogins. That test crashes
with "close of synctest channel from outside bubble", the known #3632,
in filememo and not touched here.
- gofmt -l: clean.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
vet ./...: all 0.
- go build for darwin, linux (nogui) and windows: ok.
Run again after rebasing on origin/main
|
||
|
|
198c7637a1 |
gateway tests: the queued-stream tests order the gateway's writes and the vendor's arrivals by a sequence, not a clock that ticks every ~0.5ms on Windows (#2249)
TestQueuedStreamKeptAliveForASlot checked heard.Before(asked) on
wall-clock times. On Windows time.Now() advances in ~0.5ms ticks, and
the keepalive, the slot being freed and the vendor being asked fit in
one, so heard == asked and the test failed with the right order.
Loosening it to !asked.Before(heard) would pass a broken keepalive: with
queued keepalives off, the first write (the reply) lands in the same ms
as the ask, seen below.
A shared counter (step) now gives each gateway write a place in order,
taken before the write so nothing the agent does on hearing it can come
earlier, and each vendor arrival and answer one too. The sibling checks
use it: TestQueuedStreamKeptAliveForTheMinute's same heard-before-asked
and TestQueuedStreamKeptAliveOnceSentToItsVendor's writeLog.within (its
"kept alive before the vendor was asked" is the same strict compare on
the one write that frees the slot).
Run:
- Reproduced by truncating both clocks to 100ms (forced equal ticks):
old ForASlot FAIL 5/5 at queue_keepalive_test.go:387 with equal
times, the issue's message; OnceSentToItsVendor FAIL 5/5 "the agent
wasn't kept alive before the vendor was asked". With the fix and the
same truncation, all TestQueuedStream* pass 3/3.
- Broke the guarded behaviour by hand (queuedAlive := func() {} in
gateway.go): all three tests FAIL at the body check; with the body's
": keepalive" check also dropped, each FAILs at the new order check
(ForASlot :433, ForTheMinute :304, OnceSentToItsVendor :368).
- go test -tags nogui -race -count=20 -run of these and
TestTranslatedSilenceStillTimesOut: ok (358s). gofmt -l clean,
go vet -tags nogui ./internal/gateway (darwin) clean.
Not run: the full go test ./..., GOOS=linux/windows vet, the Windows
box. Stopped because the disk dropped below 10G free.
|
||
|
|
ee20a1511b |
gateway: the package's tests wait ~42s less for queues and OTel exports (#1654)
internal/gateway hit go test's default 10m timeout under a full ./... on
a loaded Mac. go test -json timed its 1583 top-level tests at ~306s
summed (they run one after another); the slowest few waited on real
clocks for things the tests don't check.
- TestQueuedStreamFailureIsTheStreamsError (27s -> 0.3s): it queued for
room in a 3s minute (MaxRPM 1), and each of the vendor's two retries
waited a minute more, 9s a protocol. It now queues for a slot
(MaxConcurrency 1, freed once the agent has heard a keepalive), which
goes through the same keepQueued, queuedAlive and watch around the
attempt, so its retries go at once. The assertions are unchanged.
- TestQueuedStreamKeptAliveOnceSentToItsVendor (15s -> 7.6s): the same
slot instead of a 4s minute; keepHeldAfter 1.5s, keepalive 100ms and
the vendor's 1s quiet stay. With the h.alive.sent clause in
holdWriter.watch removed by hand it goes red on all three protocols
("wrote nothing ... between the vendor being asked and its answer").
- TestQueuedStreamKeptAliveForTheMinute keeps the MaxRPM queue.
- A shared holdSlot helper holds the slot; it frees itself after 5s and
in cleanup, so a test that hears nothing fails instead of hanging.
- usage.OTelEvery / OTelSessionsEvery (5s / 2s, read once when StartOTel
starts an exporter) replace the hard-coded tickers; the gateway's OTel
tests set them to 200ms / 50ms through fastOTel.
TestOTelClaudeMainAndChildDedupRetainsHelper 10s -> 4.5s (the rest is
sessions' 2s settle before a Claude transcript counts as finished),
TestOTelSessionDedupOnlyUnkeyedLoopback 2.25s -> 0.4s. Production
intervals are unchanged.
Not cut: TestPluginStreamLargeReplies (22s, 24MB throttled at 3MB/s),
TestPluginStreamLongActiveReader (16s, sized to outlast a 10s stall
window the plugin host dropped in
|
||
|
|
c0a13dee3c |
gateway: a queued stream's agent, kept alive while it waited, goes on hearing a keepalive every 15s once the request goes to its vendor, not up to 30s of nothing
keepQueued keeps a streaming agent alive while its request waits for a
slot (MaxConcurrency) or for room in its minute (MaxRPM): past
keepHeldAfter it sends the stream's 200 and a comment every
keepaliveEvery (15s each). When the wait ends, keepQueued stops and the
try's watch starts, and watch only called keepQuiet once keepHeldAfter
(15s) had passed since it began, as if the agent had heard nothing yet.
An agent sent its last keepalive just before the handoff then went up
to keepHeldAfter + keepaliveEvery, ~30s, with nothing while the vendor
was quiet, twice the cadence magpie promises. Found while fixing
TestQueuedStreamKeptAliveForTheMinute's flake (
|
||
|
|
3f4287e674 |
gateway tests: the queued-keepalive tests ask that the gateway wrote to the agent before the vendor was asked, not for a client's idle timeout
|
||
|
|
4caae1c8e0 |
gateway tests: the queued-stream tests count an agent's idle timeout only until the reply's last event, and time the minute from the first request's start
TestQueuedStreamKeptAliveForTheMinute/responses failed in a full
go test ./... at load ~130: "the agent gave up after 1.496s of a queued
request: i/o timeout", with the stream read whole: 22 keepalives, then
response.created, the delta and response.completed. The keepalives
were fine. What timed out was the wait after the reply's last event:
serve's bookkeeping (usage ledger, the route's trace, affinity) runs
before the handler returns and net/http closes the stream, and the
test's idleConn still counted its 400ms idle timeout there. No agent's
idle timeout counts that wait (Codex hangs up on response.completed),
the same cause
|
||
|
|
24bef0f9be |
gateway: a streamed request waiting for its key's slot (Concurrency) or for room in its minute (Requests per minute) has its agent sent the stream's 200 and SSE keepalives after 15s, as a held try's stream is, instead of nothing until it is sent (coeo91 on Discord: WorkBuddy, Trae and Qoder said it timed out)
serve's try took its lane slot and waited for the minute ( |