Commit Graph
224 Commits
Author SHA1 Message Date
yetone ae58ec9b44 providers: a key's provider can have its model list off
axelburks on Discord: Ark's pay-as-you-go list names models that can't
be asked for, and each one is asked by an endpoint id the user made. A
key's provider can now have its list off (Provider.ListOff): nothing
asks its vendor for a list (Fetch, Refetch, List, RefreshLists, a test,
a new key's prefill, a resting key's probe), a list fetched before and
models.dev's are not read, and only the ids added by hand are served.
The editor shows it as "Fetch the model list", ticked by default;
unticked, Fetch models and Forget go. A save that doesn't name listOff
keeps it. CLI: `magpie provider set <id> list=off`. Accounts and plugins
list as their sign-in does, so they don't take it.

Broken by hand: ListAsks returning false for a list-off provider turns
TestListOffAsksNoListAndServesTheIDsAdded red; dropping the keep in the
save turns TestProviderSaveListOff red.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: a real Ark account; the switch was checked against fake
vendors only.

Reported-by: axelburks (Discord)
2026-11-08 11:28:54 +08:00
yetone 30b7a17326 codex: a relay's dated or renamed GPT id keeps its xhigh, max and Ultra levels
Found while looking into maomao_00001's report on Discord: the Windows
Codex app offered no xhigh or Ultra for a relay's model. Their relay
(vip.aipro.love, ids from its public /api/pricing) names its 31 models
plainly, and every one already got its full levels in
magpie-models.json before this change and gets the same after it, so
this is not their fix. Exact ids (gpt-6.1-sol, openai/gpt-6.1-sol)
were fine; two spellings other relays use were not:

- OpenAI's dated snapshot id (gpt-6.1-sol-2026-09-29) was unknown to
  the catalog, so it got the low/medium/high fallback. borrowedEfforts
  now drops a dated suffix and takes the base model's levels.
- A relay's rename (codex-gpt-6.1-sol, "[A] gpt-6.1-sol", an id the
  user marked the same as gpt-6.1-sol) got the levels up to max but no
  Ultra, because OffersUltra matched exact ids only. It now matches
  through catalog.IsOneOf, the lookup ContextOf and EffortsOf use.

Only known models change: a dated id whose base is unknown
(model-x-2026-01-01) keeps low/medium/high, a dated Luna gets its own
levels without Ultra, and glm-5.3-flash keeps [low high max].

Not changed: a dashed-date id's window and price are still unknown,
because catalog.SameModel doesn't strip that date form (#5643).

Run:
- TestCodexCatalogRelaysKnownModelsLevels red on the old code (the
  dated Sol and Luna at [low medium high], three renames without
  ultra), green with the fix.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and builds on mote.
- go test -tags nogui ./internal/catalog ./internal/provider
  ./internal/agent ./internal/codexcat on mote: all ok.
- The relay's 31 ids put through codex's Set with the real
  models.dev file (a probe, not committed): the same levels on
  origin/main and with this change.
- Full suite: not finished. My probe runs reused the suite's copy
  on mote, so it was stopped; it runs again after the push.

Refs: maomao_00001 (Discord)
2026-11-08 02:37:42 +08:00
yetoneandmdwsk88 6ac1e04244 provider: a Claude model on Copilot has its 1-hour cache write priced as Copilot bills it, at the 5-minute write (#3435)
Copilot bills a cache write at one price however long it is kept. Its
copilot_usage counts a 1-hour write as the cache_write a 5-minute one
is, and GitHub's "Models and pricing for GitHub Copilot"
(docs.github.com/en/copilot/reference/copilot-billing/models-and-pricing)
lists one "Cache write" price per Claude model, no 1-hour tier (Opus
5.5: input $4, cached input $0.20, cache write $5, output $20). magpie
gave every Claude model's list price Anthropic's 1-hour write, 2x input
(catalog.OneHourFor), so copilot/claude-opus-5.5 was priced at $8 per
million for an hour's write where Copilot bills $5: on the reporter's
request, $0.125456 against Copilot's own $0.078443.

A Copilot price (tariffOf, cacheWritesAlike) now has no 1-hour write of
its own, so an hour's write is billed as a 5-minute one
(catalog.Price.OneHour), its tiers alike, copied as they may be the
catalog's. This holds for a call read after Copilot was signed out too
(tariffOf's unknown-provider path, MakerPrice), which the reporter's
patch left at 2x. A price the user gave for a Copilot model keeps the
1-hour write they gave, and one they left out isn't filled with 2x input
(userPrice, so UserBasePriceIn reads it alike). Every other provider is
as before: Anthropic, Bedrock, Vertex and relays bill the hour at 2x, so
the rule is scoped to Copilot's id, not taken off every non-Anthropic
provider. Usage rows are priced as they are read (Record.CostAt), so
calls already recorded read at the new price too. docs/reference.md and
ModelPrice's comment say so.

Run on mote (go1.26.8, macOS) at 400b66ec3 plus this commit and the
next:
- go test -tags nogui ./internal/provider ./internal/tune
  ./internal/catalog: ok.
- TestCopilotOneHourCacheWriteAtItsWritePrice is red with models.go at
  400b66ec3 ("copilot/claude-opus-5.5 = {... CacheWrite1h:8 ...}").
  With the unknown-provider strip taken out by hand, its two new checks
  are red ("signed-out copilot/claude-opus-5.5 = {... CacheWrite1h:8
  ...}" and "BasePriceIn(copilot, claude-opus-5.5) with no Copilot ...").
Not tried: a live Copilot request; the figures are Copilot's own
copilot_usage for the reporter's request. A plugin that serves Copilot
(OpenCode's github-copilot auth) is priced as before; how it is billed
wasn't checked.

Reported-by: mdwsk88 (dawei on Discord)
Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
2026-11-07 04:03:00 +08:00
yetone fe61503e60 provider: a Remote magpie whose computer took another address is found on the network
luckymanjc (Discord) uses computer A's magpie from computer B over the
LAN. A's router hands it a new DHCP address after a boot, and B's Remote
magpie, saved at the old one, reached nothing until the address was
typed in again.

When B can't connect to a Remote magpie at all (a dial error, not an
answer), the list fetch (models.go) and the gateway's request (forward
in gateway.go) now call provider.SeekMoved (remote_moved.go). It dials
every address of the old one's /24 and of up to four of B's own private
/24s at A's port (500ms each, 128 at once). The first that lists
/v1/models 200 for the provider's key, and whose list this magpie didn't
make (magpie_via), is A: a LAN caller always needs a gateway key, so
another magpie answers 401. That address is saved as the provider's and
the request is made again there. A name or a public address is never
looked around, an address the user changed meanwhile stands, and a
provider is looked for once a minute at most, callers at once sharing
one look.

Run:
- mote-run go test -count=1 -run 'TestRemoteMagpie|TestLANNeighbours|TestDialable|TestRemoteSelf' ./internal/provider ./internal/gateway: ok
- mote-run go vet, GOOS=windows and GOOS=linux go vet of both packages: ok; gofmt -l clean
- Live: A was a real magpie on mote (10.0.0.121:3511), B a -tags nogui
  build in WSL magpie-desktop (127.0.0.1:3522), sandbox HOMEs. B's
  provider was saved at the dead 10.0.0.250:3511. B's start fetch found
  A ("found at 10.0.0.121:3511, saved there") and a chat answered 200 in
  4.2s. Then, with B running, the address was set dead again: a request
  to office/group/rot found A and answered 200 in 4.4s, saved at .121.

Broken by hand, each red: the gateway hook off (502), the fetch hook off
(fetch error), the self check off (saved at this magpie itself).

Not tried: a real Windows A; a mDNS name (.local) that changed address
(left to the name); A on a different /24 than B. On Linux a dial to a
dead LAN address took ~54s (no route to host) before the look starts;
not changed here.

Reported-by: luckymanjc. (Discord)
2026-11-06 18:11:41 +08:00
yetone 978284dd69 gateway: a transport failure or a plain 502 is not told as too long
Filed as #5486. ne9ko9 runs Codex through magpie to a custom OpenAI Responses relay
(gpt-6-astra, effort max). Three failures reached Codex as HTTP 400
"prompt is too long: about 385K/404K tokens, more than gpt-6-astra's
context window of 272000": a plain 502 "Upstream service temporarily
unavailable", a TCP connect timeout (dial tcp … connectex) and a TCP
read timeout. Codex took them as context_window_exceeded and ended the
turn instead of asking again, although the same session had just been
answered at 454K and 474K, and Codex's own window was 828,400.

tooLongUnsaid now:
- reads a 5xx as an overflow only for Devin (busyOverflows: p.ID or its
  plugin's host), the vendor b3ab3e42e added the 5xx for; every other
  vendor's 5xx is a busy moment and is asked again as before;
- never infers an overflow from a failure that is no vendor's answer
  (transportFailed): dial/read/TLS timeouts, resets, refused or closed
  connections, unexpected EOF, Bun's ConnectionRefused, and magpie's own
  "reply ended before it was complete" / "did not stream";
- weighs the request against no less than the most the model was seen to
  answer for this provider since start (Server.noteHeld, from the
  answered try's usage), and no less than the provider list's
  max_context_window (new provider.Entry.MaxContext, from
  catalog.Model.MaxContext).
An upstream that says context_length_exceeded is still passed as one,
and the 400/413/422 inference for Qoder/WorkBuddy-style refusals stays.
Mid-stream SSE is untouched (the inference runs only on a held try).
No setting: the fix is the default. NEKO-CwC's candidate (ac4aeb85d,
a passthrough request mode that turns off inference, retries and
fallback) was read; its tests are about that mode, so none were ported.

Tests (internal/gateway/toolong_transport_test.go):
TestTransportFailureIsNotTooLong (the reporter's connectex and read
timeout among 9 messages, plain and Devin), TestDevinBusyOverflowStillTooLong
(devin and devin-plugin ids), TestPlain502IsNotTooLong (the reporter's
body, end to end; a 400 context_length_exceeded still says so),
TestUnreachableIsNotTooLong, TestWindowNotBelowWhatWasAnswered,
TestWindowNotBelowListedMax. TestOverflowTheVendorDidntSay's "502
anthropic" row is now "502 plain", asked again (1+lastRetries+replanRounds).

Broken by hand, each on mote, with the targeted tests:
- busyOverflows returning true: TestPlain502IsNotTooLong and
  TestOverflowTheVendorDidntSay red;
- transportFailed returning false: TestTransportFailureIsNotTooLong red;
- held passed as 0: TestWindowNotBelowWhatWasAnswered red;
- windowMost returning 0: TestWindowNotBelowListedMax red.
The original Devin 502 and Qoder/WorkBuddy 400 cases stayed green in
each.

Run (mote-run): go vet (darwin, GOOS=linux, GOOS=windows) of
internal/gateway and internal/provider; go test -count=1 of
internal/gateway and internal/provider: vet ok on all three; gateway ok (809s); provider red only in
TestRenewLoginsKeepsClaudeReading, already #5481 and red on main 0f07fbd0c. Full suite after the
push, under ~/suite.lock.

Not tried: the reporter's real relay or a Windows run; held is kept in
memory only, so after a restart the first failure is weighed against
the listed window again.

Reported-by: ne9ko9 (Discord)
Reported-by: mahiro233 (Discord)
2026-11-06 16:33:39 +08:00
yetone cd9c52c16e library: a Remote magpie's MCP router is a Library server of its own
With another magpie as a provider (preset remote-magpie), its router's
MCP servers took adding that same magpie again under Library -> MCP.
Now the gateway's info (GET /v1) says "mcp_hub": true to a caller it
serves MCP to while its router is on with a server that isn't itself
another magpie's router. A fetch of a Remote magpie's models asks that
info with the provider's key, only while the library would still give
it a server, and the library then adds one: named for the provider,
http at <root>/mcp/magpie/hub with Authorization: Bearer <key>, kept to
this computer (local), on for the agents given the hub's entry.

- Offered once (bridgesOffered in library.json): removed or switched
  off by the user, it stays so until the provider is removed and added
  again.
- A server the user already has at that magpie's router (same origin,
  the router's path) is the one; none is added beside it.
- The provider removed takes its server out (adoptBridges, at Sync and
  the View read); providers.json unreadable takes nothing out; the
  provider's address or key changed changes the server's; edited to
  another address or key it becomes the user's own (keptBridge).
- No loop: every dial to a URL under /mcp/magpie/hub carries
  X-Magpie-Router, and a request with it is given no such server,
  neither listed (library Tools, gateway hubServersOf) nor run (Call,
  hubToolNamed). A server carried in by sync is never a bridge.
- No GUI change: it is a server row as any other.

Run (mote, at base 1c45645b5):
- gofmt -l clean; go vet ./internal/{gateway,library,provider} on
  darwin, GOOS=windows, and GOOS=linux -tags nogui: ok.
- go test ./internal/gateway -run 'TestHubLeavesRemoteRouterToARouter|
  TestInfoSaysMCPHub|TestHubMCP'; ./internal/provider -run
  'TestRemoteHubNoted|TestRemoteSelf'; ./internal/library -run
  'TestRemoteMagpieRouter|TestCarriedServerIsNoBridge|TestPluginTools|
  TestHub': ok.
- Real two-magpie run on mote: a built binary, two sandbox HOMEs /
  XDG_CONFIG_HOMEs, B on 3512 with a python stub provider and a stub
  HTTP MCP server behind its router, A on 3513 with B as a Remote
  magpie. After `magpie sync` on A, A's library.json had home-magpie
  (http://127.0.0.1:3512/mcp/magpie/hub, Bearer key, bridge home) and
  bridgesOffered [home]; A's /mcp/magpie/hub listed
  home-magpie__stubmcp__echo and tools/call returned the stub's echo;
  A asked with X-Magpie-Router listed nothing (loop guard); B asked
  with it still listed its own stubmcp__echo.

Broken by hand, each red: the Tools filter, the Call filter, the router
header in remoteHeaders, the same-origin dedup, offered-once, the
unreadable-providers keep, the key refresh, keptBridge, putServers'
carried reset, hubServerOf's Bridge, the gateway's hubServersOf, the
gateway's header -> ctx, info's non-bridge check, fetch's hook, the
older-magpie check and the this-magpie check.

Not tried / not handled:
- The real run was over loopback; a LAN remote's key check is covered
  only by the existing TestHubMCPRemoteEntryNeedsKey path.
- The provider's own extra headers (a proxy's) aren't carried to the
  server; a remote with several keys is asked with p.Key.
- A remote whose router is turned off later keeps its server (it lists
  no tools).
- A server the user added by hand at another magpie's router now sends
  X-Magpie-Router too, so that router leaves out its own Remote
  magpies' servers for it.
- Windows and Linux test runs (vet only).

Reported-by: treeman_26897
2026-11-06 14:33:18 +08:00
yetone 773902a77b provider: Find copies the provider it gives; a list asks each group once
In the same live profile (v0.1.2906, two idle minutes, 269 MB):
- provider.Find copied every provider through All, each account's keys
  and headers, to give one (9.3 MB); All's copies were 4.6 MB of their
  own. sharedAll is the providers held, for reading; Find and resolveIn
  copy only the one they give, and the pricers read sharedAll.
- buildModels asked a group's members up to five times (its compaction,
  its price twice, its protocols, its tiers), each walking the members
  and resolving each (GroupFinder 7.9 MB, membersFound 6.3 MB).
  provider.FoundOnce answers each group once per build; every caller
  only reads the members.

Run (mote, at this tree):
- gofmt -l internal, go vet ./..., GOOS=windows and GOOS=linux go vet
  ./internal/agent/ ./internal/provider/: clean
- go test -count=1 -timeout 45m ./... (all three commits' tree): 85
  packages ok, internal/gateway 748s, internal/provider 193s. Two red:
  internal/gui's TestMainWindowCorners/macOS_26_SDK, mote's macOS 27
  (#3949, filed before, untouched here), and internal/agent's
  TestCodexEffortOptionsReadTheKeptList, whose bar counted the
  environment's copy (see the effort test's comment), fixed in its test.
- then go test -count=1 -timeout 45m ./internal/agent/ with that fix:
  ok (200.1s)

Broken by hand (mote, -run):
- Find through All again: 167 allocations against a bar of 60, red;
  green it is 6 (TestFindCopiesTheOneItGives, which also checks that a
  change to what Find gives reaches neither the next Find nor All).
- FoundOnce forgetting what it found: group:a walked 5 times, red
  (TestFoundOnceAsksEachGroupOnce).

Not tried: the numbers on the live app after this build.
2026-11-06 12:48:51 +08:00
yetone e17c6976b2 provider: Voyage AI preset, its embedding and rerank models (heatonz on Discord)
heatonz on Discord asked for Voyage AI, its embeddings and rerank. The
gateway already had /v1/embeddings and /v1/rerank; what was missing was
a way to add Voyage and have its models found there.

- presets.go: `voyage`, a vendor with an API key at
  https://api.voyageai.com/v1 (docs.voyageai.com, keys at
  dashboard.voyageai.com). Voyage has no /models, so it is NoList and
  the preset names its models in two new PresetDef fields, Embeddings
  (voyage-4-large, -4, -4-lite, code-4, finance-2, law-2, 3-large, 3.5,
  3.5-lite, code-3, code-2) and Rerankers (rerank-3, -3-lite, 2.5,
  2.5-lite), as Voyage's docs list them on 11-06. Region gets
  Rerankers too.
- models.go: planMedia marks each plan model with what it serves
  (catalog.Model.Serves), falls back to the preset's own lists when the
  provider has no region, and PlanRerankers / PlanRetrieval(kind) sit
  beside PlanEmbeddings. A NoList provider's ListAll has them too,
  marked, so catalog.Chat keeps them out of agents' lists, keys and
  Routing's chat pickers.
- gateway: resolveRetrievalModel and servesKind look up the kind asked
  for (PlanRetrieval(kind)) and not only embeddings. Before this, a plan's
  embedding model named on /v1/rerank was sent there, and a plan's
  reranker was never found.
- catalog.ServesOf: `voyage-*` is an embedding model (its ids have no
  "embed"), so Test, detection and a relay serving voyage ids know it.
- test.go / gui providers.go: the retrieval-only Test fallback and the
  editor's "retrieval" count read PlanRetrieval as well.
- docs/reference.md: a new "Embeddings and rerank" section with both
  routes' bodies (OpenAI's for embeddings; the Cohere/Jina/Voyage shape
  for rerank, top_n or top_k) and the Voyage preset. READMEs and the
  import docs pages (en, ja, zh) list it.

