Commit Graph
8 Commits
Author SHA1 Message Date
yetone 94aa153973 tui, provider, serve: a signed-in account's models are fetched at start, so Routing offers Cursor's whole list without m (#1789, reyoung)
The terminal and `magpie serve` never called provider.FetchNew, which the
window calls at start: a signed-in Cursor account's list exists only at
Cursor, so the TUI's Routing pickers (and a headless gateway's /v1/models)
offered the fallback cursor/auto alone until the list was fetched by hand
with m on the Providers page.

- tui: Init fetches the new lists (fetchModelsCmd, alongside the catalog
  sync). A model picker open when they arrive (Routing members, the
  classifier, a provider's models, an agent's model field) is filled in
  place through its relist, keeping its filter and the model under the
  cursor. A list left missing (no network) is asked for again a minute
  later (modelsRetry). Built on reyoung's branch and test.
- serve: FetchNew at start, again each minute while a list is missing.
- provider: FetchNew reports whether a list is missing, and waits for a
  CLI asked who is signed in for the first time (awaitIdentities), then
  lists the accounts again. With the real Cursor account in a fresh
  sandbox, `cursor-agent about` answered after a look's 3s firstAsk, so
  FetchNew saw no Cursor account and `magpie serve` still listed 1 model
  with the TUI fix alone. The window's startBackend gets the same wait.
- docs: providers-accounts.md says who fetches the lists and when.

Run:
- internal/tui TestTUIFetchesSubscriptionModels (6 views) and
  TestTUIAsksAgainForAMissingList, -race x3; red with the Init fetch,
  the relist, the cursor restore or the retry tick each removed by hand.
  A first `about` slowed to 12s injected: passes (the test re-asks).
- internal/provider TestFetchNewWaitsForASlowSignIn: red without
  awaitIdentities (no provider "cursor"); TestFetchNewAccount covers the
  missing result.
- Real Cursor account, sandbox HOME with a keychain holding only Cursor's
  two items: TUI on main showed cursor/auto only in Routing; the fix shows
  the full list and "24 models" on Providers. `magpie serve`: main 1
  Cursor model at /v1/models, the fix 24 within 5s.
- gofmt -l, go vet (darwin, GOOS=linux, GOOS=windows), go test ./... in a
  sandbox HOME.

Not tried: Linux and Windows real Cursor CLIs (the fake CLI tests skip on
Windows); Devin's CLI identity goes through the same wait but wasn't
tried with a real account.
2026-10-12 20:49:41 +08:00
yetone 8c5b9f928d provider, agent, gui: subscription accounts can be turned off, and then no agent's sign-in is read (#1535, MaxHaiCom)
What changed: Settings → Privacy → Subscription accounts (On/Off),
`magpie accounts discovery [on|off]` and MAGPIE_NO_ACCOUNTS=1 turn off
account discovery. It stays on by default. While it is off, magpie reads
none of the agents' sign-ins: ~/.claude/.credentials.json, .claude.json's
account, ~/.codex/auth.json, Copilot's, Cursor's, Devin's, Kiro's,
Gemini's, ZCode's, Command Code's and OpenCode's files. It runs no
`security` / `secret-tool` for the Keychain or Secret Service, and asks no
agent CLI who is signed in. It serves no subscription. API-key providers,
middleware plugins and Pi extensions work as before.

Why: the reporter runs magpie on machines where reading other tools'
credentials isn't wanted. The owner delegated the call.

How: settings.NoAccountDiscovery (kept per computer by KeepOwn) and
settings.AccountDiscoveryOff(). The variable only ever turns discovery
off. The gates sit at every reader (readAccountFile, discoveryOff) and at
every route that reads or writes a sign-in, so a route that skips
Accounts still reads nothing:
- Accounts, All, Logins, usage, renewal, warm-up, session identities,
  check-ins;
- switching, forgetting, SetLoginOn, StartSignIn, the imports;
- moves onto plugins.
The ones that write refuse with an error that names how to turn it back
on. On the agent side, Agent.Source and OpenCode's auth.json are gated,
and Codex wiring goes by magpie's stash instead of auth.json, so a
toggle never rewires Codex. logins.json and plugin-auth.json are left
untouched and serve again when discovery is turned back on. A change
applies at once (ForgetAccounts).

Docs: providers-accounts.md, README (en, zh-CN), and the site's CLI table
(en, zh, ja).

