Commit Graph
18 Commits
Author SHA1 Message Date
yetone 2f660ca86b sessions, usage: Antigravity's gemini-4-argon-d is gemini-4-argon, not a second unpriced model
oioio's Antigravity database names gemini-4-argon's generator
"gemini-4-argon-d". agAppModel took only "-n" off a gemini-* id (Google's
gemini-3.8-flash-n, b2432754e), so the Usage panel showed gemini-4-argon
twice and the -d one had no price. usage.GeminiServing had the same
"-n"-only rule, so the gateway's log would call gemini-4-argon answered
as gemini-4-argon-d a swap.

Both now ask sessions.GeminiDeployment: a gemini-* id with one lowercase
letter after its last hyphen is that model's deployment. Google's own
ids never end in a lone letter (-lite, -nano, -pro, -001, -exp), and
other makers' ids (gpt-5-d, claude-sonnet-4-5-n) stay as written. The
rule is by shape, not by the catalog: a catalog lookup at parse time
would freeze a "-d" into the kept parses whenever models.json wasn't
there yet. antigravity's parseVersions and callParseVersions go to 1,
so parses and call shards kept with gemini-4-argon-d are read again on
update; nothing else is reread.

Run (mote, at this tree):
- go test -tags nogui ./internal/sessions ./internal/usage: ok.
- go vet, GOOS=windows go vet, GOOS=linux go vet -tags nogui on both
  packages; gofmt -l prints nothing.
