Files
magpie/internal/provider/left_alone.go
T
yetone 9fa11784db provider: a provider's proxy and off switch are read from providers.json as parsed once
A live magpie's heap profile (v0.1.2404, 53 minutes) allocated 3.6 GB of
its 33 GB in provider.load, a parse of the whole providers.json, mostly
for one field of one provider: storedPicks (its proxy, 1.73 GB) and
leftAlone (switched off or hidden, 1.24 GB), asked for each request and
each background look, then customIDs, keptAs, loginSwitching and
accountRemoved.

These six only read, so they now go through storedFile: filememo's
parse of the file, kept until its time or size changes (and its bytes,
written in the last two seconds), and dropped by every write magpie
makes (writePrivate's Forget). A file missing or not decoding goes the
way load goes, to its last good generation. What load's other callers
get is unchanged, as some of them edit what they read before a save.

TestStoredParsedOnceUntilTheFileChanges: 30 providers of 100 models.
storedPicks and leftAlone with the file unchanged take under 40
allocations (a parse is 3381); a provider switched off since is left
alone at once; another process's edit of the same size is seen; a
zeroed file still finds its providers. Broken by hand: storedFile
parsing each time, red (3386 allocations); a broken file read as none,
red.

Run at this tree on mote: gofmt clean; go vet ./internal/provider on darwin, linux and windows; go test -count=1 -timeout 45m ./internal/provider (ok 116.0s) ./internal/gateway (ok 613.2s).
2026-11-01 00:43:15 +08:00

30 lines
1.1 KiB
Go

package provider
// A provider the user switched off (Provider.Off) or whose account they
// removed from magpie (Provider.Hidden) is left alone in the background:
// no CLI is asked who is signed in (`claude auth status`, `cursor-agent
// about`, `devin auth status`), no allowance is read, no sign-in renewed,
// no window warmed, no account switched, no daily check-in made and no
// model list fetched. What was last known of it is still shown. Each of
// those ran every minute or so for a Claude switched off, and a request
// made just as a proxy came back up after a restart went out on the
// machine's own address (Riko on Discord).
//
// One read is kept for Codex: the account it is signed in to, while it
// takes magpie's models, for whether the Codex app holds it
// (codexHoldReading), which decides where Codex sends at all.
// leftAlone says whether magpie leaves provider id alone in the
// background: switched off, or its account removed from magpie.
func leftAlone(id string) bool {
if id == "" {
return false
}
for _, p := range storedFile().Providers {
if p.ID == id && (p.Off || p.Hidden) {
return true
}
}
return false
}