Not served: Voyage's contextualized and multimodal embeddings (their own
endpoints). A Voyage 4xx comes back as its raw {"detail": ...} body with
its status (errorSaid has no "detail" reader).

Tests (no network; a fake built from Voyage's documented request and
reply shapes): TestVoyageEmbeddingsAndRerank (bare and provider ids,
input_type/output_dimension and top_k/return_documents passed on, usage
total_tokens recorded), TestVoyageModelsStayOnTheirRoutes,
TestVoyageRefusalSaysWhy, TestVoyagePreset,
TestVoyageTestAsksItsRetrievalAPIs, TestServesOf's voyage cases.

Run on mote: go test -count=1 -timeout 45m ./internal/provider
./internal/catalog ./internal/gui ./internal/gateway. provider, catalog
and gateway ok. gui has one red, TestMainWindowCorners/macOS_26_SDK,
which is #3949 (red on macOS 27); this change doesn't touch AppKit.
go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./... ok. gofmt -l clean.

Broken by hand:
- resolveRetrievalModel/servesKind back on PlanEmbeddings:
  TestVoyageEmbeddingsAndRerank red (rerank-3: 404 "magpie knows no
  model"), TestVoyageModelsStayOnTheirRoutes red (voyage-4 on /v1/rerank
  answered 200).
- the voyage- prefix out of ServesOf: TestServesOf and TestVoyagePreset
  red.

