Files
magpie/internal/catalog
yetone ef6d5ca400 provider: a model's listed APIs, Cline/Kilo free mark and remote price are looked up, not the whole list copied for each, so 2,500 models' /v1/models is 0.8s again (K.Liu on Discord)
K.Liu: /v1/models with 2,000+ models took 2.8s on 127.0.0.1, where it
took 1.6s before, so third-party apps couldn't show the whole list.

Cause: 644ad1ed7 (#2094, first in v0.1.1234) has Exposed() ask
NoAPIFor of every listed model, and NoAPIFor asks ListedAPIs, which
read the saved list through p.live(): catalog.Live copies the list's
chat models (Chat) and ListedAPIs scans that copy, once a model. A
request that doesn't hold the catalog (/v1/models doesn't) did it
2,500 x 2,500 times, and /v1/models' nativeEndpoints did it again for
each row. Bisected with one sandbox HOME (one key provider, 2,500
listed models, all picked), server CPU for 4 requests: v0.1.1207
7.6s, v0.1.1222 8.3s, v0.1.1230 9.0s, v0.1.1232 9.2s, v0.1.1234
18.0s, v0.1.1237 18.0s, main 18.8s.

What changed:
- catalog: readLive indexes the chat models by id once a parse
  (filememo keeps it while the file is unchanged); LiveByID gives a
  model's entries in list order.
- provider: ListedAPIs, clineFreeModel, kiloFreeModel and remotePrice,
  each asked once a model, look the model up through p.liveByID (same
  p.lists() gate as p.live()) instead of scanning a fresh copy. Same
  first-match rules as before.

Measured, same sandbox HOME, 127.0.0.1, machine at load 40-90:
origin/main 4.7-5.9s a request, 18.8-19.6s server CPU for 4; with this
0.6-1.0s, 2.6-3.0s CPU for 4. The /v1/models body, sorted, is byte for
byte the same as origin/main's (2,500 models, 2,487 with
native_endpoints).

Test: TestListedAPIsCostGrowsWithTheList weighs Exposed() for 500 and
2,000 listed models by bytes allocated (not time). On origin/main it
fails "allocated 92034888 bytes for 500 models and 1416709568 for
2000: 15.4 times for 4 times the models"; with this it passes
(-count=3).

Run: gofmt -l clean; go vet -tags nogui for darwin, linux and windows
clean.

Max's report on Discord ("0.1.1265 所有供应商的额度似乎都无法刷新了") was
not reproduced: on v0.1.1265 in a sandbox, key balances and plan cards
refresh from the GUI's refresh, /api/usage/quotas and the background
loop. The one link found: with Gemini or Antigravity quotas, exposedIDs
runs Exposed() for every provider, the same per-model scan this
removes, inside /api/usage/quotas' 12s budget. Unconfirmed as their
cause; asked them for details.

Full suite: set -o pipefail; go test -timeout 45m ./... at 8b84dc902 +
this (sandbox HOME, load average 130-320 from other sessions): 63
packages ok; gui red only in TestPanelJoinsFullScreenSpaces (#2450,
fixed on main since in 63be47717); agent and gateway timed out at 45m
with no failed test. Rerun agent+gateway at -timeout 90m: agent ok
(3913.8s); gateway red in TestPluginStreamLargeReplies JSON_fast /
JSON_throttled (client timeout, filed #2551) and
TestMaxRPMTooLongIs429WithRetryAfter (Retry-After 1 for 2, #1791). An
earlier 60m rerun had agent red with the failing test cut from the log
and TestDesktopSubagentEffortScope red at 30.77s (passes alone, 12.9s).
Both gateway reds pass rerun alone at load ~240 (ok 52.5s).

After rebasing onto e733b0722: go vet -tags nogui ./... for darwin,
linux and windows clean; internal/catalog and internal/provider ok.
2026-10-16 18:51:40 +08:00
..