Run:
- TestAccountDiscoveryOffReadsNoSignIn (provider) and
  TestAccountDiscoveryOffAgentsReadNoSignIn (agent). Every credential
  path is a FIFO that records each open, and security, secret-tool,
  claude, codex, cursor-agent, devin, kiro-cli, copilot and grok are fakes
  on PATH. Both fail with the gate removed: they show the opens and
  `security find-generic-password -s Claude Code-credentials`, among
  others. Both pass with the gate in place.
- TestAccountDiscoverySetting and TestAccountsDiscoveryCmd.
- account-discovery.test.cjs: chromium and webkit, 900 and 360 wide,
  en/zh/zh-TW/ja/de, 32/32. The neighbouring privacy, redact,
  settings-sections and i18n-keys GUI tests: 49/49.
- The full `go test -tags nogui ./...`, gofmt -l, and go vet for darwin,
  linux and windows on the touched packages.

Not tried: a real machine under fs_usage, and Linux and Windows at
runtime. The FIFO tests are !windows.
2026-10-11 06:38:40 +08:00
yetone 9c37723110 provider: a test binary keeps no CLI identity on disk, so a late ask can't write into the next test's folder (#1538, sibling of #1524)
TestDshHomePickSurvivesSyncAndEffort failed under full-suite load and
passed alone. The cause is cliIdentity: a look starts an ask of the CLI
(a failing testenv stand-in) and, once the answer is a minute old, a
refresh in a goroutine. keep() writes cli-identity.json under the
XDG_CONFIG_HOME current when it finishes, so an ask slow under load,
still going when its test ended, wrote into the config folder of the
test running then while t.TempDir's cleanup was removing it:
"TempDir RemoveAll cleanup: ... directory not empty".

4ee3a76b fixed this for internal/gateway alone (KeepCLIIdentities=false
in its TestMain). internal/agent, and every other package whose tests
read the accounts (., access, backup, davsync, gui, profile, sessions,
stats, tui, usage), still could. keep() now skips in any binary testenv
isolated (MAGPIE_TEST_SANDBOX, as internal/proc's sandboxVar reads it),
and the provider tests of the file itself turn keeping back on with
keepIdentities(t). The gateway's own switch and its test are gone;
TestCLIIdentityNotKeptInATestBinary covers every package.

Ran:
- Reproduced by injection (get refreshes on every look, 15ms sleep after
  c.ask()), agent Dsh tests -count=3: old code red 2 of 6 runs with the
  exact TempDir cleanup error; new code 0 of 6.
- Broke by hand (keepsIdentities() returns true):
  TestCLIIdentityNotKeptInATestBinary red, "written in a test binary".
- go test -count=1 ./internal/provider ./internal/agent ./internal/gateway: ok
- gofmt -l clean; go vet provider, agent, gateway on darwin,
  GOOS=linux -tags nogui, GOOS=windows: clean.
2026-10-11 03:28:48 +08:00
yetone 4ee3a76b7f gateway: a test's config folder isn't written into by a CLI identity asked behind its request (#1524)
TestEncodedBodyInflatedPastLimit failed under load at its TempDir cleanup
("unlinkat .../001/magpie: directory not empty"). The server wasn't the
writer: New() starts no goroutine, and httptest's Close waits for the
handlers. The writer is provider's cliIdentity. Reading the accounts
reads Cursor's and Devin's identity. In the gateway's tests, testenv's
stand-in cursor-agent and devin are on PATH, so their CLIs count as
installed. After the first answer, a look older than a minute asks the
CLI again in a goroutine and doesn't wait for it. When the stand-in
answers signed out, keep() writes cli-identity.json (MkdirAll, then a
temp file renamed in) under the XDG_CONFIG_HOME of whatever test is
running then. Under load the stand-in takes seconds, so the write lands
as that test's TempDir is removed.

Found by injecting a delay, not by rerunning. With get() refreshing at
every look and a 15ms sleep after the ask, a -count=3 run of
TestEncodedBodyInflatedPastLimit failed 3 subtests with the exact error
from the issue (/v1/responses/zstd, /v1/chat/completions/zstd,
/v1/videos/gzip). With this change and the same injection,
-count=5 of TestEncodedBody*, TestUnknownBodyEncodingRefused and
TestKeyLimitReservesDecodedBody passed.

provider.KeepCLIIdentities (default true) now decides whether the
answers are kept on disk. The gateway's TestMain turns it off, as it
already turns off keepRoutes for the same reason. Production doesn't
change. TestNoCLIIdentityKeptInTests goes red if TestMain leaves it on.
TestCLIIdentityNotKeptWhenOff checks that an answer is still served and
nothing is written.

The same pattern: every gateway test that calls New() and never stops it
was a suspect. Server has no Stop and New() starts nothing, so the pattern
itself is harmless; the background write was the cause wherever a
request looks at the accounts. provider's own tests still keep
identities on, since several of them test the file; they haven't failed
this way.

Run: go test -tags nogui -count=1 -timeout 40m ./internal/gateway
./internal/provider (ok); gofmt -l; GOOS=linux and GOOS=windows go vet
-tags nogui ./internal/gateway ./internal/provider.
2026-10-11 00:52:58 +08:00
yetone 1f14004676 provider: a CLI that fails to say who is signed in, or takes 5s or more, is asked again after 1, 2, 4… minutes up to 30, not every minute: a cursor-agent that calls itself no longer runs for 10s every minute (#1278, JJ-Lin)
Cursor's and Devin's sign-in is read from their CLIs (cliIdentity), asked
again behind what is served once the last answer is a minute old. A
cursor-agent that calls itself (an old ~/.local/bin wrapper running
`cursor agent`) never answers: each ask ran its 10s timeout and started
hundreds of processes, every minute magpie's pages or gateway read the
accounts. With no Cursor token kept, it still counted as an answer (nobody
signed in), so a "failed asks back off" rule alone would not have reached
JJ-Lin's case: an ask that takes slowAsk (5s) or longer backs off too. A
quick answer, or a sign-in or out (forget), has the CLI asked every minute
again. What is served is unchanged: a failed ask keeps it, a slow answer is
taken as before.

Verified:
- red without the change: TestCLIIdentityFailingAskedLessOften/fails and
  /slow both fail with "asked again a minute after the second"; pass with
  it (-race -count=3 with the other TestCLIIdentity tests).
- go test -tags nogui ./internal/provider/ in a sandbox HOME; go vet -tags
  nogui of provider for darwin, linux and windows.
2026-10-08 18:18:15 +08:00
yetone 2de043dabf provider: Cursor stays listed when cursor-agent can't say who is signed in (cataglyphis: 供应商选型中间歇无法显示 cursor,导致路由里不能正常路由到 cursor 的模型) — who Cursor's account is comes from cursor-agent about --format json, asked again behind the served answer every minute, and any about that failed, ran past its 10s (it asks Cursor's servers), or printed something besides its JSON was taken for nobody signed in: Cursor dropped out of the Providers page and of routing (All() lists the accounts for both), and that was kept on disk, until an ask a minute or more on came back. Now an ask that couldn't tell leaves what was served, on disk too, and is asked again in a minute (cliIdentity's ask returns an error for that); Cursor is taken as signed out only when about says so in its JSON or cursor-agent keeps no token. About's JSON after a line of its own (an update notice) is read too. Devin's ask is as before. Tested with fake cursor-agent scripts in a temp HOME (signed in, update notice, says nobody, fails, no JSON, fails with the token gone) and the cache through a failed ask and a sure sign-out; not tested against a real cursor-agent, and what made reporter's about fail isn't known 2026-09-28 21:02:48 +08:00
yetone 8ad73e8bfc accounts: a slow or hanging agent CLI no longer holds the providers page (#123) — its timeout now ends the call (a CLI that is a script running node left node holding the output, and the call waited for it however long, the 10s timeouts notwithstanding: a CLI's pipes are closed 2s after); a CLI never answered before is waited for 3s, once, then served as nobody signed in until its answer comes behind; and a CLI saying nobody is signed in is kept like any answer, where before it wasn't and every start waited for it again. Tried with cursor-agent and devin hanging 20s and the network black-holed: the first providers call went from 40.6s to 6s on a first start, and to 13ms on the next 2026-09-28 11:20:14 +08:00
yetone 0686bdffa7 accounts: a magpie just started no longer holds every page and request for cursor-agent and devin — who their CLIs say is signed in is kept on disk (cli-identity.json), served at once on the next start and asked again behind it; only a first look ever, or one after a sign-in or out, waits for the CLI. The window's first read went from ~4s to ~0.15s here with both signed in, and the gateway page shows its skeleton, not blank cards, while the state loads (#123) 2026-09-28 09:21:24 +08:00