Commit Graph
5774 Commits
Author SHA1 Message Date
yetone 5ebceee2da usage: the tool legend keeps each spelling's own kind (#2969)
Follow-up to ggbdpq's b2a8b74c7 (the tool list grouped case-blind).
That change put every spelling's calls in the legend under the kind of
the spelling seen first, so where two spellings have different kinds
("task" is Other, "Task" is Task) the Categories legend changed with
the order sessions were read in, and no longer matched the weeks
(pd.tools), which count each spelling under its own kind. The legend
now counts each call under ToolCategory of the name it was called by,
as before b2a8b74c7; only the Top rows merge. The tie-break comment
said "the shorter name", where the code takes the first in byte order.

TestToolUseMergesSpellings gains "the legend keeps each spelling's own
kind" ("task" 3 then "Task" 5: legend Task 5, Other 3). Broken by hand:
with b2a8b74c7's stats.go it is red ("categories [{Name:Other Calls:8
Sessions:2}]"), green with this.

Run at the pushed head on mote: go test ./... -timeout 45m on mote with this branch on 41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at 41b5c0f19 too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at 41b5c0f19 and here. Rebased on f856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased on bb478f0e5: agent and gateway ok, gui the same. The last rebase, onto 573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch.
2026-11-01 06:21:39 +08:00
ggbdpq 1c76095e97 usage: the tool list groups tools case-insensitively, as its summary does (#2969)
What changed
- toolUse now folds a tool's spellings into one row of the sessions'
  "Tool use" detail list: its calls and sessions are summed under one
  case-insensitive name, the row is shown by the summary's own spelling
  when the tool is its kind save for the case ("bash" as "Bash"), and by
  its most called spelling otherwise. A session that called both ways
  counts once.
- The summary's per-kind list ("Bash 2.2K") already merged the spellings,
  via ToolCategory; the detail list keyed its rows by the raw name, so
  the same tool read as two.

Why (issue #2969)
The card's left list split `bash` (1.4K calls, 20 sessions) from `Bash`
(779, 2), `read` (192, 15) from `Read` (123, 1) and `write` (64, 13) from
`Write` (56, 1), while the right legend showed one Bash 2.2K, Read 315,
Write 120 - the sums of each pair. Same card, two answers. The detail
rows now answer with the summary.

Run
- go test ./internal/sessions/ -run TestToolUseMergesSpellings: fails on
  the old code (the split above), passes on the new; a session that
  called `read` and `Read` counts once, and tools that only share a kind
  (two mcp__ tools) stay apart.
- go test ./internal/sessions/: ok.
- gofmt -l on the touched files: clean; go vet ./internal/sessions/: clean;
  go build ./...: ok.

Landed (yetone), at the pushed head on mote: go test ./... -timeout 45m on mote with this branch on 41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at 41b5c0f19 too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at 41b5c0f19 and here. Rebased on f856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased on bb478f0e5: agent and gateway ok, gui the same. The last rebase, onto 573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch. The next commit
keeps the legend's kinds per spelling.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 06:21:39 +08:00
yetone fcf87a7853 test(gui): four pages with a 5s default get the navigation's minute (#4622)
nav-timeout.test.cjs, the #4470 guard, is red on origin/main 41b5c0f19
on any machine, an idle one too. It is a scan of the test files, not
something that varies with load, which is how #4622 filed it. Four
files added since set setDefaultTimeout(5000) without the
setDefaultNavigationTimeout(60000) the guard asks for:
editor-quota-quiet (a9154b170), routing-moved-why (6b8261029),
sync-note-show (225b494be) and sync-own-fields (a511b11d8). Each gets
that one line, and nothing else changes.

Run at the pushed head on mote (load ~115):
- nav-timeout.test.cjs: red alone at 41b5c0f19, listing the four files;
  green with this.
- The four files, chromium and webkit, every language and width they
  draw: green, in one node --test run with the #3382 and #3484 files
  (13 files, 189 cases, 187 pass. The 2 reds are signin-proxy's webkit zh and zh-TW at 380px, red alone at origin/main 41b5c0f19 (#4643). internal/gui/assets is the same at 573b21f4b).
- go test ./... -timeout 45m on mote with this branch on 41b5c0f19: 83 packages ok. internal/gui is red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949), both red alone at 41b5c0f19 too, and on TestColdTurnsTaken (#4510). internal/update is red on TestRelaunchOpenTriedAgain (#3881). The last two pass alone at 41b5c0f19 and here. Rebased on f856d381a: agent, gateway, plugin, provider and sessions ok, gui red on #4514 and #3949 only, gofmt -l clean, go vet ok for linux (nogui), windows and darwin. Rebased on bb478f0e5: agent and gateway ok, gui the same. The last rebase, onto 573b21f4b, brings in only internal/gui/providers*.go and internal/provider/models.go, which this branch doesn't touch

Not tried: the whole GUI suite.
2026-11-01 06:21:39 +08:00
yetone 573b21f4b0 gui: the Providers answer is written a provider at a time
Each poll encoded /api/providers whole, growing json's buffer to the
answer's size once the GC had emptied its pool. writeProvidersJSON
writes the same bytes with each provider's row encoded alone, as
writeStateJSON does for agents; every handler that answered
writeJSON(rw, providersState()) uses it.

Real accounts (sandbox copy of the owner's HOME, network blocked), 40
polls, bb478f0e5 (mshare) vs this tree (mall):
  the providers write 37.7 MB (writeJSON, cum) -> 13.6 MB
  (writeProvidersJSON, cum)
  /api/providers equal but for `fetched` and `lapsed` (a refused
  refresh in the blocked sandbox); /api/state and drift identical

TestProvidersWrittenAsEncoded: the bytes are json.Encoder's for a big
answer, an empty list and none. TestProvidersWriteGrowsNoBufferItsSize:
under half the answer's size allocated per write. Broken by hand on
mote (writeJSON put back): "writing a 549015-byte answer allocated
2101096 bytes, want under half its size".

Run on mote at this tree: gofmt; go vet darwin and windows; the new
tests with TestStateWritten* 3/3 ok; go test ./internal/gui: the known
reds #4514, #3949 and TestColdTurnsTaken (#4510). GOOS=linux go vet of
internal/gui can't run here (Wails' Linux files need cgo; WSL has no
gtk4/webkitgtk-6.0); this change has no OS-specific code.
Not run: the full ./... suite.
2026-11-01 06:16:35 +08:00
yetone ce20d5658f provider: Catalog's list is made once with room for every entry
catalogKeeping cloned the groups' entries at their size and grew the
list by append for every provider's model, about twice the list it
gave. It is now made once with room for the groups and every entry.

Real accounts (sandbox copy of the owner's HOME, network blocked), 40
polls of /api/state, /api/providers and drift, pprof alloc_space
between two heap snapshots, bb478f0e5 (mshare) vs a build with this and
the next commit (mall):
  catalogKeeping flat 21.1 MB -> 13.5 MB, cum 23.7 MB -> 14.0 MB
  /api/state and drift bodies byte-identical, /api/providers equal but
  for `fetched` and `lapsed` (a refused refresh in the blocked sandbox)
  the total went 584 -> 613 MB, the rise in paths neither commit
  touches (providerInfoWith +16 MB, agentFields +9 MB): runs of the
  same build vary that much

TestCatalogMadeOnce: a 400-model provider, the catalog held; making it
allocates under 1.5x the list. Broken by hand on mote (the clone put
back): "a catalog of 595200 bytes allocated 1563137 to make".

Run on mote at this tree plus the next commit: gofmt; go vet darwin and
windows (provider, gui, agent); GOOS=linux go vet ./internal/provider
ok; the new test with TestCatalogKeptAcrossRequests and
TestCatalogForKeptAcrossPolls 3/3 ok; go test ./internal/provider ok
(118s); go test ./internal/gui: the known reds #4514, #3949 and
TestColdTurnsTaken (#4510, 0.00s; passes alone 3/3 and in the next
full gui run).
Not run: the full ./... suite.
2026-11-01 06:16:35 +08:00
yetone bb478f0e50 agent: a look that only ranges over magpie's models reads the list kept
magpieModels gives each caller its own copy of the list it keeps per
agent. Most callers only range over it, or count it, and a range copies
each model anyway, so the copy guarded nothing for them (the models'
own lists were shared before too: the copy was shallow). sharedModels
is the list kept, read only; every `range magpieModels(` and
`len(magpieModels(` in internal/agent (39 files) takes it. Callers that
keep the list, append to it or hand it on still get their copy.

Real accounts (sandbox copy of the owner's HOME, network blocked), 40
polls of /api/state, /api/providers and drift, pprof alloc_space
between two heap snapshots, 616405061 (mrows) vs this (mshare):
  stampedLists.get's slices.Clone 36.7 MB -> gone (under pprof's cut);
  most of it was piOffered (22.5 MB) and claudeViaMagpie (13.7 MB)
  total 637 MB -> 584 MB (runs vary +-25 MB)
  /api/state and drift bodies byte-identical, /api/providers equal but
  for `fetched` and `lapsed` (a refused refresh in the blocked sandbox)

TestModelReadersShareTheList: sharedModels gives the kept array, not a
copy, and no non-test file in internal/agent ranges over or counts
magpieModels(. Broken by hand on mote: sharedModels through get fails
"a shared look copies the kept list"; one `range magpieModels("kimi")`
put back fails naming kimi.go.

Run on mote at this tree (before rebase): gofmt; go vet for darwin,
windows and linux; the new test with TestMagpieModelsKeptWhileCatalogStays,
TestKeptListSharedWithoutACopy and TestViaMagpieKept 3/3 ok;
go test ./internal/agent ok (201s); go test ./internal/gui: only the
known reds TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949).
Not run: the full ./... suite.
2026-11-01 06:09:56 +08:00
yetone 616405061a gui: a provider row's models and agents are made once at their size
providerInfoWith grew a row's model list by append for the decision
models the vendor list lacks and for the picks it lacked, then grew it
again with slices.Insert to put those picks in front, and grew Agents
one append at a time. The rows are now counted first and each list is
made once at its size, in the same order as before.

Real accounts (sandbox copy of the owner's HOME, network blocked),
40 polls of /api/state, /api/providers and drift, pprof alloc_space
between the two heap snapshots, v0.1.2484 (mhost) vs this (mrows):
  providerInfoWith flat 50.7 MB -> 38.5 MB, cum 164.9 MB -> 138.8 MB
  providersState cum 273.2 MB -> 270.5 MB (the total is noisy +-25 MB
  from the state encoder's pooled buffers: 621 vs 637 MB)
  /api/state and drift bodies byte-identical; /api/providers equal
  but for `fetched` and one login's `lapsed`, set by a refused refresh
  in the blocked sandbox when a token came due during one of the runs
  (logins_on.go), a path this change doesn't touch.

TestProviderRowListsMadeAtTheirSize: 107 rows from 100 listed models,
7 picks the list lacks plus one it has, 3 agents; picks in front in
their order, cap == len for Models and Agents. On the old
providers.go (at HEAD) it fails: "models made for 219, 107 rows".
Forcing growth by hand in the new code fails it the same way.

Run on mote at this tree: gofmt, go vet, GOOS=windows go vet ok; the
new test and the model-order tests 3/3 ok; go test ./internal/gui:
only the known reds TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949) failed.
Not run: the full ./... suite.
2026-11-01 06:01:05 +08:00
yetone 5bfa9f0762 gateway: a group's backup gives the conversation back once the member listed ahead of it is ready again (01huadalang on Discord)
01huadalang on Discord, after 76e4494db: Codex on several accounts in a
group with mimo2.6pro as the backup, Stays on Auto. Once Codex had quota
again, requests kept going to mimo.

The cause: when Codex couldn't answer, the turn fell over to mimo and the
session was stuck to mimo. On the next turns affine kept it there by
"cache", because only In order had a way back (backToFirst, Why "order").
A Smart group (and the other routings) never gave the conversation back to
the member ahead, however long Codex had been ready.

The fix: at the answer, the gateway records whether the member that
answered stood in for one listed ahead of it in the group: one that was
resting, or known all but used up (Used >= SpentShareOf). planGroup now
gives each candidate its member and its place in the group (placed), and
standsInFor reads the plan made before the tries. The flag is the stick's
stoodIn, inherited while the same who and model keep answering, and saved
in affinity.json (stoodIn). With Stays on Auto, a stick that stood in goes
back to the group's first member once that one is ready and not set aside
(backFromStandIn), with the new Why "back" and its Routing page line in
all five languages. A member put first on its merits (not a stand-in)
keeps its cache as before; Off, Session, Strict, Turn and In order keep
their own rules.

Not changed, by design: Smart and Least used count a key with unknown
usage (mimo) as unused, so with every Codex account at 90% or more of a
window a new session can go to mimo first. In order keeps a backup last;
the routing doc says so.

Tests (internal/gateway/group_stand_in_test.go, new):
- TestGroupBackupGivesTheConversationBack: smart auto with usage known
  and unknown go back ("back"); in order auto "order"; in turn and smart
  turn "new-turn"; smart off "off"; smart session, smart strict and in
  order session stay on mimo.
- TestGroupBackupStandingInWhileTheFirstIsBackAndBehind,
  TestGroupMemberPutFirstOnItsMeritsKeepsItsCache,
  TestGroupStandInStaysWithinATurn, TestGroupStandInSurvivesARestart.
- affinity_fallback_test's TestGroupMemberKeepsTheConversationOnceAnother
  IsBack pinned the old behaviour; it is now
  TestGroupMemberGivesTheConversationBackOnceTheOneAheadIsBack.
- routing-affinity-order.test.cjs gains the "back" line.

Run, all on mote:
- With the non-test changes stashed (old code): both smart auto cases,
  StandingInWhileTheFirstIsBackAndBehind, SurvivesARestart and
  GivesTheConversationBackOnceTheOneAheadIsBack are red. Green with the fix.
- Broken by hand, each red: the "back" case off (smart cases,
  StandingInWhileBehind); no inherit (StandingInWhileBehind); rest/spent
  check off (usage-known case, StandingInWhileBehind); stoodIn check
  dropped from the back case (PutFirstOnItsMerits); StoodIn not loaded
  (SurvivesARestart). A check of failed tries stayed green when turned
  off, since a failed try rests what failed, so it was removed.
- go test -tags nogui -count=1 -timeout 45m ./... at 80bcef18f + this:
  every package ok except internal/gui, whose two reds are red on
  origin/main d714c4216 too: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514) and TestColdTurnsTaken (#4510).
- Rebased on 5a56bc7d7: internal/gateway, internal/provider and
  internal/catalog ok; internal/gui has only the same two reds (#4514,
  #4510). Main then moved three provider-only commits; at the pushed
  parent f856d381a, internal/provider ok and internal/gateway -run
  'Group|Affinity|Fallback|Ordered|Strict|Rotating|Stick' ok.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/gateway ok.
- GUI (Chromium and WebKit): routing-affinity-order, routing-js,
  i18n-keys, gui-zh-tw and gui-de pass; gui-ja's one red is #4580
  (a7b47d57e's string, not this one).
- Every routing-*.test.cjs file on mote (2050 tests, both engines, five
  languages) at load 140 to 200 from other sessions' suites: 35 red in 10
  files, all timeouts or moves under load. The same 10 files run alone,
  serially, at this head and at origin/main 41b5c0f19 are red in the same
  tests (27 and 30, differing only in which language flaked). All filed:
  #4585, #3789, #3096, #3094, #3799, #3412, #1804, #4560, #3593, #4082,
  #4627, #4628, #3954, #4629.

Not tried: no real Codex or MiMo account; the case was reproduced with a
fake upstream only. A stick saved before this change has no stoodIn, so a
conversation already stuck to the backup stays there until it goes cold
(5 minutes idle) or a new session starts.
2026-11-01 05:59:05 +08:00
yetone f856d381ac provider: Host finds the first protocol spoken without building a list
Host read Speaks' whole list to take the first protocol with an address.
IsBedrock, IsKilo, IsCline, IsOpenCode and IsBedrockMantle each ask Host,
for every provider on every poll. Building that list was 8 MB of what
twenty polls of the Providers page allocated with real accounts.

Speaks' rule now lives in speaking, an iterator. Speaks collects it, and
Host stops at the first protocol with an address. The order and the
Code Assist, Vertex and Gemini cases are unchanged.

Test: TestHostBuildsNoList. For six providers it checks that Host equals
the host of the first of Speaks() with an address (else Decide's), and
that a look allocates nothing. With range p.Speaks() put back by hand it
fails at 3 to 5 allocations a look.

Run on mote at this tree:
- gofmt, go vet, and GOOS=windows and GOOS=linux vet of internal/provider:
  ok.
- TestHostBuildsNoList, TestNoAPIFindsTheProvidersAPIsOnce, and the
  Speaks, Vertex and Gemini tests alone, 3 times: ok.
- Not run with this change: the whole ./internal/provider suite. It
  passed on mote with only the market commit, before this change was
  made.
2026-11-01 05:51:27 +08:00
yetone b19d085935 plugin: a plugin's market icon parses the cached list once per copy
Before the market is fetched, or with no network, plugin.Icon read the
cached plugin-market.json and parsed it whole for every look. The
Providers page looks once for each plugin's row on each poll: 13 MB of
what twenty polls allocated with real accounts.

The copy is now read through filememo.Read, which parses it again only
when the file changes. The built-in list is parsed once (sync.OnceValue).
Both are shared and only read.

Test: TestMarketIconParsesTheCopyOnce. It caches the built-in list as the
copy and allows at most 20 allocations a look. With the old ReadFile and
parseMarket put back by hand it fails at 260 allocations a look. It also
checks that a rewritten copy is read again and that with no copy the
built-in list answers.

Run on mote at this tree:
- gofmt, go vet, and GOOS=windows and GOOS=linux vet of internal/plugin
  and internal/provider: ok.
- TestMarketIcon* and TestMarketSources alone, 3 times: ok.
- go test -timeout 45m ./internal/plugin ./internal/provider: ok.
- ./internal/gui: TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners (#3949) fail, both already filed. Nothing else
  failed.
2026-11-01 05:51:13 +08:00
yetone 3a3bdb9f23 provider: IsOpenCode reads the host without parsing a URL
The Providers page asks IsOpenCode for each model of each provider, and
it parsed "//"+host with url.Parse each time: url.parse was 20 MB of what
20 warm rounds of drift, state and providers allocated with the owner's
real accounts, OpenCodeURL's share 7.5 MB.

openCodeAt takes the host as Host gives it: whatever is before the last
'@' aside, an IPv6 literal never OpenCode's, the port aside, then the
same openCodeHost check OpenCodeURL ends in.

Run on mote (mote-run, Go 1.26.8):
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestOpenCodeAtReadsTheHostAsAURLWould alone: ok. It checks openCodeAt
  against OpenCodeURL for 18 hosts (user info, ports, IPv6, a trailing
  dot, look-alikes such as opencode.ai@evil.com and opencode.ai.evil.com)
  and that a look allocates nothing.
- Broken by hand (openCodeAt answering through OpenCodeURL): red, "a look
  allocated 3 times, want 0".
- go test -timeout 45m ./internal/provider ./internal/gateway: ok
  (156s, 681s), at 606743831; this head is it rebased on main.

Real use: the owner's real-account sandbox, offline (proxy to :9), 20
warm rounds of /api/drift, /api/state and /api/providers, at this head:
- net/url.parse 20.5 MB -> 5 MB (what is left is openCodeGateway and
  others, not IsOpenCode); all allocated 371 MB -> 327 MB.
- /api/state and /api/drift bytes identical to 6a7a690be's (cmp);
  /api/providers differs only in each provider's "fetched" time.
2026-11-01 05:42:21 +08:00
yetone 5a56bc7d73 gateway: a CI job trades its OIDC token for a short-lived key (#4531)
xazaj on X asked for GitHub OIDC: a GitHub Actions job should get a
gateway key without a long-lived magpie key in the repository's secrets.

A rule (magpie gateway-key oidc add --key <id> --repo owner/name
[--ref …] [--environment …] [--claim k=v] [--ttl 1h] [--issuer URL]
[--audience a]; oidc list, oidc remove) names an issuer (GitHub Actions'
by default, any https issuer), an audience (magpie-<rule id> by default,
so a token asked for one rule opens no other, and the workflow needn't
know the gateway's address), claims (exact or path.Match globs) and the
gateway key the keys are issued under, which must be let issue. A GitHub
rule names the repository or its owner with no wildcard, or every
repository on GitHub could get in. No rule, no exchange.

POST /v1/magpie/keys/oidc with Authorization: Bearer <token> and an
optional {"ttl","models"} verifies the token (RS256 only, keys from the
issuer's discovery document's https jwks_uri, exp required, nbf/iat with
a minute's leeway, the rule's aud and claims, a jti traded once) and
issues a key through access.IssueKey under the rule's key, named
repo@ref (run N), living no longer than the rule. Everything issued keys
guarantee holds: bounded by the issuer's models and accounts, its spend
counted against the issuer, stopped when the issuer is turned off.

- A token is judged only against rules naming its iss, so it can't make
  magpie fetch from a URL of its choosing.
- Keys are cached an hour per issuer, read by one request at a time with
  no lock held across the fetch, asked again for an unknown kid at most
  every 10s, and kept while the issuer is down; with none ever read,
  nothing is let in.
- The route is lanGuard's one exemption from remoteKeyed (that exact
  path, POST, no gateway key): only while shared, past the allow list,
  and a refused token counts against tooManyAuthFails (429 past the
  burst). A read-only key is refused it.

The issue's open questions, decided: rules are generic from the start
(the GitHub repository rule applies to GitHub's issuer); rules are CLI
and file only for now (oidc-rules.json), no GUI.

Docs: docs/subsystems/gateway-routing.md (Trading an OIDC token for a
key, routes table) and site/public/docs remote in en, zh and ja, with
the workflow snippet.

Tests: TestOIDCTokenTradedForKey (no rule, a traded key that works on
chat with its TTL capped and its name, a model past the issuer, another
branch, no token, 51 bad tokens -> 429, issuer turned off, a token on a
model route, loopback, not shared -> 403); TestMatchEachCheck (14 bad
tokens, list aud, replay, the refusal naming the claims);
TestKeysCachedAndKept (8 concurrent tokens one fetch, rotation, a made-up
kid inside and past the gap, the issuer down 2h later, an unnamed issuer
never fetched); TestUnreadKeysLetNothingIn; TestAddRefuses;
TestGatewayKeyOIDCCLI; TestReadOnlyKeyEveryRoute with the new route.
A JWKS from an httptest TLS server, never the network.

Broken by hand, each red then restored: the signature check, the claims
match, the jti check, the exp check, the refetch gap, the GitHub scope
rule, the lanGuard exemption, the throttle and the TTL cap.

Run at this head (rebased on 6a7a690be), on mote: go test ./internal/oidc/...
./internal/cli (whole packages) and go test -run 'OIDC|ReadOnlyKeyEveryRoute|
KeysEndpoint|IssuedKey|AuthThrottle|Route' ./internal/gateway: ok; gofmt -l
clean. At the 13aa33eac base: go vet (darwin, GOOS=linux -tags nogui,
GOOS=windows): ok; node --test site/*.test.mjs: 63 pass.
Full suite (-tags nogui -timeout 45m ./...) on the Linux box at the
13aa33eac base, still running when this was pushed (mote had two other
sessions' suites at load 291); so far every package ok except
internal/agent's TestInstalledVersion, TestGrokInstalled,
TestCopilotFolderFromAnIDEPluginIsNotTheCLI and TestOmpDetectedWithPiDir,
the WSL box's fake-binary reds filed as #4033 and #3548. The rest of the
run goes on #4531.

Not tried: a real GitHub Actions run against a shared magpie; a
connection open when an exchanged key expires.
2026-11-01 05:39:02 +08:00
yetone 6a7a690be0 gateway: the Providers page's drawers come from the list it has
Each /api/providers poll asked gateway.Drawers for each provider's image
models, and Drawers read the provider's model list again (p.Available)
though providerInfoWith already had it in the kept Listing. In a
real-account heap profile (20 warm rounds of drift, state and providers)
Drawers was 14.4 MB of what was allocated.

DrawersOf takes the list as a func, called only on the paths that read
it (a Google sign-in's, a plugin's), and the Providers page passes its
Listing's Available, which is p.Available() kept (Provider.Listing).
Drawers itself is DrawersOf(p, p.Available) for every other caller.

Real use: the owner's real-account sandbox, offline (proxy to :9), 20
warm rounds of /api/drift, /api/state and /api/providers, at this head:
- Drawers 14.4 MB -> DrawersOf 3.1 MB.
- /api/state and /api/drift bytes identical to 6712e367e's (cmp);
  /api/providers differs only in each provider's "fetched" time.

Run on mote (mote-run, Go 1.26.8):
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestDrawersOfTheCallersList alone, 3 times: ok.
- Broken by hand (DrawersOf reading p.Available()): red, "drawers [],
  want gemini-3.1-flash-image alone".
- go test -timeout 45m ./internal/gateway: ok (669s). ./internal/gui:
  FAIL on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners (#3949), both red on main and filed. That run
  was at dd7442f28; this head is it rebased on 6712e367e (the stash and a
  Claude account-switch change, neither in gateway's draw path), built
  and run for the numbers above.
2026-11-01 05:35:21 +08:00
yetone 6712e367e8 agent: a look at the stash shares one read of it
Each /api/state and /api/drift poll asked the stash (stash.json) for one
value hundreds of times, through Detected, Drift and the agents' wiring
checks, and each ask read the file and parsed it again. In a real-account
heap profile (20 rounds of drift, state and providers) stashLoad was
24-34 MB of what was allocated.

stashShared reads it through filememo.Read, so every look shares one
parse until the file changes, by magpie or by another process. Every
read-only caller uses it now, the 24 files here and QwenPaw's
unstashPeek. stashLoad, which callers change and write back, still gives
each its own map, cloned from the same parse.

Real use: the owner's real-account sandbox, offline (proxy to :9),
20 warm rounds of /api/drift, /api/state and /api/providers:
- allocated 477 MB (d307aa648) -> 411 MB; stashLoad is out of the
  profile.
- /api/state and /api/drift bytes identical to d307aa648's (cmp).

Run on mote (mote-run, Go 1.26.8), at this head rebased on d307aa648:
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestStashLooksShareOneRead alone, 3 times: ok.
- Broken by hand (stashShared reading through stashLoad): red, "a look
  at the stash read and parsed it again".
- go test -timeout 45m ./internal/agent ./internal/gateway: ok (263s,
  691s).
2026-11-01 05:32:29 +08:00
yetone 41b5c0f19a accounts: Claude Code stays on the account it moved to till that is spent too (hxy920830 on X)
hxy920830 on X wants Claude Code to use one account to 98%, move to the
next and use that one to 98%, not jump back the moment the first resets.
No setting gave that. NextLogin (#408) signed the agent back in to the
first account as soon as it was under 90% again, under every routing.
KeepLogin pins one account, In order goes back too, and switch only
went back as well.

Where the sign-in is what spends the accounts (Claude Code, whose own
requests never pass the gateway, and Codex under switch only), the
sign-in now stays on the account it moved to until that one is spent
or fails, then moves on to the next ticked account with room. It goes
back to the first only where the user said the first comes first:
routing In order, or KeepLogin. Codex through the gateway keeps going
back, because Smart routing sends its requests to the first account
(#209) and the sign-in follows it. This is returnsToFirst in
codex_switch.go. The return record is still written, so turning In
order on later goes back as before. An old record is ignored otherwise,
and its "First again" label (logins.go) is hidden. No user setting is
overridden: In order and KeepLogin keep their meaning.

GUI: the Routing note for Claude Code (and Codex under switch only) now
says it stays on the account till that one is 98% used too. The two
switch-only tooltips no longer promise going back. New and changed
strings are in zh, zh-TW, ja and de. app.js lost a 3-line comment so
the core script budget holds without a raise (core 1,531,108 of
1,533,105).

Run on mote at 94cd5edde (base d307aa648):
- go test -tags nogui -count=1 ./internal/provider/: ok. New test
  TestSignInStaysOnTheAccountMovedTo (claude, claude switch only, codex
  switch only stay; claude in order goes back).
- TestCoreScriptBudget and the gui package's budget tests: ok.
- go vet -tags nogui ./internal/provider/ ./internal/gui/ with GOOS
  darwin, linux and windows: clean. gofmt -l: clean.
- GUI, Chromium and WebKit: account-return, switch-only,
  claude-switch-only, i18n-keys, keep-login, routing-signin, gui-zh-tw,
  gui-de, gui-ja. 116/117 and 64/65 passed. The one red is gui-ja's
  "{agent} three times" string, red on origin/main dd7442f28 too (#4580).
- Full suite at the earlier base 76c130b29, -timeout 45m: provider ok.
  Reds, all already filed: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), TestCodexListTagNotKeptOverAFreshFile (#4216),
  TestUnroutedRequestShownThenAnswered (#4200). TestCoreScriptBudget
  failed by 41 bytes, fixed above. internal/gui hit its 45m timeout in
  TestUpdateInATerminalRestartsTheAppWithoutCuttingIt.

Broken by hand: with returnsToFirst forced to true,
TestSignInStaysOnTheAccountMovedTo (all three staying cases) and
TestCodexSwitchOnlyStillSwitchesTheSignIn went red. With the note forced
back to the "back to the first" text, the new account-return GUI test
went red in Chromium en and zh.

Not tried: a real Claude account moving and its first renewing (needs
two real windows to run out), runs on the Windows and Linux boxes, and
the full GUI suite at this head.
2026-11-01 05:23:58 +08:00
yetone d307aa6485 gui: /api/state is written one agent at a time, for the page and the kept sum at once
Each poll of the Agents page encoded the whole state (1.3 MB with real
accounts) into json's buffer, and the GC between polls empties the pool
that buffer comes from, so it grew to the state's size again each poll:
48 MB of what twenty rounds allocated (v0.1.2477 build, real-account
sandbox), and 68 MB at v0.1.2463.

writeStateJSON encodes the state without its agents twice (as sent, and
as keepState keeps it, without the settings), and each agent once,
straight to the response and to keepState's sha256, through one encoder.
keepState is split so the handler hands it that sum (keepStateSummed).
When the splice can't be made (no agents, or a field put before
"agents"), it writes and sums the state whole, as before.

Measured on this Mac with the real-account sandbox (abr.sh, 20 rounds of
drift + state + providers):
- v0.1.2477: writeJSON under /api/state 48 MB, 511 MB in all.
- this change: writeStateJSON 15 MB, 477 MB in all. The /api/state
  bytes are identical to v0.1.2477's (cmp).

Run on mote (mote-run, Go 1.26.8):
- gofmt clean; go vet ok, also GOOS=windows.
- TestStateWrittenAsEncoded (same bytes as Encode, same sum as keepState,
  for a large state, an empty agent list and none) and
  TestStateWriteGrowsNoBufferItsSize, with TestKeptState* and TestLast*:
  ok 3 of 3.
- Broken by hand (the whole-state path always taken): red, "writing a
  1614586-byte state allocated 4207139 bytes, want under half its size".
- Not run before this push: the full internal/gui package; it runs next.
2026-11-01 05:12:20 +08:00
yetone 13aa33eac5 provider: CatalogFor is kept across polls until something it reads changes
Each /api/state poll and each Codex subagent list rebuilt an agent's
catalog from scratch. In a real-account heap profile (m2463, 20 polls)
CatalogFor and catalogKeeping were 69 + 36 MB of what was allocated,
and CodexSubagentModels' 39 MB came through the same call.

CatalogFor now goes through keptOf under "catalog-for\x00"+agent, so it
is rebuilt only when the stamp keptOf already watches changes. Callers
get their own clones of the shown and hidden lists, so a caller that
writes into them never reaches the kept copy or another caller.

Run on mote (mote-run, Go 1.26.8):
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestCatalogForKeptAcrossPolls alone: ok.
- Broken by hand (keptOf bypassed): red, "20 polls with nothing changed
  built the catalog 20 times, want 0".
- go test -timeout 45m ./internal/agent ./internal/gateway: ok.
  ./internal/provider: ok except this test's first version, which
  wrote s[0] before reading its ids; fixed, and it passes alone.
2026-11-01 05:00:54 +08:00
yetone 93879515a0 agent: QwenPaw, each of its agents' active_model one of magpie's (pkh1585 on Discord)
pkh1585 asked for QwenPaw (AgentScope, github.com/agentscope-ai/QwenPaw)
on Discord. Read in its source, 2.2.2.post1, as data:

- Its folder is QWENPAW_WORKING_DIR, else ~/.copaw when that exists (the
  old name), else ~/.qwenpaw; WORKING_DIR/.env is loaded without
  overriding the environment. config.json's agents.profiles lists the
  agents, each with a workspace_dir whose agent.json holds active_model
  {provider_id, model}, read again on each message.
- Providers are no plain config: SECRET_DIR (QWENPAW_SECRET_DIR, else
  "<WORKING_DIR>.secret") holds providers/{builtin,custom}/<id>.json,
  read once at start. A plain api_key there is encrypted to "ENC:" at
  start, so that is the place QwenPaw itself keeps keys.

What magpie does now:

- `magpie qwenpaw <model>` and the GUI: a row per QwenPaw agent
  (qwenpaw#<id>, the default one as plain qwenpaw), skipping agents whose
  backend is ACP (another CLI runs those) and agents turned off.
- Connecting writes providers/custom/magpie.json (mode 600, the gateway's
  /v1 and the magpie-qwenpaw key, magpie's models as extra_models with
  their window, output and tool use) and sets that agent's active_model
  to {magpie, <provider>/<model>}. The old active_model is stashed as it
  was and put back verbatim on disconnect, absent and null included.
  The provider file is removed only when no QwenPaw agent still uses it.
- A sync after QwenPaw re-saved the provider (encrypted key, discovered
  models, its own defaults) keeps what QwenPaw wrote and changes only
  what magpie owns, so a second connect leaves the file as it is.
- The notice says QwenPaw reads providers at start-up: restart it once
  after connecting and after magpie's models change. New text in every
  locale.
- appdir: QWENPAW_WORKING_DIR and QWENPAW_SECRET_DIR take ~/ as QwenPaw's
  expanduser does; agentenv clears them in tests.
- README (en, zh), docs/reference.md, agent-wiring.md, the site's agent
  list and start pages (en, zh, ja), icon.

Run:
- internal/agent's QwenPaw tests (Connect, AgentsAreRows, SyncKeeps-
  WhatQwenPawChanged, Check, NotStartedYet, Folders, OwnModelAfter-
  Magpies, SyncAfterQwenPawSaved, NullModelRestored) on mote, and the
  all-agent tests (applied, rewire, lan_kept, proxy_kept, spelled) with
  a QwenPaw fixture.
- Broken by hand, each red: always rewriting the key
  (SyncKeepsWhatQwenPawChanged), removing the provider while another
  agent uses it (AgentsAreRows), no backend filter (AgentsAreRows lists
  qwenpaw#coder), dropping the keep of QwenPaw's own fields
  (SyncAfterQwenPawSaved), IsObject for Exists (NullModelRestored).
- Real QwenPaw 2.2.2.post1 (Python 3.12 via uv) in a sandbox HOME on
  the Linux box (WSL magpie-desktop), magpie on 3741, a fake OpenAI
  upstream on 3742: first start wrote config.json and agent.json;
  `magpie provider add fake …`, `magpie serve`, `magpie qwenpaw
  magpie/fake/echo-1`; after a restart QwenPaw encrypted the key (ENC:)
  and `qwenpaw agents chat` answered "PAWPAW-OK from the fake upstream",
  its log "built agent … model=magpie/fake/echo-1"; the upstream saw
  /v1/chat/completions model echo-1 streamed, magpie's usage.jsonl
  agent qwenpaw status 200. A second connect and `magpie models` left
  the provider file unchanged. `magpie qwenpaw default` took
  active_model back out (the only diff in agent.json) and removed the
  provider; QwenPaw started clean after.
- gofmt -l clean; go vet darwin, GOOS=linux and GOOS=windows -tags nogui.
- Full suite on mote (go test -tags nogui -count=1 -timeout 45m ./...)
  at 9554883db on d714c4216: 84 packages ok, internal/gui red on
  TestSettingsSaveKeepsWhatItDoesNotSend only (SearchAll from
  b09349d17, red on main, #4514). Rebased onto 15066f84f (an appdir
  change among the four new commits): appdir, agentenv, agent,
  filememo, gateway ok again, gui the same #4514 red; vet darwin,
  linux and windows of agent, appdir, agentenv ok. Rebased again onto
  dd7442f28 (edit, provider and agent changes): edit, provider, agent,
  appdir, agentenv ok, vet linux and windows of agent ok. Rebased onto
  6a23d9d75 (606743831's registry-following agent variables, which
  QWENPAW_WORKING_DIR and QWENPAW_SECRET_DIR now follow as agentenv
  vars): appdir, edit, agentenv, agent ok, vet linux and windows ok.
  Rebased onto 61b536d78 (provider's model lists): agent, appdir ok.
- GUI on mote, the files this reaches (i18n-keys, gui-de, gui-ja,
  gui-zh-tw, agent-connect, agent-layout, agent-notice-lang, brand,
  builtins, desktop-lang, header-relang, icon-tile, icon-url):
  Chromium 103/104, WebKit 59/60, the one red each gui-ja's ja for
  removing an agent's only account (a7b47d57e, #4580). The whole GUI
  suite wasn't run: mote had three other sessions' whole GUI suites
  running (load ~130) and WSL one more.

Not tried: Windows, the macOS desktop app, QwenPaw in WSL wired from
Windows magpie, the ACP backend, QwenPaw's web console after connecting,
a real legacy ~/.copaw.
2026-11-01 05:00:36 +08:00
yetone 61b536d788 provider: MemberGroups and GroupKept are built once while a request holds
The providers' page asked MemberGroups for each provider and GroupKept
for each model, and each call built the groups again from every
provider's entries: 11.6 MB of what twenty window polls allocated with
real accounts (m2463 profile). Both now go through heldFrom, as the
other catalog reads do: built once per Hold, kept across requests
while the stamp stays, shared and only for reading.

Test: TestMemberGroupsBuiltOnceWhileHeld. 20 looks under one Hold,
each asking MemberGroups 12 times, build it once at most; a group
saved after (g5) is in the next look.

Run on mote, at this tree on dd7442f28:
- gofmt, go vet (darwin, windows, linux): ok
- the new test with TestUnlistedGroupKept, 3 times: ok
- broken by hand (MemberGroups built afresh each call): red, "20
  looks under one Hold built the member groups 20 times, want 1 at
  most"
- go test ./internal/provider: ok. TestModelSpecWinsOverTheListAndASync
  was red once in the run before (with only the test's assertion
  since fixed) and ok alone 3 times and in this run: #4637
- go test ./internal/gui: every test ok except the known
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners (#3949)

Not run: an A/B with the real-account sandbox for this change alone.
2026-11-01 04:53:36 +08:00
yetone 323159f1cc usage: a Codex reset's confirmation picks which of the account's resets is used (01huadalang)
01huadalang on Discord: resets were used only automatically, or by hand
the one that runs out first. Which account was already the user's to pick
(each account's card has its own Use); which of its resets was not.

- Usage card's "Use a reset" and the menu bar panel's "Use one...": when
  the account holds two or more resets listed with their ids, the
  confirmation has a "Reset to use" pop-up (the app's menu, not <select>),
  soonest first and picked unless another is. Once another is picked it
  names the account and that reset ("The one used is me@'s reset that
  runs out ..."), and says the sooner one is kept and lost if unused.
  Escape closes the open menu first, not the confirmation.
- POST /api/usage/codex-reset takes an optional credit. The server reads
  the account's resets again and spends that credit only if it is still
  held; a gone one is refused and no other is spent in its place. With no
  credit it is as before (the soonest). Auto-use is unchanged.
- ResetCard carries the credit id; `magpie quota reset --card n` is the
  CLI's sibling, its prompt naming the reset.
- askReset's dialog moved out to resetask.js, imported when Use is
  pressed (like signsheets.js), so the core's scripts are 1,530,733 bytes,
  under the 1,533,105 budget with no raise (the pick alone took it 2,068
  over). Five keys in zh, zh-TW, ja, de.

Run on mote (mote-run), at the base 2597c9636:
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... ok.
- go test -tags nogui ./internal/provider ./internal/cli ok;
  ./internal/gui: only TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestColdTurnsTaken (#4510) red, both filed and the same on main;
  TestCoreScriptBudget ok after the move.
- GUI, Chromium and WebKit, 78/78 each: reset-pick-card (new: en, zh,
  zh-TW, ja, de; Usage at 900 and 390px, panel at 440px), codex-resets-used,
  account-every-reset, codex-reset-lead, reset-each-title, reset-providers,
  reset-reminder, panel-usage, old-webkit, i18n-keys, codex-auto-reset,
  codex-auto-reset-settings, warm-reset-asleep, quota-credits,
  usage-accounts.
- Red on the old code: reset-pick-card against origin/main's assets fails
  at "an account with three resets offers the pick"; TestUseCodexResetCard
  and TestCodexResetsCounted fail without the change.
- Broken by hand, each red then restored: the chosen credit ignored
  (spent [soon]); the held check skipped (a used credit spent); ids dropped
  from each; the credit left out of the POST; the Escape guard removed.

Again at the pushed head (rebased on 88372a39d): go vet ./... ok;
provider, cli ok; gui only #4514 red (TestColdTurnsTaken passed this
time); reset-pick-card, old-webkit, i18n-keys in Chromium 15/15.

Not run: the full go test ./... and the whole GUI suite. mote had two to
three other full Go suites and several whole GUI suites running the whole
time (load 120 to 250), and the WSL box too; one suite per machine.
Not tried: a real account's reset spent (none was, by design: fakes only),
so that Codex's consume takes a credit_id other than the soonest is
inferred from it being the same field the soonest is sent in.
2026-11-01 04:51:55 +08:00
yetone 9bb1efdde3 gateway: a reply names the model the agent asked for when it went out under another name (issennknight)
issennknight on Discord (#general): an agent asked for deepseek-v4.1-flash,
which goes out as deepseek-v4.1-flash-1017 (settings' ModelIDs). The vendor's
reply said -1017, magpie passed it back, and the agent warned that the model
didn't match.

Before, only MemberModel (#822) or X-Magpie-Response-Model: member rewrote a
reply's model, and only to the group member's id. Now the default is
nameAsked. When magpie sent the request under another name than the agent
asked for (a model's own id, a routing group, a provider/model id), the
reply names the asked model. That covers Chat and Anthropic `model`,
Responses `response.model` (created, in_progress, completed), Anthropic
`message.model` (message_start) and Gemini `modelVersion`, streamed and
whole, translated paths and plugins included: it all goes through serve's
one memberWriter. A vendor that sent back the wire name as asked keeps its
own name, a dated -20261017 too. Usage rows, recent calls and the Routing
page still record served = the vendor's name: the writer sits outside
captureResponseWriter. Claude Code, Claude Desktop and Codex get the asked
name (or the vendor's), never the member's id, as before.

Streams are rewritten one complete line at a time (memberLines). A run
with no "model" in it is written through as the same slice. Only a JSON
reply that has a target at decide time is held whole, which is what
MemberModel already did.

A JSON body that doesn't parse (a reply cut short) goes on as it came.
A request to a remote magpie now sends X-Magpie-Response-Model: vendor
(passOnCaller). That magpie names the vendor's model, as before, so this
one still records what served the call (TestRemoteMagpieGroupNotSwapped
went red without it).

Existing tests that held a native reply byte for byte now expect only
its model renamed to the asked id (namedAs in member_test.go):
passthrough_severed, stream_accounting, refusal, refusal_thinking,
thinking_signature and vertex. The archive keeps the reply as the
vendor sent it, under the vendor's name (archive_test).

Also dropped: the openai-model header code. serve never relays that header,
so the test for it could not pass.

Run (mote, at this head rebased on origin/main 15066f84f):
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok
  except internal/gui: TestSettingsSaveKeepsWhatItDoesNotSend (#4514,
  SearchAll from b09349d17) and TestColdTurnsTaken (#4510). Both are filed,
  and neither touches this change. Three other sessions' suites ran on
  mote at the same time.
  The first full run (base 80bcef18f) had internal/gateway red in 10
  tests: the byte-for-byte tests above, the remote-magpie served test and
  the truncated JSON body. Each one was fixed as described.
- Rebased on 544b91ca8 (no gateway files changed in between): go build ./...,
  go vet, then go test ./internal/gateway ./internal/settings
  ./internal/provider: all ok.
- go vet -tags nogui ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: clean (cgo warnings only); gofmt -l clean.
- go test -race -count=3 on the member and served tests: ok (122s).
- the 10 formerly red tests with TestReplyNames, TestGeminiReplyNames,
  TestMemberLine, TestMemberWriter and Masked, after the rebase: ok.

Red on the old code (the new tests over a git archive of the base):
- TestReplyNamesAskedModel: 36 subtests fail (own id, group and provider
  id, x 6 protocol paths, x streamed or not), e.g. `the reply names
  "deepseek-v4.1-flash-1017", want "deepseek-v4.1-flash"`.
- TestGeminiReplyNamesAskedModel: both subtests fail (modelVersion -1017).

Broken by hand: dropping `|| m.wire == m.asked` from target() fails
"as asked, dated" in 12 subtests.

Real use: Codex 0.165.0 (codex exec --json) under a sandbox HOME and
CODEX_HOME on mote. A fake Responses vendor always answered
deepseek-v4.1-flash-1017, and a tee between Codex and `magpie serve` logged
what Codex got. providers.json had d with deepseek-v4.1-flash and group
fast; settings.json had modelIDs d/deepseek-v4.1-flash ->
deepseek-v4.1-flash-1017.
- old build: the vendor was asked for -1017; Codex got "model":
  "deepseek-v4.1-flash-1017" in response.created, in_progress and completed,
  both for -m deepseek-v4.1-flash and for -m group/fast.
- new build: the vendor was still asked for -1017; Codex got
  "deepseek-v4.1-flash" and "group/fast"; the usage rows still say served
  deepseek-v4.1-flash-1017. Codex answered "pong" both times. Codex 0.165
  itself shows no warning for a body model either way (its "model
  rerouted" reads the openai-model header), so the agent behind the
  report's warning was not the one run.

Not tried: the reporter's own agent (not named) and Claude Code; the
Responses WebSocket path (responses_ws.go's own frames); a compressed
reply, which still goes through as it is; Antigravity's effort-variant
wire, where the wire differs from the asked name on purpose.
2026-11-01 04:51:17 +08:00
yetone f99b227c27 filememo: a parse is kept under a struct key, not a joined string
read joined kind + "\x00" + path into a new string for every read,
and Look scanned every key with HasSuffix of another joined string.
A read is asked for each model of each provider a poll lists, so the
keys alone were 33 MB of what twenty window polls allocated with
real accounts (m2463 profile). seen is now keyed by
memoKey{kind, path}; a held read and Look allocate nothing.

Test: TestHeldReadAndLookAllocateNothing. 50 files in a long folder,
under Hold: AllocsPerRun of a read found unchanged is 0, and of Look
0; a write then Look reads the new value.

Run on mote, at this tree on 88372a39d:
- gofmt, go vet (darwin, windows, linux): ok
- the new test alone: ok
- broken by hand (the old filememo.go back): red, "a held read of a
  file found unchanged allocated 1 times, want 0"
- go test ./internal/filememo ./internal/settings ./internal/catalog
  ./internal/provider ./internal/agent: all ok

Not run: an A/B with the real-account sandbox for this change alone.
2026-11-01 04:50:29 +08:00
yetone 0aafcc0fd0 provider: which models a provider has no API for is found once per list
NoAPIFor found the protocols the provider speaks for every model it
was asked about, and APIs did again through ModelAPI, so a list of N
models built 2N Speaks slices. The providers' page, ExposedOf and
servable ask it for each model of each provider: 16 MB of what twenty
window polls allocated with real accounts (m2463 profile).

NoAPI() finds the protocols once and gives a func for each model;
APIs and ModelAPI take them through apisAmong and modelAPIAmong.
NoAPIFor, APIs and ModelAPI answer as before.

Test: TestNoAPIFindsTheProvidersAPIsOnce. 100 models of a relay,
half listed on chat: Speaks looked up once (5 at most, for another
test's look), the chat half kept, NoAPIFor the same for each.

Run on mote, at this tree:
- gofmt, go vet (darwin, windows, linux): ok
- the new test with TestExposedOnlyOnTheAPIsTheProviderHas and
  TestListedAPIsCost, 3 times: ok
- broken by hand (NoAPI back to a per-model NoAPIFor): red, "100
  models looked up the provider's APIs 200 times"
- go test ./internal/provider: ok
- go test ./internal/gui (before the apisAmong step, which touches
  internal/provider only): every test ok except the known
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners
  (#3949) and TestColdTurnsTaken (#4510)

Not run: an A/B with the real-account sandbox for this change alone.
2026-11-01 04:49:32 +08:00
yetone 6a23d9d755 gui: the kept state and providers are marshaled only when they changed
keepState and keepProviders ran json.Marshal on every /api/state and
/api/providers poll to compare the answer with the one kept on disk.
They now keep a sha256 of what was written and hash the new answer
into it with an Encoder; only a changed answer is marshaled and
written. json.Marshal there was 38.6 MB (keepState 25.9 MB,
keepProviders 12.7 MB) of what twenty window polls allocated with
real accounts (m2463 profile).

Test: TestKeptStateMarshaledOnlyWhenChanged. Twenty identical keeps
marshal nothing, nor does a keep after the file is read again; a
changed state is marshaled once and read back.

Run on mote, at this tree on dd7442f28:
- gofmt, go vet (darwin, windows, linux): ok
- the new test alone 3 times: ok
- broken by hand (the sum check made never true): red, "20 polls of
  the same state and list marshaled them 20 times, want 0"
- go test ./internal/gui: every test ok except the known
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners (#3949)

Not run: an A/B with the real-account sandbox for this change alone;
it goes with the next batch's profile.
2026-11-01 04:46:38 +08:00
yetone 606743831e appdir: on Windows an agent's folder variable follows the registry, and a gone folder it names isn't made again (bm_rabbit on Discord)
bm_rabbit (0.1.2405, Windows x64, Pi 1.4.0) moved Pi's AgentDir from
F:\piData\.pi\agent to F:\HarnessData\Pi\.pi\agent, deleted the old one and
set the User variable PI_CODING_AGENT_DIR to the new path. Changing Pi's
model in magpie then made the deleted folder again with only models.json
and settings.json in it.

Cause: Windows gives a process its variables once, from the registry, and
never passes a changed User variable to one already running. magpie runs
for days in the tray, so appdir.Getenv("PI_CODING_AGENT_DIR") (piDir) kept
the old path, and edit's write did MkdirAll on it. Every agent folder
variable (CODEX_HOME, CLAUDE_CONFIG_DIR, ...) had the same problem.

Fix, where every agent folder is read (appdir.LookupEnv, follow.go): on
Windows a variable in agentenv.Vars that came from the registry (its value
in magpie's environment at start matched the registry's, unset in both
counts too) is read from HKCU\Environment, else HKLM's Session Manager
Environment, with %...% expanded, at most once a second, and set in
magpie's environment so the programs magpie starts get it too. A value
the launcher set itself, or one set inside magpie since (a test sandbox),
stands. The direct os.Getenv reads of agent variables go through appdir
now: claudetui's CLAUDE_CONFIG_DIR, sessions' CODEX_SQLITE_HOME and
PI_DESKTOP_DATA_DIR, cliupdate's GROK_HOME, omp's OMP_PROFILE/PI_PROFILE.

And edit's writeFile no longer makes a missing tree of folders that an
agent's variable names: when the folder the variable names is missing
and so is the folder above it (bm_rabbit's whole F:\piData was gone),
appdir.Gone returns a GoneError naming the variable and the folder. The
named folder itself is still made when its parent is there, as mkdir
would (a CODEX_HOME or ANTE_HOME set before the agent first ran; 12
internal/agent tests rely on it), and an agent's default folder is made
as before. TestAnteHome's ANTE_HOME was <tmp>/elsewhere/ante with
elsewhere missing; it now makes elsewhere first. Writes that call
os.MkdirAll themselves don't ask yet: #4634.

Pi's install-layout.json isn't Pi's: Pi 1.4.0's getAgentDir
(@earendil-works/pi-coding-agent dist/config.js) reads PI_CODING_AGENT_DIR,
else ~/.pi/agent, and no file in the package names install-layout.
magpie doesn't read it.

Tests: TestAgentVarFollowsTheRegistry, TestAgentVarAddedLaterFollows,
TestAgentVarSetByHandStands, TestRegistryReadAtMostEachFollowFor,
TestGoneNamedFolderIsNotMade (internal/appdir, a fake registry), and
TestWriteNeverMakesANamedFolderAgain (internal/edit).

Broken by hand: LookupEnv back on os.LookupEnv, TestAgentVarFollowsTheRegistry
and TestAgentVarAddedLaterFollows FAIL ("after the user moved it,
PI_CODING_AGENT_DIR = .../old, want .../new"); Gone's refusal turned off,
TestGoneNamedFolderIsNotMade and TestWriteNeverMakesANamedFolderAgain FAIL
("= <nil>, want a GoneError", "the folder was made again"); Gone refusing
whenever the named folder is missing, TestGoneNamedFolderIsNotMade FAILs
("a named folder whose parent exists: ..."). All put back, green.

Real Windows run on xiaomi-gpu, sandbox USERPROFILE/APPDATA/LOCALAPPDATA,
at this head: a probe built from this tree started with
PI_CODING_AGENT_DIR=<sb>\piData\.pi\agent in its environment and the User
registry; then the User variable was set to <sb>\HarnessData\Pi\.pi\agent
and <sb>\piData deleted, and agent.Find("pi").Apply("model", ...) ran in
the same process. Pi's dir and os.Getenv are the new folder,
settings.json written there, piData not made. With HarnessData deleted
too: "PI_CODING_AGENT_DIR names <sb>\HarnessData\Pi\.pi\agent, which
doesn't exist and neither does the folder above it: ...", not made. An
earlier run of the old code (LookupEnv on os.LookupEnv, no Gone) wrote
into the old folder and made it again: bm_rabbit's case. The User
variable was removed after; the box had none.

Full run at this change on d714c4216: on mote,
gofmt -l (nothing), go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./..., and go test -tags nogui -timeout 45m ./...:
83 ok, 2 red, each open and not this change's: internal/gui
TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red alone on origin/main)
and TestColdTurnsTaken (#4510, warm-up ordering race, 0.00s), and
internal/cli TestLibraryMCPHub (#4140, TempDir cleanup; passes alone).
internal/appdir, internal/edit and internal/agent again alone: ok.
Rebased onto 76c130b29 (eight commits, edit's and appdir's among them;
file.go's imports merged by hand): gofmt -l (nothing), the three go vets,
and internal/appdir, internal/edit, internal/agent, internal/claudetui,
internal/sessions on mote: all ok. Not the whole suite again there.
Rebased again onto 88372a39d at push (six commits, none in appdir or
edit; dd7442f28 in internal/agent): go vet ./internal/..., internal/appdir
and internal/edit ok; internal/agent not run again at this head.
Windows (xiaomi-gpu, at d714c4216): internal/appdir, internal/edit, internal/claudetui
ok; internal/agent's 12 tests that make a named folder, TestGrok* and
TestPi* ok; internal/sessions red only in TestAgySessions and
TestAgyRowOnly, the same alone on origin/main (#4115).

Not tried: magpie's own GUI on Windows (the probe calls the same
agent.Apply the GUI's /api/set reaches); a REG_EXPAND_SZ value and a
Machine-only value on the real box (code path read, not run); bm_rabbit's
junction at C:\Users\Administrator\.pi.
2026-11-01 04:40:44 +08:00
yetone 88372a39d8 provider: listing accounts with nothing to change copies none of them
sideLogins and pluginLogins read the saved logins as a copy of the
whole list each time, to change it if a sign-in was new. The Providers
page and the panel list an agent's or a plugin's accounts a dozen times
a poll, and almost always nothing changes: 61 MB of what twenty window
polls allocated with real accounts. They now look at the logins as kept
(sharedLogins, read only), and a list that has a change makes its own
copy (readLogins) before it changes and writes it.

TestAccountListsCopyNoLoginsUnchanged: twenty lists of a side sign-in
and a plugin's accounts with nothing new copy the logins 0 times; a new
plugin account is still written and listed.

Run on mote (macOS 27):
- gofmt, go vet ./internal/provider (darwin, windows, linux): ok
- broken by hand (side_logins back on readLogins): red, "20 lists with
  nothing to change copied the accounts 40 times"
- the new test alone, -count=3: ok
- go test ./internal/provider ./internal/gateway: ok

Not run: the whole suite; internal/provider and the gateway that reads
its accounts are what this reaches.
2026-11-01 04:37:22 +08:00
yetone 178a781ff9 library: a skill made again under the same name after its repo's copy was deleted is filed under 本机 (X: AzheRise)
AzheRise on X: a skill downloaded from a GitHub repository was deleted,
another of the same name was made in an agent's own folder
(~/.dsh/skills), and once brought into the Library it sat under the old
repository instead of This computer.

Cause: two records outlive the skill and are matched by name only.
- The skills CLI's lock (~/.agents/.skill-lock.json, or under
  $XDG_STATE_HOME) keeps an entry for a skill deleted by hand or from
  magpie. repoOf filed the library's own copy (a folder moved in) under
  the lock's repository by its name, and tracer.folder did the same for
  one in ~/.agents/skills, which importSkill then kept as From. On this
  machine's real lock, agent-browser is such an entry, with no folder.
- CC Switch's folder (~/.cc-switch/skills/<name>) outlives a copy of it
  deleted from the library. ccSwitchOrigin filed any later own copy of
  that name under CC Switch's repository, and made it "updatable", so
  Update would have put the repository's skill in place of the user's.
- Sibling: a removed skill stayed in the user's own group (SkillGroups),
  hidden only while no skill had its name, so a new one of that name came
  back in the group.

Fix:
- A lock entry counts for a folder only when the CLI wrote that folder: a
  file in it is no newer than the entry's updatedAt (else installedAt)
  plus a minute (lockRepo, madeBy). On this machine's 27 live entries the
  CLI's files are 0.4 to 2.8s older than updatedAt. A lock without times
  groups by name as before. Brought in from an agent's folder, a copy the
  CLI wrote is kept as From at once, so an edit later leaves it grouped.
- Existing data is judged again on every read: a moved-in copy has no
  From and goes through lockRepo, and a From that is the lock's
  repository for a folder in ~/.agents/skills the CLI didn't write is
  passed over (staleFrom). So the reporter's skill moves to This computer
  with no action.
- ccSwitchOrigin takes a library-own copy as CC Switch's only when its
  SKILL.md is CC Switch's own.
- removeSkill drops the skill from the user's groups.

Not changed: noteFrom's pack rule (a skill traced nowhere, of a name a
repository being installed from has, is grouped with it when the library
has others from there). That is by name on purpose (White Immortal's
edited older copies), and runs only when the user installs from or
regroups that repository, not on import. MCP servers, hooks and
subagents keep no origin by name (a server's icon is by what it runs).

Tests: TestDeletedSkillsLockNotInherited (the reporter's case, one made
in ~/.agents/skills, the CLI's --copy copy and linked skill, data as
brought in before, an edited CLI copy), TestUndatedLockStillGroups,
TestRemovedSkillLeavesItsGroup, TestCCSwitchNameNotInherited.

Run at 76c130b29 plus this change, through mote-run, and again after the rebase onto dd7442f28 (vet of internal/library for darwin, linux and windows, and its tests, ok in 165.9s): gofmt -l internal clean;
go vet -tags nogui ./... for darwin, linux and windows ok; go test
-tags nogui -count=1 ./internal/library ok (186.7s). The new tests and
TestSkillRepo*, TestCCSwitch* also pass on Windows (win-run).
Broken by hand: with the three source files back at 76c130b29, three of the
new tests fail (notes and shared filed under someone/skills, the CLI
copy given no From, the group keeping notes, the user's pdf with CC
Switch's origin and updatable); TestUndatedLockStillGroups passes, as it
should.
Not tried: a real npx skills add / delete / re-create in the GUI, real
CC Switch, the full go test ./... suite, a copy moved into the library
across disks before this change (its files' times are reset, so it is no
longer grouped by the lock).
2026-11-01 04:36:37 +08:00
yetone a38a0d7794 gui: a provider's models are put in order once, not copied for each pick put first
providerInfoWith grew each provider's Models from nothing, and put each
model the user picked that its vendor no longer lists at the front with
an insert, a copy of the whole list each time. In twenty polls of the
Providers page with real accounts that was 13 MB of copies and 22.6 MB
of growth. The list is now made at its length, and the unlisted picks
are put in front with one insert, in the order they were before.

TestUnlistedPicksShownFirst: Available a, b and Exposed a, x, y, z show
as z, y, x, a, b with four exposed, as before.

Run on mote (macOS 27):
- gofmt, go vet ./internal/gui (darwin, windows, linux): ok
- the new test alone, 3 runs: ok
- broken by hand (the reverse taken out): red, "models shown as
  [x y z a b], want [z y x a b]"
- go test ./internal/gui: ok but for two reds already filed and red on
  main: TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestMainWindowCorners (#3949)

Not run: the whole suite; this changes one function of internal/gui.
2026-11-01 04:36:12 +08:00
yetone dd7442f283 agent: a look at the via-magpie options shares the kept list
viaMagpie handed every caller its own copy of the options list it keeps
per stamp, and a window poll asks for it from most agents' fields and
pickers. In a real-account sandbox (abr.sh, 20 polls of drift, state and
providers on v0.1.2463) those copies were 33.7 MB of slices.Clone, plus
~8 MB more on the way, of the 713 MB the polls allocated.

viaMagpieShared returns the kept list itself, clipped, so an append
makes the caller's own array. The 58 callers that only read it, or
append onto it, now take it; viaMagpie (a copy) stays for the ones that
change it.

TestKeptListSharedWithoutACopy checks that 20 shared looks return the
kept array, and that an append onto a shared look and a write into
get's copy leave the kept list as it was.

Run on mote at this tree:
- gofmt, go vet (darwin, GOOS=windows, GOOS=linux with gateway),
  go build ./...: ok.
- Broken by hand (shared returns slices.Clone): the test is red, "a
  shared look copies the kept list".
- go test -count=1 ./internal/agent: ok (480s).

Not run: internal/gateway and internal/gui packages on this tree.
2026-11-01 04:25:59 +08:00
yetone 544b91ca87 dsh: magpie's routes wait for a slow reply as long as the gateway does (tim on Discord)
tim's first "who are you" to gemini-3.8 through the third-party plugin
magpie-gemini-web 0.8.0 took minutes in dsh and ended in 499 ("the agent
canceled the request"). dsh hung up: llm-pi-ai gives a turn up after 5
minutes with no pi-ai event (DEFAULT_STREAM_IDLE_TIMEOUT_MS, every
dsh-llm-pi-ai from 0.1.5 to 0.2.2), and the gateway's ": keepalive"
comments (keepQueued, keepQuiet) are not events. The plugin serves one
request at a time (maxConcurrency 1), dsh's own session title goes to the
same route model in parallel, and the plugin's backend sends no byte
before its first token, so the turn's 5 minutes ran out in magpie's queue
and the backend while the gateway (10 minutes for headers) and the plugin
(240s per wait, then its own 504) were still waiting.

Every one of magpie's dsh routes (patch lists and deepseek-acp's
settings.yaml, all through dshPutProviders) now has streamIdleTimeoutMs:
600000 (dshIdleWait), the gateway's upstreamHeaderWait. A value already on
the route, set in dsh's Models page or by hand, stays. Codex's
comment-blind limit is still met in the gateway (agentQuietMost); dsh's is
a route setting. The plugin's own slowness is its maintainer's and is not
changed here.

Verified:
- New tests TestDshRoutesWaitAsLongAsTheGateway and
  TestDshRouteKeepsTheUsersIdleWait (internal/agent/dsh_idle_test.go),
  green on mote. Broken by hand: without the field the first fails
  ("route magpie waits 0ms for the next event, want 600000"); without the
  keep the second fails ("sync 1: the user's 120000 became 600000").
- Real dsh 0.2.1-rc.2 (headless, sandbox HOME/DSH_HOME, the route as
  magpie writes it, a fake Chat server on 127.0.0.1:3561 that answers
  after 8s): streamIdleTimeoutMs 3000 -> "TIMEOUT: pi-ai stream idle
  timeout after 3000ms"; 600000 -> "hello there", exit 0. With headers
  sent at once and ": keepalive" every second it still timed out at 3000,
  so comments don't feed the watchdog. dsh-llm-pi-ai 0.1.5-rc.3,
  0.1.7-rc.2, 0.2.0-rc.2 and 0.2.1-rc.5 (npm pack, read) all take the
  field per provider, max MAX_TIMER_DELAY_MS.
- gofmt -l clean. On mote: go vet ./..., GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build -tags
  nogui, GOOS=windows go build: all ok.
- Full suite, go test -tags nogui -count=1 -timeout 45m ./..., on the
  Linux box (wsl-run, magpie-desktop; mote had two full suites running)
  at d714c4216 + this change: 83 packages ok; internal/agent red on
  TestInstalledVersion, TestGrokInstalled,
  TestCursorFolderFromTheEditorIsNotTheCLI, TestOmpDetectedWithPiDir
  (#4033, #3548) and internal/gui on TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514) and TestColdTurnsTaken (#4510). The first five fail the same
  on origin/main 15066f84f run alone there; TestColdTurnsTaken passed
  alone on main and failed alone with this change (5 counts, gui only,
  which this change doesn't touch), as #4510 describes.
- After rebasing on 2597c9636, internal/agent again on the Linux box: the
  new tests pass; reds TestInstalledVersion, TestGrokInstalled,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI/qoder-cn,
  TestOmpDetectedWithPiDir, all the #4033 class (Qoder noted there).

Not tried: tim's own setup (the plugin is not run against a Google
account); a real 5-to-10-minute wait in dsh; Windows.
2026-11-01 04:23:05 +08:00
yetone f598edf6d5 providers: a provider's model lists are kept across polls with the catalog
The Providers page's state built each provider's Available,
ExposedOf(Available) and NewestInFamily(Available) lists again on every
poll. Over twenty polls of the real-account sandbox that was 159 MB of
the 371 MB providerInfoWith allocated (Available 72, NewestInFamily 60,
ExposedOf 27). provider.KeptListing keeps the three lists in keptOf, the
cross-request cache that drops them when the catalog, providers.json,
settings or a plugin changes (StampNow) and after keptFor, and only while
a request holds. providersState passes the kept Listing; providerInfo,
for one provider after an edit, still builds a fresh one. The lists are
clipped, so an append makes the caller's own.

TestProvidersListingKeptAcrossPolls: twenty polls with nothing changed
build the listing 0 times and match a fresh Listing; after a Save of the
provider's models the next poll shows the new ones. With keptOf swapped
for a direct call by hand it is red: "built the listing 20 times, want 0".

Run on mote at this tree (on 2597c9636): gofmt; go vet for darwin,
windows and linux (provider); internal/provider ok; internal/gui has
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners
(#3949) red, both red on main before this.
Not run: the full suite at the rebased head.
2026-11-01 04:16:57 +08:00
yetone 76c130b29c edit: a TOML file's table names are listed once a read, not on each look
TOMLTables walked the parsed file and built a fresh sorted list of table
names on every call. The window's polls ask it for every agent's config
several times a poll, and twenty polls of the real-account sandbox spent
46 MB on those lists. The names are now filled when the file is parsed
(the parse is already kept by mod time and size), clipped, and handed out
shared; a caller that appends gets its own copy.

TestTOMLTablesListedOnceARead holds the allocation of repeated looks at
the same file to a small bound. With the old code put back by hand it is
red: 158474 bytes a look.

Run at 554291774's tree (on 2597c9636):
- Windows (win-run): go vet ./internal/edit ok, go test ./internal/edit ok.
- Linux (wsl-run): gofmt, vet ok; internal/edit ok. internal/agent has
  TestGrokInstalled, TestCursorFolderFromTheEditorIsNotTheCLI,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI and TestOmpDetectedWithPiDir
  red, the install-detection reds filed as #4033 / #3141; this change
  doesn't touch install detection.
Not run: the full suite at the rebased head.
2026-11-01 04:13:05 +08:00
yetone 2597c96365 agent: Codex's config.toml is decoded once a read for a sync's own looks
A sync to Codex decoded the whole config.toml again for each thing it
checked: codexMultiAgentV2On, putThreadTables, codexEnableEfforts and
codexAsyncNow each ran toml.Unmarshal over the file. Codex writes a
[projects."…"] table for every folder it was opened in; the owner's
config is 1.5 MB with 10,932 tables, and with 10,000 such tables one
sync allocated 21 MB.

codexTopOf decodes only the top tables these look at (features,
model_providers, desktop, profile, profiles) and keeps the result in
filememo by the file's mod time and size, so a sync and the polls
after it share one decode until the file changes. A missing file is
an empty config, as before.

TestCodexSyncDecodesTheConfigOnce: 10,000 project tables, one sync
to settle, then five more; each must allocate under 12x the file and
leave config.toml unwritten. Now ~5 MB a sync. Red on the old code:
51,257 KB a sync over an 868 KB file, past the 10,421 KB bound.

Run at this head on mote: gofmt clean; go vet (darwin, GOOS=windows,
GOOS=linux) ok; go test -timeout 45m ./internal/agent
./internal/gateway ok.
2026-11-01 04:06:09 +08:00
yetone 05f6ca39b3 provider, gui: settings only read go through the shared copy
settings.Load clones the whole Settings, every provider's model prefs
included. CompactsOf, OutputsOf, ModelNames, ModelEfforts,
settings.SavedAddr and the GUI's providerInfoWith only read it, and
providerInfoWith took a copy for each provider: 16 MB of what twenty
window polls allocated in a real-account sandbox, more with each
model a user has set prefs for.

They read settings.Shared() now. ModelEfforts hands back a clone of
the slice it finds, so a caller's change never reaches the shared
settings.

TestModelPrefsReadTheSharedSettings: 3000 other models' prefs; the
values are right, a caller's change to ModelEfforts' list doesn't
reach the settings, and each look allocates at most a tenth of
Load's. Red on the old code: ~6058 allocations a look against 6056
for a Load.

Run at this head on mote: go vet (darwin, GOOS=windows, GOOS=linux
without the gui package) ok; go test ./internal/settings and
./internal/provider ok; ./internal/gui red only in
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949), both red on main.
2026-11-01 04:05:38 +08:00
yetone 4d1ec346aa edit: a JSON file is made plain JSON once a read, not on every look
GetJSON, GetJSONRaw and GetJSONItem copied the file and ran jsonc.ToJSON
over it on every look. The window's polls look up agent settings many
times a round, so twenty polls allocated 80 MB in that conversion alone
(heap profile of a real-account sandbox).

jsonHeld keeps the plain-JSON bytes in filememo, keyed by the file's
mod time and size, so a look reads them shared. gjson.GetBytes copies
what it returns, so nothing a caller gets aliases the held bytes. A
write (SetJSON and the rest) changes the file, and the next look reads
it again.

TestGetJSONConvertsTheFileOnce: a 290 KB JSONC file with a BOM, 20
looks must each allocate under a tenth of the file, and a value set
afterwards is seen. Red on the old code: 296 KB a look.

Run at this head:
- mote: go vet (darwin, GOOS=windows, GOOS=linux) ok; go test
  ./internal/edit ok, and ok under -race.
- WSL (magpie-desktop): internal/edit ok, internal/provider ok;
  internal/agent red only in TestInstalledVersion, TestHowInstalled,
  TestGrokInstalled, TestCursorFolderFromTheEditorIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI and
  TestOmpDetectedWithPiDir, the install-detection reds of #4033.
2026-11-01 04:04:50 +08:00
yetone 15066f84f6 appdir: a folder and file name are joined once, not on every read
appdir.Config and Cache, catalog.CachePath and LivePath, settings.Path,
provider.Path and the logins path each ran filepath.Join on every call,
and they are called on every read of a cached file, many times a request.
Those joins were 70 MB of the 1.4 GB twenty window polls allocated.
appdir.Join and JoinFile keep each (dir, name, ext) they joined, up to
4096 of them, so a path named again is the same string. A changed HOME
or folder is a different key, so a test's sandbox still gets its own
path.

TestFoldersJoinedOnce and TestLivePathNamedOnce: 0 allocations a call.
Broken by hand on mote (the files before this change) they are red at 1
allocation a call, and 3 for LivePath.

Run on mote at this tree (on d714c4216): gofmt clean; vet ok on darwin,
windows and linux (appdir, catalog, settings, provider); go build ok;
appdir, catalog, settings (49s), provider (187s), agent (324s) and
gateway (1244s) ok.

At the pushed head (on 019bfc951, which adds provider.Held): vet of
appdir, catalog, settings, provider and gui ok, go build ok, appdir,
catalog and gui's TestAccountLabelsBuildTheAgentsOnce ok.
2026-11-01 03:52:46 +08:00
yetone 019bfc951b gui: a page of accounts builds the agent list once, not once a row
accountLabel and the excluded-agents loop called agent.Find for each row,
and Find builds All() again each time: about 3,300 allocations a call.
Over 20 window polls that was 58 MB of the 1.4 GB a magpie allocated.
provider.Held keeps All() for the request that holds it (the gui's held
middleware holds every /api/ request), and agent.FindIn looks the name up
in that list. Outside a hold Held builds it as before, so a caller with
no request in hand gets the same answer.

TestAccountLabelsBuildTheAgentsOnce (sandbox HOME): outside a hold the
label's name and icon are the same; under Hold a row allocates 3 times
against 3302 to build every agent. Broken by hand on mote (agentNamed
back to agent.Find) it is red at 3305 a row.

Run on mote at this tree (on d714c4216): agent (846s) and provider
(459s) ok; gui red only in TestSettingsSaveKeepsWhatItDoesNotSend
(#4514, red on main) and TestMainWindowCorners (#3949, macOS 27). vet ok
on darwin and windows (agent, provider, gui) and linux (agent, provider;
gui needs cgo there).
2026-11-01 03:49:03 +08:00
yetone 68c413ea05 filememo: a file written just now is read again into one buffer
A file whose time is under two seconds old is read again on every read
and compared with the bytes parsed, since a second write inside a clock
tick can leave the same time and size. Each of those reads made a new
buffer. As magpie starts, Codex's sync writes ~/.codex/config.toml, and
every read of it for the next two seconds made one. With the owner's
real 1.45 MB config.toml, v0.1.2432's startup profile has
readCodexStoreSetting reading it ~155 times (226 MB) and the TOML table
spans ~89 times (129 MB). That is 381 MB of the 1.37 GB allocated before
the window's first poll, and the peak RSS with it.

Now a read that finds the same size and time reads into a buffer kept on
the entry while its bytes are, and gives the buffer back when they
match. A read beside it takes the buffer out first, so it reads into one
of its own. Bytes that differ are parsed from that read's buffer, which
no one else has. Nothing changes in what is looked at: the file is still
read and compared each time until it settles.

steady.ReadThereInto is ReadThere into a caller's buffer.

TestRecentFileReadAgainIntoOneBuffer (a 1.2 MB file stamped now): 20
reads allocate under a quarter of the file each, it is parsed once, 8
readers at once each get the right length, and a write of the same size
and time is seen and kept as its own bytes. Broken by hand on mote, with
the buffered path off, it is red (1191002 bytes a read).

Run at 8ce36a0ef (on d714c4216), on mote: gofmt clean; filememo, steady,
provider (146s) and agent (300s) ok. gateway: TestBurstTellsNoSpeed red
(#2719, under load, no file read on its path). gui:
TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red on main) and
TestMainWindowCorners (#3949, macOS 27). vet ok on darwin, linux and
windows. Windows: filememo and steady ok. WSL: filememo, steady,
provider and gateway ok; agent's 6 reds are the same on origin/main
80bcef18f (#4033, #3548).
2026-11-01 03:47:03 +08:00
yetone bb50f4ad94 gateway: a Codex passthrough member OpenAI doesn't know is left out and asked again
xuanwo on X: every new conversation in the Codex app (two agents) ended
at once with the ChatGPT backend's 400 "[ObjectParam]
[input[55].internal_chat_message_metadata_passthrough.content_token_count]
[unknown_parameter]". The member is new in the Codex app's bundled
build; no open-source Codex sends it (main 67f0994, npm 0.166.0), and
openai/codex#52313 was the same refusal of content_item_metadata in
0.163.0-alpha.1. magpie sends the passthrough as Codex wrote it to
OpenAI hosts and ChatGPT accounts (forVendor), so the refusal reached
the app. The reporter's own look at magpie's routing log: the main
conversation failed at input[49] and input[55], and a conversation
with no subagent failed the same way, so subagents aren't the cause.

The member is Codex's own attribution, not the conversation. A turn
turned away over one passthrough member, or the passthrough as a whole,
is asked once more without it on every item, with the other members
and every other byte kept as written. The provider isn't sent that
member again (unfit, as for a tool's strict). The signed-in Codex
relay's retry (withoutUnreadable) takes the same refusal.

Run (mote, go1.26.8):
- TestPassthroughMemberLeftOutWhereRefused, TestPassthroughRefusalWordings,
  TestWithoutPassthrough: ok.
- Broken by hand: with the retry turned off, TestPassthroughMemberLeftOut
  WhereRefused gets the reporter's exact 400 back.
- At d714c4216 + this: gofmt clean; go vet ./internal/gateway on
  darwin, linux and windows ok; go test ./internal/gateway -run
  'Passthrough|ToolStrict|Unreadable|Optional|LiteSubagent' ok.
- The whole internal/gateway package was still running at push (the
  owner's ship-at-once rule); its result is not in this record.

Not tried: the reporter's Codex app build. Its content_token_count isn't
in any build that can be downloaded, so the fixture is the refusal text
from their screenshot.
2026-11-01 03:45:10 +08:00
yetone d714c4216d catalog: a newer model's line is looked up in the index made once per load
KinEfforts gives a model newer than the catalog its line's levels (gpt-
6.1-sol's from gpt-6-sol). borrowedEfforts asks it for every model with
no levels of its own, on each look at the providers. Each ask ranged
over every model of every maker's catalog and split and joined each key
to compare its versionless shape: 66 MB of the 1.4 GB a main magpie
allocated over 20 window polls with the owner's real config.

levelIndex (97ec2f8ae) now also holds each provider's thinking keys
that aren't budgeted, by their versionless shape (kin), in key order,
made once per catalog load. KinEfforts reads the keys of the id's
shape. Which one wins doesn't change: the newest, then within one
provider the greater key, then the first provider.

TestKinEffortsReadsAnIndex: 2000 thinking models of other shapes beside
zai's glm-5.3-flash; glm-6.1-flash takes its levels, an ask takes under
8KB, and a catalog loaded since is read at once. Broken by hand on mote
(the old catalog.go): red, "an ask took 128458 bytes with the catalog
unchanged".

Run on mote at 80bcef18f (go test -timeout 45m): internal/catalog ok
0.8s, internal/provider ok 238s. go vet of both on darwin, windows and
linux ok; gofmt -l clean.
2026-11-01 03:24:38 +08:00
yetone ddc225c964 Revert "site: the favicon and iPhone icon fill their tile, no white margin"
This reverts 25d405814. It answered a message the owner then said
was not meant for this session, so the site keeps its icons as they
were. Redeployed with wrangler and fetched both icons back.
2026-11-01 03:24:23 +08:00
yetone 83b2be2b25 provider: Hidden reads providers.json as parsed once, not once per account
Hidden lists the signed-in accounts the user removed from magpie. The
Providers page asks it on every load, and for each signed-in account it
parsed the whole providers.json again (load). With the owner's real
config that was 68 MB of the 1.4 GB a main magpie allocated over 20
window polls. It now reads storedFile(), the file as parsed once until
it changes, which only reads it; Excluded, its other caller, does too.

TestHiddenParsedOnceUntilTheFileChanges: a signed-in Claude account
hidden beside 30 providers of 100 models, the file dated an hour back.
Hidden costs less than a quarter of a parse over what Accounts costs,
and an account shown again since is seen at once. Broken by hand on
mote (load().Providers in the loop again): red, 3353 allocations over
Accounts' 396 against a parse's 3352.

Run on mote at 1f9f74d1c (go test -timeout 45m): internal/provider ok
171s; internal/gui FAIL on TestSettingsSaveKeepsWhatItDoesNotSend (#4514)
and TestMainWindowCorners (#3949), both red on main already. go vet of
provider darwin, windows and linux ok, of gui darwin and windows ok
(gui's linux vet needs cgo for wails); gofmt -l clean.

Rebased on 80bcef18f: internal/provider ok 202s at that head.
2026-11-01 03:23:52 +08:00
yetone 25d4058146 site: the favicon and iPhone icon fill their tile, no white margin
On a phone a usemagpie.ai link showed its icon inside a white ring
(the owner: "包了一层白边"). favicon.png and the apple-touch-icon
(img/icon-256.png) were the macOS app icon, a rounded tile with ~10%
transparent margin on each side; a phone fills the transparency white
and rounds the square itself, so the tile sat inside a white border.

- favicon.png: 64px from the GUI's full-bleed apple-touch-icon,
  opaque, no margin.
- apple-touch-icon.png (new, 180px, also the path iOS asks for by
  itself): the GUI's apple-touch-icon, which already fills its square.
  Every page's <link rel="apple-touch-icon"> points at it.
- img/icon-256.png is left as it was: install.sh takes it as the Linux
  desktop icon and the READMEs show it, where the macOS shape is right.

Run: sips on both files (64x64 and 180x180, opaque); looked at both;
grep shows no page still names /img/icon-256.png as its touch icon.
Deployed with wrangler and fetched both from usemagpie.ai.
Not tried: a real iPhone's home screen or Safari tab after the deploy.
2026-11-01 03:22:50 +08:00
yetone 80bcef18f0 provider: PublicRef reads the groups held without copying them
PublicRef is asked for every model a page lists (the Providers page, every
agent's picker). Each call went through Groups(), which copies every group
and its rules so the caller can change them, to read one group's Spelled
and Ref. With the owner's real config that was 115 MB of the 2.6 GB a
v0.1.2432 magpie allocated over 20 window polls.

sharedGroups() is the held slice itself, for callers that only read it:
PublicRef, the families list (visible.go) and DisabledGroup, which still
hands its caller a copy of the one group it found.

TestPublicRefCopiesNoGroups (41 groups with members and a rule, under
provider.Hold and filememo.Hold as a request runs): PublicRef takes far
fewer allocations than a copy of the groups, and DisabledGroup's caller
can't write into the groups held. Broken by hand on mote: PublicRef back
on Groups() is red (165 allocations against 164 for a copy), and
DisabledGroup returning the shared group is red.

Run on mote at the rebased head (go test -timeout 45m): internal/provider
ok 125s, internal/agent ok 207s. go vet of internal/provider on darwin,
windows and linux ok; gofmt -l clean. On the Windows box
internal/provider has the same 14 reds at origin/main f9ca3dd44 with
and without this change (#4115, #2808, #4446, #4633), and no other.
2026-11-01 03:10:49 +08:00
yetone 3182a66586 provider, gateway: OpenRouter's decision model picked with a variant (inception/mercury-decide:free) is a decision model, never sent to chat/completions
coeo91 on Discord (2026-10-31): inception/mercury-decide:free, picked by
hand into a group used as smart routing's decision model, failed with
"OpenRouter: inception/mercury-decide:free is a decisions model and
cannot be used with the chat/completions endpoint. Use the
/api/alpha/decisions endpoint instead."

Cause: magpie already reads OpenRouter's decision models from its own
list (/models?output_modalities=decisions: output_modalities
["decisions"], endpoints ["/api/alpha/decisions"]) and asks them at
/api/v1/systemone. That list names each model once, without variants,
so the hand-picked ":free" id was taken for a chat model. Its group was
a chat group and the classifier asked it in words on chat/completions.

Now a variant of a model OpenRouter's decisions list names (base id
before the last ":", OpenRouter providers only; Ollama's :tag stays a
name of its own) is a decision model (openRouterVariant):
- it is kept from agents' model lists, and its group is a decision
  group, asked at /api/v1/systemone (classifier, RouteDecider);
- an agent's chat naming it gets magpie's 400 "only decides", with
  OpenRouter not asked;
- count_tokens naming it, or its decision group, gets the same 400
  (count_tokens had no decision guard and forwarded upstream);
- test-models sends it the System One yes-or-no, and the provider
  editor marks it as a decision model (/api/providers deciders).

Not done: an /api/alpha/decisions client. OpenRouter's /api/v1/systemone
(what magpie uses) answered the same model the same way as the alpha
path in a real probe (200, identical System One shape), so the alpha
endpoint adds nothing but an alpha contract.

Real probe (owner's OpenRouter key, 2026-11-01): chat/completions with
inception/mercury-decide:free gives the reporter's 400 word for word;
/api/v1/systemone and /api/alpha/decisions give 200 for
inception/mercury-decide and 404 for :free ("This model is unavailable
for free... use this slug instead: inception/mercury-decide"). So
after this change the reporter's group is asked the right way, and
OpenRouter's own 404 says to pick the paid slug.

Tests (fixtures are OpenRouter's real list and answer bytes):
TestOpenRouterDecisionModelVariant (provider),
TestOpenRouterDecisionVariantNeverChats (gateway: classifier group asked
at /systemone, chat and count_tokens refused, OpenRouter asked once),
TestOpenRouterDecisionVariantPicker (gui). Each is red on the old code
(provider: "taken for a chat model"; gateway: the reporter's 400 as the
classifier's error; gui: deciders without the variant), checked at
0565c0bba and again after the rebase. With only gateway.go reverted,
count_tokens answered 200 {"input_tokens":0}.

Run:
- full `go test -tags nogui ./... -timeout 45m` on mote at 970931203
  (this change on 0565c0bba), log kept: every package ok except three
  reds that fail the same at 0565c0bba without this change or pass
  alone, each filed: TestBrowserExtensionOnlyFromItsOrigin (#4631),
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestColdTurnsTaken
  under the full run (#4510).
- gofmt -l, go vet, GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./... at 970931203.
- after rebasing on f9ca3dd44: gofmt, GOOS=linux and GOOS=windows go vet
  ./internal/..., and go test ./internal/provider ./internal/gateway
  ./internal/gui ./internal/catalog -count=1 at 182d84f2b on mote:
  provider and catalog ok; gateway and gui red only in
  TestBrowserExtensionOnlyFromItsOrigin (#4631) and
  TestSettingsSaveKeepsWhatItDoesNotSend (#4514), as on main.
- An earlier WSL full run wedged in go test with no child for 30
  minutes beside two other sessions' GUI suites and was stopped; its
  internal/agent reds are WSL's binfmt (#4033, #3548).

GUI: app.js is unchanged; only /api/providers' deciders list gains a
hand-picked variant, which app.js already reads. The GUI suite was not
run; its decision tests run on fixtures.

Not covered: a custom (non-preset) provider at openrouter.ai has no
Decide base, so its decision models still go to chat/completions
(#4614): filling Decide by host could override a value the user cleared.

Not tried: the whole magpie path end to end with a real OpenRouter key
(the probe called OpenRouter directly).
2026-11-01 03:07:06 +08:00
yetone 1f9f74d1c5 provider: the live-model test weighs the same steps on Windows too
TestLiveModelReadWithoutACopy (v0.1.2449) took LiveListed alone as the
cost of a look before the copy. liveByID also asks whether the list is
the provider's and the id it is listed by, which cost more on Windows,
whose stat allocates more: green on macOS, red on Windows ("a look at
one model took 2552 bytes, the list's read 1232"). The baseline now
takes the same steps, and the bar is half a model: the same steps leave
~0 bytes over, a copy 448 and more (on macOS the bar was 16 bytes from
the old code's 1112).

Run on mote and on the Windows box: the test ok -count=10 on each; with
liveByID back on the copying LiveByID it is red 10 of 10 on each. go
vet darwin and windows of internal/provider ok, gofmt -l clean. The
rest of internal/provider on Windows has 14 reds that are the same at
origin/main f9ca3dd44 (keychain, git links, daemon env, two allocation
tests): TestResolveKeptAcrossRequests is #4633, filed now; the
others are #4115, #2808 and #4446.
2026-11-01 03:05:59 +08:00
yetone f045ec1ea5 gateway: the extension socket's test takes a 401 from the LAN guard as refused
TestBrowserExtensionOnlyFromItsOrigin (0e9057227) wanted 403 for every
case. On Linux the other computer's try is answered by the LAN guard
first, 401 for no key, before the handler's 403; it is refused either
way, never switched to a WebSocket. Found by the full suite in
magpie-desktop after the push.

Run: go test ./internal/gateway -run Browser on mote (macOS) and in
magpie-desktop (Linux, -tags nogui), both ok. The rest of that Linux
full run at 0565c0bba: ., internal/cli ok with -tags nogui; reds that
fail the same at origin/main f9ca3dd44 or are filed: internal/agent's
install tests (#4033, #3548), TestSettingsSaveKeepsWhatItDoesNotSend
(#4514), TestColdTurnsTaken, ok alone (#4510).
2026-11-01 03:03:30 +08:00
yetone f9ca3dd44c provider: a look at one model of the vendor's list reads it without a copy
ListedAPIs, the Kilo and Cline free marks, a model's fast tiers and a
remote magpie's price each look up one model of the provider's fetched
list (liveByID), for every model a page lists. Each look copied the
models of that id out of the list read, to read one field. With the
owner's real config the copies were 32 MB of the 2.6 GB a v0.1.2432
magpie allocated over 20 window polls.

catalog.LiveByIDShared is LiveByID without the copy (clipped, so an
append is the caller's own); liveByID uses it, and still copies a model
the user gave its own id, to set that id. Every caller only reads it.

TestLiveModelReadWithoutACopy (a 200-model list, under provider.Hold and
filememo.Hold as a request runs): a look costs less than a model over the
list's read itself, a caller's append doesn't reach the list, and
LiveByID still hands back its own copy. Broken by hand on mote: liveByID
back on LiveByID is red (1112 bytes a look against 520 for the read; a
model is 432).

Run on mote (go test -timeout 45m): internal/catalog ok 0.7s,
internal/provider ok 112s. go vet of both on darwin, windows and linux
ok; gofmt -l clean.
2026-11-01 02:54:20 +08:00
yetone e6b595e1ab claude: Interactive only, a setting under which a model request never runs as claude -p (_yuchanns_ on X)
_yuchanns_ on X, on the interactive mode falling back to -p: for people
who stayed off magpie's Claude subscriptions because of -p, a fallback
is a time bomb. Settings › Models › Replies › Claude Code's interactive
mode now has three choices: Off (always -p), On (the default, falling
back to -p as before) and Interactive only.

With Interactive only (settings.ClaudeTUIOnly; ClaudePrintMode set too
wins):
- a run claudeTUI would make -p is not started; the request fails with
  the reason and the setting (claudeOnlyErr, claudeNotTUIWhy);
- the helper is handed MAGPIE_CLAUDE_TUI_ONLY=1 (claudetui.OnlyEnv,
  claudeCLI.tuiEnv). Where it would exec -p (no start, sign-in, first-run
  notes, untrusted folder, 45s timeout) it exits with the reason
  (fallBack in Run), and it ignores the broken mark;
- a helper that never answers initialize ends the turn with an error,
  not a -p retry, and `broken` isn't counted (claudeMachineWhy), so the
  next run tries the interactive mode again;
- the model test's and warm-up's "hi" (askClaude) runs through the
  helper (askClaudeTUI) in stream-json, its stdin closed at the first
  result. The helper command and env are built in one place now
  (tuiCommand, tuiEnv) for both.
Reading the plan's allowance (/usage) asks no model and stays -p; the
setting's text says so. Docs: claude-subscription-bridge.md.

Provider editor, on e8347401f's "Claude Code runs as" pill
(ClaudeMode.Only): with the interactive mode in use and no last
request, it says a request it can't take fails, and the card's foot says
nothing runs as -p. Where the interactive mode can't run, the pill names
Interactive only, never claude -p, the line says "Claude requests fail:
<why>", and Change in Settings goes to the row. A request refused this
way never ran, so it isn't noted as the last request (noteClaudeRun
comes after the refusal).

app.js: the Replies rows share one helper (segRow, which waitRow uses
too), so app.js is 530 bytes under main's with the third choice; no
budget raise.

Tests: TestClaudeTUIOnlyRefusesPrint, TestClaudeTUIOnlyHungHelperNoPrint,
TestClaudeTUIOnlyTellsHelper, TestAskClaudeTUIOnly (gateway);
TestShimOnlyNeverPrints (claudetui: fake fail/trust/login/notes each
exit with an error and no -p, a marked-broken run still interactive);
claude-tui-setting.test.cjs (three choices, Only saves claudeTUIOnly with
claudePrintMode false) and claude-mode.test.cjs (Only in use, and Only where it can't run).

Broken by hand, each red, then put back: the startRun gate off
(RefusesPrint 200); start()'s Only check off (HungHelper 502 without the
Only reason); tuiEnv's OnlyEnv off (TellsHelper); askClaude's branch off
(AskClaudeTUIOnly); the helper's fallBack ignoring only (4 subtests);
BrokenSince's `&& !only` gone ("marked broken"); the save without
claudeTUIOnly (16 of 16 setting tests) and claudemode.js's m.only
branches gone, rebuilt on e8347401f's file (10 of 10 Only tests,
Chromium).

Run on mote at e8347401f + this commit:
- at f1d6f4137 (main, after #4571's claude_cache.go) + this commit: go
  vet of gateway and gui ok, CoreScriptBudget|I18n ok, the gateway's
  TUI|Warm|Claude|AskClaude|Cache tests ok; the rest below at e8347401f
- gofmt -l clean; go vet and GOOS=windows go vet of claudetui, gateway,
  settings and gui ok; Linux vet (wsl-run, -tags nogui) ok
- go test ./internal/claudetui ./internal/settings ok; the gateway's
  TUI|Warm|Claude|AskClaude tests ok
- internal/gui CoreScriptBudget|I18n|Settings: ok but
  TestSettingsSaveKeepsWhatItDoesNotSend, SearchAll, red on main since
  b09349d17 (#4514)
- GUI (Chromium + WebKit, every language): claude-mode, claude-tui-setting
  and i18n-keys 94 of 94 at e8347401f; with the other Replies rows'
  files (claude-lean-prompt, member-model, loop-guard, refusal-retries,
  classify-timeout, image-timeout) 180 of 180 at 2e9df9b1b. Earlier
  segs-press-redraw's searchAllRow red is #4566, not this change.
Not tried: a real account under Interactive only (the fallback paths
are forced by the fake Claude Code); the full GUI suite (mote had
another session's full GUI suite and an agent+gateway suite going).
2026-11-01 02:53:08 +08:00
yetone f1d6f4137c gui: a provider's row reads the vendor's list once
providerInfoWith read p.Available() four times for one row: for the
picks (Picks), for what is exposed (Exposed, twice: the exposed set
and the picks the list doesn't know) and for the newest of each
family. Each read builds the list whole with its names, levels and
plugin models. In a profile of v0.1.2432 against the owner's real
config (20 rounds of the window's polls), providersState was 1.34 GB
of 2.62 GB allocated, Exposed 390 MB, Picks 155 MB and the row's own
Available 146 MB of it.

Provider gains ExposedOf(avail) and PicksOf(avail), Exposed and
Picks of a list the caller has read already; Exposed and Picks call
them with p.Available(), so every other caller is unchanged. The row
reads the list once and hands it to both.

TestProviderInfoReadsTheListOnce: a 2000-model catalog provider with
three picks, one of them unlisted, read the way the page's request
reads it (provider.Hold and filememo.Hold). The row's Chosen equals
Picks(), its exposed count equals len(Exposed()) and the unlisted
pick goes first. A row takes 28.6 MB against the list's 8.0 MB
(each model's own price, window and protocol look-ups besides);
on the old code 54.4 MB, red at the 5x bar.

Run on mote at 27401edd6 (go test -timeout 45m): internal/provider ok
161s. internal/gui: three reds, each already filed and failing the
same on main: TestSettingsSaveKeepsWhatItDoesNotSend (#4514),
TestMainWindowCorners (#3949), TestColdTurnsTaken (#4510). go vet
darwin and windows ok, gofmt -l clean.
2026-11-01 02:48:54 +08:00