From aa2d99bd13c68ffc117d5d7b7ad04c80c0eabd4c Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 10 Oct 2026 01:10:39 +0800 Subject: [PATCH] qoder 0.2.12: a chat Qoder refuses (401/403) keeps Qoder's own reason in the error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Yayoi_no_yume on X: a request made right after signing in came back "Qoder: the sign-in lapsed — sign in again" (401), and only installing and signing in to Qoder CLI made it work. failure() replaced whatever Qoder said with that fixed text, so the real reason for the refusal could not be seen. The message is the same, with "(Qoder said : )" added when Qoder gave one; the account is still left unmarked (X-Magpie-Sign-In: kept), as before. usage.test.mjs gains the case (a 401 whose body says why); it fails on 0.2.11 and passes. bun test (89 pass) and scripts/check.mjs qoder under a scratch HOME pass. Not tried against Qoder itself (no Qoder account here), so the cause of the reporter's 401 is not known yet. --- packages/qoder/index.mjs | 9 +++++++-- packages/qoder/package.json | 2 +- packages/qoder/usage.test.mjs | 8 +++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/qoder/index.mjs b/packages/qoder/index.mjs index a1df7b5..afbbb0a 100644 --- a/packages/qoder/index.mjs +++ b/packages/qoder/index.mjs @@ -708,8 +708,13 @@ function failure(status, text) { } catch {} msg ||= STATUS_CODES[status] ?? `HTTP ${status}` // a refused chat is the built-in's 401, which never marked the account - // lapsed: only a refused refresh did (errorResponse says kept) - if (status === 401 || status === 403) return { status: 401, message: "the sign-in lapsed — sign in again" } + // 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 + // sign-in, and its reason is what says what is (Yayoi_no_yume on X). + if (status === 401 || status === 403) { + const said = msg && msg !== STATUS_CODES[status] ? ` (Qoder said ${status}: ${msg.slice(0, 300)})` : "" + return { status: 401, message: "the sign-in lapsed — sign in again" + said } + } if (status === 429 || msg.toLowerCase().includes("quota")) return { status: 429, message: "usage limit reached: " + msg } return { status, message: msg } } diff --git a/packages/qoder/package.json b/packages/qoder/package.json index c980544..bf2d1b2 100644 --- a/packages/qoder/package.json +++ b/packages/qoder/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-qoder-auth", - "version": "0.2.11", + "version": "0.2.12", "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 16870de..13554b6 100644 --- a/packages/qoder/usage.test.mjs +++ b/packages/qoder/usage.test.mjs @@ -151,12 +151,18 @@ const ASK = { method: "POST", body: JSON.stringify({ model: "qmodel", messages: test("a refused chat, 401 or 403, is the built-in's 401 and leaves the account unmarked", async () => { for (const status of [401, 403]) { - const { fetch } = await chat(LISTING, () => new Response("nope", { status })) + const { fetch } = await chat(LISTING, () => new Response("", { status })) const res = await fetch(API_CHAT, ASK) expect(res.status).toBe(401) expect(res.headers.get("X-Magpie-Sign-In")).toBe("kept") expect((await res.json()).error.message).toBe("the sign-in lapsed — sign in again") } + // what Qoder says of the refusal is kept: a 401 just after signing in + // has some other reason, and only Qoder's words tell it + const said = await chat(LISTING, () => new Response(JSON.stringify({ message: "device not trusted" }), { status: 401 })) + const r = await said.fetch(API_CHAT, ASK) + expect([r.status, r.headers.get("X-Magpie-Sign-In")]).toEqual([401, "kept"]) + expect((await r.json()).error.message).toBe("the sign-in lapsed — sign in again (Qoder said 401: device not trusted)") // refused in the stream, before any answer: the same const sse = (v) => new Response(`data: ${JSON.stringify(v)}\n\n`, { headers: { "Content-Type": "text/event-stream" } }) const { fetch } = await chat(LISTING, () => sse({ statusCodeValue: 403, body: "" }))