qoder 0.2.40: a queued request gives way at once when magpie has another candidate

axuhere on X sat at "模型请求正在排队 · 预计等待超过 10 分钟" on a free
model while another provider could have answered. Through magpie, a
Qoder free model queued with 10605 was waited out for up to 4 minutes
even when the request had another account, provider or routing group
member after it.

magpie now sends x-magpie-fallback: 1 on a plugin request that isn't
the last candidate (the host keeps it from the vendor). Told so, a
queued request isn't waited out: the 503 with Qoder's Retry-After comes
at once, and magpie asks the next. The message now also says how many
are ahead when Qoder says it ("Qoder queued the request for dfmodel
(this plan's queue: p3, 3 ahead); try again in 30s"). Without the
header, the wait is as before.

Run: packages/qoder `bun test` (268 pass, 22 files); `bun
scripts/check.mjs` all green.
Broken by hand: index.mjs as before with the new tests: the fallback
test and the budget test's message red (2 of 12 in queue.test.mjs).
Not tried: a real Qoder account queued live; the 10605 shape is
testdata/queued-10605.json's, captured before.
This commit is contained in:
yetone
2026-10-27 18:53:25 +08:00
parent b1bc778edf
commit bc25bc5077
4 changed files with 40 additions and 7 deletions
+18 -1
View File
@@ -147,13 +147,30 @@ test("a wait held past the budget is the 503 with Retry-After it was, the reques
const res = await fetch(API_CHAT, ask())
expect(res.status).toBe(503)
expect(res.headers.get("Retry-After")).toBe("30")
expect((await res.json()).error.message).toBe("Qoder queued the request for dfmodel (this plan's queue: p3); try again in 30s")
expect((await res.json()).error.message).toBe("Qoder queued the request for dfmodel (this plan's queue: p3, 3 ahead); try again in 30s")
expect(sent.chats.length).toBe(1)
// 30s pauses, the last cut to what was left of the budget
expect(pauses.reduce((a, b) => a + b, 0)).toBe(QUEUE.budget)
expect(Math.max(...pauses)).toBe(30_000)
})
// With another candidate after it (magpie's X-Magpie-Fallback: the model's
// next account or provider, a routing group's next member), a queued
// request isn't waited out: its 503 goes back at once, with where it stood
// in the queue, and magpie asks the next (axuhere on X: a free model held
// at "预计等待超过 10 分钟" while another provider could answer). The last
// candidate isn't told, and waits as Qoder's client does (above).
test("told another candidate follows, a queued request is answered at once with the queue's reason", async () => {
const { fetch, sent } = await loader({ chats: () => refused(), statuses: () => status(QUEUED) })
const res = await fetch(API_CHAT, { ...ask(), headers: { "x-magpie-fallback": "1" } })
expect(res.status).toBe(503)
expect(res.headers.get("Retry-After")).toBe("30")
expect((await res.json()).error.message).toBe("Qoder queued the request for dfmodel (this plan's queue: p3, 3 ahead); try again in 30s")
expect(sent.chats.length).toBe(1)
expect(sent.statuses.length).toBe(0)
expect(pauses).toEqual([])
})
test("the pause is the queue's retryAfterSeconds held to 0.5s..30s, and 30s when it says none", async () => {
const states = [
{ ...QUEUED, retryAfterSeconds: 0.1 },