With Codex signed in to ChatGPT, Codex asks magpie's /backend-api/codex/models
for its list, and codexModels passes the backend's own models through,
narrowed only by the codex provider's picks (CodexNativePicked) and the
Agents page's hides (CodexNativeHidden, built from Catalog()). A provider
set to "Only through routing groups" (Provider.Unlisted) has none of its
models in Catalog(), so neither filter saw them: all of the account's
models stayed in Codex's picker, and the Agents page had no Codex group to
hide. Every other agent's list is Catalog-based and already left them out.
provider.CodexNativeUnlisted says which of the account's models are kept
out of agents' lists: every one when the codex provider is Unlisted, and by
slug those a group with Unlists names. codexModels drops them (hidden
entries such as codex-auto-review stay, as with picks; a Codex reached for
failover alone keeps them, as it is handed no groups), spawnChoices drops
the same ones from spawn_agent's list, and CodexListTag carries them so
Codex refetches. gateway-routing.md says so.
Test: TestCodexModelListUnlistedForGroups (a group unlisting gpt-5.5 takes
gpt-5.5 alone; the provider Unlisted takes gpt-6-sol and gpt-5.5 and keeps
codex-auto-review; ETag changes; spawn_agent offers neither; own-only keeps
them). With codex_backend.go and codex_spawn_models.go reverted it fails on
all three checks. Not tried with a real ChatGPT sign-in and Codex app.
Run (sandbox HOME, private GOCACHE, worktree at origin/main 97dfed0f3):
gofmt -l; go vet ./... (darwin), GOOS=linux -tags nogui, GOOS=windows;
go build for all three; go test -tags nogui ./internal/gateway
./internal/provider ./internal/catalog ./internal/codexcat: all ok.
10086gg reported that Codex's auto-review through magpie almost never
used codex-auto-review. It ran on the conversation's own model at low
effort, which costs more.
Cause: codexModels narrows the ChatGPT backend's list to the models the
user picked on the codex provider (CodexNativePicked). Hidden entries
(visibility "hide") never reach magpie's catalog (parseCodexModels), so
no one can pick them, and the narrowing always dropped them.
codex-auto-review is one of those hidden entries. Codex 0.162 picks the
reviewer this way (codex-rs/ext/guardian-reviewer/src/model.rs,
select_review_model):
1. the entry's auto_review_model_override;
2. else codex-auto-review, if the list has it;
3. else the conversation's model, at low effort.
So once the list was narrowed, every review fell to step 3. On a relay
model it was charged to the relay; on a ChatGPT model it ran on that
model. OpenCodex had the same bug: lidge-jun/opencodex#6712 recorded
direct ChatGPT login as codex-auto-review/low and their proxy as Sol/low.
Fix: the narrowing keeps hidden entries. No picker shows them, so the
user's picks still decide what Codex's /model lists. A user who wants
reviews on a relay model can still set Codex's auto-review model
(#938), and that setting still wins (step 1).
Which account pays changes for a user with picks whose conversation
runs on a relay model: auto-review moves from the relay to the ChatGPT
account's codex-auto-review. That is what Codex does without magpie.
OpenAI's help article "Using Codex with your ChatGPT plan" says:
"When you're signed in with a ChatGPT account, auto-review safety
checks are free and don't count toward your plan's usage limits."
New test TestCodexModelListPicksKeepHidden. It fails on the old code:
after the picks only gpt-6-sol is listed, with no codex-auto-review.
docs/subsystems/gateway-routing.md says this.
Run:
- gofmt -l internal/gateway
- go vet -tags nogui ./internal/gateway, on darwin, linux and windows
- go test -tags nogui ./... with a temp HOME and pinned caches: green
Not run: a real Codex signed in to ChatGPT through the gateway. The
reviewer choice was read from the Codex source.
With several ChatGPT accounts on, failover writes openai_base_url into
~/.codex/config.toml so a turn the signed-in account can't pay for goes on
to the next account. With Codex's switch off, the row said only "not
connected", but every request still went through the gateway, and the
gateway's /backend-api/codex/models answer added all of magpie's models
(62 for the reporter).
- agent: Agent.FailingOver means not wired, while the stash's codex.failover
(or a CC Switch mirror's codex.mirror_failover) base URL points at magpie.
FailoverSaid is the line the CLI list and the TUI show. CodexOwnOnly is
true for this machine's Codex when it is failing over and no WSL Codex is
connected, since a WSL Codex shares the gateway path. Sync ages a
models_cache.json that isn't tagged with the own-only list.
- gateway: codexModels leaves out provider.CodexListed when
gateway.CodexOwnOnly (set by main to agent.CodexOwnOnly) says so. The
ETag and X-Models-Etag carry provider.CodexOwnListTag. Neither tag
contains the other, so Codex fetches the list again when it is connected
or disconnected.
- gui: /api/state carries failover. The row says "Not connected · goes
through magpie only to fail over to your other ChatGPT accounts". Its
title says what turns it off. A "ChatGPT accounts" button opens
Providers › Codex. Strings are in zh, zh-TW, ja and de. openProvider no
longer draws the Providers list before it has loaded. It was only safe
once the tab had been opened, and this is its first caller from another
page.
- docs: agent-wiring and gateway-routing describe the failover-only Codex
and list the new tests.
A user's hand-written openai_base_url (#856) isn't failover's, so it stays a
plain not-connected row.
Verified:
- TestCodexFailoverOnlyKeepsOwnModels (agent) builds the reporter's state in
a temp HOME: Codex signed in, two more ChatGPT logins on, Sync, so the
stash has codex.failover=1 and no joined/beside. It checks that the row is
not wired and is FailingOver, that FailoverSaid names Providers › Codex,
and that the real gateway handler's /backend-api/codex/models lists only
the backend's gpt-5.5. It also checks that the cached full list is aged,
and that after Join magpie's fake/m1 is back.
- TestCodexModelListOwnOnlyForFailover (gateway) checks the list and both
ETags with the hook on and off.
- agent-failover.test.cjs checks the row text, title and button in en, zh,
zh-TW, ja and de, at 980px and 420px, in Chromium and WebKit (20 pass).
It also checks that the button opens Codex's editor, that the page
doesn't scroll sideways, and that no click moves it.
- Broken by hand, each test goes red:
- codexModels ignoring the hook fails both Go tests.
- failingOver returning false fails the agent test.
- dropping the Sync cache case fails the agent test.
- removing the GUI branch fails the GUI test.
- drawing the list before it has loaded (the old openProvider) fails the
GUI test.
- go test -tags nogui ./internal/agent ./internal/gateway ./internal/provider
./internal/gui ./internal/tui ./internal/codexcat . in a temp HOME: all ok.
- node --test agent-*.test.cjs (254 pass) and i18n-keys, gui-ja, gui-de,
click-scroll: all pass.
- gofmt -l is clean.
- go vet -tags nogui on darwin, linux and windows: clean.
- go build, and GOOS=windows go build: ok.
* feat(routing): group requests by session with names and estimated costs
* fix(routing): address session view review feedback
Preserve Luna Reserve and other header fallbacks for ordinary Codex turn metadata; reuse metadata and the kind across trace and native accounting. Default to By request and persist the grouping choice. Store only token accounting fields in route history while retaining legacy JSON compatibility.
Add regressions for helper precedence, native kind accounting, history compatibility and grouping preferences.
* 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>