workbuddy 0.2.36: a refused free window says 100% used with no made-up count

wsyfree on X: one of four WorkBuddy (China) accounts on the Routing page
read "deepseek-v4.1-flash token(估算) 200,000,000 / 200,000,000 · 已用
100%", and routing kept it for last. That is the card a WorkBuddy refusal
makes. A 429 whose named reset is still ahead, read from the ledger or a
routing trace (0.2.29), fills the window: card(win.cap, …) gave it the cap
as its count, under the "(est.)" name. The account is refused for the
model until the reset, and routing is right to keep it for last. But the
card showed a number nothing measured and called it an estimate, so it
read as magpie's estimate gone wrong.

The refused card now has no count. It shows used 100, the vendor's reset,
no amount, limit or display, and a name without "(est.)"
("deepseek-v4.1-flash tokens"; WorkBuddy AI keeps "Free model tokens").
The ledger estimate card is unchanged and still set aside, so routing
never stops an account on an estimate. Only the refusal stops one, as
before.

Run (on mote, HOME=$(mktemp -d)): packages/workbuddy bun test 383 pass,
0 fail; bun scripts/check.mjs exit 0, 59 ok.
Broken by hand: with index.mjs at 6514f69e, the four refused-card tests in
freewindow.test.mjs fail (China under the cap, the routing trace's reset,
accounts/models/builds apart, refused under the cap), 55 pass.
Not tried: the reporter's own ledger and routing trace, or a real refused
account. magpie needs i18n entries for the new name, and the mover's min
raised.
This commit is contained in:
yetone
2026-11-16 14:58:12 +08:00
parent 6514f69e62
commit 2af72df71a
3 changed files with 34 additions and 15 deletions
+15 -7
View File
@@ -235,12 +235,17 @@ test("a China account refused under the cap reads full", async () => {
cnRefusal("2026-11-02 19:17:02"),
]
const w = _internal.freeWindowOf(rows, "me@example.com", at("2026-11-02T12:00:00+08:00"), _internal.CN_ESTIMATED_WINDOWS[0])
expect(w.amount).toBe(2e8) // the rows sum to 80M
expect(w.used).toBe(100)
expect(w.refused).toBe(true)
expect(w.aside).toBeUndefined() // the vendor's word stops the model
expect(w.resetsAt).toBe(iso("2026-11-02T19:17:02+08:00"))
expect(w.display).toBe("200.0M / ~200M")
// the refusal says no count, and nothing in it is an estimate: no
// "200,000,000 / 200,000,000" under "(est.)" (wsyfree on X), the rows'
// 80M not passed off as the window's either
expect(w.name).toBe("deepseek-v4.1-flash tokens")
expect(w.amount).toBeUndefined()
expect(w.limit).toBeUndefined()
expect(w.display).toBe("")
})
// readLedgerTail stops the chain on both languages' edges: a Chinese refusal
@@ -296,7 +301,8 @@ test("a routing trace's failed WorkBuddy attempt pins the vendor reset", async (
writeFileSync(join(root, "routing", `${day}.jsonl`), routingTrace([routingRefusal("2026-11-02 19:17:02")]) + "\n")
const rows = await _internal.freeWindowRows("me@example.com", now, root, {}, join(root, "nohome"))
const w = _internal.freeWindowOf(rows, "me@example.com", now)
expect(w.amount).toBe(1e8)
expect(w.used).toBe(100)
expect(w.amount).toBeUndefined()
expect(w.refused).toBe(true)
expect(w.aside).toBeUndefined()
expect(w.resetsAt).toBe(iso("2026-11-02T19:17:02+08:00"))
@@ -358,7 +364,8 @@ test("a routing trace keeps accounts, models and builds apart", async () => {
now,
_internal.CN_ESTIMATED_WINDOWS[0],
)
expect(cn.amount).toBe(2e8)
expect(cn.used).toBe(100)
expect(cn.name).toBe("deepseek-v4.1-flash tokens")
expect(cn.refused).toBe(true)
expect(cn.resetsAt).toBe(iso("2026-11-02T19:17:02+08:00"))
} finally {
@@ -650,9 +657,10 @@ test("an account refused under the cap reads full, not 93%", async () => {
row("2026-10-18T19:52:04+08:00", { status: 429, err: `${TIMEOUT_BEFORE_RESET}2026-10-19 19:52:24 UTC+8, alternatively, you can switch to the other models to continue using it.` }),
]
const w = _internal.freeWindowOf(rows, "me@example.com", at("2026-10-18T23:00:00+08:00"))
expect(w.amount).toBe(1e8) // the rows sum to 92,792,962
expect(w.used).toBe(100)
expect(w.display).toBe("100.0M / 100M")
expect(w.used).toBe(100) // the rows sum to 92,792,962
expect(w.amount).toBeUndefined()
expect(w.display).toBe("")
expect(w.name).toBe("Free model tokens")
expect(w.resetsAt).toBe(iso("2026-10-19T19:52:24+08:00"))
expect(w.refused).toBe(true)
})
+18 -7
View File
@@ -2802,6 +2802,8 @@ const CN_ESTIMATED_WINDOWS = [
aliases: ["deepseek-v4.1-flash-sg"],
cap: 2e8,
name: "deepseek-v4.1-flash tokens (est.)",
// the card WorkBuddy's refusal makes: nothing in it is estimated
refusedName: "deepseek-v4.1-flash tokens",
short: "~200M",
// no unit: the name already says tokens, and magpie's narrow account
// cards cut a unit short ("tok…") beside the nine-digit numbers
@@ -2966,12 +2968,21 @@ function freeWindowOf(rows, account, now = Date.now(), win = FREE_WINDOW_AI) {
if (now >= end) return null // lapsed: nothing is exhausted, a new window opens on the next request
const card = (amount, resetsAt, refused) => ({
name: win.name,
used: Math.min(100, (100 * amount) / win.cap),
amount,
limit: win.cap,
unit: win.unit,
display: `${tokensShort(amount)} / ${win.short}`,
name: (refused && win.refusedName) || win.name,
// A refusal is the vendor's word that the window is spent, and says
// nothing of a count: the card says 100% used and when WorkBuddy said it
// resets, with no tokens. It used to say the cap as its count,
// "200,000,000 / 200,000,000" under "(est.)", a number nothing measured,
// which read as magpie's estimate gone wrong (wsyfree on X).
...(refused
? { used: 100, display: "" }
: {
used: Math.min(100, (100 * amount) / win.cap),
amount,
limit: win.cap,
unit: win.unit,
display: `${tokensShort(amount)} / ${win.short}`,
}),
resetsAt: new Date(resetsAt).toISOString(),
span: FREE_WINDOW_SPAN / 1000,
// the window's own model and the ids that share it, so magpie's exact
@@ -2993,7 +3004,7 @@ function freeWindowOf(rows, account, now = Date.now(), win = FREE_WINDOW_AI) {
if (!Number.isFinite(t) || t <= now || t <= start) continue
if (live === null || t > live) live = t
}
if (live !== null) return card(win.cap, live, true)
if (live !== null) return card(0, live, true)
return card(used, end, false)
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-workbuddy-auth",
"version": "0.2.35",
"version": "0.2.36",
"description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
"type": "module",
"main": "./opencode.mjs",