Not tried: against the real API. No Voyage key was available, so the
endpoints, auth and shapes come from Voyage's docs alone. Not tried in
the GUI's Add sheet by hand, and not on Windows or Linux beyond vet.
2026-11-06 10:17:08 +08:00
yetoneandggbdpq baf70992f6 usage: a call the vendor answered with another model is priced as the model that served it (#5340)
The ledger priced a call at the model asked for and fell back to the
model the reply named (Served) only when the asked-for one had no price
(#1498). That order is right for a relay that sells kimi-k3 as
moonshot-kimi-k3 and bills by the name it sold, but it also priced a
real substitution: claude-opus-5-5 asked, claude-opus-5 served. The
vendor bills for the model that ran. kaimo455's ledger had 836 such
rows, every one at the asked-for rate: $374.06 reported against
$493.28 at the served model's rate. gateway-key cost limits (KeySpent,
NewCoster) and budgets read the same pricer.

Pricer now prices a call the ledger marks swapped at the served model's
price. That covers a price the user set for the served model and every
other layer of BasePriceIn. A price the user set for the model asked for
still wins, 0 included (new provider.UserBasePriceIn is BasePriceIn's
user layer alone). When the served model has no price, the asked-for
one's stands. Renames, vendor aliases, serving names and region
deployments price as before, and rate windows still read each record's
own time. apiPricer, the API price behind a subscription window's whole,
follows the same rule: the served model's API price first, then the
asked-for one's.

Review changes on top of ggbdpq's patch:
- The swap is judged the way the ledger's Swapped column judges it: on
  the model id and on the name that went out (SentNameIn over the
  user's ModelWires). A model the user sends under the served one's name
  was answered as asked, so it keeps its own price. The patch judged the
  model id alone, so such a row was priced as swapped while the Requests
  page said it wasn't. The pricers' memo keys now include the effort,
  because the sent name depends on it.
- apiPricer (window holds) got the same rule. The patch left it on the
  old order.

Tests:
- TestLedgerPricesASwappedCallAsTheModelThatServed (patch, plus a
  ModelWires case) checks the ledger and the Requests page.
- TestLedgerPricesARenamedModelAsTheOneServed: the sol row (sol asked,
  kimi-k3 served, both priced) is a genuine swap, so it now prices at 3,
  not 2.
- TestHoldsPriceTheModelTheReplyNamed: claude-opus-4-7 answered by
  gpt-5.5 is priced at gpt-5.5's API price. Answered by an unpriced name,
  it keeps opus's.

Run on mote at this tree, on origin/main 4e7661adc:
- The three tests above: ok.
- Product files (ledger.go, window_holds.go, provider/models.go) put
  back to origin/main, tests kept: all three FAIL ("served luna:
  priced=true cost=10, want 33"; "sol: ... cost=2, want ... 3"; "a call
  answered by another model wasn't priced as that one: &{Input:5 ...}").
- servedInstead's sent-name check broken by hand (return true): the
  ModelWires case FAILs ("served luna: priced=true cost=33, want 10").
- go test -tags nogui -count=1 ./internal/usage/ ./internal/provider/
  ./internal/budget/ ./internal/otlp/ ./internal/middleware/: all ok
  (usage 44.9s, provider 158.3s).
- gofmt -l: clean. GOOS=linux go vet -tags nogui and GOOS=windows go vet
  of internal/usage and internal/provider: clean.

Not tried: a real ledger with Anthropic's refusal fallback. The rows in
the tests are built from the shape the reporter describes. The full
suite runs after the push.

#5340, kaimo455 (report, measurement and the proposed order)

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 09:57:18 +08:00
yetone acde144a7a providers: a vendor of embedding and rerank models alone is detected on /embeddings and /rerank (heatonz)
heatonz on Discord (#help, 11-05): a custom provider whose models are only
embedding and rerank models couldn't be added. Detect APIs ("检测协议")
picked the first listed model, an embedding model, and asked it to chat on
every API, so nothing answered.

- tiny: an embedding or rerank model (catalog.ServesOf) on Chat is asked
  where the gateway's retrieve sends it: the OpenAI base's /embeddings
  ({"model","input"}) or /rerank ({"model","query","documents"}). tested
  adds no extra body there, as the gateway sends none.
- detectModel asks each API a model that chats when the list has one, so
  a chat vendor's detection is unchanged. A retrieval model is a last
  resort on Chat only. Responses, Anthropic and Gemini say why they weren't
  asked (DetectModels too).
- testModel: a saved provider with nothing to chat with tests on a
  retrieval model its list keeps apart (LiveServing). testOne asks such a
  model on Chat and never moves it to another API.
- provider.ListAll is List with Serves models kept. /api/provider/list and
  the provider's JSON carry a `retrieval` count. The add form's Fetch models
  and the saved editor say "Only embedding and rerank models are listed.
  They need no pick: ask them on /v1/embeddings and /v1/rerank." in place
  of "the list is empty". One new string, in zh, zh-TW, ja and de.
- app.js stays under TestCoreScriptBudget with no raise: +42 bytes, paid
  for by two add-form comments cut.
- The gateway already routes /v1/embeddings and /v1/rerank to such a
  provider (#765, resolveRetrievalModel by prefix or KindGroup), so nothing
  changed there.

Run (mote, at this tree on origin/main 60fe6645a):
- go test ./internal/provider ./internal/catalog: ok.
- go test ./internal/gui: ok, except TestMainWindowCorners/macOS_26_SDK,
  which is #3949 (mote is macOS 27).
- go build ./..., go vet (darwin), GOOS=linux go vet -tags nogui and
  GOOS=windows go vet of provider and gui: ok. gofmt -l: clean.
- node --test, chromium and webkit: provider-retrieval-only (new: en, zh,
  zh-TW, ja, de, with and without retrieval models, add form and saved
  editor), provider-detect, provider-add-models, azure-endpoint,
  provider-listed-as, provider-add-gemini, i18n-en-no-cjk and i18n-keys.
  94 of 95 pass. The red is i18n-keys "a plugin's words are its own", red
  on origin/main 60fe6645a too (#5332/#5327).

Broken by hand:
- New tests on origin/main's code. TestDetectEmbeddingOnly red ("The
  model BAAI/bge-m3 does not support chat" on chat, 404 on the rest).
  TestTestEmbeddingOnly red ("no model to try"). TestProviderListBeforeSave
  red (retrieval = 0).
- Retrieval models not kept out of chat probes: the mixed-list case is red
  (bge-m3 asked beside glm-5).
- tested adding the extra body to /embeddings: red (prompt_cache_key
  sent).
- detectOne asking non-Chat APIs with a retrieval model: red (404 on
  /v1/responses).
- testModel's LiveServing fallback off: TestTestEmbeddingOnly red.
- provider-retrieval-only on the old app.js with the new i18n.js: the 5
  retrieval cases red, the 5 empty-list ones green.

Not tried:
- A real embedding/rerank vendor (heatonz's is unknown). Fake httptest
  servers only.
- The whole GUI suite.
- Windows and Linux test runs (vet only).
- Models whose ids don't say embed, bge- or rerank (gte-, e5-, m3e-,
  text2vec-, voyage-) are still taken as chat models. The /embeddings probe
  goes by the id, and a Xinference model_type isn't read.
2026-11-06 05:21:05 +08:00
ggbdpq cfadcde168 provider: a model list OpenCode's key is refused is asked again bare, so the picker says what the vendor serves (#4900)
What changed: OpenCode's model lists are public - the vendor answers its
/models without a key. When a provider's keyed ask of the list is
refused (an expired or wrong key), the same list is asked once more
without credentials, and what the vendor serves is saved as the
provider's list. The picker then shows the vendor's word instead of
falling back to the models.dev catalog, which files free rows under
opencode-go that Go doesn't serve (cat-jam-free, minimax-m3.1-flash-free,
step-5-preview-free, longcat-2.5-preview-free) while missing the free
rows it does (beam-free). The retry is kept to OpenCode's own hosts
(IsOpenCode): no other vendor's list is known to answer bare, and a
partial public list would stand in for the keyed one. Multi-key
providers, account (sign-in) lists and the add form's List are not
covered.

Reviewed and ported (on origin/main 1b0340fdb, cherry-picked clean;
the hunk now sits in fetchList, which fetch was split into since):
- mote: TestOpenCodeListAskedBareWhenTheKeyIsRefused and
  TestOpenCodeListNotAskedBareAtAnotherHost green. With models.go put
  back to main and the tests kept, the first is red:
  "the bare ask should have answered where the key was refused: no
  model list: https://opencode.ai/zen/go/v1/models: (Invalid API key)".
- mote: go test -tags nogui ./internal/provider ./internal/catalog ok;
  go test -tags nogui -timeout 45m ./internal/gateway ok (1009s); go vet
  (darwin), GOOS=linux go vet -tags nogui, GOOS=windows go vet on
  provider, catalog and gateway ok; gofmt -l clean.
- Read: the bare retry follows any failed keyed ask, not only a 401/403
  (the list errors are untyped strings); a network failure costs one
  more ask and keeps the first error. Provider Test still probes each
  endpoint with the key, so an expired key is still shown red there.
Not tried: a real expired OpenCode Go key; the tests serve the vendor
from a stub transport, no network.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
Generated-by: GLM-5.3-Flash (ZCode)
2026-11-05 18:31:16 +08:00
yetone 2f59545d29 gateway: a key not given a group listing alone is listed the members it may use (luckymanjc)
luckymanjc on Discord (#general, 11-05): on a second computer, through
Remote magpie, his three Codex accounts offered GPT-6-Luna alone, with
the key his Remote magpie uses held to "Codex 的全部模型" (codex/*),
GPT-6-Luna and the accounts. His screenshot of that key's picker, on the
host, offered GPT-6-Luna alone under Codex too.

Cause: a routing group listing alone (Group.Unlists, "the group alone")
keeps its members out of Catalog(), so out of /v1/models and the key
picker (/api/caller-keys/models), as the group stands in for them there.
Since d1cdce130 (11-03) that holds for subscription models again. But a
group of the user's own is never a key's unless the key names it
(kautism's rule, groupAllowed), so a key held to codex/* was given
neither the group nor its members: only the Codex models no such group
named were left, Luna here. The picker read the same Catalog(), so there
was nothing else to tick.

Fix: the group stands in only where it is given.
- provider.GroupStandIns: the models groups listing alone keep out, with
  the groups' ids (groupsKeeping, which unlistedByGroups now reads; a
  provider kept for routing groups alone is not among them).
- gateway keyListed: for a key that may use none of the groups standing
  in for a model and may use the model, the model is listed beside its
  provider's others; the list's own picks still leave one out. Every key
  list goes through it: catalogFor (/v1/models and what it feeds, the
  remote magpie's fetch included), /v1/models/{id}, the key's page,
  Codex's catalog and spawn choices. A key that names the group gets the
  group in place of its members, as before. Unrestricted callers are
  unchanged: the group alone, as the option says.
- The key picker offers those models after their provider's.
It is the same for every provider a group can list alone, not Codex
alone. Docs: reference.md, gateway-routing.md.

Tests (mote):
- TestKeyNotGivenTheGroupIsListedItsMembers (gateway): Free + Pro Codex
  sandbox accounts, a group listing sol/astra/terra alone. Unrestricted
  list: group, no members. The reporter's key (codex/*, codex/gpt-6-luna,
  both accounts): every Codex model, no group. A key of one member: that
  one. A key naming the group: group, no members. A Remote magpie on the
  reporter's key fetches every Codex model. Red on the old code (sol,
  astra, terra missing), green now.
- TestCallerKeyModelsOfferGroupKept (gui): the picker offers the kept
  models, beside their provider's. Red on the old code, green now.
- Broken by hand: dropping the "a group standing in is given" check
  turns the key-naming-the-group case red.
- go vet provider, gateway, gui; go test ./internal/provider ok;
  ./internal/gui all ok but TestMainWindowCorners (#3949, AppKit titlebar on
  mote's macOS, untouched here); ./internal/gateway -run
  "Key|Codex|Model|Remote|Group|Catalog|Spawn|Unlist|Caller" ok.

Not tried: the reporter's own host (his groups are inferred from the
screenshot: only Luna left under Codex in the picker); two real magpie
apps on two machines; real Codex accounts.
2026-11-05 18:28:38 +08:00
yetone a732f3c493 gateway: models of one API other than chat are grouped by id on their route (#5339)
XYenon (Discord) has the same embedding model at several providers and
asked why it isn't grouped the way chat models are. It wasn't even
listed: a fetched list dropped every embedding, rerank, speech and
transcription model, so "embed-1" on /v1/embeddings was a 404 unless a
hand-made group named it.

- catalog: a fetched list keeps those models, tagged with their API
  (Model.Serves, read from the id by ServesOf: rerank, embed/bge-,
  whisper/transcribe, tts-/-tts). Chat() and Live() leave them out, so
  agents' model lists, gateway keys and Routing's chat pickers never
  see them; LiveServing(id, kind) reads them. The live file says
  "kinded": true; a list fetched before this is fetched again once a
  run (autolist), with no schedule needed.
- provider: KindGroup(kind, ref) is made per request, never stored, so
  it is in neither Groups() nor Catalog(). Its id is
  auto-<kind>:<model> ("group/auto-embedding:embed-1"); its members are
  the providers that serve exactly that id for that API, in the order
  they were added, none off, decide-only, serving none, or with the
  model disabled.
- gateway: embeddings, rerank, speech, transcriptions and videos pick
  the group by route (mediaMembers): a bare id is a kind group when
  more than one provider serves it, the group's own id always; a
  hand-made group still works through offChatList. A group is of its
  own API: an embedding model's id on /v1/rerank is a 404.

Run at bd0f33828 + this change, on WSL magpie-desktop (mote was
running another session's full suite):
- go test -tags nogui -count=1 -timeout 45m ./internal/catalog
  ./internal/provider ./internal/gateway: ok, ok, ok (594s). The first
  run was red in three tests that held a fetched list to leaving its
  embedding model out (TestFetchArkMarksVideoModels,
  TestNvidiaModelScopeLiveList, TestTencentTokenHubList); they now hold
  it kept, tagged embedding, and out of catalog.Chat.
- 22 GUI files over the model lists and Routing pickers, both engines,
  every language (group-pick-drawers image-models-hide video-models-hide
  model-kind routing-kind agent-models agent-models-picker
  agent-model-groups agent-models-only-picked gateway-key-models
  gateway-key-groups group-from-model-add unlisted-models
  models-select-all-api provider-add-models provider-detect-models
  routing-rule-models panel-routing-pick fallback-group group-unlists
  settings-groups i18n-keys): 229 of 244 pass. The 15 reds are in six
  files that a control run of those six at bd0f33828 has red the same
  (14 of 56): #4389, #4964, #5332, #4616 and, new, #5357
  (routing-rule-models webkit 390). agent-models webkit zh's opacity
  0.998 was red here only, a fixed 250ms wait: #5358. No GUI asset is
  changed here; the GUI tests stub /api.
- on mote: TestProviderListBeforeSave (internal/gui; the add form's
  list keeps an embedding model out) and
  TestPiModelsAskedOnTheirNativeAPI (internal/agent), ok.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet of catalog,
  provider and gateway on mote at this head, ok.

Rebased then on origin/main d620ff6b5 (one commit, internal/agent and
internal/sessions only), and b63b28958 (one mover min line) after; at
d620ff6b5 + this on mote: go build ./..., go vet
of catalog, provider, gateway, agent and sessions, go test
./internal/catalog and -run 'Kind|Fetch|Nvidia|Tencent|Serving' of
provider and gateway: ok.

Red on the old code: TestKindGroupsServeEachAPIByRoute (embed-1 404)
and TestVideoKindGroupByTheModelsID (404).
Broken by hand, each red, then restored:
- the fetch dropping serves != "" again: TestFetchKeepsModelsOfOtherAPIs;
- the once-a-run refetch forced off: TestKindlessListFetchedOnce;
- KindGroup's disabled-model check removed:
  TestKindGroupHoldsTheExactModel;
- LiveServing asked with "" (any kind): the rerank-by-embedding-id
  check gets 200 instead of 404.

Known gaps, not done here:
- The Routing group editor still offers only chat and image models, so
  a new hand-made group of different ids (bge-m3 / BAAI/bge-m3) can't
  pick kind models: #5352.
- A bare id whose every member is disabled is a 404, not a 403.
- Rerank, Qwen3-Embedding and bge models that sat among a provider's
  chat models before (textModel's words missed them) leave agents'
  lists now. A hand-made group naming one keeps serving.
- /v1/models lists no kind model; the Routing live view may show the
  raw kind id.
Not tried: real vendors' lists and routes; the full ./... suite at this
head (queued on mote after another session's run; reds get issues).
2026-11-05 16:22:31 +08:00
yetone 1826c4bd99 providers: a Remote magpie that is this magpie says so and is left out, unless kept (hanslin1666)
B uses A through a Remote magpie provider, and sync carries that
provider to A, where it points at A. Each of its models was one of A's
own, listed again beside it and taken by A's found groups, and a request
through it passed through A's gateway twice.

A fetch of a Remote magpie's list now reads its models' magpie_via: when
the magpie that listed them (the last entry) is this magpie's own
catalog.Self, remote-self.json keeps the provider id and the address it
answered at (noteSelf). Another lister, or a list with no via, takes
the record away; an empty list or a failed fetch changes nothing; a
provider moved to another address is not self until a fetch there says
so. The file is this computer's own, never in a backup or sync.

Such a provider is left out (SelfLeftOut in On, SwitchedOff and
remoteMagpies): not in /v1/models, the catalog or a found group. A
request naming one of its models, an agent's pick synced from B, is
served here with the remote's id taken off (ThroughSelf in Resolve and
ResolveRoute), once through the gateway. A 404 for it says why and how
to keep it.

The Providers row shows "This magpie" (greyed while left out), with the
reason as its title; the editor has a note and a "Use it anyway" tick
(KeepSelf, POST /api/provider/keepself). KeepSelf belongs to the user
and to this computer: Mirror and Restore keep the local value (false for
a provider new here), davsync's hashes blank it, and a provider save
keeps it. Strings in en, zh, zh-TW, ja, de.

Docs: providers-accounts.md (two magpies row), sync-backup.md (what
stays on each computer).

Run at this tree on origin/main 4e85cac01:
- gofmt -l: nothing. app.js 1,309,132 bytes (budget 1,316,874).
- mote: go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet of
  provider, gateway, gui, davsync, catalog: ok.
- mote: go test catalog, davsync ok; gui red only in
  TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27); provider and
  gateway did not build there (mote's disk full, "no space left on
  device"), so they were run on:
- Linux (WSL magpie-desktop): go test -tags nogui provider, gateway,
  gui, davsync: all ok.
- Windows (xiaomi-gpu): go test -run 'RemoteSelf|KeepSelf|RemoteMagpie|
  Mirror|KeepLogin' provider, gateway, davsync: ok.
- mote: remote-self.test.cjs 16 of 16 (chromium and webkit, 1100 and
  420, en zh ja de), before the rebase; the rebase touched no line of it.

Broken by hand, each red, then restored:
- noteSelf a no-op: TestRemoteSelfRecord and
  TestRemoteMagpieThatIsThisOneIsLeftOut red.
- ThroughSelf a no-op: the gateway test red (404 for rem/own/m1).
- On() without SelfLeftOut: the gateway test red (listed, 2 passes).
- davsync hashes without the KeepSelf blank: TestKeepSelfIsNoChange red.
- Mirror without keeping KeepSelf: TestMirrorKeepsKeepSelf red.
- The row's badge removed: remote-self.test.cjs red (chromium 1100 en).
- The tick's onchange a no-op: remote-self.test.cjs red (webkit 420 zh).

Not tried: two real computers syncing each other (the case is built in
one process: the gateway test's Remote magpie is its own gateway);
the Linux and Windows apps' webviews; the whole GUI suite (mote's disk is full);
remote-self.test.cjs again after the rebase.
2026-11-05 12:37:30 +08:00
yetone 7b5e773873 provider: a model at a window (claude-opus-5-5@300k) is priced as its model, so Cursor's sized ids have a cost
RyuJeXu on X (tweet 2117971061103100279), building an iOS board on magpie's
usage data: "cursor的用量好像不计费呀". Cursor calls showed no cost.

Cause: the Cursor plugin lists each model once per context size
(claude-opus-5-5@300k, @1m, gpt-5.5@272k, ...), lists them all at cost 0
(no price, pluginPrice), and its reply echoes the asked id, so usage rows
carry the sized id. pricedNames only took a window off grok- ids, so every
other sized id fell through the maker catalogs with no price. The plain ids
(claude-opus-5-5) were priced at the maker's list price all along.

Fix: pricedNames also tries the id with an "@<digits>k|m" window taken off
(modelWindow), for every provider. The window names the context size, not
a different model; long-context tiers still follow the call's own prompt
tokens through Price.At. Dated ids (claude-opus-4-5@20251101) and ids with
anything else after the @ are left alone. The regexp runs only for an id
with an @, since every listed model is priced on each Providers poll.

Tests:
- internal/provider/cursor_price_test.go: a moved Cursor provider prices
  @300k, @1m, upper case, a maker-prefixed id and gpt-5.5@272k/@1m as the
  plain model, through ListPrice, MakerPrice, PricedName(For), and its
  tier at 300K prompt tokens; a dated id, "@272", "@", "@272kb", an
  unknown model and auto stay as they were.
- internal/usage/cursor_window_cost_test.go: a Cursor row for
  claude-opus-5-5@300k costs what the plain id does ($6 each), auto stays
  unpriced, the page total is $12.
- grok_price_test.go: gpt-6-astra@500k under grok is now priced ($10/$50);
  grok-4.7-build@500k still isn't.

Run (all through mote-run, go1.26.8, base 823e7c250, the committed tree):
- gofmt -l internal/provider internal/usage: clean.
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
  ./internal/usage ./internal/usageapi: ok 239s / 75s / 1s.
- GOOS=windows go vet and GOOS=linux go vet -tags nogui of provider,
  usage, usageapi: ok.
- Real catalog (a copy of the owner's models.json) before the change: every
  non-Grok sized Cursor id was unpriced; plain ids priced.

Broken by hand: with the old models.go put back, the two new tests fail on
every sized id (usage total 6 instead of 12) and TestGrokEffortListPrice
fails on gpt-6-astra@500k.

Not tried / not changed:
- No real Cursor call; the owner's ledger copy has only auto rows.
- Cursor's own auto and composer-2.5, and its own spellings (glm-5p3,
  deepseek-v41-flash-1017) and gemini-3.1-pro have no catalog price and
  stay unpriced; the plugin would have to give them a cost.
- Not ./... and no GUI suite: the change is in provider's price lookup
  only.
2026-11-04 22:45:40 +08:00
yetone 1a67ca614e provider: Fetch models refreshes each key's own models, keeping what the user un-ticked (young02036)
young02036 on Discord: a provider holds several keys, each at a group of
a relay's that serves different models. Each key's own list was read
only when the key was added (PrefillNewKeys); Fetch models merged every
key's list into the provider's (fetchPerKey marks each model with the
keys that list it) but never changed a key's own models, so a model a
group took on later was never sent to its key and one it gave up still
was.

Fix: refetch, which every Fetch goes through (the editor's button, the
CLI, the TUI, the automatic re-list), takes each key's marks before and
after the fetch and carries the difference into that key's
AccountModels (key_models_refresh.go): a model the key's list has now
and didn't before is ticked for it, one it had and has no more is taken
out. A model the user un-ticked that the list had before and still has
stays un-ticked; one the user ticked that the list never had stays
ticked. Only keys with a list of their own are touched (a key serving
every model still does), a key with no marks before or now (one key
on, just added, a list that failed) is unknown and left alone, nothing
is ever narrowed to an empty list, and a key whose models the user
changed while the lists were asked keeps the user's. The provider's own
picks (what agents get) are not touched. No GUI change: the editor's
Fetch already redraws the key rows from the saved provider.

Test: TestFetchRefreshesEachKeysModels, against an httptest relay whose
per-key lists change between fetches: add a key (prefill), un-tick by
hand, groups change, fetch; un-tick again and tick a model the list
lacks, fetch twice; a key's list failing; the provider's picks unset.

Red on the old code (the refreshKeyModels call removed): "sk-a after a
fetch: [gpt-5.5 deepseek-v4], want [gpt-5.5 kimi-k3]", "sk-c after a
fetch: [deepseek-v4 qwen3-max], want glm-5 ticked", and the gateway's
AccountServes check. Broken by hand: ticking every listed model instead
of only those new to the key turns the un-tick, hand-tick and failed-list
cases red (4 errors).

Run on mote at this tree (on 78128b510): gofmt clean; go vet
./internal/provider ./internal/gui, GOOS=linux -tags nogui and
GOOS=windows go vet: ok. go test -count=1 -timeout 45m
./internal/provider ./internal/cli ./internal/tui: ok. ./internal/gui:
TestCoreScriptBudget (#5139) and TestMainWindowCorners/macOS_26_SDK
(#3949) red, the same as for 78128b510; no gui file changed here.
GUI files, chromium and webkit, every language they run:
account-models and account-refresh 26/26 ok. provider-fetch-again,
provider-picks-stay and gateway-key-models (en) are red, and red the same
way at a clean 78128b510 checkout with no change of this commit: #5232
and #5233.

Not tried: a real relay with per-group keys, and the full suite before
the push.
2026-11-04 19:30:08 +08:00
yetone 47b7ba3030 models: a model its provider lists at $0 says free in the pickers and Routing (jiangguochao666 on X)
jiangguochao666 asked for each provider's free models to show in Routing
and the model settings, to route to them. The green free tag was shown
only for a plan's free model or a model with "free" in its name.

provider.PricedFree says a model is free only when its price for that
provider is known to be $0:
- A price the user set comes first (provider/model, provider/*, then
  the model's own key). A $0 one makes it free, and any other price, a
  paid tier included, makes it paid.
- Otherwise the provider's own catalogs decide. A $0 from a plan's
  catalog (-plan, membership catalogs) is the plan's per-token price,
  not free. A $0 from only the model's maker is not free either: a
  relay serving Zhipu's free glm-4.7-flash may charge for it.
- No known price means not free.
FreeModel (Free first, Cheapest first routing) is unchanged.

From the local models.dev cache this tags:
- every model of NVIDIA NIM and ModelScope;
- the :free / -free models of OpenRouter, OpenCode Zen and Go, Kilo,
  AIHubMix, ZenMux, Vercel, Requesty and other relays;
- Zhipu's and Z.ai's glm-4.x-flash.
No coding or token plan is tagged.

Where it shows, with the hover "free: listed at $0 on this provider":
- an agent's model picker (agent.Option.Zero);
- the provider editor's model chips, and its Free only button
  (modelJSON.Zero);
- Routing's Add a model and classifier pickers (modelRef.Zero).
The word is new in en, zh, zh-TW, ja and de.

Tests, each red on the old code:
- TestPricedFreeIsTheProvidersOwnZero: own, plan, maker-only, unpriced
  and user prices.
- TestPickerSaysAZeroPricedModelIsFree: Option.Zero, cleared at once by
  a price the user saves.
- TestZeroPricedModelsSayFree: the editor's and Routing's JSON.
- zero-priced-free.test.cjs: the three surfaces, in Chromium and WebKit,
  at 1100 and 420px, in all 5 languages. It checks the tag's text,
  hover and fit, that the paid model has no tag, that a plan's free
  model keeps its own hover, no sideways scroll and no page errors.

Broken by hand (each restored, diff checked):
- The source check ignored (maker and plan $0 count): the provider test
  goes red on the plan model and the relay's glm-4.7-flash.
- PricedFree always false: the provider, agent and gui tests go red.
- The user's price ignored: the provider and agent tests go red.
- The badge's o.zero / m.zero and Routing's zero dropped in app.js and
  routing/client.js: zero-priced-free goes red, "the $0 model has no
  free tag in the agent's picker".

Run at this commit's tree (base 3f1f1882a):
- mote, go test -timeout 45m ./...: 84 ok, 19 with no tests, 3 FAIL.
  Each red is filed and fails the same way at origin/main 7d022bdb6:
  - TestEveryRouteHasACommandOrIsNamed: /api/context/reply, #5026.
  - TestMainWindowCorners/macOS_26_SDK: macOS 27, #3949.
  - TestCompactionOverByteCapEveryTime: red only in the full gateway
    run, ok alone here and at main, #4862.
  TestCoreScriptBudget passed; no budget was raised.
- gofmt -l: clean. GOOS=windows go vet (mote): ok. go vet -tags gtk3 on
  Linux (wsl, magpie-desktop): ok. A cross GOOS=linux vet from macOS
  fails inside wails' cgo files on main too.
- wsl: zero-priced-free + i18n-keys, 24 of 24 pass.
- wsl: the whole GUI suite, concurrency 4: 19062 of 19585 pass,
  523 fail in 127 files, at load ~86 on a shared box. Those 127 files
  run again at concurrency 2: 465 red here and 417 at the base
  3f1f1882a, the same files on both. 11 files with a red only on this
  tree, the routing, model and search ones near this change, run again
  alone at load ~3: the same 7 fail on both trees
  (33 here, 27 at the base), and which cases fail changes from run to
  run with the same errors. None is in a test that reads the free tag.
  Filed already: #3096 and #5035/#5088 (routing-rule-*, rest-try-now),
  #4388 (model-chip-steady alone on WSL), #4585 and #4932 (under load).
  The other files red only on this tree (usage wheels, tray, archive
  rows) were not run again alone; nothing in them reads the free tag.

Not tried: a real provider's list in the live app (the tests use
fixture catalogs); Free first routing choosing a $0-priced model it
didn't choose before (FreeModel is unchanged on purpose).
2026-11-04 05:00:18 +08:00
yetone d1cdce1302 provider: the group alone keeps subscription models out of agents' lists (shaoyang.)
shaoyang. on Discord (#general, 11-03): with a routing group's Model
lists set to the group alone (its card's 成员模型不单独列出), the model
list fetched still had every model of the group.

Cause: 88e6fb9cf (v0.1.2176, 10-30) had catalogOf keep a signed-in
subscription's models (SubscriptionKept: a ChatGPT, Claude, Copilot or
plugin account's) for every agent, leaving the group alone only for a
client that is no agent (""). Over HTTP no client is "": agentOf falls
back to usage.AgentOf(User-Agent), which is "other" or the UA's name, so
every /v1/models fetch, every agent's written list and every picker
listed a subscription member beside the group. For a group made of
subscription models, as most are, the option changed nothing.

Fix: catalogOf gives every agent but Codex Catalog(), as before
88e6fb9cf; Codex keeps its ChatGPT sign-in's own models (CodexOwn,
a3ee00c05), which its app reaches on that sign-in. SubscriptionKept is
gone; Unlisted() and GroupKept() name subscription members again, so the
picker's "kept for routing groups" note and the provider editor's
"listed alone" line (3d063e34f) say where they went. The routing editor's
hint says Codex keeps its own, in en, zh, zh-TW, ja and de. Docs:
reference.md, gateway-routing.md.

Behaviour change for 士奇's case (88e6fb9cf): with "The group alone" on,
Hermes, WorkBuddy and the rest lose the group's subscription models
again; that is what the option says. Listing its models too keeps them beside
the group, which the new test checks.

Tests:
- gui TestGroupAloneKeepsSubscriptionModelsOutOfEveryAgentsList (replaces
  TestSubscriptionModelsStayInEveryAgentsListWithGroupOn): a sandbox
  ChatGPT sign-in's 5 models in a group listing alone. For every agent
  but Codex that lists the group, its Agents-page list, CatalogFor and
  model pickers leave them out; Unlisted names them; with "Its models
  too" hermes, workbuddy, claude and codex list them.
- gateway TestGroupAloneKeepsSubscriptionModelsOffAgentsModelList:
  GET /v1/models with no key, "magpie" and magpie-hermes/-claude/-opencode
  lists group/mine and not its members; /v1/models/{id} doesn't find one
  for Hermes; Codex's key lists and finds them; listed again with
  listed too.
- TestCodexOwnModelsListedOnlyThroughGroups again expects Claude Code not
  to list a group-alone member.

Run on mote at 3da80330a (rebased on origin/main c3593dc49): gofmt -l
clean; go vet (darwin -tags nogui, GOOS=linux -tags nogui at the base,
GOOS=windows) on provider, gateway, gui ok; go test -timeout 45m
internal/provider ok, internal/gui ok, internal/gateway -run
"TestGroup|TestCodex|TestUnlisted|TestModels|TestDesktop" ok. At the
base 40a287b21: internal/provider, gateway, gui and agent whole ok;
internal/cli red only in TestEveryRouteHasACommandOrIsNamed (GET
/api/context/reply, #5026, red on main since 0872bc2a0). GUI:
group-unlists (en/zh/zh-TW/ja/de, 1100 and 420px), unlisted-group-kept,
unlisted-models, agent-models-group-on, i18n-keys in chromium and webkit,
56 of 56.

Broken by hand: catalogOf back to SubscriptionKept with the new tests in
place; the gui test failed with 484 "the group alone" errors (codex/gpt-5.5
in claude's, claude-desktop's, claude-science's lists and pickers among
them) and the gateway test for every key, no key and "magpie" included.

Not tried: a real ChatGPT/Claude sign-in or the running app, and the
reporter's Docker deployment (same /v1/models path, no OS branch); which
agent fetched the list isn't known.
2026-11-03 18:23:13 +08:00
yetone 7c115f6f5b provider: picks gone from a list for over an hour serve the list (maxleebeta)
maxleebeta on Discord: with WorkBuddy and WorkBuddy AI both signed in,
the Agents page's model picker had no WorkBuddy AI model, and its
Providers row read "已登录 · 1 个图像模型 · Free plan" where WorkBuddy's
read "1 个模型".

WorkBuddy AI's /v3/config (read 2026-11-03 with the owner's account) no
longer lists deepseek-v4.1-flash, its free model until now; hy3 is at
x0.00 instead. The China build still lists deepseek-v4.1-flash. A pick a
plugin's list stops listing goes to Delisted (8febe3a50), and a provider
whose every pick is there serves none of its models (waitsForPicks), for
as long as the list leaves them out. A Free plan account whose one pick
was deepseek-v4.1-flash was served nothing, for good. The row counts
chat models on, and with none it shows the plan's drawers from
/v3/config: "1 image model". The owner's own providers.json has the
same state: workbuddy-ai picks [gpt-6-astra], delisted
[deepseek-v4.1-flash].

Now Provider.DelistedAt keeps when the last pick still in Models left
(dropGonePicks sets it, a pick listed again clears it, Save keeps it
across other settings: delistedAtWith, accountSettings). waitsForPicks
holds only for pickWait (an hour) after it. Past that, or for picks set
aside before DelistedAt was kept (DelistedAt is zero), the list is
served as if none were picked. The picks still come back with a list
that has them. Our Free Model's restart, which the wait was for, lists
its channels again within minutes, and relistSoon asks again in 5.

The plugin is unchanged: its list is what WorkBuddy AI serves today.

New test: TestPicksGoneForGoodServeTheList (the real ids: before
deepseek-v4.1-flash, -sg, glm-5.3-flash; after hy3, -sg, glm-5.3-flash).
It checks: none is served at once; the list is served past pickWait,
with another setting saved on the way; the list is served for picks set
aside with no time kept; and the pick and nothing else is served once it
is listed again. Broken by hand:
- waitsForPicks back to its old body: the new test is red ("served []
  after pickWait").
- Save dropping DelistedAt: TestEveryPickDelistedServesNone is red
  ("served after another setting was saved: [pool-a]").

Run on mote on origin/main 6a6e4fefa plus this change: gofmt -l clean; go vet for GOOS=linux (nogui)
and windows of internal/provider and internal/gui; go test -timeout 45m
of internal/provider, internal/gui, internal/routes and
internal/gateway: provider and routes ok; gui red only in TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27 on mote); gateway red only in TestCodexPoolSaysTheClientsVersion (#4807).

Not tried: a real WorkBuddy AI Free plan account (we have none); the
owner's account's config was read, not changed. The full ./... suite
wasn't run: one was already running on mote.
2026-11-03 09:26:51 +08:00
yetone 3e61d814e5 gateway: an AI Studio key speaks the Gemini API too, and searches by googleSearch
cocoasoda (Discord) asked for a native Gemini API mode on the Gemini API
provider, so it can search with Google Search on the API credit a Gemini
subscription comes with.

The Google Gemini preset (and any provider whose Chat URL is AI Studio's
OpenAI-compatible one) now gets AI Studio's Gemini API base,
https://generativelanguage.googleapis.com/v1beta, at the same key, filled
in by normalize, so existing providers get it on load. A Gemini URL of the
provider's own is kept; other hosts, Vertex and sign-ins get nothing.
Ordinary turns stay on Chat as before. What changes:

- A Gemini client (Gemini CLI) is relayed natively, its googleSearch tool
  included, instead of being translated onto Chat.
- A web search with no tools of the client's own (Claude Code's
  WebSearch) goes to the Gemini API with tools [{"googleSearch":{}}], and
  the grounding comes back as the client's search result.
- A turn with function tools stays on Chat: Gemini doesn't take
  googleSearch beside function declarations, so before this the switch to
  Gemini dropped the search silently. Its model is given magpie's search
  tool, and the same key answers it by a tool-less googleSearch request
  (searchesOwn / ownSearcher, as Google sign-ins do since #757), on the
  user's own credit, not another provider's.
- The model list isn't asked twice: AI Studio's OpenAI-compatible list is
  its Gemini API's list.

Run on mote at this change on 2c90922b0 (pushed on 898c314b7, which adds
GUI files and a WorkBuddy mover min only): gofmt -l clean;
GOOS=windows go vet ./... ok; GOOS=linux go vet -tags nogui ./... ok;
go test ./internal/provider ok (194s). The whole ./internal/gateway run
was still going under other sessions' suites when this was pushed. The
new gateway tests (below), TestCodeAssistSearchesWithoutTools,
TestCustomGeminiUpstream and TestAIStudioThinking passed at the same
code before the rebase, which brought in only GUI and provider-pick
commits.

New tests: TestAIStudioSpeaksGemini, TestAIStudioKeySearchesByGoogleSearch,
TestAIStudioKeySearchesBesideTools, TestAIStudioKeyRelaysGeminiClient,
TestGeminiKeySearchesScope. The upstream is a fake transport for
generativelanguage.googleapis.com with Google's grounding example's shape
(webSearchQueries, groundingChunks, groundingSupports); no network.

Broken by hand, each red:
- normalize without aiStudioNative: TestAIStudioSpeaksGemini and all three
  gateway tests (Chat asked, 404 on the Gemini client).
- searchesFor without the AI Studio branch: BesideTools (the turn went
  to Gemini, where googleSearch would be dropped) and Scope.
- searchesOwn without geminiKeySearches: BesideTools (the search tool
  call went back to the client unanswered).

Not tried: a real AI Studio key (none here), so Google's live replies are
from its docs, not seen. Gemini 3's googleSearch beside function tools
(includeServerSideToolInvocations) is not used. The derived Gemini URL
can't be cleared by the user while the Chat URL is AI Studio's; normalize
fills it again.
2026-11-03 02:21:35 +08:00
yetone 952309abcf provider: a provider of keys' picks saved before PickedFrom are served as they are (yuancjun)
yuancjun (#help on Discord, magpie web on Linux at v0.1.2679) found that
the provider editor saved every model when one was picked, and sent the
fix from their fork (yuancjun/magpie, fix/legacy-picks-serve-all,
2d82267d2). Ported here, with the Save side added.

withNewlyListed reads picks saved before PickedFrom was kept as "held
every model" when they hold every model released up to the newest pick,
and adds every model released after it. A pick of one OLD model reads
the same way, so every newer model was served beside it, the editor
showed them all as picked, and the next Save wrote them all down. With
10 models released 2026-01..10 and "models":["m0"] with no "pickedFrom",
Exposed() was 10. PickedFrom is nil too for a provider whose picks were
saved before its list was fetched (an import), not only for old ones.

- A provider of keys (no Account) with no PickedFrom: its picks are
  served as they are (yuancjun's change). A subscription keeps the date
  rule: its list is the catalog's and Select all is a state its editor
  offers (TestClaudePicksOfEveryModelTakeOnesListedSince).
- listedWith: such a provider's next Save keeps the list with its
  picks, the same picks too (it used to keep was.PickedFrom, nil, so a
  key provider whose every model was picked before PickedFrom would
  never be given a model listed later). A subscription's same-picks
  Save still keeps what it had.

Every path that writes picks reads them through Picks(): the GUI editor
(PicksOf in /api/providers' chosen), the TUI's model toggles
(pages.go). The CLI's `provider set models=` and the importers write the
ids given, and their Save goes through listedWith.

Users whose picks were already saved as every model can't be told from
a real Select all: those picks have PickedFrom kept and are served as
saved. They unpick in the editor (Picked only, or Select none, then the
models wanted). A provider that showed every model but was never saved
since is back to its own picks at once.

TestLegacyPicksServeWhatWasPicked (yuancjun's, plus a Save as the editor
does it) and TestLegacyPicksOfEveryModelGetPickedFromAtSave.

Run on mote at this commit: go test ./internal/provider ./internal/tui
ok; go vet GOOS=linux and GOOS=windows ./internal/provider ok; gofmt -l
clean. Broken by hand: the Account==nil branch off, the first test is
red with all 10 served [m1..m9 m0]; the listedWith change off, both
tests are red (PickedFrom [] after the Save; m3 not added).
Not tried: a real relay with a real providers.json from before
PickedFrom.
2026-11-02 22:28:57 +08:00
yetone 4dfdd0cd63 provider: a provider switched off is asked for nothing, its plugin's model list included
ChangQiu on Discord switched a provider off long ago, and magpie still
reached it. Routing, fallback, usage and balance reads, warmups,
check-ins and keepalive were already held back (On(), leftAlone,
KeepListsFresh). These were not:

- The plugin host's providers listing ran every plugin's models hook,
  which asks the vendor, and its sign-in renewal (fresh), for every
  plugin provider, on or off. Go now passes the ids switched off
  (plugin.ListingOff, provider.pluginsOff: the provider's id and the
  plugin's own id, read from providers.json alone). host.js lists such
  an id without running a hook (info(..., quiet)), so its row stays and
  keepListed keeps the last list.
- Sync (POST /api/sync, `magpie sync`) fetched every ready provider's
  list. Both now go through provider.RefreshLists, which skips one
  switched off.
- Saving or switching on in the GUI fetched the list even for one left
  off; PrefillNewKeys asked one switched off too.

What still asks one switched off, by the user's own click: the TUI's
refetch, the provider Test button and `magpie provider models <id>`
refetch.

Tests: TestOffPluginProviderAskedNoModels (the fake plugin's models
endpoint counts its hits: 0 while off, the list kept, asked again once
switched on), TestPrefillAsksNoProviderSwitchedOff,
TestPluginsOffNamesThePluginsOwnIDs and
TestRefreshListsAsksNoProviderSwitchedOff.

Run on mote at this head (first at a4916aec1):
- go test -timeout 45m ./internal/provider ./internal/plugin
  ./internal/gui ./internal/cli ./internal/tui ./internal/gateway:
  provider, plugin and tui ok. Three reds, each also red on origin/main
  and filed: gui TestMainWindowCorners/macOS_26_SDK (#3949), cli
  TestEveryRouteHasACommandOrIsNamed (#4826), gateway
  TestCodexPoolSaysTheClientsVersion (#4807).
- After rebasing on ce2e81da1: provider and plugin again, plus darwin
  vet of the four packages. One provider run went red on
  TestClaudeAccountServesModelsListedSinceItsFetch (#3174, full-run
  only). It is green alone 3/3 on this head and on origin/main, and the
  next full provider run was ok on both.
- GOOS=windows go vet of plugin, provider, cli and gui: clean.
  gofmt -l: clean. Linux go vet (WSL magpie-desktop) of plugin and
  provider: clean. cli and gui can't be vetted there: the distro has no
  gtk4/webkitgtk-6.0 headers for wails' cgo.
Broken by hand: with each guard taken out, its test went red ("switched
off, the vendor was asked 2 times", "the vendor asked 2 times",
"pluginsOff = [fakeco onco openai openai-plugin]", "the provider
switched off was asked 1 times").
Not tried: a real plugin provider switched off in the app. Which
provider ChangQiu had switched off isn't known, so his exact case is
not reproduced.
2026-11-02 14:30:45 +08:00
yetone d1a94f5792 provider: a Codex pick the ChatGPT list dropped is not offered (#4772)
Cause: the owner's codex provider keeps picks (providers.json "models")
made while ChatGPT listed gpt-5.5. ChatGPT has since stopped listing it:
the backend's /codex/models for the Pro account (client_version 0.165.0,
asked 11-01) and the saved Plus account's list both have gpt-6.1-sol,
gpt-6-astra, gpt-6.1-terra, gpt-6-sol, gpt-6-luna, gpt-5.6-sol/terra/luna
and no gpt-5.5, and Codex CLI 0.165.0's models_cache.json has none
either. ExposedOf offers a pick the vendor's list lacks as typed in by
hand, and an account's refetch never drops gone picks (dropGonePicks is
for key providers), so codex/gpt-5.5 stayed first in /v1/models. The
backend refuses any model its list leaves out: a real request for
gpt-5.5 on the Pro account answered 400 model_not_found "The 'gpt-5.5'
model is not supported when using Codex with a ChatGPT account", while
gpt-5.6-luna answered 200. Not plan-specific: Plus and Pro alike.

Fix: a ChatGPT account (listedOnly) is treated as Copilot's already is:
with its list fetched, a pick the list doesn't have is left out of what
agents are offered. The pick itself stays saved and comes back when the
list has it again. The list is the pool's (codexPoolModels), so a model
only a saved account has is still offered and routed to it
(Account.Lists).

Run (mote, at this tree on origin/main 1fac66c06):
- gofmt -l internal: clean; go vet ./internal/provider, GOOS=linux
  -tags nogui and GOOS=windows: ok
- go test ./internal/provider (full): ok 131s
- go test ./internal/tui ./internal/codexcat ./internal/usageapi
  ./internal/cli ./internal/catalog ./internal/agent: all ok
- go test -run 'Codex|Pick|Expos|Listed|Models' ./internal/gateway
  ./internal/gui: ok
- Real accounts, sandbox HOME (copy of ~/.codex/auth.json and the live
  providers.json and codex model lists): `magpie models` built from
  origin/main lists codex/gpt-5.5 first; built from this tree it lists
  only the six models the account serves.

Broken by hand: with ExposedOf's condition put back to unusable != nil,
TestCodexPickTheListDroppedNotOffered fails ("offered [gpt-5.5
gpt-6-astra gpt-6-sol]").

Not tried: the full ./... suite and the whole gateway package (mote was
at load ~290 with another session's suite running); the GUI suite; the
ChatGPT API provider (siwc), which keeps a fetched list too but was not
checked for refusing unlisted models, so it is left as it was.
2026-11-01 18:35:15 +08:00
yetone 21882a68dc providers: a model's list price skips Grok's two name patterns unless it names grok-
/api/providers prices every model of every provider on each poll, and
pricedNames ran grokWindow and grokEffort over each id, lowercasing it
twice. Both patterns need "grok-" in the lowercased id, so any other id
now returns before them; what a Grok id is priced as is unchanged.
pricedOnce's memo key is sized once instead of growing by doublings.

Run (on mote unless named):
- go test -count=1 -timeout 45m ./internal/provider ok (103.8s),
  ./internal/catalog ok; GOOS=linux and windows go vet of both ok;
  gofmt clean (here).
- Broken by hand: the guard narrowed to "grokx-" turns
  TestGrokEffortListPrice, TestCursorGrokFastPrice and
  TestGrokWindowWithoutKListPrice red, so the Grok aliases are covered.
- Here, 200 GET /api/providers on the sandbox with the real config
  copy (offline, proxy :9), against v0.1.2548's tree: pricedNames
  0.28s -> 0.02s, ListPrice 0.63s -> 0.40s; process CPU 4.62s ->
  4.24s, median 20.4ms -> 19.0ms. pricedOnce stayed ~0.20s: its cost
  is the key's bytes, not the growth.

Not run: the full ./... suite; GUI tests (the JSON is the same).
2026-11-01 13:52:21 +08:00
yetone 3ee6c2d948 providers: a provider list looks at the stamps, plugin logins, client shapes and accounts once a request
/api/providers took ~25ms of CPU a call with the owner's real config (25
providers, plugins signed in), polled by every open window. Its profile
had file system calls at about half, each repeated for every provider
the list shows:

- StampNow stat'ed providers.json, settings.json and the catalog for every
  provider (KeptListing); under a request's Hold it is looked at once.
- plugin.ListedAt was asked for every plugin provider's Listed(); once a
  request (heldOf "plugin-listed").
- pluginLogins took logins.json's lock, a file opened across magpies,
  for every plugin even with nothing to change. It now settles the list
  as read first, and takes the lock and settles again from a fresh read
  only when something changes.
- clientShape read and parsed client-shapes.json for every relay a list
  shows (TestsAs); parsed once until the file changes (filememo), a copy
  given out.
- Logins(agent) took the same lock for every provider, twice with its
  account models; listed once an agent a request, a copy each, listed
  anew after a write (writePrivate's filememo.Forget).

Run (on mote unless named):
- go test ./internal/provider ./internal/gui -timeout 45m: provider ok
  (102s) with the new tests; gui red on TestMainWindowCorners (macOS 27,
  #3949) and on TestSettingsSaveKeepsWhatItDoesNotSend, red on main since
  b09349d17, fixed by #4514's commit before this one.
- At the pushed head (rebased on e84870f17): go test ./internal/provider
  ok (100.7s), ./internal/plugin ok (102.7s), TestLoginsListedOnceARequest
  -count=5 ok (it now clears the 30s look another test left), gui
  TestSettingsSaveKeepsWhatItDoesNotSend and TestCoreScriptBudget ok;
  GOOS=linux and windows go vet ./internal/provider ok.
  Then rebased onto 3defaf662 (internal/agent dsh.go only); not rerun.
- New tests: TestStampLooksOnceARequest, TestClientShapeParsedOnceUntilWritten,
  TestLoginsListedOnceARequest, and TestAccountListsCopyNoLoginsUnchanged
  now counts the lock. Broken by hand, each goes red: "51 stamps in one
  request looked 51 times, want 1", "30 asks parsed the file 30 times",
  "20 plugin lists with nothing to change took the lock 20 times",
  "20 lists in one request listed 20 times".
- GOOS=linux and windows go vet ./internal/provider: ok. gofmt clean.
- Real config, on this Mac: a copy of the owner's ~/.config/magpie in an
  offline sandbox HOME (proxy :9), 200 GET /api/providers each:
  v0.1.2541 5.04s CPU (25.2ms a call, median 22.5ms wall), this change
  4.55s (22.8ms, median 20.3ms). The profile's stats under StampNow fell
  from 2.17s to 0.34s.

Not run: the full ./... suite; GUI (browser) tests, as nothing the page
gets changed. What is left in the profile: StepFun's sign-in file,
sync.json, plugin icons and agent detection, each read once a request.
2026-11-01 13:32:30 +08:00
hlyx1 2b067434d7 provider: a Kimi Code membership's k3.1-pro and k3.1-pro-highspeed are priced at the Kimi API's (#4635)
hlyx1's fix (#4635, branch hlyx1/magpie kimi-code-k31-pro-price), asked
to be expedited by matrix0487 on Discord. Kimi Code's plans serve
k3.1-pro and k3.1-pro-highspeed, which models.dev's kimi-code-plan-*
catalogs list at the membership's $0. Neither id was in kimiCodeAPI, so
a membership's call on either was unpriced on Usage. They now map to
kimi-k3.1-pro and kimi-k3.1-pro-highspeed, like k3 to kimi-k3, and the
Requests list names that model (PricedNameFor).

Checked: Kimi Code's own /models answer (internal/catalog/testdata/
kimi-code-cn-models-2026-10-31.json) lists k3.1-pro "K3.1 Pro" and
k3.1-pro-highspeed "K3.1 Pro Highspeed". Kimi's pricing page
(platform.kimi.ai/docs/pricing/chat, read 2026-11-01) and models.dev's
live moonshotai entry both give kimi-k3.1-pro $2 in / $10 out / $0.20
cached / $2 5m write, and kimi-k3.1-pro-highspeed $4 / $20 / $0.20 / $4.
The fixture's new entries match models.dev's api.json in id, name, cost
and canonical_model_id.

The alias stays Kimi Code's (kimiCodePlans): the test's relay catalog
now lists a k3.1-pro of its own at $0.50/$1, which keeps that price, and
PricedNameFor(relay, k3.1-pro) stays k3.1-pro.

Docs: docs/reference.md, docs/subsystems/providers-accounts.md.

Run on mote (Go 1.26.8), at this change rebased on fb3942ee6 (the
pushed head adds only 784b66366, app.js and a GUI test): gofmt -l
clean; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
go vet ./... ok; go test -count=1 -timeout 45m for internal/provider,
usage, gateway, agent, cli, routes, sessions, usageapi: all ok.
TestKimiCodeListPrice and TestKimiCodeCost red with models.go at
origin/main (k3.1-pro {0 0 0 0} false; kimi-code-cn/k3.1-pro
priced=false cost=0, want true 3.264), green with it. Taking the
kimiCodeMember() check out by hand turns PricedNameFor(relay, k3.1-pro)
into kimi-k3.1-pro and the test red.
Full go test ./... at base da0005df8: every package ok but internal/gui,
red on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners/macOS_26_SDK (#3949), both open on main and not
touched here.
Not tried: a real Kimi Code membership's k3.1-pro call through the GUI.
2026-11-01 11:19:26 +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 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 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 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 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 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 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
yetone 4a7d1c63ac provider: Resolve keeps the listed-by map and finds a group without copying the catalog
A live magpie's heap profile (v0.1.2404, 53 minutes) allocated 1.3 GB
in isMagpie -> provider.Resolve, from the window's drift poll asking
every 15s for each model value an agent's settings name:
- a bare model no entry has ("gpt-5.5") built listedBy, every
  provider's whole model list, again on each request: heldOf only kept
  it for one second inside a Hold (835 MB);
- a group ref copied the whole Catalog() to find one group (425 MB).

listedBy now goes through keptOf, the Stamp-keyed store the catalog
already uses, so it is built again only when providers.json, a group or
a setting changes. A group ref is looked up in the groups' own entries
first, and the full catalog stays the fallback.

TestResolveKeptAcrossRequests: three providers with 40 models each and
a group, each request in its own Hold. "group/g", "nope" and "m-b2"
take 44, 43 and 28 allocations once built (bar 60), they resolve right,
and a provider saved since is resolved by the next request. Broken by
hand: heldOf("listed", listedBy) put back, red; the Catalog() copy
first put back, red.

Run at this tree on mote: gofmt -l clean; go vet ./internal/provider
for darwin, linux and windows ok; go test -count=1 -timeout 45m
./internal/provider ok (126.0s), ./internal/agent ok (199.3s),
./internal/gateway ok (595.0s).
2026-11-01 00:28:03 +08:00
yetone 3d063e34fd providers: the editor names a routing group listed alone that keeps a model from agents (hayden4608)
hayden4608 on Discord: with a provider's "Only through routing groups"
switched off, its models still weren't on the Agents page. Switching it
off does bring them back to every list (tried in a sandbox HOME on mote:
POST /api/provider/save unlisted:false, then /api/agent-models/codex,
/api/state's Codex options and provider.Catalog all list them; nothing
caches the old list). What still keeps them out, with the switch off,
is a routing group whose Model lists is "The group alone"
(Group.Unlists, #1783): its members leave every agent's list. The
editor said nothing of it, so the switch looked broken.

The provider's JSON now carries keptBy (provider.GroupKept: model ->
the names of the groups listed alone that keep it out, a signed-in
subscription's models excepted as Catalog excepts them), and the editor
says under the models, and on each chip, which group keeps which model
out and that its Model lists is changed on the Routing page. Words in
zh, zh-TW, ja and de. unlistedByGroups returns the groups' names now
instead of a bool; Catalog and Unlisted read it as before.

Not confirmed for hayden's own setup: the other reasons a model is
missing there are Codex's list in "Only models I pick" (the editor
already names that agent) and GitHub sync bringing the other device's
providers.json back (newer wins per part). The reply asks which.

Run on mote at e94fb18b8 + this change; at this head (rebased on c63c2136b,
which touched internal/provider/visible.go) the provider and gui packages
and the new GUI file ran again with the same results:
- gofmt -l internal/provider internal/gui: clean
- go vet -tags nogui (darwin, GOOS=linux, GOOS=windows) ./internal/provider ./internal/gui: ok
- go test -tags nogui -count=1 ./internal/provider: ok
- go test -tags nogui -count=1 ./internal/gui: one red, TestSettingsSaveKeepsWhatItDoesNotSend
  (SearchAll), filed as #4514, not this change
- GUI, Chromium and WebKit: unlisted-group-kept (new, en/zh/zh-TW/ja/de,
  1000 and 420px), agent-hides-editor, unlisted-models, group-unlists,
  i18n-keys: 67 of 68; the red is i18n-keys' "Unmarked", #4524, not this
  change
- core budget tests: ok (app.js 1,310,619 of 1,316,874, no raise)
Broken by hand: GroupKept's loop out of providerInfo makes
TestUnlistedGroupKeptSaid red (keptBy map[]); the old app.js makes the
new GUI file 0 of 20.
Not run: the full go test ./... (another session's full GUI suite was
on mote); no real Discord user's settings tried.
2026-10-31 21:00:55 +08:00
yetone 7b09d2c951 provider: a model can be listed by an id of the user's at its provider, asked for by its own
zeewell on X (tweet 2116404121930432888): relays serve one model under
ids of their own (deepseek-v4.1-flash-1017, grok-4.6@500k). They want to
give each one their own id at the provider layer. magpie then lists,
routes, groups and finds groups by that id, and the upstream request
still carries the vendor's id.

Choice: a new per-model map, settings' ModelIDs
("<pid>/<local>": "<own id>"), served through the wire names that
already exist. ModelSameAs was not widened. It means "same as another
vendor's model": it lends specs and joins found groups. Making it rename
models everywhere would change every existing user's ids and refs.
ModelWires was not reinterpreted either, for the same reason. ModelIDs is
ModelWires turned round: a wire keeps magpie's id and changes the one
sent, and this keeps the one sent and changes magpie's. Settings.Wires()
merges each entry in as a wire name (wrapped by a "<pid>/*" wire). Every
place that sent a ModelWires name (gateway, usage ledger, request page,
UpstreamName, UpstreamNameAs) reads Wires(), so the upstream id needs no
new path. An explicit ModelWires entry for the same id wins.

- Listed by the local id: Available, liveIDs/liveByID, Serving and
  ListPrice translate through OwnModelID. /v1/models, agents' lists,
  Resolve, routing groups and found groups (auto/<local>, merged with
  every other provider serving that id) all see the local id.
- Only a provider of the user's own (Account == nil) takes one. An
  account's or a plugin's request is built from its list's id, which no
  wire reaches.
- Two variants of one provider given one id: the latest given it wins,
  and the earlier one is listed by its own id again. The CLI names it.
  The editor refuses two rows given one id in one save. A model of the
  provider's own id that a variant is listed by (plain grok-4.6 beside
  grok-4.6@500k) is not listed while the variant has it.
- The user's values are never overridden. SetModelID moves picks,
  contexts, fallbacks, groups' members/rules/fast/placed/off/weights/
  classifier/pick, the pickers' lists, every per-model setting
  (Settings.MoveModel) and gateway keys' models (provider.ModelMoved,
  set by access) to the new id, but only where nothing is under the new
  id yet. Agents' own files are not rewritten: an old provider/<own id>
  still resolves and is sent as it is. Group match patterns and key
  patterns stay as written.
- Key limits: a key held to either id passes for both (modelAllowed:
  the ref, OwnModelID, ListedModelID). Group members use the same check.
- Usage: model = the listed id, served = the vendor's id from its reply.
  The price is the own id's first.

CLI: magpie model id <provider/model> [<id>|--reset], magpie model ids.
GUI: Providers > a provider's editor > Names & levels > "Listed as",
beside Same as. It is staged with the editor's Save and taken back by
Restore default, in zh, zh-TW, ja and de. Accounts have no box.
Docs: providers-accounts.md, gateway-routing.md, and site start.html in
en, zh and ja.

Run (mote-run, at this tree rebased on 841326709):
- go test -tags nogui of internal/gateway, provider, settings, access,
  usage and cli: ok. internal/gui: ok but for
  TestSettingsSaveKeepsWhatItDoesNotSend's SearchAll, red on main since
  b09349d17 (#4514, yiqiui's patch); its ModelIDs case passes.
- TestAutoVisionDoesNotBuildListsAgain: 457 allocations with 4 models,
  458 with 400 (main 459), searcherModel within its 50. Reading
  Shared() per list cost 3041; SharedModelIDs parses only modelIDs once
  per file change, the settings path is built again only when what it is
  built from changes, and Serving looks up the own id only when a key is
  listed to some model.
- TestCoreScriptBudget: raised by 1,178 bytes for the Listed as box,
  with a note.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet ok.
- GUI: provider-listed-as (en, zh, zh-TW, ja, de), provider-same-as,
  provider-detect in Chromium on mote and WebKit on the Linux box (mote's
  WebKit launch hangs, #4125): 9 of 9.
Broken by hand, each red: the wire name (wires), the list (list), a key
held to the own id (keyown), the key move hook (hook), liveIDs, liveByID,
moving refs (moverefs) and moving per-model settings (movemodel).
Not tried: a red for ListPrice's or Serving's own-id lookup; a real relay
with variant ids; Match patterns are not rewritten to the new id. The
full Go suite and the whole GUI suite are still running and their reds
get their own issues.
2026-10-31 15:04:44 +08:00
yetone 0407d69e84 provider: a group of Kimi models keeps always_thinking, dynamic tools and its default effort
jiabubu on Discord (#feedback): one Kimi Code model put in a routing group
so it lists first lost "always thinking" and "dynamic tool loading" in Kimi
Code, which the same model straight from its provider has. buildGroupEntries
never set AlwaysThinks, DynamicTools or DefaultEffort on a group (the Entry
comment said "a group has none of them"), so kimiModelTables wrote the
group's table without always_thinking and dynamically_loaded_tools, and
default_effort fell back to high.

groupSharedKimi now gives a group each of the three when every member's
entry says the same, and none of it when one member doesn't or has no
entry: a group request can reach any member (rule targets are members too,
ruledEntry's of()), so Kimi Code must not shape a request for a member that
can't take it. The capability words are Kimi Code 2.4.1's own
(catalog-runtime.ts capabilityFromDeclared), already written for direct
models; kimi-cli still gets neither.

Tests: TestGroupSharesKimiFacts (provider: all share, one without, efforts
differ) and TestKimiCodePlanCapabilities now writes a one-member group
"top" (the reporter's case: always_thinking, dynamically_loaded_tools,
default_effort max) and a group "mix" with a relay model (neither word).

Run on mote (mote-run, sandbox HOME):
- At 83a630d69 (on fbb1b36d1): gofmt -l internal/provider internal/agent
  clean; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./... ok; go test -tags nogui -count=1 -timeout 45m ./...: every
  package ok but internal/gui TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514) and internal/proc TestNoCommandBypassesProc (#4491). Both fail
  the same at origin/main 841326709, just fetched; neither touches this
  change.
- At the pushed head (rebased on 841326709): go test -count=1 -timeout 45m
  ./internal/provider ./internal/agent ./internal/catalog ok.

Broken by hand: without the groupSharedKimi call, both tests go red
(group/top loses always_thinking and dynamically_loaded_tools and gets
high). With "any member" instead of "every member", both go red
(group/mix and the mixed auto groups get the words).

Not tried: a real Kimi Code session picking the group (the words are the
ones real Kimi Code 2.4.1 already reads for direct models), Windows and
Linux test runs (vet only), nested groups.
2026-10-31 14:59:44 +08:00
yetone 45de2ddb96 provider: a provider the user counts free goes first under Free first (jiabubu on Discord)
jiabubu asked on Discord #help for a way to mark a provider, model or key
as free, so that Free first routing spends it first. Their example is
ModelScope, which has a free daily quota. Until now routes.Seat.Free
came only from the vendor catalog's Free flag, and there was no way for
the user to set it.

Provider.CountFree ("Free for me" in the provider editor's Advanced fold,
`magpie provider set <id> free=yes|no` in the CLI) makes FreeModel true
for every model of that provider. Routing therefore treats it like a
vendor's free model: Free first uses it before paid ones, and Cheapest
first weighs it at nothing, because PriceAt, which only routing reads,
returns 0 for a free model. Prices shown (ListPrice and the model list)
and the costs Usage counts (EffectivePrice) are unchanged. The mark says
what to spend first, not what a call cost, and a quota that runs out
still bills at the listed price. Key and account (subscription)
providers both carry it, through withPicks, the account literal and the
copy merge.

Tests:
- internal/gateway TestFreeFirstSpendsTheProviderTheUserCountsFree:
  - a Free first group [paidv/m, mine/m] sends its first call to mine
    once mine is marked, and the trace row says Free;
  - EffectivePrice is still the listed 3/15;
  - Cheapest picks mine first;
  - unmarked, paidv goes first again.
- internal/gui TestProviderSaveKeepsCountFree: the preset and typed-in
  providers save the mark and clear it, and /api/providers reports it.
- internal/cli TestProviderSetFree: free=yes and free=no work; the value
  shows in `provider <id>`; free=maybe, an empty value and --help are
  refused and change nothing.
- GUI internal/gui/tests/provider-count-free.test.cjs covers the
  ModelScope preset, a custom provider saved with the mark, and a Codex
  account. It runs chromium and webkit, in en, zh, zh-TW, ja and de, at
  widths 900 and 440. It checks the Advanced fold, the check and save
  POST bodies, that the row fits with no sideways scroll, and that each
  string has a translation in I18N.

Core script budget: rebased on fa5e86cf2, the core's scripts came to
1,538,236 bytes, 880 over coreScriptBudget, which TestCoreScriptBudget
caught. The budget is not raised. countFreeField's comment and five
long comments on the editor's helpers (proxyPicker, concurrencyField,
priceRateField, pluginOptionsField) are cut down, so app.js ends 212
bytes smaller than before this change.

Run (mote via mote-run, at this change's tree on base 8ee75adbf):
- go test of internal/gateway (-run FreeFirst|InOrder), internal/gui,
  internal/cli and internal/provider: ok.
- GUI test: chromium 30/30 on mote. WebKit could not launch on mote at
  all at the time (a bare webkit.launch probe timed out at 60s, and
  other sessions' WebKit launches were stuck there too). WebKit was run
  on Linux instead (wsl-run, magpie-desktop): 30/30.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./... ok; go build for darwin, linux (nogui) and
  windows ok.
- At the pushed head (rebased on fa5e86cf2, comments cut): go test of
  internal/gui, internal/cli, internal/provider and internal/gateway
  -run FreeFirst|CountFree ok (internal/gui was red only on
  TestCoreScriptBudget before the cut); node --check app.js ok; the GUI
  test in chromium 30/30.
- The full Go suite (go test -tags nogui -timeout 45m ./...) is still
  running on mote at ship time, per the owner's ship-at-once rule. Any
  red it finds gets a follow-up commit. The whole GUI suite was not run:
  mote's WebKit cannot launch and the Linux box was running other
  sessions' GUI suites.

Broken by hand:
- With the CountFree line taken out of FreeModel, all three Go tests
  went red, e.g. 'Free first went to "paidv" (free false) first'.
- With `pr.CountFree = in.CountFree` taken out of the preset save
  branch, TestProviderSaveKeepsCountFree went red ("the preset's mark
  wasn't kept").

Not tried:
- A real ModelScope account; the tests use fake upstreams.
- A per-model mark (optional in the request); the mark is
  provider-wide.
- The TUI editor (the CLI setter covers the terminal).
2026-10-31 04:21:21 +08:00
yetone 2ac423f4f2 kimi: a Kimi Code plan model is told always_thinking, dynamically_loaded_tools and its default effort, as Kimi's list says (jiabubu)
jiabubu on Discord (Kimi Code 2.2.0, Windows): Kimi Code's own provider
gives K2.8 Preview and K3.1 Pro the capabilities thinking,
always_thinking, image_in, video_in, tool_use and
dynamically_loaded_tools; through magpie they had thinking, image_in and
tool_use, so Kimi Code offered a thinking switch the models refuse to
turn off, and started K2.8 on high where Kimi's own starts it on max.

Kimi Code 2.4.1's managed provider (packages/oauth managed-kimi-code.ts,
capabilitiesForModel) derives them from /coding/v1/models:
supports_thinking_type "only" -> thinking + always_thinking,
supports_dynamic_tools -> dynamically_loaded_tools, supports_video_in ->
video_in, think_efforts.default_effort -> the default. magpie now reads
the same fields (flat, or nested reasoning.type, tools.dynamic_load,
reasoning.effort.default) into catalog.Model (AlwaysThinks,
DynamicTools, DefaultEffort; kimiFacts), carries them through
provider.Entry and the agent's model list, and the new Kimi Code's table
gets always_thinking, dynamically_loaded_tools and default_effort at the
vendor's default (else high, as before). Only Kimi's list sends these
fields, so another vendor's model is written as before; kimi-cli, which
refuses unknown words, gets none. A routing group has none of them.

default_effort is now recorded in the stash as magpie's (kimiOwn), so a
level the user picked stays while the model has it. A table with high
and no record is read as the high magpie wrote before it kept one, and
becomes the vendor's default (max on K2.8, high on K3/K3.1).

Left out:
- video_in: with type="kimi" Kimi Code uploads a video to
  {base_url}/files (purpose=video) and sends the ms:// id. The gateway
  has no /files route, and the id belongs to the account that stored it.
  Filed as #4485.
- dynamically_loaded_tools works (Kimi Code's tool select is behind
  KIMI_CODE_EXPERIMENTAL_TOOL_SELECT): the loaded tools' system message
  is lifted into the request's tools (liftMessageTools, #2322), so they
  stay callable (TestKimiCodeLoadedToolsReachKimi), but each load
  restarts Kimi's prompt cache. Filed as #4486.
- max_output_size: Kimi's own provider writes none; magpie keeps writing
  the model's known reply cap (32768 on K2.8 per models.dev), unchanged.

This also covers #3399 (K3.1 offered thinking off): Kimi's list says
"only" for both K3.1 models.

Real list: tests read Kimi's /coding/v1/models reply of 2026-10-31
(internal/catalog/testdata/kimi-code-cn-models-2026-10-31.json, read
with the owner's kimi-code-cn key, no key in the file).

Run (mote, at this commit on origin/main b62fa332f; the agent-wiring.md
line was added after the run, docs only):
- go test -tags nogui -count=1 -timeout 45m ./... : 79 packages ok;
  internal/proc (TestNoCommandBypassesProc) and internal/sqlitedb
  (TestOnlyThisPackageReachesSQLite) red on a Go module cache my e2e
  sandbox had left inside the run folder (vendor files under
  e2e-kimi/sb/home/go/pkg/mod); with it removed both ok.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./... ok; gofmt -l clean.
- Real Kimi Code 2.4.1 (npm) in a sandbox HOME/KIMI_CODE_HOME on mote,
  with a sandbox magpie serve (MAGPIE_ADDR 127.0.0.1:34652), the
  kimi-code-cn preset pointed at a fake upstream that serves the real
  list: magpie wrote the six tables (K2.8: thinking, always_thinking,
  image_in, tool_use, dynamically_loaded_tools, support_efforts low/high/
  max, default_effort max; K2.7 Highspeed without
  dynamically_loaded_tools), Kimi Code took the config, and `kimi -p`
  reached the upstream with thinking enabled and reasoning_effort max
  (K2.8) and high (K3.1 Pro).
- Rebased onto 43966a53f..f2eb56c6b (claude, GUI budget, usage; none of
  them touch these files) as f5a82f215, then again at this head:
  internal/agent, internal/catalog, internal/provider ok, internal/gateway
  -run 'Kimi|MessageTools|Lift' ok. The full suite was not rerun there.

Broken by hand, each red then green:
- kimiFacts not called: TestFetchKimiCodeFacts and
  TestKimiCodePlanCapabilities red.
- fields not carried in route.go / entryFor: TestKimiCodePlanCapabilities
  red.
- the unrecorded-high rule off: TestKimiCodeOldHighBecomesTheVendorsDefault
  red.
- always_thinking without the !legacy guard: the kimi-cli case red.

Not tried: the TUI picker by eye (that the thinking switch is gone);
tool select with a real MCP server and the experimental flag; Windows
(the reporter's system; nothing here is OS-specific); a real Kimi
upstream through magpie (the list was real, the chat was a fake).
2026-10-31 03:27:34 +08:00
yetone 4f2d5fc7e0 routing: a group can put its cheapest member first, by each one's price at that hour
liyuanzheng (#general) and lam_em (#feedback) both asked for the same
thing. Off-peak, DeepSeek's own API should come first for deepseek-flash.
At DeepSeek's peak (weekdays 01-04 and 06-10 UTC, billed 2x since
v0.1.2173), another provider should come first, Ollama say. A schedule
editor would make the user copy DeepSeek's hours into magpie. Instead,
a group gets one more routing, "Cheapest first" (`cheap`). Each request
sorts the members by what they cost right then: input + output price per
million, at the peak rate when it is peak hours. A tie goes to the lower
cache-read price. Free models count as 0. A member with no known price
keeps its listed place after the priced ones. Prices come from the same
priceOf the usage ledger bills with, so the user's own ModelPrices,
list prices and maker prices all count, and so does a provider's rate
windows.

- routes: Seat carries Priced/Cost/CacheCost; Strategy.ByPrice; Cheapest
  is a stable sort, so equal prices keep the user's order.
- gateway: weighRouted prices each seat at priceClock() (time.Now; a test
  holds it) through the new provider.PriceAt. The trace's Weighed row
  gets a price (input/output/cacheRead/peak) so Routing can say why.
- It is a group's alone, like Manual. A provider saved with it drops it,
  and `magpie provider set … routing=cheap` refuses it. Groups take it in
  the GUI menu (one more item, no new controls), the TUI and
  `magpie group set <id> routing=cheap` (aliases cheapest, price, cost).
- Routing's mode line says why the first one is first, e.g. "Cheapest
  first: deepseek-v4-flash costs least on ollama-cloud now — $0.150 in,
  $0.600 out a million tokens.", with peak and unpriced variants.
  en/zh/zh-TW/ja/de.
- Docs: gateway-routing, plugin-runtime, reference (it also points at
  Time window and Pause rules for a fixed schedule) and the site's start
  pages (en/zh/ja).

Run, at f7f2d75f2 (this change rebased onto it):
- Red on the old code: TestCheapestFirstGroupFollowsPeakHours (deepseek
  vs ollama with ModelPrices, priceClock held at 14:00 UTC off-peak and
  02:00 UTC peak) and TestCheapestOrdersByPriceNow did not compile
  without Cheapest. TestCheapestFirstIsAGroupsOnly checks that a provider
  drops it and a group keeps it.
- Broken by hand: without `pr = pr.In(at)` the gateway test is red ("at
  DeepSeek's peak ... went to deepseek"). With Cheapest returning the
  order unchanged, both the routes test and the gateway test are red.
  Both were restored.
- Full Go suite on mote (-count=1 -timeout 45m ./..., log kept): every
  package ok except two. internal/provider had
  TestQuotaSpanCarriesEveryWindowField, which is red on origin/main (#4457,
  fixed since in ccbefe2a2). internal/gui had ten AppKit window tests
  killed at their 20-40s deadlines (TestPanelCloseHidesIt,
  TestMainWindowCorners and others). Three of them are red the same way
  on a fresh origin/main f7f2d75f2 copy, under #2645/#4125 (mote has
  several GUI suites running). After the rebase, go vet and the Cheapest,
  SpeedFirstGroup, ParseRouting, ApplyGroupPairs and ProviderRouting tests
  are ok. go vet darwin, GOOS=linux -tags nogui and GOOS=windows are ok,
  and gofmt is clean.
- GUI on WSL (Linux, chromium + webkit): routing-cheapest-first (new,
  3 scenes x en/zh/zh-TW/ja/de x 2 engines), routing-group-strategy,
  builtins, i18n-keys and routing-speed-first gave 95 of 96. The one red,
  routing-group-strategy "webkit en light ... the pick moved nothing", is
  a wheel-scroll timing red. It fails 3 of 3 on origin/main and 1 of 3 here
  (#4459). Core-script budget ok (app.js +9 bytes).
- The whole GUI suite (1025 files) was started on WSL at this tree and
  was still running when this was pushed, at load ~160.

Not tried: real DeepSeek or Ollama accounts, and a real request during
DeepSeek's peak hours. Ollama Cloud's price here is the catalog's, not
checked against a bill.
2026-10-30 23:59:31 +08:00
yetone 8921ef8056 provider: the Command Code plan prices DeepSeek V4.1 Flash, with its peak hours (treeman on Discord)
treeman_26897 (#help): in the price editor the Command Code plan's
deepseek/deepseek-v4.1-flash showed empty boxes, and typing a price lost
the peak/off-peak split.

What was wrong, on the plan (served by its plugin since the retire):
- No price at all. models.dev's DeepSeek now lists V4.1 Flash only as
  deepseek-flash, by the dated canonical deepseek/deepseek-v4.1-flash-1017,
  so no maker price matches the undated id, and the plugin's own model list
  gives cost 0 (none). Its calls were counted unpriced, at nothing, and the
  editor had no list price to show. models.dev's own "commandcode" catalog
  does list it ($0.15/$0.60, cache read $0.003); the Command Code API-key
  preset already read it through its endpoint, the plan didn't.
  ListPrice now falls back to that catalog for the plan (vendorListPrice),
  after the maker's price, so a model DeepSeek prices keeps DeepSeek's.
- No peak hours. PeakOf judged the vendor by the provider's URLs, and a
  plugin provider's are plugin://, which matched nothing. plugin:// URLs
  are now left out, so the plan is told by its id as before.
- A user's own price was flat at every hour. It is now the off-peak base,
  doubled in the peak hours of a vendor that bills by the hour (DeepSeek,
  Command Code's DeepSeek V4, OpenCode Go's two), as the vendor does to
  its own price. Chosen over a second "peak price" field: smaller, no new
  UI. The editor's hint says it ("Off-peak price, the list's or one set
  here: ... doubles it", en/zh/zh-TW/ja/de).
  Behaviour change for existing users: a price already set on such a model
  now counts double in those hours on the Usage page. It was not left
  alone because the vendor itself doubles whatever the off-peak price is;
  a price set for every other model is unchanged (tested: OpenCode Zen and
  an OpenAI model hold at every hour).

Tests:
- TestCommandCodePlanPrice (new, models.dev's bytes of 2026-10-30): the
  plan's plugin provider lists 0.15/0.6/0.003, 0.30 at peak; DeepSeek V4
  Pro keeps DeepSeek's 0.66; a set price is 0.1 off-peak, 0.2 at peak; a
  relay doesn't take Command Code's catalog.
- TestPeakOf: the plan with plugin:// URLs, its flash-fast, another plugin.
- TestPriceOfPeak: a set price doubles at peak; Zen and OpenAI set prices
  don't.
- model-price-edit.test.cjs: the hint names a price set here.

Broken by hand (each red, then put back):
- peak.go at origin/main: TestPeakOf plugin case and four
  TestCommandCodePlanPrice checks red.
- vendorListPrice off: "list price ... false", "unpriced".
- the user price's Peak line removed: TestPriceOfPeak (3 keys) and
  TestCommandCodePlanPrice (2 keys) red.
- origin/main's app.js with the new GUI test: model-price-edit red.

Run:
- mote-run go test ./... -timeout 45m -count=1 at acdc85ac8 + this change:
  every package ok but internal/gui, whose 10 reds are its real-window
  AppKit tests (TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt,
  TestMainWindowCorners, ...) killed at their deadlines while pboard was
  down on mote (pgrep pboard empty, crash reports 10-29 22:45): #4125.
  The size budgets in it passed.
- mote-run GOOS=linux go vet ./internal/provider, GOOS=windows go vet
  ./internal/provider ./internal/gui: ok.
- wsl-run model-price-edit.test.cjs: Chromium 2/2, WebKit 2/2.
- wsl-run, Chromium and WebKit: i18n-keys, gui-ja, gui-zh-tw,
  model-price-edit, model-price-tiers, provider-price-rate,
  usage-unpriced-names, usage-unpriced-sum, commandcode-risk.
  Each engine 27 pass, 1 fail: gui-ja's "ja has every zh string", on
  the Routing plugin's connection-check string from da3c5e0c0, red on
  origin/main a0cb8b646 too; fixed in the next commit (gui-ja and
  i18n-keys 7/7 after it).
- After rebasing onto origin/main 2df46e3c8 (which added i18n.js lines):
  mote-run go test ./internal/provider: ok; internal/gui -run
  'Budget|Size': ok; wsl-run i18n-keys, gui-ja, gui-zh-tw,
  model-price-edit with the next commit: 14/14.

Not tried:
- No real Command Code bill compared with magpie's count, and no real
  plan account used: the prices are models.dev's, the hours are the
  ones 9e73f69af already uses for Command Code.
- The whole GUI suite: the WSL box had ten other suites running (some for
  4h+); it runs after this push and is reported separately.
- Not checked against the real catalog: whether another relay with no
  catalog of its own that serves the undated deepseek-v4.1-flash is
  unpriced the same way since models.dev's dated canonical.
2026-10-30 23:00:01 +08:00
yetoneandYangHonghang 9e73f69af4 providers: rate windows bill a provider's hours at its own rate (#2463)
A provider can have up to 8 rate windows: days, a span that may cross
midnight (on this computer's clock), and a rate. Inside a window a call
costs the base price times the rate. The base is the user's model price
as set, or the list price times PriceRate with the vendor's own peak
(DeepSeek, Command Code, OpenCode Go) already in it. The author gave
this order as the spec: a 0.8 window on a shared DeepSeek key takes 0.8
off the peak price at peak. The editor's hint says not to set the
official peak hours again as a window, in every language.

Each call is priced at its own time on the Usage page and its CSV, in
the Requests tab's rows, and against a gateway key's cost limit. The
Sessions page, group templates and the model list written into an
agent's own config use the base price. /v1/models prices at now.

Ported from YangHonghang's 2c9d459ff (rate-windows-2463-v2). The Go
pricing, its tests and the translations are theirs. Changed here:
- No budget raised. Their commit raised appScriptBudget and
  coreScriptBudget; core_budget_test.go is main's again. The editor's
  window rows, time menus, validation and hint moved to ratewindows.js,
  which app.js imports when the field is drawn (as signsheets.js is).
  The sliding-thumb and modalDepth comments were cut down to make room.
  The core is 1,535,528 of 1,536,586 and app.js 1,312,242 of 1,315,316.
  Until the script has loaded, a save leaves rateWindows out, and the
  server keeps the saved ones.
- Their unrelated TestAssetsHaveNoConflictMarkers is dropped (one
  commit, one goal).
- The row badge shows only for a provider with windows. Before, every
  provider with a price rate alone got a new ×badge. Its title is
  shorter, and so are its translations.
- AgentPricer (agent model files: Pi, omp, OpenCode cost) uses the base
  price. Nothing rewrites those files when a window opens or closes, so
  a price taken at Sync stayed on outside the window.
- internal/budget gets a TestMain through testenv, so the new test
  runs in a home of its own.
- old-webkit's list of lazily loaded scripts names ratewindows.js.
- The draft keeps each window as a shallow copy, and a day chip
  replaces its days array, so the saved provider is never changed.
- The GUI test waits for the lazy script's hint, not a fixed 300ms.
  It also checks the peak note in each language.

Run first on 2f5a3f1c0, then again after rebasing on 70d9996c5,
8acb0d3a7 and d609729cf. The rebase onto 70d9996c5 met main's ruleedit.js in
old-webkit's list, and both are listed.
- gofmt -l internal: clean at 8acb0d3a7 (129578c3d gofmt'd main's
  pi_api_test.go).
- mote, on 8acb0d3a7: go vet on usage, provider and gui
  ok; GOOS=linux and GOOS=windows go vet -tags nogui ./... ok.
  go test -tags nogui for internal/usage, provider, gui, budget and
  sessions: ok. The five internal/agent tests that are red on WSL
  (below) pass on mote there. On d609729cf (a one-line mover min in
  internal/provider), internal/provider again: ok.
- On 2f5a3f1c0: internal/provider, usage, budget and sessions, and the
  gui RateNow|PriceRate|CoreScript|Budget tests, each under TZ=UTC,
  Asia/Shanghai and America/Los_Angeles: all ok.
- wsl-run (magpie-desktop, Playwright chromium and webkit) on
  70d9996c5: provider-rate-windows, old-webkit, i18n-keys,
  provider-price-rate, provider-advanced-fold, agent-hides-editor,
  key-box-once, provider-many-keys, nokey-editor and
  editor-short-window: 200/200. On 2f5a3f1c0 the first five and
  model-price-edit: 132/132. On mote the same files hit WebKit launch
  timeouts (180s) under another session's full GUI suite (load 30), and
  that run was stopped.
- Full suite, wsl-run (mote was running another session's full suite),
  go test -tags nogui -count=1 -timeout 45m ./... at 6e534f546 (this
  change on 70d9996c5): every package ok except internal/agent.
  internal/agent fails TestInstalledVersion, TestGrokInstalled,
  TestCursorFolderFromTheEditorIsNotTheCLI, TestOmpDetectedWithPiDir
  and TestZedAppPath. This change doesn't touch internal/agent. At
  origin/main 8acb0d3a7 on the same box, TestInstalledVersion,
  TestGrokInstalled and TestOmpDetectedWithPiDir fail too: a fake CLI
  in /tmp exec'd with "Invalid argument". That is #4033 and #3548
  (WSL2 binfmt interop).
- Broken by hand, red each time:
  - Pricer without the window: TestPricerRateWindows,
    TestBlockRowsTakeTheirRateWindow, TestCostLimitCountsTheRateWindow.
  - Block rows without atWindow: TestBlockRowsTakeTheirRateWindow.
  - AgentPricer at now: TestAgentPricerLeavesTheRateWindowOut.
  - Badge for a price rate alone: TestRateNowOf.
  - Peak note removed: provider-rate-windows, 10 of 10 chromium
    layouts.
  - ratewindows.js not in old-webkit's list: old-webkit.

Not tried:
- A real relay billed by the hour.
- The real desktop app (WebKitGTK, WKWebView).
- The full GUI suite (mote was running another session's).
Known limits:
- No rate is stored per record, so changing the windows reprices
  history, as a changed PriceRate does.
- Windows follow this computer's zone, with no zone of their own.
- The Sessions page uses the base price.

Co-authored-by: YangHonghang <honghang.yang@qq.com>
2026-10-30 18:55:51 +08:00
yetone 88e6fb9cf7 provider: a signed-in subscription's models stay in every agent's list with a group listing alone on
士奇 on Discord (Simplified Chinese GUI, the third report of this): with
routing groups off, Hermes Agent's and WorkBuddy's model lists had the
ChatGPT subscription's GPT models. With routing groups on, they were gone.

Cause: the user's group names those models and lists itself alone
(Group.Unlists, the routing plugin's option for that, #1783). While the
group is on, catalogKeeping drops what it names from Catalog(), and every
agent's list starts from Catalog(). With groups gated off the group's
Unlists goes away, so the models came back. a3ee00c05 kept them for the
Codex agent only; its body said other agents still didn't see them.

Fix, at the one point every agent's list starts from: catalogOf(agent)
keeps a signed-in subscription's own models (SubscriptionKept: no group
entry, Provider.Account set, the provider not kept for routing groups)
for every agent, so a group is added on top of what agents had. A client
that is no agent ("" on /v1/models) still gets the group alone, as #1783
asked. Provider.Unlisted ("Only through routing groups") still hides the
provider's models from agents other than Codex. Unlisted() no longer names
a kept subscription model, so the picker's note doesn't call it kept for
groups.

Siblings: every agent writer reaches catalogOf through CatalogFor and
ListedFor. Two gateway lookups read Catalog() directly and now use the
agent's catalog (CatalogOf): /v1/models/{id} and Claude Desktop/Science's
alias lookup. agent.go and codex.go read Catalog() only for error text or
a fallback and are left alone. The routing plugin's hint for that option
says, in every language, that a signed-in subscription's models stay in
agents' lists.

Test: TestSubscriptionModelsStayInEveryAgentsListWithGroupOn signs in a
ChatGPT account in a sandbox and switches on a group naming its 5 models
that lists itself alone. For every agent that lists the group (68,
including hermes, workbuddy, claude and codex), the agent's list and
CatalogFor have the models, and a picker offering the group offers them.
Catalog() and CatalogFor("") still don't. With the provider set to
Unlisted, Hermes doesn't list them. TestCodexOwnModelsListedOnlyThroughGroups
now expects Claude Code to keep the models under a group alone.

Run (on mote):
- Broken by hand: catalogOf reverted to a3ee00c05's Codex-only version.
  The new test went red with 340 errors across 68 agents, e.g.
  "codex/gpt-5.5 not in hermes's list map[group/mygpt:true]", and the
  same for workbuddy, claude and claude-desktop. Green with the fix back.
- gofmt -l; go vet on darwin, linux (nogui) and windows; builds: clean.
- go test -timeout 45m ./... at 035d87b80 (this change on 4a4a90c23,
  before a test comment was reworded): every package ok except
  - internal/gui TestMainWindowCorners/macOS_26_SDK: #3949, red on
    origin/main accb951ab on mote too (macOS 27);
  - internal/provider TestClaudeAccountServesModelsListedSinceItsFetch:
    #3174 (red in a full run, green alone). 5 of 5 green alone and
    green in a whole internal/provider run at that head.
- At this commit on b26fa0903: gofmt -l on the
  changed Go files, go vet of provider, gateway and gui on darwin, linux
  (nogui) and windows: clean. internal/provider whole: ok.
  internal/gui and internal/gateway with -run
  "Codex|Group|Subscription|Unlist|Catalog|AgentModel": gui ok; gateway
  red on TestAntigravityTurnsCodexsGPT5ThreadAwayOnce and
  TestCodexSpentGrokFailingIsTold, both red the same way on origin/main
  b26fa0903 (3 of 3) and filed as #4362.
- GUI files the change reaches, on b26fa0903: agent-model*, group-unlists and
  i18n-keys: every Chromium case and i18n-keys pass (46); every WebKit
  case timed out launching the browser (180s, #4125: WebKit doesn't start
  on mote right now). The same files at 035d87b80 passed in both engines
  but i18n-keys, whose one red (the new test quoted a routing-plugin
  word) is fixed here.
- Rebased on 101775657 (main had moved models.go and gateway.go): gofmt,
  go build for darwin, linux (nogui) and windows, go vet of provider,
  gateway and gui on all three: clean. go test -run
  "Codex|Group|Subscription|Unlist|Catalog|AgentModel" ./internal/gui
  ./internal/provider and -run "Model|Desktop|Alias|Catalog"
  ./internal/gateway: ok.
- The whole GUI suite (1004 files) at fd50ed116 was still running when
  this was pushed (mote shared with other sessions' suites). Reds it
  shows get their own issue unless already red on main.

Not tried: no live ChatGPT account and no real GUI app run (the test signs
in a sandbox account). No separate gateway test for /v1/models/{id} or the
Desktop alias lookup. Provider.Unlisted stays honoured, on purpose.
2026-10-30 15:38:06 +08:00
yetone 643b525469 usage: a DeepSeek call at peak hours costs double its off-peak list price
treeMan on Discord: DeepSeek bills off-peak at half the peak rate, and the
Usage page didn't follow it. The catalog's list prices for these models
are already the off-peak ones: models.dev's DeepSeek, Command Code and
OpenCode Go entries give the off-peak rate as the price and a factor-2
multiplier for peak hours, and api.json leaves the multiplier out
(deepseek-flash: $0.15/$0.60/$0.003, DeepSeek's page says $0.30/$1.20/
$0.006 at peak). So every peak call was counted at half its cost. Now a
call made from 01:00 to 04:00 or 06:00 to 10:00 UTC, Monday to Friday,
costs twice the list price. The call's own timestamp decides.

Which providers (provider.PeakOf, by base URL, or by preset/id only for a
provider with no URL, such as a plugin's or a removed one):
- DeepSeek's API (api.deepseek.com), every model, except on Chinese
  public holidays (catalog.PeakDeepSeek);
- Command Code (api.commandcode.ai, the commandcode preset and the
  commandcode-plan plugin): deepseek-v4.1-flash, -v4.1-flash-fast,
  -v4-flash, -v4-flash-vision-exp and -v4-pro, every weekday, since its
  docs name no holiday. deepseek-v4-flash-fast is one price at every hour;
- OpenCode Go (opencode.ai/zen/go): deepseek-v4.1-flash and
  deepseek-v4-pro, every weekday.
Unchanged: OpenCode Zen (a flat $0.30/$1.20), ZenMux, Cline Pass,
OrcaRouter and every other relay, a price the user set (ModelPrices
returns before a Peak is set), a "same as" price and every other model.
The provider's price rate still applies.

Holidays: catalog.cnHolidays has 2026 from the State Council's notice
(2025-11-04). TestCNHolidaysCoverThisYear fails on 2027-01-01 unless that
year's notice, due in November, is added. A year missing from the table
counts no holidays.

Where the hour is applied (catalog.Price.In): Record.CostAt (Usage's
totals and groups), the packed gateway blocks (priceBlock), OTLP's
exported cost and budget's estimate (now). The Sessions page sums per
model without per-call times and stays at the list price. The model
editor's price box says when a list price counts double (four languages;
app.js kept under its budget by shortening, not by a raise).

Run at the tree pushed (parent 32f5c3369), on mote:
- gofmt -l clean
- go vet on the six packages
- go test of catalog, usage and otlp whole, and provider and gui -run
  Peak|PriceIn|CNHolidays|Price|TestCoreScriptBudget, with TZ=UTC and
  with TZ=Asia/Shanghai: all ok
At 76b18f68d (the same change before the last two rebases), on mote:
- go vet ./internal/..., GOOS=linux -tags nogui and GOOS=windows vet of
  ./..., and the darwin, linux nogui and windows builds: ok
- catalog, provider, usage and otlp whole, in both zones: ok
- internal/gui: TestCoreScriptBudget was red (app.js 108 bytes over),
  fixed by shortening the hint. Ten AppKit window tests were killed at
  their 30s bar at load ~130 (TestDockJoinLeadsCommandTab,
  TestMainWindowCorners and others); this change doesn't touch them.
GUI:
- model-price-edit (now checks both peak hints and none on a plain list
  price), model-price-tiers, provider-price-rate and i18n-keys: Chromium
  ok on mote.
- WebKit on mote couldn't launch at all (browserType.launch timed out at
  180s, 69 WebKit processes from other runs), so the three price files ran
  in WebKit on Linux (wsl-run): 8 of 8 ok.
- The whole GUI suite (both engines) at ff23724f3 was still running at
  load 110 to 150 when this was pushed, 119 red of ~7200. Every file
  checked so far is a timeout under load or in #4304 / #3476.
  model-chip-steady is red the same way on origin/main 0911a65e7.

Broken by hand, each red:
- CostAt without .In(r.Time): TestCostAtTheCallsHour (0.753 at peak,
  want 1.506)
- priceBlock without .In(p.Time): its block half
- Peak.At ignoring holidays: TestPeakHours on 2026-10-05
- priceOf never setting Peak: TestPriceOfPeak
- OpenCode Go's model list dropped: TestPeakOf (kimi-k3 "weekdays")

Not tried: a real call to DeepSeek, Command Code or OpenCode Go at peak
and off-peak to compare against their bills; a full go test ./...; the
holiday rule's handling of the swapped working weekends (DeepSeek says
Monday to Friday, so a worked Saturday stays off-peak here); ZenMux,
whose own docs give no schedule.
2026-10-30 15:22:55 +08:00
yetone 7946256933 agents: omp, OpenCode and Crush get each model's price, and a group of mixed prices is priced at its first member (taotao7 on Discord)
taotao7 (#help, msg 1565576524193857678): omp on magpie's group/* models
counted every call at 0. omp's custom provider prices a call by the cost
in models.yml alone (omp 18.9.1: pi-catalog src/models.ts
calculateUsageCost, USD per 1M tokens; models-config-schema-bundle.ts
cost {input, output, cacheRead, cacheWrite}). magpie wrote no cost into
omp's models.yml for any model; an ordinary id still got one from omp's
bundled reference match, a group/* id matched none. And a group whose
members cost differently had no price in magpie's agent list at all
(EntryPricer prices only one-price groups), so Pi had none either.

- provider.AgentPricer: as EntryPricer, but a mixed-price group is priced
  at the member it sends to first (a manual group's pick, else the first
  not switched off); a fast or unpriced first member leaves it unpriced.
  Chosen over "the member it routes to most" because that needs usage
  history and would rewrite agents' files as traffic shifts; the first is
  what an In order / Manual group sends to while it answers. Read at each
  Sync, so it follows the members. The gateway's /v1/models keeps
  EntryPricer.
- omp: models.yml model entries carry cost.
- Siblings: Pi, mothx, alma, penguin, plugged already wrote m.Price and
  now get group prices too. OpenCode got no cost at all: now cost
  {input, output, cache_read, cache_write} (OpenCode 2.0.25). Crush:
  cost_per_1m_in/out/in_cached(write)/out_cached(read) (Crush 0.39.3).
- docs/subsystems/agent-wiring.md says so.

Run (mote): TestGroupModelsCarryTheirFirstMembersPrice ok; full
go test -timeout 45m ./... at load ~150-210 from other work: agent and
provider ok, 77 ok; reds TestTOMLBigFileParsesInLinearTime (#4109) and
the Antigravity turned-away tests + TestCodexSpentGrokFailingIsTold
(#4362), both filed against main. GOOS=linux/windows go vet of agent and
provider ok. Real omp 18.9.1 in a sandbox HOME: `omp models list --json`
reads group/mix with cost {1,2,0.1,1.25}, pricingStatus fixed.
Broken by hand: route.go back on EntryPricer -> red (group/mix cost
nil); omp's Cost line dropped -> red (a/cheap cost nil).
Not tried: a real omp turn through the gateway showing the cost; OpenCode
and Crush showing a session's cost in their UIs (keys read from their
binaries' strings only).
2026-10-30 13:25:55 +08:00
yetone e887139e7a providers: Best in family serves the newest model of each family a provider lists
Steven on Discord #feedback asked for a provider to serve only the newest
model of each family, so a newer one (Opus 5.6) takes the old one's place
without re-picking.

The provider editor's Models control gets a fourth option, beside
Vendor's list / Picked only / Usage only: Best in family. It is also on the
CLI as `magpie provider models <id> best`. With nothing picked, the provider
serves only the newest model of each family in the vendor's list, up to 24.
A family is the id with its version numbers taken out
(catalog.FamilyOf/BestInFamily in internal/catalog/family.go). A dated
snapshot counts as its alias, and sizes and suffixes (mini, flash, -fast,
-thinking) stay part of the name. Provider.Exposed applies it, and so does
Codex's native list (CodexNativePicked). A provider/model a request names
explicitly is still served, since resolve doesn't go through Exposed. A pick,
Select none or Usage only clears the flag (normalize), and a providers.json
without bestInFamily reads as before, so every existing mode is unchanged.
The editor draws the family's newest as dashed (m.best) before saving. Every
language has the wording (zh, zh-TW, ja, de). The design reference is
docs/subsystems/providers-accounts.md (Model picks).

Tests: family_test.go is a table of real ids, including the models.dev Claude
list in testdata (no network). There are also best_in_family_test.go
(provider), TestProviderModelsBest (cli), provider_save_best_test.go (gui
save keeps/clears), codex_best_in_family_test.go (gateway) and
provider-best-in-family.test.cjs (5 languages x chromium/webkit x 1100/420).

Broken by hand: with the BestInFamily filter in Exposed and in
CodexNativePicked turned off, the 4 new Go tests went red.

Budget: after the rebase app.js went over appScriptBudget. Comments were cut
and the tooltip and hint merged into one string, so app.js is 1,311,399 of
1,311,735. Neither budget was raised.

Run at this head, on origin/main 1027db408, via mote-run (macOS 27):
- gofmt -l clean; go vet clean for darwin, linux -tags nogui and windows
  (at base 05a6087e1, the same Go diff).
- go test -count=1 ./internal/catalog ./internal/provider ./internal/cli
  ./internal/gateway: ok.
- go test ./internal/gui: everything except TestMainWindowCorners/macOS_26_SDK
  (red on macOS 27, #3949; not this change).
- node --test: provider-best-in-family, provider-none-picked,
  provider-picked-only-shows-picks, i18n-keys, gui-de, gui-ja, gui-zh-tw,
  context-map and gateway-key-models, 113 tests, 108 pass. The 5 reds are
  context-map 420px "two tiles overlap" (#3488, #4304) and gateway-key-models
  webkit en (#4304). Both fail the same way on a clean origin/main 1027db408
  checkout run alone (8 of 30 red there).
- The earlier wider GUI run (38 provider/routing files, concurrency 3) had
  the same red files on origin/main deb0b8da7 as at this change's head:
  model-chip-steady, models-works-only, provider-fetch-again and the others
  in #4304. Three with no issue were filed: #4320 (recovered-file),
  #4321 (tencent-cloud), #4322 (warm-now).

Not tried: no real account or real magpie app; the editor was checked
through Playwright screenshots only. Families are read off the id alone, so
a vendor whose ids don't put the version in numbers (or orders them
oddly, e.g. grok-4.20 against grok-4.7 compared numerically) may group
or rank unexpectedly. Bedrock's -v1:0 counts as version digits.
2026-10-30 04:48:17 +08:00
yetone 10c85e1fe9 provider: Ark's plan models that see images are sent them, not their descriptions (tongzhenbao on X)
tongzhenbao on X (10-29): an image sent to a Volcengine model took 100+ s
to the first token. Ark's Coding and Agent Plans list no models
(/models is empty for them), so their models come from arkPlanModels
with no word on images, and the gateway judged them by models.dev
(catalog.SeesImages). That says no for doubao-seed-2.1-pro (resellers
tie), doubao-seed-2.1-lite and ark-code-latest, so blindTo held them
blind and every image was first described by the vision model
(visionTimeout 3 min, up to 4 at once) before the model was asked at
all. Not a regression of today: SeesImages answers the same at
479de8900 (10-26), and describing for an unknown model dates from
6cab11673 (10-03).

Region.Images now says which plan models take images, as Ark's own
/api/coding/v3/models says (input_modalities, read 10-29):
doubao-seed-evolving, doubao-seed-2.1-pro, -2.1-lite, -2.0-mini and
kimi-k3.1-pro do; glm-5.3-flash and the deepseek-v4 models don't.
planModels sets ImageInput/Images for those. ark-code-latest,
glm-5.3, kimi-k3, kimi-k2.8-preview and minimax-m3 aren't in that list
and are judged as before.

Timings (mote, M5 Pro, BenchmarkImageRequest, 8 images, 20.2 MB per
request, fake upstream): magpie's own work is 133-288 ms a request
(responses-to-chat 228 ms, chat-to-chat 182, messages-to-chat 133,
responses-to-responses 288), unchanged here; it was never the 100 s.
The describer step, one vision call per image before the model is
asked, is gone for a plan model that sees.

Tests:
- TestArkPlanImagesAreThePlans: every listed id is a plan model and
  planModels marks images exactly as the list says, nil for the rest.
- TestArkPlanModelThatSeesIsSentTheImage: doubao-seed-2.1-pro on the
  plan gets the image itself and glm-5.3-flash the description, the
  describer asked once.

Run at 06074b6c0 (origin/main has moved by 00e0fd11b since, GUI files
only): gofmt -l internal cmd clean; go vet ./internal/provider
./internal/gateway on darwin, linux and windows ok; go test -count=1
-timeout 45m ./internal/provider (85.7s) ./internal/gateway (468.6s)
./internal/catalog ok, all on mote.

Broken by hand: with the Images map unread in planModels,
TestArkPlanModelThatSeesIsSentTheImage is red (doubao-seed-2.1-pro
was sent the description) and TestArkPlanImagesAreThePlans red.

Not tried: a real Coding or Agent Plan key (none here), so the 100 s
itself wasn't reproduced; the pay-as-you-go Ark key lists its own
models and isn't on this path.
2026-10-29 21:10:37 +08:00
yetone 65bd4e4f72 provider: a model is priced at its maker's own API before a reseller's (bestony on Discord)
bestony on Discord (#feedback) asked that a subscription with no price of
its own, such as Command Code, be costed at the model's official list
price. magpie already estimates every subscription at the maker's list
price, but the maker step (PricedBy over the maker presets) took the
first preset that listed the id, and Mistral resells other labs' models:
deepseek-v4.1-flash-1017 was costed at Mistral's $0.30/$1.20 instead of
DeepSeek's $0.15/$0.60, glm-5-2 at Mistral's instead of Zhipu's, and a
lab that isn't a preset (Meta's muse-spark, Sakana, Tencent hy4-preview)
had no price at all.

catalog.MakerPriced prices a model at a models.dev provider that lists it
as its own: the entry's canonical_model_id names that provider as maker,
or the provider id is the maker's with a region (alibaba-cn), never a
plan's ("-plan") and never an entry at $0. A maker preset that is such
an API is asked first, in preset order, then the other owners by id;
the old PricedBy over the presets stays the fallback. makerListPrice
uses it in ListPrice's maker step, MakerPrice and PricedName. No new
setting: a model no maker lists still takes the user's price or a
same-as model.

Over every id in the real models.dev cache (2026-10-29, ~4086 ids) the
only prices that changed are the deepseek-v4.1-flash-1017 family
(0.30 -> 0.15), glm-5-2 (Mistral 1.40 -> Zhipu 1.19516), and newly
priced Meta, Sakana, Thinking Machines and Tencent hy4-preview models.

Run (mote-run, rebased on 1a8539432; catalog, provider, usage run again at this head):
- TestMakerPriceIsTheMakersOwn (fixture: literal entries of the real
  models.dev cache) red on the old code, 10 errors (Mistral's resale
  price, Meta unpriced), green on the new.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
  for internal/catalog, internal/provider, internal/usage.
- go test -timeout 45m ./internal/catalog ./internal/provider
  ./internal/usage: ok.
- go test -run 'Pric|Cost|Usage' ./internal/gateway ./internal/gui
  ./internal/cli: ok.

Not tried: a real Command Code request and its Usage row in the GUI;
the full gateway suite; Windows/Linux runs of the tests.
2026-10-29 19:01:04 +08:00
yetone c201fe2266 usage: Codex's auto-review through a ChatGPT sign-in costs nothing (silverzhou)
silverzhou (Discord): codex-auto-review has been free for a long time,
but magpie still estimates a cost for it. OpenAI's Codex lead
(thsottiaux, "Day 2.1"): "We have made Auto-review free for all users
signed in through a ChatGPT account."

provider.ListPrice now prices codex-auto-review at $0 on the "codex"
provider, the one that holds only ChatGPT sign-ins, unless that sign-in
is on the Free plan: cybercaius measured auto-review spending the Free
allowance, which is why the gateway's freeOnChatGPT already left Free
out. That rule now has one owner, provider.ChatGPTReviewFree, and
freeOnChatGPT calls it. The plan is read from Codex's current sign-in;
an unreadable plan or a Codex signed out since counts as a paid plan
(priceOf's unknown-model branch answers $0 for it too).

Still priced, since nothing says those are free: codex-auto-review sent
with an API key (openai, chatgpt-api), through a relay, or a review
magpie made follow the session's model (the row's served model is that
model). A price the user set for the model wins over the $0.
PricedNameFor names the model itself, so the Requests list no longer
says "priced as gpt-5.6-luna". The usage summary cache key carries the
Codex plan, so a plan change re-prices cached views.

Old rows: prices are applied when the log is read, so every past
codex-auto-review row through a ChatGPT sign-in reads $0 after the
upgrade: Usage's Overview and Requests, the tray, the ledger and key
limits' estimated-cost caps (their in-memory sums are rebuilt at start).
Nothing is rewritten on disk.

Left alone: a Codex window's holds (apiPricer) still count these calls,
filed as #4181. docs/subsystems/providers-accounts.md has the rule.

Run at this tree (rebased on 033b17baf):
- mote-run: TestAutoReviewFreeOnChatGPTSignIn (provider) and
  TestAutoReviewFreeOnChatGPT (usage: ledger, Summarize, ledger sum,
  NewCoster), the KimiCode, CodexSignInPlan and gateway Review tests: ok.
- Red on the old code: both new tests fail with the code changes taken
  out (codex priced at luna, $0.234; summary 0.992 vs 0.758; key limit
  0.134).
- Broken by hand: dropping the plan check or the provider check turns
  the Free-plan and relay/openai assertions red in both tests.
- go vet on mote, and GOOS=linux and GOOS=windows; gofmt -l clean.
- At the rebased head, mote-run go test ./internal/provider
  ./internal/usage ./internal/usageapi ./internal/gateway: all ok (gateway 1883s, provider 846s,
  usage 158s, usageapi 4s); gofmt -l clean.
- Full suite: a mote run at the pre-rebase head reached two packages (ok)
  and then died (exit 144) when the touched-package run re-synced the
  same mote copy, at load ~340 with five other full suites; per the owner's
  ship-at-once rule it is run again after the push.
Not tried: a real auto-review row (none in ~/.codex/sessions or the
real usage log); a multi-account Codex with mixed plans (the live
sign-in's plan decides); the summary cache's plan key was not broken by
hand.
2026-10-29 16:11:26 +08:00
yetone 0daf363325 gateway: a key resting after an outage is asked again in the background
heatonz on Discord: a key or provider paused after a failure stayed out
for its whole rest, even after its vendor was back. Only Try now got it
back early. probeOne asks only the resting candidate that comes back
soonest, so a key behind ready ones was never asked again early.

What changed:
- gateway/rest_probe.go: the background ask, with no setting.
  - Which rests it asks: a key's own rest from a failure that names no
    time (a 5xx, a 408, no connection), resting by backoff, at a vendor
    whose model list is asked over the network (provider.ListAsks).
  - How it asks: the vendor's model list, with the key and its p.Via
    proxy. A list costs no allowance.
  - When: 1m into the rest, then 2m, 5m and every 10m, each ask at least
    half a step before the rest ends. The rest is lifted as soon as the
    list answers, the way Try now lifts it (unsink, trace).
  - Cost: one list per resting key per step, so at most 4 lists in a
    10-minute rest.
- The loop runs from ListenAndServe. A Server whose loop isn't running
  (a test's) queues nothing. A loop that ends waits for the asks under way.
- Not asked: a Retry-After or ratelimit reset header, quota or credit, a
  rate limit, a refused key, a 4xx, one model's rest, a subscription's
  account, a plugin. Those still end on time.
  - Rate limits are left out on purpose. A model list answers while chat
    still gets 429, so lifting early would undo Sink and go around the
    vendor's limit.
- A list answers for the vendor, not for every model behind it. A key
  that fails again within 30 minutes of a lift is not asked again until
  it answers a real request (probeAnswered in served).
- Rest.Probed / KeyRest.Probed. The provider's key row and Routing's
  words for the try add "checked in the background, back as soon as it
  answers", in en, zh, zh-TW, ja and de.
- app.js stays under its budget with no raise: a shared hhmm helper, and
  resetUsedWhen folded into the identical stamp.
- docs/subsystems/gateway-routing.md describes it.

Tests:
- rest_probe_test.go:
  - lifted after one failed ask and one answered, asked with the resting
    key;
  - no ask again after a missed lift;
  - each excluded rest: never queued, 0 asks;
  - no loop, no queue; the loop waits for its asks, and a cut-short ask
    doesn't lift.
- gui/tests/rest-probed.test.cjs: 5 languages x 1100/420px x chromium and
  webkit, 40/40. Red on origin/main's assets.

Broken by hand on mote, each red:
- no lift: test 1 times out;
- no status check: refused key and bad request get asked;
- Retry-After ignored;
- no miss guard;
- no asks.Wait() in the loop's exit.

Run:
- go test -race -count=5 -run TestRestProbe ./internal/gateway: ok.
- mote: internal/gateway ok (636s); internal/provider ok.
  internal/gui TestMainWindowCorners/macOS_26_SDK is red on macOS 27,
  unrelated, #3949.
- Linux Go full suite (wsl-run, -timeout 45m) at 6cbd77608 (the same
  change on 157d575c3):
  - 72 packages ok, gateway ok (445s), provider ok;
  - root, cli and gui don't build there (no gtk4/webkitgtk-6.0 in that
    distro);
  - internal/agent reds are #4033, red at base too;
  - internal/library TestUpdateKeepsASkillChangedHere red once under load,
    passes 3/3 alone at head and base: #4106.
- gofmt -l clean. go vet on darwin (gateway, provider, gui), GOOS=linux
  -tags nogui ./..., GOOS=windows ./...: clean.
GUI:
  - The whole suite on mote was stopped at 744 tests: mote was at load 140
    from other sessions' suites, and browsers took over 180s to launch.
    The reds there were launch timeouts and one account-alias click.
  - Instead, the 141 files the change can reach (key-*, rest-*, routing-*,
    search-keys, codex-resets-used, usage-ledger, i18n-keys, plus the files
    red on mote), in both engines on Linux (wsl-run), at a6f01cf23 rebased
    on ddf31ca30: 2001/2096 pass. The same files at base ddf31ca30:
    1974/2056. The reds are in the same files at head and base, mostly
    WebKit.
  - Serial rerun of the files red only at head: head 200/211, base
    196/211, with the same files red on both sides. Filed as #4121.
    rest-try-now and routing-bodies are already #2564 and #2559.
  - rest-probed 40/40; codex-resets-used (stamp) 10/10.
  - mote at a6f01cf23: go vet for gateway, provider and gui ok; the gui
    Budget tests ok; TestRestProbe -race ok.

Not tried:
- a real outage at a real vendor;
- subscriptions and plugins, which aren't asked;
- a Windows run of the gateway package;
- a macOS full Go suite at the pushed head (mote was busy with other
  sessions' suites).
2026-10-29 05:13:53 +08:00