qoder 0.2.71: a queue with nothing ahead that hasn't moved in 5 minutes ends with its 503 (#1220)

nsyan's Qoder CN account answered 10605 in ~190ms with
{queueCount: 1, queueType: p4, subCode: RESOURCE_LIMIT,
retryAfterSeconds: 60}, and queue/status gave the same bytes back at every
ask. The 120s silent watchdog (#1204) doesn't cover a call that answered,
so a streamed request was held for QUEUE.held (an hour) and the agent
heard keepalives only until it cancelled.

- queueWait ends the wait when nothing is ahead of the request
  (queueCount 1 or none) and the state (isQueued, serviceAvailable,
  queueCount, queueType, subCode, retryAfterSeconds) has been the same at
  every ask for QUEUE.stuck (5 minutes). The stream's error is the
  queue's 503 with Retry-After, plus "the queue hasn't moved in 5 minutes
  with nothing ahead".
- A queue with others ahead is still waited out as Qoder's client waits
  it (#807), changed or not; a state that changes resets the clock.
- queueState also reads queueCount and subCode.

Run (mica, HOME=$(mktemp -d); mote was at load 36):
- bun test packages/qoder: 450 pass, 0 fail.
- bun scripts/check.mjs qoder: ok.

Broken by hand: origin/main's index.mjs with the new tests: the 5-minute
cutoff test fails (19 pass, 1 fail); the two no-regression tests pass on
both.

Not tried: a real Qoder CN account in a frozen queue (none here); the
fixture is the reporter's literal state.
This commit is contained in:
yetone
2026-11-16 18:40:38 +08:00
parent aafb20e6bf
commit bf47b85b56
4 changed files with 91 additions and 6 deletions
+8 -2
View File
@@ -193,7 +193,7 @@ itself.
| A refused sign-in (no code, or code 105) | 401 |
| A quota (codes 110, 112–119, 122) | 429 |
| A model the account's listing has off while its usage says no credits are left (since 0.2.64, #880) | 429 usage limit reached, with the credits used and the model; a model off with credits left, or whose usage can't be read, stays 400 `unknown or disabled model`, and an id Qoder never served is that 400 at once |
| Busy or queued for the model (code 10605) | Since 0.2.28 the request waits in Qoder's queue as Qoder's client does (below), then is sent again; since 0.2.62 a streamed request is answered 200 at once and kept alive with SSE comments for up to an hour, its outcome in the stream; past the wait, 503 with `Retry-After` from Qoder's `retryAfterSeconds` (30s when it gives none). Since 0.2.40, when magpie has another candidate after this request (`x-magpie-fallback: 1`), the 503 comes at once, saying the queue and how many are ahead, and magpie asks the next. The sign-in is untouched |
| Busy or queued for the model (code 10605) | Since 0.2.28 the request waits in Qoder's queue as Qoder's client does (below), then is sent again; since 0.2.62 a streamed request is answered 200 at once and kept alive with SSE comments for up to an hour (since 0.2.71, 5 minutes when the queue hasn't moved with nothing ahead), its outcome in the stream; past the wait, 503 with `Retry-After` from Qoder's `retryAfterSeconds` (30s when it gives none). Since 0.2.40, when magpie has another candidate after this request (`x-magpie-fallback: 1`), the 503 comes at once, saying the queue and how many are ahead, and magpie asks the next. The sign-in is untouched |
| A refusal of the request itself (codes 406, 416, 430, 80411, 80412, 100400–100403) | 400, with Qoder's words |
| "Error in upstream response", the model's own vendor behind Qoder failing, which Qoder sends as a 400 (since 0.2.24) | 502, so magpie asks again or another account; the sign-in is untouched |
| "Range of max_tokens should be [1, N]" behind "Error in upstream response" (since 0.2.63) | Asked again once with max_tokens N, which later requests for that model are sent from the start; refused again, 400 with Qoder's words, the sign-in untouched. QoDuck (`lmodel`) is never sent more than 131072, and a model whose listing entry names `max_output_tokens` never more than that; a smaller max_tokens goes as asked |
@@ -596,7 +596,13 @@ SSE comment saying the queue (": Qoder queued the request for smodel
on: a Codex client is told `response.in_progress`, the event its 300s idle
timeout counts, and a Chat client gets the comment. What comes of the wait
goes on in the same stream: the answer, or a refusal (the queue's own after
the hour) as the stream's error. Nothing needs setting. A request that isn't
the hour) as the stream's error. Since **0.2.71** a wait with nothing ahead of
the request (`queueCount` 1 or none) whose queue state comes back the same
at every ask for 5 minutes ends there, with the queue's 503 and "the queue
hasn't moved in 5 minutes with nothing ahead" (plugins#1220: Qoder CN held
such a RESOURCE_LIMIT queue unchanged, and the agent heard only
keepalives); magpie can then rest the account or ask the next. A queue with
others ahead is still waited out. Nothing needs setting. A request that isn't
streamed has nothing to keep its client alive with, so it still waits 4
minutes at most before the 503. Claude Code takes a ping as life only 30
times in a row, about 35 minutes, so a longer wait still ends there. Qoder's client also reports the end
+33 -3
View File
@@ -1735,6 +1735,15 @@ const QUEUE = {
// fail over from. A queued call answers its 10605 at once, and a
// thinking model streams its reasoning, so a real answer starts sooner.
silent: 120_000,
// the longest a wait goes on with nothing ahead of the request
// (queueCount 1 or none) and the queue's state the same at every ask.
// Qoder CN once held such a RESOURCE_LIMIT queue unchanged, 1 in p4,
// for every request from one hour on (plugins#1220): the hour's hold
// then left the agent with keepalives only. After this it is the
// queue's 503 with Retry-After, which magpie can rest the account on
// or fail over from. A queue with others ahead is waited out as
// Qoder's client waits it (#807).
stuck: 5 * 60 * 1000,
now: () => Date.now(),
// every calls fn each ms until the returned stop is called
every: (fn, ms) => {
@@ -1788,7 +1797,7 @@ function queueState(text) {
if (isQueued !== undefined || serviceAvailable !== undefined) {
const num = (v) => (v == null || v === "" || !Number.isFinite(Number(v)) ? undefined : Number(v))
const str = (v) => (typeof v === "string" && v ? v : undefined)
return { isQueued, serviceAvailable, modelKey: str(o.modelKey), queueType: str(o.queueType), retryAfterSeconds: num(o.retryAfterSeconds) }
return { isQueued, serviceAvailable, modelKey: str(o.modelKey), queueType: str(o.queueType), retryAfterSeconds: num(o.retryAfterSeconds), queueCount: num(o.queueCount), subCode: str(o.subCode) }
}
for (const k of ["data", "result", "message", "body"]) {
const v = o[k]
@@ -1820,13 +1829,25 @@ async function queueStatus(api, cred, { requestSetId, modelKey, queueType, reque
return st
}
// stuckKey is what a queue's state says of the request's place in it, or
// "" when others are ahead of it (a queue that moves while they are
// served is waited out, QUEUE.stuck never ends it).
function stuckKey(st) {
const n = Number(st?.queueCount)
if (Number.isFinite(n) && n > 1) return ""
return JSON.stringify([st?.isQueued, st?.serviceAvailable, Number.isFinite(n) ? n : null, st?.queueType ?? null, st?.subCode ?? null, st?.retryAfterSeconds ?? null])
}
// queueWait waits in Qoder's queue for the request, from the state its
// refusal gave, until the queue lets it through (true) or the wait ends
// (false). A cancelled request throws.
// (false). A wait ended by QUEUE.stuck sets ask.stuck. A cancelled request
// throws.
async function queueWait(api, cred, ask, first, signal, deadline, site) {
let q = first ?? {}
let asked = false
let failed = 0
let same = stuckKey(q)
let since = QUEUE.now()
for (;;) {
if (signal?.aborted) throw signal.reason ?? new DOMException("aborted", "AbortError")
if (QUEUE.now() >= deadline) return false
@@ -1845,6 +1866,14 @@ async function queueWait(api, cred, ask, first, signal, deadline, site) {
}
failed = 0
q = { ...st, modelKey: st.modelKey ?? q.modelKey, queueType: st.queueType ?? q.queueType }
const key = stuckKey(q)
if (!key || key !== same) {
same = key
since = QUEUE.now()
} else if (QUEUE.now() - since >= QUEUE.stuck && st.isQueued !== false) {
ask.stuck = true
return false
}
if (st.isQueued === false) {
if (st.retryAfterSeconds > 0) await QUEUE.pause(Math.min(queuePause(st.retryAfterSeconds), Math.max(0, deadline - QUEUE.now())), signal)
return QUEUE.now() < deadline
@@ -3858,7 +3887,8 @@ const makePlugin = (site) => async ({ client }) => {
onHeld(held.response)
}
try {
if (!(await queueWait(api, cred, ask, f.queue, signal, deadline, siteOf(site, cred)))) return errorResponse(f)
if (!(await queueWait(api, cred, ask, f.queue, signal, deadline, siteOf(site, cred))))
return errorResponse(ask.stuck ? { ...f, message: `${f.message} (the queue hasn't moved in ${Math.round(QUEUE.stuck / 60_000)} minutes with nothing ahead)` } : f)
} catch (e) {
return errorResponse({ status: 502, message: e?.message ?? String(e) })
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.70",
"version": "0.2.71",
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship, VPC and dedicated domains",
"type": "module",
"main": "./opencode.mjs",
+49
View File
@@ -412,3 +412,52 @@ test("the same request not streamed still waits 4 minutes at most, then the 503"
expect(res.status).toBe(503)
expect(pauses.reduce((a, b) => a + b, 0)).toBe(4 * 60_000)
})
// plugins#1220 (nsyan): Qoder CN answered 10605 at once with this state and
// gave it back unchanged at every status ask, 1 in p4 for RESOURCE_LIMIT,
// so an hour's hold left the agent with keepalives only. The reporter's
// own bytes, the inner message of the refusal and of each status.
const FROZEN = { errorCode: 0, isQueued: true, modelKey: "dfmodel", queueCount: 1, queueType: "p4", retryAfterSeconds: 60, serviceAvailable: true, subCode: "RESOURCE_LIMIT", waitTime: 60 }
test("#1220 a streamed wait with nothing ahead and the queue's state unchanged for 5 minutes ends with the queue's 503, saying it hasn't moved", async () => {
const { fetch, sent } = await loader({ chats: () => refused(FROZEN), statuses: () => status(FROZEN) })
const res = await fetch(API_CHAT, streamed())
expect(res.status).toBe(200)
const { lines } = await read(res)
const data = lines.filter((l) => l.line.startsWith("data:"))
expect(data.length).toBe(1)
expect(JSON.parse(data[0].line.slice(5)).error).toEqual({
message: "Qoder queued the request for dfmodel (this plan's queue: p4, 1 ahead); try again in 60s (the queue hasn't moved in 5 minutes with nothing ahead)",
code: 503,
})
expect(pauses.reduce((a, b) => a + b, 0)).toBe(QUEUE.stuck)
expect(QUEUE.stuck).toBe(5 * 60_000)
expect(sent.chats.length).toBe(1)
expect(timers.every((t) => t.stopped)).toBe(true)
})
test("#1220 a wait with nothing ahead whose state changes isn't cut at 5 minutes, and is let through when the queue says so", async () => {
// retryAfterSeconds moving: the queue is still counting down
const { fetch, sent } = await loader({
chats: (n) => (n === 1 ? refused(FROZEN) : answered()),
statuses: (n) => status(n <= 16 ? { ...FROZEN, retryAfterSeconds: 60 - n } : { ...FROZEN, isQueued: false, retryAfterSeconds: 1 }),
})
const res = await fetch(API_CHAT, streamed())
expect(res.status).toBe(200)
const { lines } = await read(res)
expect(lines.some((l) => l.line.includes("hello"))).toBe(true)
expect(pauses.reduce((a, b) => a + b, 0)).toBeGreaterThan(5 * 60_000)
expect(sent.chats.length).toBe(2)
})
test("#1220 a queue with others ahead, unchanged, is still waited out past 5 minutes (#807)", async () => {
const { fetch, sent } = await loader({
chats: (n) => (n === 1 ? refused() : answered()),
statuses: (n) => status(n <= 20 ? QUEUED : { isQueued: false, serviceAvailable: true }),
})
const res = await fetch(API_CHAT, streamed())
const { lines } = await read(res)
expect(lines.some((l) => l.line.includes("hello"))).toBe(true)
expect(pauses.reduce((a, b) => a + b, 0)).toBe(10 * 60_000)
expect(sent.chats.length).toBe(2)
})