TestSubscriptionUsageServesStale said "a stale copy comes back at once while it
refreshes" by timing the call: a 50ms ctx and a 40ms bound on time.Since(start).
On a loaded machine the bound is what fails -- the report has "waited
311.332917ms for a stale copy" -- so the test said nothing either way about the
guarantee it guards. Which step of the call took those 311ms I did not
establish; the assertion no longer needs to know, because nothing is timed.
The refresh is now held at the vendor instead: CopilotUserURL points at an
httptest server whose handler blocks until released, so the refresh cannot
finish. The copy is asserted to come back while SubscriptionUsageReading still
reports a refresh in flight, which is the guarantee itself rather than a proxy
for it, and <-reached proves a refresh really went out, so the test cannot pass
by never starting one.
The test also resets c.asked, the one field of the cache it primes that it had
left alone. It is not set when this test runs -- AskUsage is the only setter and
quota_asked_test.go's own restart clears it -- so this is not the reported
failure's cause; it completes what the test already does to c.data, c.at and
c.pending, so the test does not depend on another file's cleanup.
What was run:
gofmt -l internal/provider/subscription_usage_test.go (no output)
go test -tags nogui -count=1 -run TestSubscriptionUsageServesStale ./internal/provider
go test -race -count=20 -run TestSubscriptionUsageServesStale ./internal/provider
go test -tags nogui -count=1 ./internal/provider (whole package)
go vet ./... ; GOOS=linux go vet -tags nogui ./... ; GOOS=windows go vet ./...
go build ; GOOS=linux go build -tags nogui ; GOOS=windows go build
go test -tags nogui ./... (53 of 54 packages ok; internal/gateway reds only in
the parallel run, which this change cannot reach -- it does not compile this
file -- and which is filed already as #1543/#1544)
Without the change: with SubscriptionUsage's "if !have && pending != nil" broken
to "if have && pending != nil" -- a copy that has data waiting for the pending
refresh -- the new test fails with
subscription_usage_test.go:97: got [], want only claude: a copy that waited
for the held refresh comes back with nothing
--- FAIL: TestSubscriptionUsageServesStale (12.51s)
Reviewed and landed from nrenvo/magpie fix/1586-stale-copy-test (b5bda612),
posted on #1586 because PRs are collaborators-only. Run at the cherry-pick on
origin/main 398f8469b, temp HOME, caches pinned, load average ~120-135:
go test -tags nogui -race -count=50 -run 'TestSubscriptionUsageServesStale$' ./internal/provider ok
go test -tags nogui -race -count=20 -cpu 1,2 -run TestSubscriptionUsage ./internal/provider ok
go test -tags nogui -count=1 ./internal/provider ok 149.7s
go vet, GOOS=linux and GOOS=windows go vet -tags nogui ./internal/provider; gofmt -l clean
Broken by hand in SubscriptionUsage, two ways, each red:
"if !have && pending != nil" -> "if pending != nil" (a stale read waits for
the refresh, up to ctx): FAIL at :96, got [] (11.6s)
an unbounded <-pending for every read: FAIL at :96, got the Copilot card read
after the held refresh gave up (21s)
The Usage page's Copilot card was asked only when copilotLogin(cfg) found the
editors' or the standalone CLI's own GitHub sign-in
(~/.config/github-copilot/apps.json or hosts.json, else ~/.copilot/config.json).
An account signed in from magpie itself is kept in logins.json, and
copilotLogin never looks there: with no editor and no Copilot CLI signed in on
the machine, no Copilot allowance was fetched at all. The Usage page, the menu
bar's usage picker and the gateway's GET /v1/magpie/quotas had no Copilot card,
while `magpie accounts` did show one (that path reads copilotLoginList through
builtinLogins, login_usage.go) and quotas.json kept a fresh reading written by
it — the account was known and readable, only never asked where the page looks.
copilotLoginList() covers both the editors'/CLI's own account and the accounts
magpie signed in (copilot_accounts.go), and loginQuota resolves each account's
own token by user, so the fetch is scheduled from that list now, as Kiro's,
ZCode's, Qoder's, Zed's and WorkBuddy's already are. The single-account branch
this replaces called copilotSubscriptionUsage with the editors' token for the
same account, which perLogin reaches the same way.
TestCopilotQuotaWithoutEditorsSignIn fails without the change ("no Copilot
card: an account signed in from magpie alone was left out") and passes with it.
go vet ./internal/provider/ and the internal/provider package's tests pass.
A signed-in Claude Code is now offered as a provider (claude/…) like Codex
and Copilot. Anthropic classifies another agent's system prompt as
third-party traffic even over Claude Code's OAuth, so magpie drives the
real local claude binary for every generation: the caller's tools are
bridged in over MCP (magpie claude-mcp-helper), and tool results resume
the same Claude Code turn. Token counting is estimated locally so the
OAuth token takes no side path.
No model list is compiled in any more. The built-in catalog, preset
defaults and Claude Code's alias list are gone; the picker shows the
models.dev catalog (refreshed in the background when stale) layered with
each vendor's own /models answer, and signed-in accounts fetch theirs at
start-up. Whether a model rejects temperature/top_p now comes from
models.dev rather than a name prefix.
The gateway retries a Chat request on the Responses endpoint when the
model is Responses-only, and remembers that. Recent calls keep the first
256 KB of request and response bodies, viewable in the call list. The
Usage tab shows subscription allowances (Claude, Codex, Copilot) as the
vendors report them.