usage: a Claude account the vendor sends no 5-hour window for shows none (shangyuan0818 on X)
claudeWithUnstarted made up an unstarted 5-hour window for every whole /usage reading without one, so a Claude Ultra account that has none (the vendor sends none) still showed one in Usage. Anthropic leaves a window null until a request starts it, so an idle account and one with no such window read alike; the use tells. claudeNoFiveHour: an account whose week rose since a reading under five hours old, still with no 5-hour window, is one the vendor sends none for; the made-up window is then left out and stays out (read from the card kept on disk after a restart too) until a reading or header tells a real one. An account not yet seen used keeps the unstarted window as before (motui9535's idle Team accounts). The Usage page's Warm up button no longer shows for a Claude account read with windows but no 5-hour one: it has none to start. ChatGPT Pro 100 (prolite): codexWindows already shows whatever primary_window and secondary_window /wham/usage sends, named by limit_window_seconds, and no path filters by plan; the ChatGPT app reads the same fields. No prolite reply is available here, so no cause was found in magpie; asked the reporter for the reply. Run (on mica; mote's load was over its cores): TestClaudeNoFiveHour red on the old code (broken by hand: claudeNoFiveHour returning false) and green on the new; go test ./internal/provider -run Claude ok; gofmt -l clean; go vet darwin, linux, windows for internal/provider. GUI quota-warm.test.cjs 10 of 10 red with the old page.js, green on the new in chromium and webkit (all five languages, 390px and wider); warm-now, warm-reset-asleep, i18n-keys green in both engines. Full `go test ./...` -timeout 45m started on mica at this tree, not finished at push. Not tried: a real Ultra account without a 5-hour window. Not changed: the warm-up still sends such an account a request on its backoff (filed).
This commit is contained in:
@@ -741,14 +741,15 @@ function quotaWho(q) {
|
||||
// /api/warm-now {agent, user}), for this account. Idle is as the
|
||||
// warm-up tells it (idle in codex_warmup.go): nothing used and its reset a
|
||||
// whole window away, or gone by; or not read at all, which a Claude account
|
||||
// never used is, while a Codex account with no 5-hour window has none to
|
||||
// start. One just warmed reads the same for warmSlack, so it waits that out.
|
||||
// never read is, while an account read with no 5-hour window (a Codex
|
||||
// plan's, a Claude Ultra's, shangyuan0818 on X) has none to start. One just warmed reads the
|
||||
// same for warmSlack, so it waits that out.
|
||||
const quotaWarmed = new Map();
|
||||
function quotaWarm(q) {
|
||||
const agent = q.provider, user = q.user, key = agent + "\n" + user?.toLowerCase();
|
||||
if (!user || q.error || !(state.settings?.[agent + "Users"] || []).some((u) => u.toLowerCase() === user.toLowerCase())) return null;
|
||||
const w = q.windows?.find((x) => x.name === "5 hours"), now = Date.now(), at = w?.resetsAt ? Date.parse(w.resetsAt) : 0;
|
||||
if (w ? !(at && at <= now) && (w.used > 0 || at && at - now < 5 * 3600e3 - 600e3) : agent !== "claude") return null;
|
||||
if (w ? !(at && at <= now) && (w.used > 0 || at && at - now < 5 * 3600e3 - 600e3) : agent !== "claude" || q.windows?.length) return null;
|
||||
const busy = quotaWarmed.get(key);
|
||||
if (busy && busy !== true && now - busy < 600e3) return null;
|
||||
const b = el("button", "text acct-warm" + (busy === true ? " busy" : ""), t("Warm up"));
|
||||
|
||||
@@ -32,11 +32,13 @@ const quotas = [
|
||||
{ provider: "codex", name: "Codex", icon: "codex-color", plan: "Plus", user: "elsewhere@example.com", windows: [{ name: "5 hours", used: 0, resetsAt: iso(now + 5 * H) }] },
|
||||
// a Claude account never used: no window read
|
||||
{ provider: "claude", name: "Claude Code", icon: "claude-color", plan: "Max", user: "claude@example.com", windows: [] },
|
||||
// a Claude Ultra read with a week and no 5-hour window: it has none to start (shangyuan0818 on X)
|
||||
{ provider: "claude", name: "Claude Code", icon: "claude-color", plan: "Ultra", user: "ultra@example.com", windows: [{ name: "7 days", used: 12, resetsAt: iso(now + 72 * H) }] },
|
||||
];
|
||||
const WHY = "429 Too Many Requests: usage limit reached";
|
||||
|
||||
function serve(lang, asked) {
|
||||
const settings = { lang, theme: "light", currency: "usd", codexUsers: ["idle-account-with-a-long-name@example.com", "busy@example.com", "ran-out@example.com", "zero@example.com"], claudeUsers: ["claude@example.com"] };
|
||||
const settings = { lang, theme: "light", currency: "usd", codexUsers: ["idle-account-with-a-long-name@example.com", "busy@example.com", "ran-out@example.com", "zero@example.com"], claudeUsers: ["claude@example.com", "ultra@example.com"] };
|
||||
const state = { agents: [], profiles: [], settings };
|
||||
return async (r) => {
|
||||
const url = new URL(r.request().url());
|
||||
@@ -116,7 +118,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.ok((await idle.getAttribute("title")).startsWith(w.tip), await idle.getAttribute("title"));
|
||||
await warmOf(page, "Ran-Out@Example.com").waitFor();
|
||||
await warmOf(page, "claude@example.com").waitFor();
|
||||
for (const u of ["busy@example.com", "zero@example.com", "elsewhere@example.com"]) {
|
||||
for (const u of ["busy@example.com", "zero@example.com", "elsewhere@example.com", "ultra@example.com"]) {
|
||||
assert.equal(await page.locator(".subscription-account", { has: page.locator(`[title="${u}"]`) }).count(), 1, u + "'s line is there");
|
||||
assert.equal(await warmOf(page, u).count(), 0, u + " has no Warm up");
|
||||
}
|
||||
|
||||
@@ -62,6 +62,41 @@ func claudeWithUnstarted(ws []QuotaWindow) []QuotaWindow {
|
||||
return out
|
||||
}
|
||||
|
||||
// claudeNoFiveHour says whether the whole reading ws of an account, read at
|
||||
// now, is of one the vendor sends no 5-hour window for, so claudeWithUnstarted
|
||||
// must not make one up. Anthropic leaves a window out (null) while it hasn't
|
||||
// started, which is all an idle account's reading says, so it is the use
|
||||
// that tells: an account whose week rose since prev, read at prevAt less than
|
||||
// five hours ago, was used inside five hours, and one used so has a 5-hour
|
||||
// window running where its plan has one. prev with no 5-hour window at all
|
||||
// (the made-up one has no reset) stays so, as does the card kept on disk, until
|
||||
// a reading tells one (shangyuan0818 on X: a verified Ultra account has none).
|
||||
func claudeNoFiveHour(prev []QuotaWindow, prevAt time.Time, ws []QuotaWindow, now time.Time) bool {
|
||||
has := func(l []QuotaWindow) bool {
|
||||
return slices.ContainsFunc(l, func(w QuotaWindow) bool { return w.Name == "5 hours" })
|
||||
}
|
||||
if has(ws) || len(prev) == 0 {
|
||||
return false
|
||||
}
|
||||
if !has(prev) {
|
||||
return true // seen without one, and nothing since says it started
|
||||
}
|
||||
if prevAt.IsZero() || now.Sub(prevAt) >= 5*time.Hour {
|
||||
return false
|
||||
}
|
||||
week := func(l []QuotaWindow) (QuotaWindow, bool) {
|
||||
for _, w := range l {
|
||||
if w.Name == "7 days" && w.ResetsAt != nil {
|
||||
return w, true
|
||||
}
|
||||
}
|
||||
return QuotaWindow{}, false
|
||||
}
|
||||
a, ok1 := week(prev)
|
||||
b, ok2 := week(ws)
|
||||
return ok1 && ok2 && b.Used > a.Used && b.ResetsAt.Sub(*a.ResetsAt).Abs() < time.Hour
|
||||
}
|
||||
|
||||
// claudeHeard is how long what Claude Code said as it answered stands in
|
||||
// for the usage endpoint when that fails.
|
||||
const claudeHeard = time.Hour
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// shangyuan0818 on X: a verified Claude Ultra account has no 5-hour limit,
|
||||
// and the Usage overview still showed one. Anthropic leaves a window out
|
||||
// until a request starts it, so a reading of an idle account and one of an
|
||||
// account with no such window look alike; the one made up for an idle
|
||||
// account (claudeWithUnstarted) stays up only till the account is seen used
|
||||
// (its week rises) with none, and then stays down, across a restart too,
|
||||
// until a reading or header tells one.
|
||||
func TestClaudeNoFiveHourWindowNotMadeUp(t *testing.T) {
|
||||
reset := time.Now().UTC().Add(72*time.Hour).Format("Jan 2 at 3pm") + " (UTC)"
|
||||
week := func(used string) string {
|
||||
return "Current week (all models): " + used + "% used · resets " + reset + "\n"
|
||||
}
|
||||
out, card := claudeUsageCards(t, week("10"), nil)
|
||||
has5 := func(q SubscriptionQuota) bool {
|
||||
for _, w := range q.Windows {
|
||||
if w.Name == "5 hours" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
// idle: no way to tell, the account is taken to have one, not started
|
||||
if q := card(); !has5(q) {
|
||||
t.Fatalf("an account not seen used shows its 5-hour window unstarted: %+v", q.Windows)
|
||||
}
|
||||
// used, and still none: the vendor sends none
|
||||
out.Store(week("12"))
|
||||
retryClaudeUsage()
|
||||
if q := card(); has5(q) || len(q.Windows) != 1 {
|
||||
t.Fatalf("an account used with no 5-hour window shows one: %+v", q.Windows)
|
||||
}
|
||||
// idle again: still none
|
||||
retryClaudeUsage()
|
||||
if q := card(); has5(q) {
|
||||
t.Fatalf("a window the account hasn't came back while idle: %+v", q.Windows)
|
||||
}
|
||||
// a reading that tells one shows it
|
||||
out.Store("Current session: 3% used · resets " + time.Now().UTC().Add(4*time.Hour).Format("Jan 2 at 3:04pm") + " (UTC)\n" + week("13"))
|
||||
retryClaudeUsage()
|
||||
if q := card(); !has5(q) {
|
||||
t.Fatalf("a 5-hour window the vendor sent: %+v", q.Windows)
|
||||
}
|
||||
}
|
||||
@@ -1067,8 +1067,20 @@ func claudeWindows(ctx context.Context, user string, active bool) ([]QuotaWindow
|
||||
}
|
||||
return ws, err
|
||||
}
|
||||
// a whole reading: a window it leaves out hasn't started
|
||||
ws = claudeWithUnstarted(ws)
|
||||
// a whole reading: a window it leaves out hasn't started, unless the
|
||||
// account is seen used with none (claudeNoFiveHour)
|
||||
prev, prevAt := e.ws, e.at
|
||||
if prev == nil {
|
||||
if q, ok := lastReading("claude/" + key); ok {
|
||||
prev, prevAt = q.Windows, e.at
|
||||
if q.ReadAt != nil {
|
||||
prevAt = *q.ReadAt
|
||||
}
|
||||
}
|
||||
}
|
||||
if !claudeNoFiveHour(prev, prevAt, ws, now) {
|
||||
ws = claudeWithUnstarted(ws)
|
||||
}
|
||||
c.Lock()
|
||||
if c.m == nil {
|
||||
c.m = map[string]claudeUsageEntry{}
|
||||
|
||||
Reference in New Issue
Block a user