From 2af72df71a57edc5126785c075af8f4e75355378 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 16 Nov 2026 14:58:12 +0800 Subject: [PATCH] workbuddy 0.2.36: a refused free window says 100% used with no made-up count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- packages/workbuddy/freewindow.test.mjs | 22 +++++++++++++++------- packages/workbuddy/index.mjs | 25 ++++++++++++++++++------- packages/workbuddy/package.json | 2 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/packages/workbuddy/freewindow.test.mjs b/packages/workbuddy/freewindow.test.mjs index 48d2456..37068f9 100644 --- a/packages/workbuddy/freewindow.test.mjs +++ b/packages/workbuddy/freewindow.test.mjs @@ -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) }) diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index fe6061a..76b8c60 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -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) } diff --git a/packages/workbuddy/package.json b/packages/workbuddy/package.json index 6f7088f..3974887 100644 --- a/packages/workbuddy/package.json +++ b/packages/workbuddy/package.json @@ -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",