usage: opening the page on Requests or Sessions asks no vendor for allowances (#4064)

Opening Usage called quotasOpened() whatever tab it opened on, so a
switch to the page on its Requests or Sessions tab started an asked
read of every vendor's allowance and the allowance history beside the
tab's own read, and the frame the switch drew waited on all of it.
Only the Overview shows the allowances; it now alone asks for them.
Clicking the Overview subtab still asks (loadUsage(true)).

allowance-open-read: leaving the page on Requests and coming back past
the 30s gap asks no vendor and no history; clicking the Overview then
asks once.

Run on mote at this tree, rebased on origin/main 96115018c (its one
new commit, #4072, touches the gateway keys page and CSS only; the
list below ran again after that rebase):
- node --test allowance-open-read, claude-usage-asked, refresh-page,
  usage-refresh, usage-refresh-flight, usage-stale-answer, quota-reads,
  quota-refresh-order, usage-quota-head, usage-loops, i18n-keys
  (chromium and webkit, en and zh): pass 123, fail 0.
- go test -tags nogui -run Budget ./internal/gui: ok.
- Broken by hand (back to `if (asked) quotasOpened()`): the four
  allowance-open-read Usage-page runs go red, 5 !== 4.
- usage-ledger's 'newest live route needs no return-to-live button' is
  red in both engines, the same alone on a clean origin/main 11cbf4de1
  copy; filed as #3104 and #4078.

Not tried: part two of #4064 (Routing's frame loop while an agent
runs) is not in this commit.

Reported-by: xisdumpling (#4064)
This commit is contained in:
yetone
2026-10-28 23:00:55 +08:00
parent 96115018cf
commit ff6fdffd60
2 changed files with 23 additions and 3 deletions
+4 -1
View File
@@ -125,7 +125,10 @@ let usageRead = 0;
async function loadUsage(asked) {
renderUsageTab();
renderUsageEvery(); // the refresh's tooltip says what it reads on this tab
if (asked) quotasOpened();
// only the Overview shows the allowances: the page opened on another
// tab asks no vendor, nor reads their history, beside its own read and
// the page's way in (#4064)
if (asked && usageTab === "usage") quotasOpened();
if (usageTab === "sessions") return loadSessions();
if (usageTab === "requests") return loadLedger();
if (usageTab === "context") return window.loadContext?.();
@@ -32,7 +32,7 @@ function serve(lang, acct) {
return json([{ provider: "codex", name: "Codex", user: "a@example.com", plan: "plus",
windows: [{ name: "5 hours", used: acct.kept, resetsAt: "2030-01-01T00:00:00Z" }] }]);
}
if (url.pathname === "/api/usage/quotas/history") return json([]);
if (url.pathname === "/api/usage/quotas/history") { acct.hist++; return json([]); }
if (url.pathname === "/api/usage") return json({ calls: 1, input: 100, output: 10, cost: 0.01, series: [], agents: [], models: [] });
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
@@ -45,7 +45,7 @@ function serve(lang, acct) {
}
async function open(browser, t, surface, lang) {
const acct = { reads: [], kept: 10, vendor: 40, hold: null };
const acct = { reads: [], kept: 10, vendor: 40, hold: null, hist: 0 };
const errors = [];
const context = await browser.newContext({ viewport: surface === "panel" ? { width: 360, height: 640 } : { width: 1000, height: 760 }, reducedMotion: "reduce" });
t.after(() => context.close());
@@ -116,6 +116,23 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await shows(80);
assert.equal(asked(), m + 1, `the Overview picked asks: ${acct.reads}`);
// the page opened from the nav on the Requests tab asks nothing, nor
// reads the allowances' history (#4064)
await page.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
await nav("agents");
await page.clock.fastForward(31e3);
await settle();
const r = asked(), hist = acct.hist;
await nav("usage");
await page.locator("#ledgerPane").waitFor();
await settle();
assert.equal(asked(), r, `Usage opened on Requests asks nothing: ${acct.reads}`);
assert.equal(acct.hist, hist, "nor reads the allowances' history");
acct.vendor = 85;
await page.locator(":is(#usageTab .opt, .nav-s):visible").first().click();
await shows(85);
assert.equal(asked(), r + 1, `then the Overview picked asks: ${acct.reads}`);
// the timed refresh, left alone for minutes, never asks
const k = asked();
for (let i = 0; i < 4; i++) { await page.clock.fastForward(61e3); await settle(); }