qoder 0.2.19: a model list that can't be read is a 502, so magpie falls back (#249)

A failed read of Qoder's model list during a chat (DNS, timeout, an HTTP
refusal) now answers 502 instead of 400, so magpie retries and falls back to
the next member of a group instead of ending the request. A lapsed sign-in
met on that read answers 401 with the sign-in mark, as the chat path does.

Run at the reviewed head fcdf173e1 (on origin/main ff13aac):
- bun test packages/qoder: 139 pass, 0 fail
- bun scripts/check.mjs qoder: ok
- with index.mjs put back to main, the two changed tests go red (2 fail)
- magpie's passing() retries 502 and falls back (internal/gateway/fallback.go);
  no magpie parity test pins the old 400
This commit is contained in:
Euraxluo
2026-10-19 19:47:00 +08:00
committed by GitHub
parent ff13aac87d
commit 3edbb18510
3 changed files with 17 additions and 6 deletions
+2 -3
View File
@@ -1708,9 +1708,8 @@ const makePlugin = (site) => async ({ client }) => {
try {
m = (await models(cred)).find((x) => x.key === chat.model) ?? (await models(cred, true)).find((x) => x.key === chat.model)
} catch (e) {
// the built-in answered any failure to read the list 400
// (QoderModelOf), a refused one included, marking nothing
return errorResponse({ status: 400, message: e.message })
if (e instanceof SignInGone || e?.expired) return signedInError(e)
return errorResponse({ status: 502, message: e?.message ?? String(e) })
}
if (!m) return errorResponse({ status: 400, message: `unknown or disabled model "${chat.model}"` })
const CHAT_URL = siteOf(site, cred).api + CHAT_PATH
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.18",
"version": "0.2.19",
"description": "Qoder subscriptions in OpenCode and magpie: Qoder (qoder.com) and Qoder CN (qoder.cn)",
"type": "module",
"main": "./index.mjs",
+14 -2
View File
@@ -181,18 +181,30 @@ test("other refusals keep their status and say nothing of the sign-in", async ()
expect(_internal.failure(400, JSON.stringify({ message: "bad", details: { error: { message: "effort" } } }))).toEqual({ status: 400, message: "bad: effort" })
})
test("a model list Qoder won't give is a 400, as the built-in's QoderModelOf answered, the account unmarked", async () => {
test("a model list Qoder won't give is a 502, the account unmarked", async () => {
for (const status of [401, 403, 500]) {
const auth = { ...account(), machineId: "m1" }
globalThis.fetch = async () => new Response("no", { status })
const hooks = await QoderAuthPlugin({ client: { auth: { set: async () => {} } } })
const l = await hooks.auth.loader(async () => auth)
const res = await l.fetch(API_CHAT, ASK)
expect([res.status, res.headers.get("X-Magpie-Sign-In")]).toEqual([400, null])
expect([res.status, res.headers.get("X-Magpie-Sign-In")]).toEqual([502, null])
expect((await res.json()).error.message).toBe(`Qoder models: HTTP ${status}: no`)
}
})
test("a network failure fetching the model list is a 502 so magpie can fall back", async () => {
const auth = { ...account(), machineId: "m1" }
globalThis.fetch = async () => {
throw new Error("getaddrinfo ENOTFOUND api3.qoder.sh")
}
const hooks = await QoderAuthPlugin({ client: { auth: { set: async () => {} } } })
const l = await hooks.auth.loader(async () => auth)
const res = await l.fetch(API_CHAT, ASK)
expect([res.status, res.headers.get("X-Magpie-Sign-In")]).toEqual([502, null])
expect((await res.json()).error.message).toBe("getaddrinfo ENOTFOUND api3.qoder.sh")
})
// the loader's fetch for an account whose job token is due, the refresh answered by refresh()
async function due(refresh, fields = {}) {
const auth = { ...account(), machineId: "m1", expires: 0, ...fields }