devin 0.1.38: a slow model list doesn't hold up quota usage (#977)

yetihan's change (fixes #976). usage() asks GetCliModelConfigs in the
background (freeIDs/configsFor with wait=false), so a slow or timed-out
model list no longer holds back the day and week windows that
GetUserStatus already returned. Free models (notModels) are added, or the
"Free models" row says why the list couldn't be read, on a later usage once
the ask has settled. Other callers keep wait=true. The asks are shared
through c.asking, failures back off for RETRY (60s), and the ask's own
try/catch means a background failure never rejects.

Reviewed at 3920118d53e7c144d9e7d54bfe6dca6069611575.

Run (WSL magpie-desktop, Bun 1.4.2, fresh HOME):
- bun test packages/devin: 209 pass, 0 fail; bun scripts/check.mjs: exit 0
- the same after merging origin/main into the head: 209 pass, check exit 0
- Windows (xiaomi-gpu, fresh HOME/USERPROFILE): bun test packages/devin,
  209 tests, 0 fail, 9 skip
- probe (not committed): 10 usages with a list that never answers make 1
  GetCliModelConfigs fetch; a fetch that throws makes 1 fetch in 10
  usages, the row names the error, and there is no unhandledRejection

Broken by hand: restoring the blocking freeIDs/configsFor calls makes
"a slow model list doesn't hold up quota usage" fail at 1017ms ("usage
waited for GetCliModelConfigs"), and the edited "logged once" test hangs to
its 5s timeout. Restored, both are green.

Version: npm had 0.1.37 and origin/main's package.json had 0.1.37, so the
bump to 0.1.38 is right.

Known: a usage read on a cold host (a fresh `magpie quota refresh` process)
returns the windows without notModels until the list has been read once.
"with no word from Devin..." now passes without its 503 being read.

Not tried: a real Devin account; Devin's API wasn't contacted.
This commit is contained in:
zhou.han
2026-11-11 16:05:32 +08:00
committed by GitHub
parent 3b314dad1c
commit 2f8e65a131
3 changed files with 47 additions and 12 deletions
+39 -6
View File
@@ -47,11 +47,38 @@ test("Devin's Free tier is read from its model configs", () => {
test("a used-up day and week don't count SWE-2", async () => { test("a used-up day and week don't count SWE-2", async () => {
// both used up: JSON leaves the 0% left out // both used up: JSON leaves the 0% left out
serve(status()) serve(status())
const u = await (await DevinAuthPlugin()).auth.usage(async () => ({ type: "api", key: "key-free-usage" })) const plugin = await DevinAuthPlugin()
await plugin.provider.models({ models: {} }, { auth: { type: "api", key: "key-free-usage" } })
const u = await plugin.auth.usage(async () => ({ type: "api", key: "key-free-usage" }))
expect(u.windows.map((w) => [w.name, w.used])).toEqual([["1 day", 100], ["7 days", 100]]) expect(u.windows.map((w) => [w.name, w.used])).toEqual([["1 day", 100], ["7 days", 100]])
for (const w of u.windows) expect([...w.notModels].sort()).toEqual(SWE2) for (const w of u.windows) expect([...w.notModels].sort()).toEqual(SWE2)
}) })
test("a slow model list doesn't hold up quota usage", async () => {
const key = "slow-model-config-key"
let finishConfigs
serve(status(), () => new Promise((resolve) => (finishConfigs = resolve)))
const plugin = await DevinAuthPlugin()
const usage = plugin.auth.usage(async () => ({ type: "api", key }))
let timeout
let u
try {
u = await Promise.race([
usage,
new Promise((_, reject) => (timeout = setTimeout(() => reject(new Error("usage waited for GetCliModelConfigs")), 1_000))),
])
} finally {
clearTimeout(timeout)
}
expect(u.windows.map((w) => [w.name, w.used])).toEqual([["1 day", 100], ["7 days", 100]])
expect(u.windows.map((w) => w.notModels)).toEqual([undefined, undefined])
finishConfigs(new Response(realConfigs))
await _internal.freeIDs(key, "https://server.codeium.com")
const refreshed = await plugin.auth.usage(async () => ({ type: "api", key }))
for (const w of refreshed.windows) expect([...w.notModels].sort()).toEqual(SWE2)
})
test("with no word from Devin on its models, the day and week count every model", async () => { test("with no word from Devin on its models, the day and week count every model", async () => {
serve(status(), () => new Response("no", { status: 503 })) serve(status(), () => new Response("no", { status: 503 }))
const u = await (await DevinAuthPlugin()).auth.usage(async () => ({ type: "api", key: "key-free-unknown" })) const u = await (await DevinAuthPlugin()).auth.usage(async () => ({ type: "api", key: "key-free-unknown" }))
@@ -94,18 +121,24 @@ test("SWE-2 the account's list leaves out goes as SNAPSHOT's variant, not the ba
}) })
test("a model list Devin won't give is said in usage and logged once, not swallowed", async () => { test("a model list Devin won't give is said in usage and logged once, not swallowed", async () => {
serve(status(), () => new Response("no", { status: 503 })) const key = "key-free-error"
let failConfigs
serve(status(), () => new Promise((resolve) => (failConfigs = () => resolve(new Response("no", { status: 503 })))))
const logged = [] const logged = []
const was = console.error const was = console.error
console.error = (...a) => logged.push(a.join(" ")) console.error = (...a) => logged.push(a.join(" "))
try { try {
const plugin = await DevinAuthPlugin() const plugin = await DevinAuthPlugin()
const u = await plugin.auth.usage(async () => ({ type: "api", key: "key-free-said" })) const first = await plugin.auth.usage(async () => ({ type: "api", key }))
expect(u.windows.slice(0, 2).map((w) => w.notModels)).toEqual([undefined, undefined]) expect(first.windows.slice(0, 2).map((w) => w.notModels)).toEqual([undefined, undefined])
const note = u.windows.find((w) => w.name === "Free models") expect(first.windows.find((w) => w.name === "Free models")).toBeUndefined()
failConfigs()
await _internal.freeIDs(key, "https://server.codeium.com")
const second = await plugin.auth.usage(async () => ({ type: "api", key }))
const note = second.windows.find((w) => w.name === "Free models")
expect(note?.aside).toBe(true) expect(note?.aside).toBe(true)
expect(note.display).toContain("503") expect(note.display).toContain("503")
await plugin.auth.usage(async () => ({ type: "api", key: "key-free-said" })) await plugin.auth.usage(async () => ({ type: "api", key }))
} finally { } finally {
console.error = was console.error = was
} }
+7 -5
View File
@@ -3042,12 +3042,14 @@ async function usage(key, server, onStatus) {
} }
// with Devin's word on its models unread, which are free is unknown, so // with Devin's word on its models unread, which are free is unknown, so
// the day and the week count them all (a used-up quota then holds SWE-2 // the day and the week count them all (a used-up quota then holds SWE-2
// too): a row says so and why, instead of nothing // too). Ask in the background so a slow model list doesn't hide quota
// GetUserStatus already returned; a later refresh adds free models or
// says why the list couldn't be read.
if (out.windows.length) { if (out.windows.length) {
const free = await freeIDs(key, server) const free = await freeIDs(key, server, false)
if (free.length) for (const w of out.windows) w.notModels = free if (free.length) for (const w of out.windows) w.notModels = free
else { else {
const c = await configsFor(key, server) const c = await configsFor(key, server, false)
if (c.error && !c.at) out.windows.push({ name: "Free models", display: "unknown: Devin's model list couldn't be read (" + c.error + ")", aside: true }) if (c.error && !c.at) out.windows.push({ name: "Free models", display: "unknown: Devin's model list couldn't be read (" + c.error + ")", aside: true })
} }
} }
@@ -3065,8 +3067,8 @@ async function usage(key, server, onStatus) {
// may ask for them: each variant's own, and each entry of the list that // may ask for them: each variant's own, and each entry of the list that
// stands for free variants alone (swe-2 for swe-2-high, -medium and -max). // stands for free variants alone (swe-2 for swe-2-high, -medium and -max).
// None when Devin hasn't said. // None when Devin hasn't said.
async function freeIDs(key, server) { async function freeIDs(key, server, wait = true) {
const c = await configsFor(key, server) const c = await configsFor(key, server, wait)
if (!c.free?.size) return [] if (!c.free?.size) return []
const ids = new Set(c.free) const ids = new Set(c.free)
for (const m of listed(c.families ?? [], [], {}, c.free)) if (m.free) ids.add(m.id) for (const m of listed(c.families ?? [], [], {}, c.free)) if (m.free) ids.add(m.id)
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@magpie-community/opencode-devin-auth", "name": "@magpie-community/opencode-devin-auth",
"version": "0.1.37", "version": "0.1.38",
"description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie", "description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie",
"type": "module", "type": "module",
"main": "./index.mjs", "main": "./index.mjs",