qiankun229 traced it in agy's own logs (#1234): at Windows startup the
background usage read ran `agy -p /usage` with an ended access token and
a refresh token. agy's silent renewal failed for a moment (a 10s keyring
timeout, or "no such host" for oauth2.googleapis.com before the network
was up) and agy fell back to an interactive Google sign-in, which opens
the browser through ShellExecuteW past the BROWSER/PATH shims. The next
read renewed the same token fine. The stored-sign-in precheck passes such
a token, since it can be renewed.
- createUsageReader: when the stored access token has ended or ends
within two minutes and has a refresh token, fetchUsage reads with
`direct`: it runs `agy --version` only (no sign-in) and reads the quota
the way agy does (readQuotaDirect, loadCodeAssist then
retrieveUserQuotaSummary, with agy's User-Agent), renewing the token in
memory. agy's stored sign-in is never written. `agy -p` isn't run.
- A failed renewal is a failed read: it backs off as before and keeps
the sign-in. A network error says to check the network or proxy.
- Google answering the refresh with invalid_grant (400/401) is
kind "auth": the account reads as signed out ("Sign in again") and
nothing runs for that sign-in again until another is stored.
- A token with time left still goes through agy -p, as before.
Tests: three tests that leaned on an ended token only to get agy to run
now use a token whose end isn't said (as the existing "refreshing" test
does); what they check is unchanged.
Run (mote, HOME=$(mktemp -d)):
- test/usage.mjs (AGY_BRIDGE_STORED_SIGNIN=skip node --test): 41 pass.
- bun test agy-cli.test.mjs: 20 pass, 0 fail.
- bun scripts/check.mjs agy-cli: ok.
Broken by hand: origin/main's usage.mjs with the new tests: the three
new tests fail (agy -p ran for an ended token; no backoff/network
message; invalid_grant not auth), 38 pass.
Not tried: Windows with a real ended token and the network down at
startup (no agy account here: the local one answers 403); the requests
are the ones the region-refusal path has made since 0.1.7x.