- Broken by hand: GeminiDeployment put back to the old -n-only rule.
  TestAntigravityAppDeploymentName failed ("gemini-4-argon-d":
  "gemini-4-argon-d", want "gemini-4-argon", fields 19, 21, 22) and
  TestSwappedGeminiServingName failed ("gemini-4-argon answered as
  gemini-4-argon-d is the model asked for"); both pass with the change.
- Full suite runs after the push (go test -tags nogui -timeout 45m ./...).

Not tried: oioio's own database (only the model name was posted), and
a real gateway request that Google answers as gemini-4-argon-d.

Reported-by: oioio (Discord)
2026-11-07 00:22:13 +08:00
yetone e156fdd032 usage: a model's region deployment answered under its own name is not a swap (plugins#628)
WorkBuddy AI lists DeepSeek V4.1 Flash as deepseek-v4.1-flash-sg, its
paid id for the Singapore deployment. The plugin's product config names
it paidId to the free deepseek-v4.1-flash, with one window for both.
WorkBuddy answers under the model's own name, so the Routing page tagged
each request "请求 deepseek-v4.1-flash-sg · 实际 deepseek-v4.1-flash".
Old routes and kept usage rows kept the mark, so removing the model and
setting the provider up again didn't clear it (chansee97, plugins#628).

- RegionTail (internal/usage/served.go) covers a name that is the other
  with -sg, -us, -eu, -cn, -intl or -global after it. Such a pair is the
  same model, and Swapped excludes it.
- A region in both names, or a name that differs besides the region, is
  still a swap.
- Kept rows (request_page.go) and kept routes (gateway history.go's
  routedAgain) are judged again with it, so old marks go too.

Run on mote, at 5f0a84a00 plus this change:
- gofmt -l internal plugins: clean.
- go test -count=1 -timeout 45m on ./internal/usage, ./internal/usageapi,
  ./internal/budget, ./internal/davsync, ./internal/middleware,
  ./internal/otlp, ./internal/gui/..., ./internal/cli, ./internal/tui,
  ./internal/gateway/..., ./plugins/middleware/..., ./plugins/otel/... and
  ./internal/agent (every importer of internal/usage): all ok except four
  reds that are filed and don't touch swap marking:
  - internal/gui TestMainWindowCorners (#3949)
  - internal/cli TestEveryRouteHasACommandOrIsNamed (#4826)
  - internal/gateway TestCodexPoolSaysTheClientsVersion (#4807)
  - internal/gateway TestUnroutedRequestShownThenAnswered (#4200)
- GOOS=linux and GOOS=windows go vet ./internal/usage
  ./internal/gateway/...: ok.

After the rebase onto a32588528, which changed internal/usage's
request_page.go and match_chunks.go:
- ./internal/usage and ./internal/usageapi: ok.
- go test -run "RouteKept|Swap|Served|History" ./internal/gateway: ok.
- vet: ok.

Broken by hand, each red:
- RegionTail taken out of Swapped: TestSwappedRegionTail.
- The kept-row re-judge taken out: TestKeptRowRegionTailNotSwapped.
- The routedAgain re-judge taken out: TestRouteKeptRegionTailNotSwapped.

Not tried:
- A live WorkBuddy AI request to -sg, which would spend credits. That
  WorkBuddy answers -sg under the plain name rests on the report.
- The reporter's screen. This assumes the "实际" tag they saw is the
  Routing page's swap tag (or Usage's Served column, which is fixed by
  the same rule).
2026-11-02 19:26:26 +08:00
ggbdpq 96a37ee5e3 usage: the vendor's own alias for a model isn't a swap (#4593)
A request via Top-API for deepseek-v4.1-flash answered under
deepseek-flash was marked a swap. It isn't one: DeepSeek renamed its
V4.1 Flash deepseek-flash (api-docs.deepseek.com/updates, 2026-09-10:
"Change the model name to deepseek-flash to call the latest V4.1 Flash
model"), and every exemption Swapped knows is structural - a dated or
pinned tail, a Bedrock geography, a relay's word in front, a serving
name - none of which an official rename reads as.

VendorAlias reads a small table of rename pairs the vendor's own docs
state (deepseek-flash is V4.1 Flash), both ways, over squashed bare
names so case and separators don't matter; a bareModel'd name feeds it,
so the dated spellings either side writes hit it too. Only pairs the
docs state go in: a retired name routed elsewhere (deepseek-v4-flash)
is another model, and catalog's SameModel keeps deepseek-flash an id of
its own. The kept-row readers take the alias in beside the other
exemptions, so rows recorded before it are read back as not swapped.

Run (sandbox HOME, GOTOOLCHAIN=auto, -tags nogui):

  go test ./internal/usage -run 'TestSwappedVendorAlias|
  TestKeptRowVendorAliasNotSwapped'  ->  ok (base f811bf291: both FAIL,
  the seven alias pairs read as swaps)

  go test ./internal/usage -run 'TestSwapped|TestKeptRow|TestListed|
  TestRelay'  ->  ok

Reviewed and landed as one batch of 12 commits (gua's #4593, #3269,
#3881, #2887, #3289, #2718, #2855, Edward4226's #2718 key-path
sibling, and four review follow-ups). Run for the batch, whose last
commit's tree is 5d58a75f3:
- Full suite before the rebase (base d307aa648, wsl-run magpie-desktop,
  go test -tags nogui -count=1 -timeout 45m ./...): 81 packages ok. Reds,
  all with issues and none in code this batch touches: internal/agent
  TestInstalledVersion, TestGrokInstalled, TestOmpDetectedWithPiDir
  (#4033, #3548, #3141); gateway TestUnroutedHeldReportSaved (#4300);
  gui TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestColdTurnsTaken (#4510); provider
  TestClaudeAccountServesModelsListedSinceItsFetch (#3174). Run alone at
  origin/main 573b21f4b, TestGrokInstalled, TestOmpDetectedWithPiDir
  and TestSettingsSaveKeepsWhatItDoesNotSend are red there too. The
  other four pass there alone.
- After the rebase onto origin/main 573b21f4b, at this tree:
  internal/usage, update, gateway and provider ok. In internal/agent,
  the #4033/#3141 install-detection reds plus TestCopilotFolderFrom-
  AnIDEPluginIsNotTheCLI and TestZedAppPath. Those two are flaky the
  same way at origin/main (-count=10 alone: 4 and 5 of 10 red) and are
  already listed in #4033. The #3269 tests (TestCopilotLauncher*) pass
  5 of 5.
- Rebased onto origin/main ef63ef4a2. The #2855 commit met 0b9727ec9
  (#2974) in responses.go: the streamed item's done now takes both, the
  upstream's own id (thinkUp) and the made-over item; and in
  gateway-routing.md main's paragraph is kept with #2855's clause. That
  matches gua's latest head (range-diff: context only). At tree d7c76c6fa:
  internal/gateway, provider, usage, redact and update ok; vet
  GOOS=linux -tags nogui ./internal/..., darwin and GOOS=windows for
  gateway and provider.
- Rebased last onto origin/main d8f7d089f (5 commits: internal/agent
  and GUI files only). At tree 0d4bfd8c8, the pushed one: internal/agent's
  TestCopilotLauncher*, TestClaude*, TestOwn* and TestVSCode* ok, -count=3;
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI red once there, as it is at
  main (#4033). Vet of internal/agent: darwin, linux and windows.
- gofmt -l clean. On mote: go vet darwin, GOOS=linux -tags nogui and
  GOOS=windows.
- Broken by hand, each turning its guard red: the lift gate
  (TestReadingKeepsARefusalsRest, TestAutoVisionKeepsOffARefusedAccount);
  the named-time condition (TestNamedQuotaTimeReplacesAGuess); the
  filter-chain hop (WholeReply/glm-5.3-flash); Edward's aAt
  (TestKeyAllowanceElapsedResetStartsAgain); and the old
  magpieMadeReasoning, which panics in TestMadeReasoningSaysItsTextOnce/
  no_summary. Every new test of gua's is red at base d307aa648.
Not tried: real OpenAI, DeepSeek, GLM or ChatGPT accounts; a real VS Code
1.144 install on Windows; a GUI run (no GUI files are touched).

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 07:06:19 +08:00
ggbdpq c2d6a64c7d usage: a Bedrock model of a newer maker answered by its own name is no swap
What changed:

vendorDot names Bedrock's makers so a reply saying the model's own id
reads as the model asked for (012be0fc, #1484). models.dev's bedrock
list has since grown makers the list did not have: xAI (xai.grok-4.7,
us.xai.grok-4.6), Writer (us.writer.palmyra-x5-v1:0), Moonshot
(moonshot.kimi-k2-thinking) and NVIDIA (nvidia.nemotron-nano-12b-v2).
A request sent as the geography.maker id and answered by the model's own
name was marked swapped — the route, its tries and the usage row — as if
the vendor had served another model. vendorDot takes the four makers
too, moonshotai kept before moonshot, so moonshotai.kimi-k3 strips
whole. Another model is still a swap (global.xai.grok-4.7 answered as
grok-4.6, us.writer.palmyra-x5-v1:0 as palmyra-x4).

Run:

- The new rows of TestBedrockProfileAnsweredByItsModelIsNoSwap fail on
  the old served.go, each with Swapped true where the model's own name
  answered (six pairs); with the change they pass, the two
  still-a-swap guards stay true, and the route and usage row of the
  anthropic run through the Bedrock preset stay unmarked.
- go test -tags nogui -count=1 ./internal/usage ok.
- go test -tags nogui -count=1 -run 'Bedrock|Swapped|Served|RelayRenamed|Rename'
  ./internal/gateway ok.
- gofmt -l clean; go vet -tags nogui of both packages on darwin,
  GOOS=linux -tags nogui and GOOS=windows clean.
- go build darwin, GOOS=linux -tags nogui, GOOS=windows ok.

Not tried: a real Bedrock account on xAI, Writer, Moonshot or NVIDIA
models; the pairs are read off models.dev's bedrock list of today.

Generated-by: GLM-5.3-Flash (ZCode)
2026-10-28 03:14:05 +08:00
yetone 841bcf8da7 usage: a reply under the name its provider's list gives the model is not a swap
jzing.draw (Discord #general, 10-27) had a Usage row for Qoder's free
Qwen model, sent as qfmodel, tagged "actual Qwen3.8-Flash". Since
plugins#412/#413 (qoder 0.2.38) the plugin answers under the model list's
display name, and Qoder's list names qfmodel Qwen3.8-Flash, so it is the
model asked for. Swapped compares names alone and can't know that.

usage.ListedAs(provider, model, served) reads the provider's own list
(Provider.Available, once a minute per provider, only once a reply already
reads as swapped) and holds when served is the name it gives the model,
spelled however (SameSpelled). Every place a swap is set or read again
asks it: the gateway's try, the ledger and request-page rows, block
pricing, a kept row read back (request_page unpack) and a kept route
(history routedAgain), so old rows lose the false tag too.

Run at this tree (base ca8a6f346):
- go vet ./internal/usage ./internal/gateway on darwin, linux (nogui)
  and windows; gofmt -l clean
- go test -count=1 -timeout 45m -p 1 ./internal/usage ./internal/gateway:
  usage ok 146s, gateway ok 887s
- the new tests (TestListedNameIsTheModelAskedFor, TestListedNamesReadOnceAMinute,
  TestKeptRowListedNameNotSwapped, TestBlockPricerListedNameNotSwapped,
  TestRouteKeptListedNameNotSwapped) pass

Broken by hand: with the call sites put back (served.go's ListedAs kept),
TestKeptRowListedNameNotSwapped, TestBlockPricerListedNameNotSwapped and
TestRouteKeptListedNameNotSwapped fail.

Real use: a binary built from this tree, under a sandbox HOME holding a
copy of the owner's ~/.config/magpie, reads the real Qoder list:
qoder/qfmodel answered as Qwen3.8-Flash and dmodel as DeepSeek-V4-Pro are
listed (not swaps), qfmodel answered as GLM-5.3 is not.

Not tried: a live gateway call through the Qoder plugin; the full
go test ./... (other packages don't call ListedAs); the gateway try's line has no test of its own beyond the kept-route
read, which uses the same ListedAs.
2026-10-27 18:54:31 +08:00
yetone 6db5e9d593 usage: ClinePass's vmc/ name for the model asked is not a swap (zRain on Discord)
zRain (Discord, 10-24) sent Snow CLI through magpie to
cline/cline-pass/deepseek-v4.1-flash-1017 and read the Routing row's
"vmc/deepseek-v4p1-flash-101…" as the upstream, so the DeepSeek pin
(cline plugin 0.1.11) looked ignored. That text is magpie's swap tag
("实际 vmc/…", "likely another model"): ClinePass answers a cline-pass/
model under its virtual model config's name, the version's dot written
"p", and Swapped read deepseek-v4p1-flash as another model than
deepseek-v4.1-flash. hy125245's pinned requests (finalProvider deepseek,
X 10-23) carried the same vmc/ name, so the name says nothing about the
upstream; the upstream is the "上游:…" tag after it, which the swap tag
pushed out of a narrow row.

Changed: usage.ServingName now includes ClineServing: served "vmc/<name>"
for a sent model with a cline-pass/ path, equal once "<d>p<d>" reads as
"<d>.<d>". Scoped to ClinePass: the same vmc/ name for deepseek/… (not
cline-pass/), another model (v4-pro answered as v4p1-flash, v4p1 vs v4p2,
glm-5.3 vs glm-5p3-flash) and another prefix stay swaps. ServingName is
what routedAgain and the ledger's kept rows already re-read, so routes
and Requests rows kept marked swapped read as not swapped too.

Facts checked, not changed:
- The pin reaches ClinePass on every path. The real opencode-cline-auth
  0.1.11 index.mjs, loaded in magpie's plugin host against a fake
  api.cline.bot (scratch wrapper over fetch, not committed), got
  providerOptions {gateway:{only:["deepseek"],has:["vision",
  "implicit-caching"]}} for a Snow-shaped streamed /v1/responses, a
  non-streamed one, /v1/chat/completions and /v1/messages, and the
  route's Upstream was the reply's finalProvider.
- With the fake refusing the pin ("no matching upstream"), the plugin's
  one unpinned retry went out and the route showed the fallback's
  finalProvider as Upstream: a fallback would show as another "上游".
- Vercel's AI Gateway lists deepseek for deepseek-v4.1-flash-1017 with
  vision and implicit-caching, so the has filter doesn't rule it out;
  "vmc" is not one of its providers.
- @magpie-community plugins update by themselves hourly; npm has 0.1.11
  since 10-23 14:18 UTC.

Run at this commit, rebased on origin/main 3e9efe1d5:
- gofmt -l, go vet (darwin), GOOS=linux and GOOS=windows go vet of
  ./internal/usage ./internal/gateway: clean.
- go test -count=1 -timeout 45m ./...: ok, 70 packages, no FAIL (internal/gateway 544.996s)

Broken by hand (ClineServing returning false), each red:
TestSwappedClineServingName, TestKeptRowClineServingNameNotSwapped,
TestRouteKeptClineServingNameNotSwapped; and the scratch real-plugin run
marked all four routes Swapped.

Not tried: a real ClinePass request (no Cline sign-in on this machine),
so whether zRain's four rows had "上游:deepseek" after the vmc/ name is
the reporter's to say; the GUI suite (no GUI file changed).
2026-10-24 16:29:44 +08:00
yetone 81a24cf8fe groups: a found group is listed as auto/<model id as the vendor spells it>
ZeroClover asked on X: Auto Group ids group/auto-<slug> can't be looked
up on models.dev. A found group is now listed and written as
auto/<model>, e.g. auto/claude-opus-5.5: /v1/models, the catalog, agent
configs, the GUI's Routing page and the CLI. Context and output limits
come from the model's metadata as before.

What stays the same:
- The internal id is still group/auto-<slug> (Group.Ref() gives the
  public one). Every old form is still accepted as input forever:
  provider.CanonicalRef turns auto/<model>[:level][[1m]] into it at the
  gateway (validateModel), keys, stats, affinity and usage, so both ids
  route to the same group and count as one.
- A key's model list allows a model by either id, group/* included
  (allows() in key_models.go).
- Hand-made groups stay group/<id>.
- A provider whose stored id is "auto" keeps its models: while one
  exists, found groups are listed by their old id (AutoRefsOn) and
  auto/<x> means that provider's model. Documented in
  docs/subsystems/gateway-routing.md.

Agent configs: SyncCatalog rewrites a field that holds a found group's
old id (renameFoundGroups), but only while the value is still what
applied.json says magpie wrote; a value the user set stays. A pick by
the old id written now is written as auto/<model> (Apply). Hidden,
picked and ordered model lists saved by the old id hold for the new one
(visible.go), and a bare model id still reaches its found group (bare.go).

Claude Code is given a dotted Claude version dashed (ClaudeSpelled), so
auto/claude-sonnet-4.5 sits in its settings as auto/claude-sonnet-4-5.
That routes to the same group, but with found groups off nothing reads
it back dotted, and Reseat took the field for changed and left the agent
on a group that was gone. Reseat now compares a group pick by its
canonical id (samePick). The old ids had no dots, so this is new with
auto/<model>.

Run at this tree (sandbox HOME, caches pinned):
- gofmt -l: clean. go vet ./...: clean on darwin, GOOS=linux -tags
  nogui, GOOS=windows.
- go test -p 4 -timeout 45m ./...: every package ok except agent and
  gateway, whose failures were the tests' expected ids (updated here)
  and two regressions now fixed (bare ids; desktop models hiding groups
  by prefix). Every failing test passes on rerun. Load average was
  ~210-290 from other sessions throughout.
- Reruns: provider, cli, codexcat ok. internal/gui: only
  TestSetAnswersWhileDevinAndProvidersHang fails (set slow/slow-1 took
  10.19s), and it fails the same in a git-archive export of 33dbdcc52.
- agent and gateway in full, -p 2 -timeout 120m: gateway ok (2996s).
  agent failed four tests that still expected the old ids
  (TestOmp/PiModelsAskedOnTheirNativeAPI, TestReseatFoundGroupsOff,
  TestReseatKeepsAFoundGroupWithAProviderOff); updating them showed the
  Reseat bug above. After the fix, go test -count=1 -timeout 120m
  ./internal/agent/: ok (1000s, load ~160-220).
- GUI files the change reaches, chromium and webkit: group-found-off and
  the routing files pass, except routing-bodies, routing-model-rest,
  routing-keys-fold and routing-request-metrics, which fail the same with
  33dbdcc52's JS.

Broken by hand and watched red, then restored: CanonicalRef in
validateModel (both-ids routing test), allows() (key tests both ways),
the Save refusal and AutoRefsOn checks in Ref/CanonicalRef (provider
named auto), catalog.Lists' preference (models.dev lookup of the part
after auto/), renameFoundGroups' applied.json check and its SyncCatalog
call (user values kept), PublicRef in visible.go, the codexcat prefix,
samePick in Reseat (TestReseatFoundGroupsOff: opus left on the gone
group).
TestBareModelIDsShared was red before the bare.go fix.

Not verified: no real agent, vendor or models.dev client run; no run on
the Windows box. Settings pickers (vision, title model) holding a saved
group/auto-... value may show it as saved. codexcat can't tell a stored
"auto" provider apart, so its models lose the "text only" hint. The
pre-existing reds above are not filed.
2026-10-20 00:18:51 +08:00
yetone 11d1d5d208 usage: a model asked for at a window (grok-4.7@500k) and answered under its plain name is no longer marked swapped (#1645, ggbdpq)
magpie offers some models at a window beside their default, spelled as
<model>@<size>: grok-4.7@500k, and Cursor's grok-4.7@256k. The vendor
answers under the plain name. bareModel left the @500k in place, so
Swapped marked every such request as answered by another model.

What changed: bareModel now drops a trailing @<digits>[k|m], right after
the [1m] tail Claude Code writes, using the reporter's regexp. Another
version or variant answered for a windowed id is still a swap.

What was run:
- TestSwappedGrokWindowID uses the reporter's cases.
- It is red with the new line commented out (all five same-model cases
  fail) and green with it.
- go test -tags nogui ./internal/usage/ is green.
- gofmt -l and go vet are clean on darwin, linux and windows.

Not tried against real SuperGrok traffic.
2026-10-12 00:44:47 +08:00
yetone f3fa5a53ce usage: a relay's rename answered under the model's own name is not marked as another model swapped in (#1498, liuweifeng)
relay-a/moonshot-kimi-k3 answered as kimi-k3 was marked swapped in the
ledger, the CSV and the Routing trace, though it is the model asked for
under the relay's own name. The same held for #1383's
claude-deepseek-v4.1-flash answered as deepseek-v4.1-flash.

RelayRenamed: sent is served's own name (after bareModel, separators
squashed) with a relay's word and a hyphen in front; Swapped no longer
counts it, and a row kept marked swapped is read back as not swapped, as
SameSpelled rows are. What is left must have a digit and a letter, so a
bare word ("flash", "mini") is never taken for the model sent; another
version behind a relay's word (kimi-k2) is still a swap, and so is the
reverse (kimi-k3 answered as moonshot-kimi-k3).

Run: TestSwappedIgnoresARelaysRename, TestKeptRowRelayRenamedNotSwapped
(both red with RelayRenamed forced false), go test -tags nogui
./internal/usage, gateway tests. Sandbox magpie with the reporter's
record: `usage --csv` swapped false (true before). gofmt -l,
GOOS=linux/windows go vet clean.
2026-10-10 19:55:29 +08:00
yetone 18d87fc51a usage: grok-4.7 answered as grok-4.7-build is the model asked for, not a swap (#1455, cybershape)
xAI answers a request for grok-4.7 with model grok-4.7-build (the
reporter's requests log; two relays' notes say the same for grok-4.6 ->
grok-4.6-build). Its own list (SuperGrok's, cached 2026-10-02) offers
grok-4.7 and grok-4.7-build-fast and no grok-4.7-build to ask for, so the
-build name is xAI's name for the build serving the model.

GrokServing reads past "-build" after a Grok model's version and joins
GeminiServing under ServingName, which Swapped, a kept requests-log row and
a kept route's try all use. Only names starting with grok count, and only
the same variant: grok-4.7 answered by grok-4.7-build-fast, grok-4.6-build
or grok-4.7-mini is still a swap, as is gpt-5 answered as gpt-5-build.

Run:
- TestSwappedGrokServingName, TestKeptRowGrokServingNameNotSwapped,
  TestRouteKeptGrokServingNameNotSwapped (new). With ServingName reduced to
  GeminiServing the usage tests fail ("grok-4.7 answered as grok-4.7-build
  is the model asked for", "serving name true, fast variant true").
- go test -tags nogui ./internal/agent ./internal/usage ./internal/gateway
  ok; gofmt -l clean; go vet for darwin, linux, windows clean.
- Not tried against xAI itself: no request was sent from the owner's Grok
  account; the served name is the reporter's.
2026-10-10 18:10:18 +08:00
yetoneandggbdpq 012be0fcbe usage: a Bedrock global. or us-gov. inference profile answered under its model's own id is no swap, so Claude on Bedrock's preset no longer shows as swapped (#1484, ggbdpq)
Bedrock's preset gives its Claude and GPT-6 models as global. inference
profiles (global.anthropic.claude-opus-5-5, global.openai.gpt-6-luna),
and a GovCloud account's are us-gov. ones. Bedrock's reply names the
model by its own id, as TestSwappedModel has it for us.anthropic.… .
bareModel stripped a profile's geography with vendorDot, which took two
to four letters only, so global. and us-gov. stayed on and Swapped
marked the route, its tries and the usage row as served by another
model. catalog's bedrockGeos already lists both.

vendorDot now takes global. and us-gov. too. Another model is still a
swap (global.anthropic.claude-opus-5-5 answered as claude-sonnet-5).
Rows and routes kept marked swapped before read as not swapped through
SameSpelled, which uses the same bareModel.

Run: TestBedrockProfileAnsweredByItsModelIsNoSwap fails on the old
served.go (Swapped true for four global./us-gov. pairs; route and usage
row marked swapped through the Bedrock preset to a fake runtime) and
passes with the change; go test -tags nogui ./internal/usage
./internal/gateway green under a temp HOME; gofmt -l clean; GOOS=linux
and GOOS=windows go vet -tags nogui on both packages. Not tried against
a real Bedrock account.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-10 17:58:07 +08:00
yetone b2432754e5 usage, gateway: Antigravity's gemini-3.8-flash answered as gemini-3.8-flash-n is no longer marked as another model (dumplings on Discord)
Google's Code Assist backend names the deployment serving Gemini 3.8 Flash
"gemini-3.8-flash-n" in modelVersion, for every level it is asked at. On the
owner's real Antigravity account (daily-cloudcode-pa, 2026-10-08)
gemini-3.8-flash-low, -medium and -high all answered gemini-3.8-flash-n, with
or without a thinking level. gemini-3.8-flash-n itself is a 404 and
fetchAvailableModels doesn't list it. 3.7/3.6 Flash's levels answer the bare
family name, which #462 already allowed. So the requests log's amber "actual
model" and its "probably swapped" note were a false flag.

usage.GeminiServing accepts the sent Gemini model's own name plus "-n".
Swapped and the readers for kept rows and routes (request_page row(),
history routedAgain) all use it, so rows already logged read correctly
too. It covers Gemini only. gpt-5 -> gpt-5-mini, gpt-5 -> gpt-5-n,
claude-sonnet-4-5 -> -n, gemini-3.8-flash -> -lite, -> gemini-3.7-flash-n,
-> -nano and -high -> -low are still swaps.

Verified: TestSwappedGeminiServingName, TestLedgerGeminiServingNameIsNoSwap,
TestKeptRowGeminiServingNameNotSwapped and
TestRouteKeptGeminiServingNameNotSwapped fail on the old code ("gemini-3.8-flash
answered as gemini-3.8-flash-n is the model asked for", "still swapped") and
pass with it. Sandbox magpie on a copy of the real Antigravity login: before,
the routing log had swapped:true on every gemini-3.8-flash-n try. After, chat
completions at none/low/medium/high and /v1/responses are not swapped, and
the ledger reads the earlier rows as not swapped. go test -tags nogui ./...
passed under a temp HOME. go vet ran for darwin/linux/windows, and the
linux/windows builds passed.
2026-10-08 15:15:37 +08:00
yetone 4a87b30610 usage, gateway: a model the vendor spells with other separators isn't marked as another one (vincentzhang on Discord: 这个说明有点奇怪。看不明白。) — Volcengine Ark answers deepseek-v4.1-flash as deepseek-v4-1-flash, the dots written as hyphens, and the Usage page's Requests and the Routing page marked every such row amber 「实际 deepseek-v4-1-flash」, saying another model had answered, not the one asked for under a dated name. Swapped now compares the bare names without their separators (. - _ and spaces) and case, so deepseek-v4-1-flash, deepseek_v4_1_flash, GLM-4-6 for glm-4.6 and gpt-4-1-2025-04-14 for gpt-4.1 are the model asked for, while deepseek-v4-flash or deepseek-v4.1-pro for deepseek-v4.1-flash still are another. Rows and routes kept marked swapped before are read back as not swapped when the names differ only so (usage.SameSpelled, in rowChunk.row and Route.routedAgain). The tag's explanation says it in plainer words: asked for {sent}, the reply says {served} answered, likely another model; the same model under a dated name or spelled otherwise isn't marked (zh, ja, de). TestSwappedIgnoresSeparators fails on the old code; TestKeptRowSameSpelledNotSwapped, TestRouteKeptSpelledOtherwiseNotSwapped. usage-ledger (its expected title updated), remote-group-served, panel-routing, gui-ja and gui-de pass on WebKit. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass (TestCodexVersion timed out once under load and passes alone). 2026-10-05 12:49:59 +08:00
yetone febbf29b0f usage: an Antigravity call at a level answered under its model's own name is no swap (#462: gemini-3.8-flash at medium marked Swapped, answered by gemini-3.8-flash) — on an Antigravity account a call at an effort goes out as that level's id (AntigravitySentID: gemini-3.8-flash-medium), and Cloud Code's reply names the family in modelVersion (gemini-3.8-flash), so Swapped compared gemini-3.8-flash-medium with gemini-3.8-flash and the request list and the Routing view tagged the model as swapped for itself. A sent id whose last word is an effort word (provider.EffortFamily: low, medium, high, xhigh, minimal, extra-low, extra-high) now matches a reply naming the id without it; a reply naming another level, or another model, is still a swap. TestLedgerAntigravityReplyNamingTheFamilyIsNoSwap fails without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (TestClaudeRunEndsWhenTheClientLeaves, a load flake, passes alone). 2026-10-02 02:24:48 +08:00
c0f3fa012a usage: combine gateway and local session requests with model charts and account labels (#239)
* usage: Requests lists the agents' own session-file calls, put to the vendor and account their files prove, charts them by provider, agent or model, shows what was said, and the tray panel gets a Usage tab

The Usage page's Requests tab now covers requests an agent sends with its own sign-in (Claude Desktop's Code tab and Cowork, Claude Code, Codex), which never pass the gateway, and shows more of every request: why it failed, what was said in it, who it was of.

Requests tab: a strip of four totals (tokens, requests, cost, cache hit rate); the trend of one metric — tokens, cost or requests — as columns by the hour, day or week, told apart by provider, agent or model (both remembered), beside a ranking of the same that is its legend and a way in (a click lists only that provider's or agent's requests; a provider picker sits beside the agent's). The ranking is as tall as the chart and scrolls in itself, with no scrollbar: a slim rail in the card's margin shows how much there is and where it is (its thumb dragged, the rail clicked), and the edge with more beyond it fades; under the chart (860px and narrower) it shows whole. A row opens to its details: the vendor's error type and words, request id, endpoint, and what was said in it (input and output, read from the agent's session file when opened, the call that ended nearest the request — nothing stored). A refresh period (off / 5 s / 10 s / 30 s / 1 min) and refresh-now. The Overview says it counts gateway calls only; Requests and the panel say they count both. The tray panel gets a Usage tab (today / 7 / 30 days, provider picker, four totals, a small chart, top five, "Open Usage"), and is as tall as its tallest tab (#124).

Provider and account of a session-file call: never magpie's "claude" or "codex" subscription. Anthropic's when Claude Desktop's session metadata (not Claude-3p) names the account and organization, with that account's email; OpenAI's when Codex's rollout names a provider that is OpenAI's in config.toml — the built-in "openai", or a named one at OpenAI's address or signed in with the ChatGPT account and no base_url (requires_openai_auth) — with the creator account's email when the file records it. Anything else is "Local session", its recorded provider id and session account kept (CSV: session_provider, session_account). The config read is today's: a file names the provider id only.

Gateway: a failed call keeps the vendor's error text and type, request id and endpoint; a Claude subscription's failure uses the status Claude Code reports (api_error_status). A request turned away before any vendor was asked is logged, marked rejected, listed in Requests and left out of every total. The client's own session header is kept as native_session beside X-Magpie-Session, and a session-file call is matched to a gateway record by request id, then by that session, equal tokens and an end within 2 s, only when unique both ways.

Reading: session-file calls live in the session index main keeps on disk, parsed incrementally and outside its lock (Claude Code, Cowork in both Claude folders, Codex); the usage log is read on from where it was; a page builds the ledger once. Days are counted on calendar dates (DST). CSV gains request_id, endpoint, error_message, error_type, source, session_provider, session_account. i18n: one "Endpoint" (终结点), which a second key had turned for Azure's field.

Tested: go vet ./..., go build (also GOOS=linux/windows, -tags nogui) and go test -tags nogui ./... pass. The whole GUI suite in Chromium and WebKit, en and zh (Playwright 1.62.1): all 393 tests pass. On this computer's files (7 days): 3,330 Claude Desktop calls resolve to Anthropic with the account, 1,991 Codex calls on a named ChatGPT-signed-in provider to OpenAI (620 with the account; older rollouts don't record it), 9 Claude Code CLI calls stay Local session.

Co-authored-by: yetone <yetoneful@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* usage: a session-file call of one of magpie's own Codex or Claude accounts is told as that provider, beside the gateway's calls on it — "OpenAI" and "Codex" (or "Anthropic" and "Claude Code") read as two vendors when they were one subscription

Codex: an official route (above) whose creator account and user are one of magpie's Codex sign-ins (the CLI's own or a saved one) is magpie's "codex", with that account's email as the gateway's rows have it. Claude Desktop (not Claude-3p): an account and organization that are one of magpie's Claude sign-ins is magpie's "claude". Only while magpie has that provider signed in; another account, a rollout with no account recorded, or an ambiguous workspace stays OpenAI or Anthropic, and a relay stays Local session.

Tested: TestSessionCallsOfMagpiesAccountsAreItsProviders (the account matched, another account, none recorded, magpie's account through a relay, Desktop in magpie's and another organization, Claude-3p, magpie signed out) and TestLedgerTellsCodexSessionCallsAsMagpiesCodex (a gateway Codex call and a session call of its account one provider of two calls, another account's OpenAI). On this computer (7 days): 3,439 Claude Desktop calls are magpie's Claude, 626 Codex calls its Codex, 1,322 older Codex rollouts with no account stay OpenAI. go test -tags nogui ./... and the usage GUI tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: 修复请求统计缓存膨胀与会话账号误归属 #239

调用明细改为按会话文件分片保存并限制内存缓存,汇总索引仅保留统计数据;网关日志按需读取。

严格匹配订阅账号与用户 ID,排除自定义渠道、非官方端点覆盖、外部 CODEX_HOME 及关闭的供应商。补齐零 token 失败去重、Codex 原始会话 ID、拒绝标记导出和面板显示修复。

通过全量 Go 测试、静态检查、受影响模块的并发检查、52 项浏览器测试及 macOS/Linux/Windows 构建;使用 35 万条合成调用验证索引体积与内存改善。

* fix: 降低请求统计刷新与写入开销并明确本地账号展示 #239

请求分片改为追加帧和字符串去重,分页复用未变化的紧凑快照,采用 LRU 并移出全局锁内的磁盘读取。缓存 Cowork 目录,补齐同前缀改写检测及崩溃临时文件清理。

本地记录仅显示匹配账号或本地会话,明确官方登录标记与请求路由的区别。默认今日与模型维度,Auto Review 复用共享目录定价并单独标注估价参考。

完整 Go 测试、vet、相关 race 和 52 项浏览器回归通过;提供 2000 文件及四个大会话连续追加的可复现性能对照。

* fix: 优化用量徽标与耗时分级并保护分页边界 #239

官方登录、API、订阅和本地会话采用独立颜色与柔和底色,兼容明暗主题。耗时按 10 秒及 30 秒阈值着色,保留估算标识与原始毫秒提示;无有效耗时显示短横线。

限制分页选取范围,避免超大偏移整数溢出及越界空页的无效堆构造。补充阈值、徽标对比度和极端分页参数回归。

* fix: 将账号与来源徽标分为两行展示 #239

* fix: 提高用量表格模型文字对比度 #239

发送模型和已知实际模型使用主题正文次级色,表头与时间同步加深。保留缺失值弱化、转发提示和本地日志来源说明。Chromium 与 WebKit 的中英文、浅深色主题 10 项界面检查通过。

---------

Co-authored-by: yetone <yetoneful@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 17:42:10 +08:00
yetone 5fe0906907 gateway: a remote magpie's routing group answering with the member it routed to isn't a swap (莫 on Discord: 发送模型 group/auto-deepseek-v4-1-flash, 实际模型 deepseek/deepseek-v4.1-flash shown amber) — a request for one of another magpie's groups ("group/<id>", the name only a magpie answers to) comes back with the model its member's vendor named, and the Usage page's Requests and the Routing page marked that as the vendor serving another model. Now it is routed, not swapped (usage.GroupRouted): the try, the route and the ledger row say so, the served member shows plain, muted on the Usage page, with a title (and a line in the request's story) saying the remote magpie's group routed the request to it, in English and Chinese. Rows recorded before are judged again as the ledger lists them, and routes kept in the Routing page's history as they are read. A real swap through a remote magpie, and a swap within a group of this magpie's own, are still marked; a swap behind the remote's group shows on that magpie's own Routing page. Checked end to end with two sandbox magpies over a fake vendor: the local ledger and routing history mark group/… false (swapped before the change) and fake/sol served as luna true. TestRemoteMagpieGroupNotSwapped, TestRemoteMagpieGroupLedgerRow, TestRemoteMagpieGroupHistory and remote-group-served.test.cjs (Chromium, WebKit, en/zh) fail without the change. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (load flakes pass alone); routing-served, usage-ledger, panel-routing, remote-magpie, click-scroll, old-webkit pass. 2026-10-01 13:46:14 +08:00
yetone ffa55fc277 copilot: Auto — Copilot's own pick, the only choice a Student plan has — is listed for every Copilot account and works through magpie, as Copilot's clients do it (#256; Discord, CakeJskSUMM: Copilot Student can only use Auto) — Copilot's /models doesn't list Auto; its clients add it themselves (Copilot CLI 1.0.79: {id:"auto",name:"Auto"}, AUTO_MODEL_ID) and ask POST {api}/models/session with {"auto_mode":{"model_hints":["auto"]}} for a session_token, the selected_model and expires_at, each request then naming that model with the token in Copilot-Session-Token. magpie listed no Auto, failed an account whose list left nothing to pick by hand ("Copilot lists no chat model for this account"), and sent "auto" as a model. Now copilot_auto.go keeps the session per GitHub account, asked again two minutes before it expires; the gateway resolves Auto before choosing the API, so a picked model served only on /responses goes there; a body still naming "auto" (the model test) is rewritten; the endpoints of every model Copilot lists, hidden ones too, are kept for the picked one. A reply to "auto" from another model isn't counted as swapped (Cursor's auto too); the Copilot CLI's picker, which offers auto itself, leaves out the listed one. Tested with fakes in a sandbox HOME: provider/copilot_auto_test.go (a Student-like account whose models are all disabled lists [auto], the session body sent as above, requests carry the picked gpt-5-mini and the token, one session reused, renewed near expiry, an object-shaped selected_model, a refusal reported) and gateway/copilot_auto_test.go (a chat request for copilot/auto goes to /responses as gpt-5-mini with the token, two turns one session; fails without the gateway change); served_test gains the auto cases. go vet ./internal/..., go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. Not tried with a real Student account: what its /models returns, whether the plain session request suffices (Auto v2's /models/session/intent is not done), and the body is from VS Code's Copilot Chat, not captured traffic. 2026-09-30 10:17:15 +08:00
yetone 1e9f3a46cb usage: a Requests tab lists every request of the period, one row each, and exports them as CSV, from the window and from magpie usage --csv (Discord 范不着: a per-request ledger as sub2api keeps, to set beside the upstream's own bill) — the Usage page summed calls by agent and model, and the log did not keep the model the agent asked for or the one the reply said answered, so a single request could not be checked against a vendor's bill. usage.Record now keeps Requested (req, the model id the client sent, a magpie alias or group as it came) and Served (served, the model the vendor's reply named, only when it named one); every usage.Append in the gateway fills them (the relayed and translated paths, Codex's backend, image draws, decide), and records written before load as they did, without them. The swap test the Routing page uses (a dated or pinned name is the same model) moved to usage.Swapped so the ledger marks the same rows. usage.Ledger gives the period's records newest first with each one's list-price cost, the agent it is counted under and whether the model was swapped, filtered by agent, failures alone and a search over the models, provider, account, session and effort; usage.WriteCSV writes them (time, agent, requested_model, provider, host, model, served_model, swapped, effort, input, output, cache write, cache read and reasoning tokens, cost_usd, duration_ms, ttft_ms, status, error, session, kind). The Usage page gets a third tab, Requests (请求), between Overview and Sessions, under the same period picker: an agent filter, All/Failed, a search field and Export CSV over a table of time, agent, requested model, provider · account, model sent, served model (amber with the Routing page's sentence when another model answered, plain on a dated name, a dash when the reply named none), effort, in, out, cache write, cache read, cost, duration and status, a failure's row marked by a red dot and bold code; the totals over it and 100 rows a page with Newer and Older. GET /api/usage/requests serves a page, POST /api/usage/requests/export saves all the filtered rows to Downloads (never over an earlier file) and opens the folder, GET /api/usage/requests.csv hands a browser the file in magpie web. The table scrolls sideways in its own box; at the window's narrowest the words after the head's cost give way so the three tabs fit without the page scrolling sideways. No border stripe; clicks move nothing (the pager held where it was). en and zh strings together. Tested with TestLedger (order, cost, swap, a dated name, an old record without the fields, each filter, the CSV exactly), TestServedModelRecorded and TestServedModelUnnamed (a request through a fake upstream answering with another model records Requested fake/sol, Model sol and the served name; one naming none leaves Served empty), TestUsageCSV (magpie usage --csv, a period, a stray argument refused), TestUsageLedgerRoutes (paging, totals, filters, export to Downloads twice) and a new internal/gui/tests/usage-ledger.test.cjs in Chromium and WebKit, en and zh, light and dark: the tabs and columns, the swap tag on the swapped row only, the 429 row, Older and Newer over 130 requests with the pager left where it was, the agent, Failed, search and period filters asking the server from the first page, Export CSV posting the filters with no page and saying where the file went, at 560 wide no tab scrolling the page sideways and the cost uncut, no left border. go build -tags nogui (and GOOS=linux, GOOS=windows), go test -tags nogui ./... and the whole GUI suite (122 tests) pass. Not tried in the real window through Wails or against a live gateway's log. 2026-09-29 21:26:01 +08:00