commandcode 0.1.19, devin 0.1.26, kiro 0.1.19: a refused sign-in marks the account signed out
blue12345655 (magpie Discord #help): a Command Code account signed in
through the plugin was signed out, and magpie offered no 重新登录, on
v0.1.1844 and still on v0.1.2021.
Cause: commandcode said X-Magpie-Sign-In "kept" on every answer and
signIn "kept" on every usage read, so a revoked key came back as a card
saying "Unauthorized" while magpie kept the account signed in, routed to
it, and never showed Sign in again on its rows. Devin and Kiro did the
same in their usage reads: their errors already said "sign in again",
but "kept" stops magpie from reading those words.
- commandcode: a usage read whose credits are refused (401/403), or a
request answered 401, asks /alpha/whoami; when whoami refuses the key
too, the usage says signIn "expired" with "Command Code's sign-in has
expired; sign in again", and the answer carries X-Magpie-Sign-In:
expired, its body unchanged. A 403 for a model the plan lacks, a 401
whoami still takes, and a whoami 500 keep the account. A clean usage
read says "renewed", which takes a mark off.
- devin: a usage read Devin answers 401 says "expired"; a clean read
"renewed"; other failures "kept". Requests unchanged.
- kiro: a usage read whose sign-in Kiro refused (the errors made by
gone) says "expired"; a clean read "renewed"; other failures "kept".
auth.refresh and requests unchanged.
The response bytes in commandcode/signed-out.test.mjs are what
api.commandcode.ai answered an unknown key on 2026-10-29 (whoami,
billing/credits, billing/subscriptions, provider/v1/chat/completions).
Run (WSL magpie-desktop, Bun 1.4.2, HOME=$(mktemp -d)):
- bun test in packages/commandcode: 82 pass, 0 fail; packages/devin:
142 pass; packages/kiro: 67 pass.
- bun scripts/check.mjs: every package ok.
Broken by hand: signed-out.test.mjs against the 0.1.18 index.mjs, 4 of
9 red (usage expired, clean read renewed, Provider API expired, Go
expired). kiro's and devin's changed usage tests against their old
index.mjs: red ("kept" received where "expired" expected).
Not tried: a real revoked Command Code, Devin or Kiro account; the
whoami check is only against an unknown key's real answers.
This commit is contained in:
@@ -415,6 +415,28 @@ function listError(text) {
|
||||
|
||||
// ---- the account --------------------------------------------------------------
|
||||
|
||||
// SIGNED_OUT is what a key Command Code turns away says, in the words
|
||||
// magpie reads as a sign-in gone (signInGone): the account is marked
|
||||
// signed out, the gateway passes over it, and its row offers Sign in again
|
||||
// (blue12345655 on Discord: a signed-out account stayed "signed in", its
|
||||
// card saying only "Unauthorized", with no way to sign in again).
|
||||
const SIGNED_OUT = "Command Code's sign-in has expired; sign in again"
|
||||
|
||||
// keyRefused says Command Code turns the key away for good: /alpha/whoami,
|
||||
// which answers every key it knows, refuses it (401 UNAUTHORIZED "Invalid
|
||||
// 'Authorization' header or token.", as every path answers a key it
|
||||
// doesn't know). Asked only after another path's 401 or 403, so a refusal
|
||||
// that is about a model or a plan, or a whoami that fails some other way,
|
||||
// leaves the account as it is.
|
||||
async function keyRefused(key) {
|
||||
try {
|
||||
await accountJSON("/alpha/whoami", key, 10_000)
|
||||
return false
|
||||
} catch (e) {
|
||||
return e.status === 401 || e.status === 403
|
||||
}
|
||||
}
|
||||
|
||||
async function accountJSON(path, key, timeout = 15_000) {
|
||||
const res = await fetch(API + path, {
|
||||
headers: { Authorization: `Bearer ${key}`, Accept: "application/json" },
|
||||
@@ -630,6 +652,9 @@ async function usage(key, saved) {
|
||||
])
|
||||
const sub = read ?? saved
|
||||
let out = { windows: [] }
|
||||
// a key whoami refuses too is signed out: said so, without the plan,
|
||||
// which is no longer the key's to tell
|
||||
if ((credits.e?.status === 401 || credits.e?.status === 403) && (await keyRefused(key))) return { out: { error: SIGNED_OUT, windows: [] }, gone: true }
|
||||
if (credits.e) out.error = credits.e.status ? statusText(credits.e.status) : credits.e.message
|
||||
else {
|
||||
// billing/credits leaves the plan out: the month of credits the pool
|
||||
@@ -643,7 +668,7 @@ async function usage(key, saved) {
|
||||
if (sub.until) out.until = sub.until
|
||||
if (sub.renew) out.renew = sub.renew
|
||||
}
|
||||
return { out, read }
|
||||
return { out, read, clean: !credits.e }
|
||||
}
|
||||
|
||||
// signedIn names a new key's account with whoami and reads its plan. Only
|
||||
@@ -1091,8 +1116,7 @@ function streamError(e) {
|
||||
}
|
||||
|
||||
// errorResponse is a failure as the built-in answered it, the account
|
||||
// kept: the built-in never marked a Command Code account lapsed, a 401 of
|
||||
// Command Code's among them.
|
||||
// kept (told then marks a 401 for a key whoami refuses).
|
||||
const errorResponse = ({ status, message, type }) =>
|
||||
new Response(JSON.stringify({ error: { message, type: type || "commandcode_error", code: status } }), {
|
||||
status,
|
||||
@@ -1108,6 +1132,16 @@ function kept(res) {
|
||||
return new Response(res.body, { status: res.status, statusText: res.statusText, headers })
|
||||
}
|
||||
|
||||
// told is an answer as kept gives it, but a 401 for a key whoami refuses
|
||||
// too says the sign-in expired, so magpie marks the account signed out and
|
||||
// offers to sign it in again. Any other 401 (a model, a plan) and every
|
||||
// other answer keep the account as the built-in did.
|
||||
async function told(key, res) {
|
||||
const out = kept(res)
|
||||
if (out.status === 401 && (await keyRefused(key))) out.headers.set("X-Magpie-Sign-In", "expired")
|
||||
return out
|
||||
}
|
||||
|
||||
// lines reads the reply a JSON object a line.
|
||||
async function* lines(body) {
|
||||
const dec = new TextDecoder()
|
||||
@@ -1375,10 +1409,10 @@ export async function CommandCodePlugin({ client, magpie } = {}) {
|
||||
} catch {
|
||||
return errorResponse({ status: 400, message: "a request that isn't JSON" })
|
||||
}
|
||||
if ((await planNow(key, saved)) === "Go") return kept(await generate(key, chat, init.signal, place, zdr))
|
||||
if ((await planNow(key, saved)) === "Go") return told(key, await generate(key, chat, init.signal, place, zdr))
|
||||
}
|
||||
// the Provider API's answer goes on as it came, the account
|
||||
// kept: the built-in neither marked one lapsed nor cleared it
|
||||
// kept, unless it is a 401 for a key whoami refuses (told)
|
||||
const body = chatting ? providerBody(chat) : undefined
|
||||
const res = await (body === undefined
|
||||
? fetch(input, { ...init, headers })
|
||||
@@ -1391,9 +1425,9 @@ export async function CommandCodePlugin({ client, magpie } = {}) {
|
||||
const text = await res.text()
|
||||
if (GO_NO_API.test(text)) {
|
||||
await isGo(key, (await getAuth()) ?? auth)
|
||||
if (chatting) return kept(await generate(key, chat, init.signal, place, zdr))
|
||||
if (chatting) return told(key, await generate(key, chat, init.signal, place, zdr))
|
||||
}
|
||||
return kept(new Response(text, { status: res.status, statusText: res.statusText, headers: res.headers }))
|
||||
return told(key, new Response(text, { status: res.status, statusText: res.statusText, headers: res.headers }))
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -1413,14 +1447,16 @@ export async function CommandCodePlugin({ client, magpie } = {}) {
|
||||
{ type: "oauth", label: "Command Code CLI's sign-in", authorize: cliSignIn },
|
||||
{ type: "api", label: "API key (commandcode.ai/settings/keys)" },
|
||||
],
|
||||
// magpie's: the plan and how much of it is used
|
||||
// magpie's: the plan and how much of it is used. A key Command Code
|
||||
// turns away marks the account signed out ("expired"), and a clean
|
||||
// read takes the mark off ("renewed": the CLI signed in again, its
|
||||
// new key read live); a read that fails otherwise leaves it as it is
|
||||
async usage(getAuth) {
|
||||
const auth = await getAuth()
|
||||
// signIn kept on each: the built-in's usage read never marked the
|
||||
// account lapsed nor cleared it
|
||||
if (auth?.type !== "api" || !auth.key) return { error: "not signed in", signIn: "kept" }
|
||||
const md = auth.metadata ?? {}
|
||||
const { out, read } = await usage(await liveKey(auth), md.plan ? { id: md.planId ?? "", plan: md.plan } : undefined)
|
||||
const { out, read, gone, clean } = await usage(await liveKey(auth), md.plan ? { id: md.planId ?? "", plan: md.plan } : undefined)
|
||||
if (gone) return { ...out, signIn: "expired" }
|
||||
// the plan read is saved with the key, so a start doesn't wait on
|
||||
// billing/subscriptions again, for the models, Go's endpoint or this
|
||||
if (read && (read.plan !== md.plan || read.id !== (md.planId ?? "")) && client?.auth?.set) {
|
||||
@@ -1428,7 +1464,7 @@ export async function CommandCodePlugin({ client, magpie } = {}) {
|
||||
await client.auth.set({ path: { id: ID }, body: { ...auth, metadata: { ...md, plan: read.plan, planId: read.id } } })
|
||||
} catch {}
|
||||
}
|
||||
return { ...out, signIn: "kept" }
|
||||
return { ...out, signIn: clean ? "renewed" : "kept" }
|
||||
},
|
||||
},
|
||||
async config(config) {
|
||||
|
||||
Reference in New Issue
Block a user