provider, gui: a held vendor read is "not refreshed this time" too, and a card refresh answered under another account still shows (#1630 review)
Review of hhh2210's f1c1be3c (applied as the commit before this one,
unchanged, onto origin/main).
- keepLast marked a reading deferred only when the error equalled one of
the three "not read yet" sentinels. With allowances read only when asked,
most vendors' reads are stopped by holdUnasked inside the HTTP client, so
the error arrives wrapped ("Get \"https://…\": not read yet: …") and the
card still said "couldn't be read just now". readDeferred now matches the
sentinels inside the error; TestQuotaDeferredReadIsNotFailure has a
"held request" case for it.
- quotaRefresh applied only the card whose key matched the refreshed one.
A card first read without its account (no user) comes back under the
account's name, and its reply was dropped until the next whole-page read.
When the requested key isn't in the reply, the reply's list is taken as
before f1c1be3c. quota-refresh-order.test.cjs covers it.
Broken by hand:
- the patch's exact-equality check back: "held request" fails with
readDeferred = false, and the report check fails;
- ReadDeferred always false: saved / not asked / manual only / held
request fail;
- ReadDeferred dropped from quotaReport: "CLI/gateway report lost
readDeferred";
- fallback removed: "the refreshed card's reply was dropped";
- keepRefreshedQuotas call removed: both "older whole-page reply
overwrote the refreshed card" cases fail;
- asOfText's deferred wording removed: usage-card-refresh fails "a request
not made was described as failed" (chromium en/zh).
Run (worktree on origin/main, sandbox HOME, private GOCACHE):
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... clean; go build, GOOS=linux -tags nogui and
GOOS=windows builds ok.
- go test -tags nogui ./...: every package ok except internal/provider
TestCopilotSecretToolUsername ("token """, the 5s secret-tool bound
under load ~270, open as #1627); it passes alone -count=3. Nothing on
that path changed here.
- GUI, chromium and webkit: quota-refresh-order, usage-card-refresh (all five
languages), claude-usage-asked, quota-read-at, quota-reads,
quota-reading-again, usage-refresh, usage-refresh-flight,
usage-stale-answer, panel-usage, tray-usages, tray-usage-redraw,
usage-remote-cards, usage-quota-head, quota-balance-error, quota-holds,
usage-accounts, i18n-keys, gui-de, gui-ja, gui-zh-tw: all pass in both
engines. The whole GUI suite was not run.
Not tried: the native app with a real saved Claude account; the response
ordering is injected in tests.
This commit is contained in:
@@ -17129,6 +17129,10 @@ function quotaRefresh(q) {
|
||||
const kept = quotas || [];
|
||||
quotas = kept.some(x => usageAcctKey(x) === key) ? kept.map(x => usageAcctKey(x) === key ? fresh : x) : [...kept, fresh];
|
||||
quotasAt = Date.now();
|
||||
} else if (Array.isArray(qs)) {
|
||||
// The card came back under another key (an account first read
|
||||
// under its name): the reply's list is taken as it was before.
|
||||
quotas = qs; quotasAt = Date.now();
|
||||
}
|
||||
} catch (err) {
|
||||
status(err.message, "err");
|
||||
|
||||
@@ -88,3 +88,13 @@ test("a failed card refresh leaves background readings usable", async () => {
|
||||
assert.equal(p.cards()[0].windows[0].used, 32);
|
||||
assert.deepEqual(plain(p.errors), ["offline"]);
|
||||
});
|
||||
|
||||
test("a card that comes back under another key still shows the reply", async () => {
|
||||
// A card read before its account was known has no user; its refresh
|
||||
// answers under the account's name.
|
||||
const p = page(), unnamed = card("", 0);
|
||||
p.seed([unnamed]);
|
||||
const refresh = p.refresh(unnamed);
|
||||
p.answer(0, [card("a@x.com", 32)]); await refresh;
|
||||
assert.deepEqual(plain(p.cards()).map(q => [q.user, q.windows[0].used]), [["a@x.com", 32]], "the refreshed card's reply was dropped");
|
||||
});
|
||||
|
||||
@@ -40,6 +40,9 @@ func TestQuotaDeferredReadIsNotFailure(t *testing.T) {
|
||||
{"saved", errClaudeSaved.Error(), true},
|
||||
{"not asked", errClaudeNotAsked.Error(), true},
|
||||
{"manual only", errNotAsked.Error(), true},
|
||||
// holdUnasked stops the vendor's request itself, so the error
|
||||
// arrives wrapped by the HTTP client.
|
||||
{"held request", `Get "https://api.example.com/usage": ` + errNotAsked.Error(), true},
|
||||
{"rate limited", "HTTP 429 Too Many Requests", false},
|
||||
{"unavailable", errClaudeUsageUnavailable.Error(), false},
|
||||
{"network", "connection refused", false},
|
||||
|
||||
@@ -111,8 +111,7 @@ func keepLast(q SubscriptionQuota, user string) SubscriptionQuota {
|
||||
if !ok {
|
||||
return q
|
||||
}
|
||||
out.ReadDeferred = q.Error == errNotAsked.Error() || q.Provider == "claude" &&
|
||||
(q.Error == errClaudeNotAsked.Error() || q.Error == errClaudeSaved.Error())
|
||||
out.ReadDeferred = readDeferred(q.Error)
|
||||
out.Name, out.Icon, out.User = q.Name, q.Icon, q.User
|
||||
if out.Name == "" {
|
||||
out.Name, out.Icon = c.m[key].Q.Name, c.m[key].Q.Icon
|
||||
@@ -120,6 +119,20 @@ func keepLast(q SubscriptionQuota, user string) SubscriptionQuota {
|
||||
return out
|
||||
}
|
||||
|
||||
// readDeferred is whether err says no read was made this time (allowances
|
||||
// read only when asked, a Claude account's /usage not run) rather than a
|
||||
// read that failed. A read held back by holdUnasked fails inside the
|
||||
// vendor's HTTP call, so its error carries errNotAsked wrapped: "Get
|
||||
// \"https://…\": not read yet: …".
|
||||
func readDeferred(err string) bool {
|
||||
for _, e := range []error{errNotAsked, errClaudeNotAsked, errClaudeSaved} {
|
||||
if strings.Contains(err, e.Error()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// load reads the last readings from disk, the first time. Called with c
|
||||
// held.
|
||||
func (c *lastQuotasT) load() {
|
||||
|
||||
Reference in New Issue
Block a user