qoder: Qoder's queue (code 10605) is a 503 to retry after its wait, not a lapsed sign-in (#98); 0.2.14

failure() turned every 401/403 into "the sign-in lapsed — sign in again".
Qoder answered every chat on a real trial account (2026-10-12) with
403 {"code":"10605","message":"{...\"retryAfterSeconds\":30,
\"serviceAvailable\":false...}"}: its queue for the model, while the same
token read the models and usage.

Codes are now read as Qoder's own client reads them (the QoderErrorCode
table in Qoder.app's qoder-agent-sdk worker), whatever the HTTP status:
- 10605, or a queue state with isQueued or serviceAvailable false: 503
  with Retry-After from retryAfterSeconds (30 when absent), no
  X-Magpie-Sign-In. magpie's gateway counts a 503 as busy and asks again
  after Retry-After (patience.go busy/noteBusy).
- 110, 112-119, 122 (usage/credits used up): 429.
- 406, 416, 430, 80411, 80412, 100400-100403 (refusals of the request): 400.
- 105 (loginExpired) or no code: the 401 as before.
Both the HTTP status path and the in-stream statusCodeValue path go
through failure(); errorResponse sends Retry-After.

Run: bun test (sandbox HOME) 1137 pass 0 fail; bun scripts/check.mjs ok.
busy.test.mjs uses the literal body as testdata; its 4 tests all fail
against the previous index.mjs and pass with this one. Not tried: a real
10605 after the change (the account's queue was open again by then: a
real chat on fast answered "ok"); the quota and request codes' HTTP
status from Qoder is not seen, only their meaning from Qoder's client.
This commit is contained in:
yetone
2026-10-12 21:22:50 +08:00
parent 04e188aaec
commit f573cfdcba
5 changed files with 133 additions and 9 deletions
+4 -2
View File
@@ -83,8 +83,10 @@ itself.
| What Qoder says | What the request returns |
|---|---|
| A refused sign-in | 401 |
| A quota | 429 |
| A refused sign-in (no code, or code 105) | 401 |
| A quota (codes 110, 112–119, 122) | 429 |
| Busy or queued for the model (code 10605) | 503, with `Retry-After` from Qoder's `retryAfterSeconds` (30s when it gives none); the sign-in is untouched |
| A refusal of the request itself (codes 406, 416, 430, 80411, 80412, 100400–100403) | 400, with Qoder's words |
| A failure before the answer starts | Qoder's status |
| A failure after the answer has started | The stream ends with an error |
+80
View File
@@ -0,0 +1,80 @@
// #98: Qoder's queue refusing a chat (code 10605) is Qoder being busy for
// the plan, not a lapsed sign-in. The body is the one Qoder gave a real
// trial account on 2026-10-12, byte for byte (testdata/queued-10605.json).
// The other codes are read as Qoder's own client reads them (QoderErrorCode
// in Qoder.app's qoder-agent-sdk worker): only 105 is loginExpired there.
import { afterEach, expect, test } from "bun:test"
import { readFileSync } from "node:fs"
import { QoderAuthPlugin, _internal } from "./index.mjs"
const QUEUED = readFileSync(new URL("./testdata/queued-10605.json", import.meta.url), "utf8").trim()
const real = globalThis.fetch
afterEach(() => (globalThis.fetch = real))
const API_CHAT = "https://api3.qoder.sh/v1/chat/completions"
const ASK = { method: "POST", body: JSON.stringify({ model: "efficient", messages: [{ role: "user", content: "hi" }] }) }
const LISTING = { chat: [{ key: "efficient", display_name: "Efficient", enable: true }] }
const json = (v) => new Response(JSON.stringify(v), { headers: { "Content-Type": "application/json" } })
const sse = (v) => new Response(`data:${JSON.stringify(v)}\n\n`, { headers: { "Content-Type": "text/event-stream" } })
// the loader's fetch against the listing and a chat reply; sets counts what
// the plugin wrote to the account
async function chat(reply) {
const auth = { type: "oauth", access: "jt", refresh: "rt", expires: Date.now() + 3_600_000, accountId: "one@x", uid: "u1", machineId: "m1" }
globalThis.fetch = async (url) => (new URL(String(url)).pathname.endsWith("/model/list") ? json(LISTING) : reply())
const sets = []
const hooks = await QoderAuthPlugin({ client: { auth: { set: async ({ body }) => sets.push(body) } } })
const l = await hooks.auth.loader(async () => auth)
return { fetch: l.fetch, sets }
}
const busy = async (res) => ({
status: res.status,
retryAfter: res.headers.get("Retry-After"),
signIn: res.headers.get("X-Magpie-Sign-In"),
message: (await res.json()).error.message,
})
const WANT = {
status: 503,
retryAfter: "30",
signIn: null,
message: "Qoder is busy for efficient (this plan's queue: p3); try again in 30s",
}
test("a 403 with Qoder's queue code 10605 is a 503 to retry after its 30s, the sign-in untouched", async () => {
const { fetch, sets } = await chat(() => new Response(QUEUED, { status: 403, headers: { "Content-Type": "application/json" } }))
expect(await busy(await fetch(API_CHAT, ASK))).toEqual(WANT)
expect(sets).toEqual([])
})
test("10605 in the stream, before any answer, is the same", async () => {
const { fetch, sets } = await chat(() => sse({ headers: {}, body: QUEUED, statusCodeValue: 403, statusCode: "FORBIDDEN" }))
expect(await busy(await fetch(API_CHAT, ASK))).toEqual(WANT)
expect(sets).toEqual([])
})
test("the queue's own wait is used, a queued request says so, and with no wait it is 30s", () => {
const q = (queue, code = "10605", status = 403) => _internal.failure(status, JSON.stringify({ code, message: JSON.stringify(queue) }))
expect(q({ isQueued: true, modelKey: "ultimate", retryAfterSeconds: 12.2 })).toMatchObject({
status: 503,
retryAfter: 13,
message: "Qoder queued the request for ultimate; try again in 13s",
})
expect(q({ serviceAvailable: false })).toMatchObject({ status: 503, retryAfter: 30 })
// the code alone, the message plain text
expect(_internal.failure(403, JSON.stringify({ code: "10605", message: "busy" }))).toMatchObject({ status: 503, retryAfter: 30 })
// a queue state under another status (429) is the same wait
expect(q({ serviceAvailable: false, retryAfterSeconds: 5 }, "", 429)).toMatchObject({ status: 503, retryAfter: 5 })
})
test("Qoder's other codes on a 403 aren't a lapsed sign-in either; 105 and no code are", () => {
const f = (code, message = "m") => _internal.failure(403, JSON.stringify({ code, message }))
for (const code of ["110", "112", "113", "114", "115", "116", "117", "118", "119", "122"])
expect(f(code, "credits used up")).toEqual({ status: 429, message: "usage limit reached: credits used up", signIn: "" })
for (const code of ["406", "416", "430", "80411", "80412", "100400", "100401", "100403"])
expect(f(code, "no")).toEqual({ status: 400, message: `Qoder refused the request (${code}): no`, signIn: "" })
expect(f("105", "login expired")).toEqual({ status: 401, message: "the sign-in lapsed — sign in again (Qoder said 403: login expired)" })
expect(_internal.failure(403, "")).toEqual({ status: 401, message: "the sign-in lapsed — sign in again" })
})
+47 -6
View File
@@ -720,19 +720,55 @@ function qoderBody(chat, m) {
return body
}
// failure is the status and message for a Qoder failure: a refused sign-in
// asks for another, a quota is a 429.
// failure is the status and message for a Qoder failure. Qoder's own code
// says what it is, read as Qoder's client reads it (QoderErrorCode in the
// app's qoder-agent-sdk worker): only 105 (loginExpired) is a lapsed
// sign-in there, so a 401/403 that carries another code isn't one here
// either (#98: a queued 10605 came as a 403 and read as "sign in again").
// A refused chat with no code keeps the built-in's 401, and a quota is a
// 429.
const QUEUED = "10605"
// the codes Qoder's client counts as a plan's usage or credits used up
const QUOTA_CODES = new Set(["110", "112", "113", "114", "115", "116", "117", "118", "119", "122"])
// refusals of this request, not of the account: sensitive content, not
// supported, input too long, too many media, a custom model's service
const REQUEST_CODES = new Set(["406", "416", "430", "80411", "80412", "100400", "100401", "100403"])
const BUSY_WAIT = 30
function failure(status, text) {
if (status < 400 || status > 599) status = 502
let msg = String(text ?? "").trim()
let code = ""
let queue
try {
const j = JSON.parse(text)
if (j?.message) msg = j.message
code = j?.code == null ? "" : String(j.code)
if (j?.message) msg = String(j.message)
// details is a JSON string, or the object itself (gjson reads either)
const d = typeof j?.details === "string" ? JSON.parse(j.details) : j?.details
if (d?.error?.message) msg += ": " + d.error.message
// the queue's state: the message itself, as a JSON string, or a field
queue = j?.queue && typeof j.queue === "object" ? j.queue : undefined
if (!queue && typeof j?.message === "string" && j.message.trim().startsWith("{")) {
const q = JSON.parse(j.message)
if (q && typeof q === "object" && ("isQueued" in q || "serviceAvailable" in q || "retryAfterSeconds" in q)) queue = q
}
} catch {}
msg ||= STATUS_CODES[status] ?? `HTTP ${status}`
// Qoder's queue for the model: busy for now, with when to ask again. The
// sign-in is fine (the same token reads the models and the usage), so it
// is a 503 with Retry-After, which magpie asks again after, and never
// touches the account's sign-in.
if (code === QUEUED || queue?.isQueued === true || queue?.serviceAvailable === false) {
const n = Number(queue?.retryAfterSeconds)
const wait = Number.isFinite(n) && n > 0 ? Math.ceil(n) : BUSY_WAIT
const model = queue?.modelKey ? ` for ${queue.modelKey}` : ""
const tier = queue?.queueType ? ` (this plan's queue: ${queue.queueType})` : ""
const what = queue?.isQueued === true ? "queued the request" : "is busy"
return { status: 503, message: `Qoder ${what}${model}${tier}; try again in ${wait}s`, retryAfter: wait, signIn: "" }
}
if (QUOTA_CODES.has(code)) return { status: 429, message: "usage limit reached: " + msg, signIn: "" }
if (REQUEST_CODES.has(code)) return { status: 400, message: `Qoder refused the request (${code}): ${msg}`, signIn: "" }
// a refused chat is the built-in's 401, which never marked the account
// lapsed: only a refused refresh did (errorResponse says kept). Qoder's
// own words go with it: a 401 right after signing in isn't a lapsed
@@ -747,11 +783,16 @@ function failure(status, text) {
// errorResponse is a failure as OpenAI's API gives it. signIn is what it
// means for the account (magpie's X-Magpie-Sign-In): a 401 keeps it unless
// told expired, since the built-in marked only a refused refresh.
const errorResponse = ({ status, message, signIn = status === 401 ? "kept" : undefined }) =>
// told expired, since the built-in marked only a refused refresh. retryAfter
// (seconds) is sent as Retry-After.
const errorResponse = ({ status, message, signIn = status === 401 ? "kept" : undefined, retryAfter }) =>
new Response(JSON.stringify({ error: { message, type: "qoder_error", code: status } }), {
status,
headers: { "Content-Type": "application/json", ...(signIn ? { "X-Magpie-Sign-In": signIn } : {}) },
headers: {
"Content-Type": "application/json",
...(signIn ? { "X-Magpie-Sign-In": signIn } : {}),
...(retryAfter > 0 ? { "Retry-After": String(retryAfter) } : {}),
},
})
// ---- the reply ----------------------------------------------------------------
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.13",
"version": "0.2.14",
"description": "Qoder subscriptions in OpenCode and magpie: Qoder (qoder.com) and Qoder CN (qoder.cn)",
"type": "module",
"main": "./index.mjs",
+1
View File
@@ -0,0 +1 @@
{"code":"10605","message":"{\"isQueued\":false,\"modelKey\":\"efficient\",\"queueCount\":0,\"queueType\":\"p3\",\"retryAfterSeconds\":30,\"serviceAvailable\":false,\"waitTime\":0}"}