From 3edbb18510e89a71c31364f7adb16e9c3e63539f Mon Sep 17 00:00:00 2001 From: Euraxluo Date: Mon, 19 Oct 2026 19:47:00 +0800 Subject: [PATCH] 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 --- packages/qoder/index.mjs | 5 ++--- packages/qoder/package.json | 2 +- packages/qoder/usage.test.mjs | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/qoder/index.mjs b/packages/qoder/index.mjs index 1d7bc80..77ed87e 100644 --- a/packages/qoder/index.mjs +++ b/packages/qoder/index.mjs @@ -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 diff --git a/packages/qoder/package.json b/packages/qoder/package.json index 85b0832..2b131fb 100644 --- a/packages/qoder/package.json +++ b/packages/qoder/package.json @@ -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", diff --git a/packages/qoder/usage.test.mjs b/packages/qoder/usage.test.mjs index 13554b6..8c339c3 100644 --- a/packages/qoder/usage.test.mjs +++ b/packages/qoder/usage.test.mjs @@ -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 }