Files
magpie/internal
yetoneandggbdpq 59907fd554 claude: a /usage count of 401 or 403 is a count, not a denial (SCIYYDy, #4995)
SCIYYDy's Claude account closed /usage with the machine's own activity,
"Last 7d · 403 requests · 388 sessions", and magpie read the count of 403
as the HTTP status. parseClaudeUsage scans every line for
claudeUsageDenied before it reads the windows (account errors come first,
#4532), and the bare \b(401|403)\b in that regex cannot tell a statistic
from a status. So a whole reading with valid session and week windows came
back "told no allowance" and the card kept none. A count of 401 denies as
much.

The scan now skips a line that reads, whole, as one of /usage's count
lines ("Last <span> · N requests · N sessions", the numbers with or without
thousands commas, so "1,403 requests" is a count too). A line that says
more ("… · HTTP 403 Forbidden") is no count line, and a real 401
Unauthorized, 403 Forbidden or authentication failure still denies the
account, on its own line and beside the windows; the #4532 precedence
holds.

Sibling (review): a count line with no windows around it fell to the "no
usage figures" error, which quoted the panel's first line, so the error
text held "403". That error is matched with claudeUsageDenied again in
subscription_usage.go, quota_last.go and codex_switch.go, where it would
read as a denial after all. A counts-only panel now gets an error that does
not quote it, and the test asserts the error does not match
claudeUsageDenied.

Run on mote (macOS arm64, go1.26.8) at the pushed head, sandbox HOME:
go test -tags nogui -count=1 ./internal/provider/ ok (116s).
Broken by hand: without the count-line skip, the counts case is red ("told
no allowance: Last 7d · 403 requests"); with the patch's narrower regex
(no commas), the "1,403 requests" case is red.
Not tried: a real Claude account whose /usage shows 401 or 403 requests;
Windows and Linux.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 05:53:49 +08:00
..
…
…
…
…
…
…