1ccacad63281094de8a3372d5a507d38f9969e5c
12
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
8de63c8b5a |
gateway, usage, gui, otlp: a request its agent canceled is no failure (#2398)
An agent that cancels its request before it is answered is logged 499 "the agent canceled the request": a person stops the reply, or sends the next message while it is coming and Claude Desktop cancels it and asks again, or Codex takes a subagent's report (#2398). The gateway already says nobody failed (no rest, no reroute: TestCanceledRequestRestsNobody), but Record.Failed is a status >= 400 or an error, so every page counted it as a failure: the Requests card's "N failed" and success share, its Failed filter, the CSV's error column, the Routing page's "errors your agent saw", the Context page's error rate, the failed colour in the Requests list, Routing and Recent calls, and the OTLP export's error status. A Claude Desktop session on 2026-10-27 had four, each a message sent mid-reply; #2398 had 91 of a day's 92 failures. usage.CanceledBy tells the agent's cancel (499 with AgentCanceled) from magpie's own limit on a request it asked of itself, logged 499 too and still a failure (#2318). The cancel is logged with an error type of its own, agent_canceled (usage.CanceledErrType, set in failedWith), so the record says what it was and nothing guesses it from a 499, as #2398 asked. Record.Canceled reads the type, and a record logged before it by its status and message, so the old log reads the same with nothing migrated. A middleware's usage rows carry the type, so a module can tell the cancel from magpie's own limit, which its rows (no error text) couldn't. Record.Failed leaves the cancel out; Totals counts it apart (Canceled, in count and plus); RetriedRequest and the first-token and speed sums ask Answered, so a canceled request is timed nowhere, as before; Codex's memory of the last model still skips it. Routes and Recent calls say canceled (set as a route is done and as a day's history is read, so old days read the same); the Routing totals and the Context page's errors leave it out. Ledger rows say canceled, and the pages show it muted, in neither the failed nor the answered colour: the Requests list and its detail ("499 · canceled"), the Requests card ("N canceled", the success share of the requests not canceled), the overview tile, the Routing page (a "gone" outcome, no speed) and Recent calls (muted). New strings are in zh, zh-TW, ja and de. The OTLP export: the records the gateway gives its observers for a request and its try carry the type too (canceledAs), and a root span's error.type follows Record.Failed, so a canceled request's span and its try's go with status code 499, no error and no error.type. TestOTelWaterfallFailureAndCancellation's canceled case held two failed spans (the try the vendor refused as the agent left is recorded canceled, as the request is); it now holds neither failed, both 499 and no error.type. That change to the test is the point of this one. mdwsk88's patch (aea0027fd) ran its tests at |
||
|
|
a10ad0ec8e |
routing: a Codex memory call put on its conversation's model says why (#5413)
The Routing page read every Codex memory move as codex-turn: "asked for
{model} ..., which magpie doesn't serve". The #4765 branch of
codexMemoryStandIn moves a bare Codex default that magpie does serve
(a provider has a model by the same name) when Codex's config names no
memory model, so that sentence was wrong for it. That branch now
records codex-follow, said as "{agent} asked for {model}, one of its
own default models, for its memories, and its config names no model
for them; magpie served it on {to}, the model of its conversation.",
in en, zh, zh-TW, ja and de. Models magpie doesn't serve stay
codex-turn.
Run (mote): go test ./internal/gateway -run
'TestCodexMemory|TestCodexSide|TestCodexMemories|TestCodex.*Follow'
-count=1: ok. node --test routing-moved-why (chromium + webkit, every
language, 1100 and 420px), i18n-keys, i18n-en-no-cjk: 27 of 28; the red
is i18n-keys "a plugin's words are its own", red the same at
origin/main
|
||
|
|
73324357ed |
gateway: a Codex memory call on a provider/model id keeps it (#5413)
Codex's memories.extract_model and consolidation_model, set to remote-magpie/sub2api/gpt-6.1-terra on the user's computer, reached the Remote magpie as sub2api/gpt-6.1-terra, which it serves. The branch of codexMemoryStandIn added for #4765 (a bare Codex default that a provider happens to serve under the same name) moved any memory call that resolves onto the conversation's model unless CodexSideSet saw [memories] set, and the remote has no Codex config to read (GetTOMLTable's absent file reads as "nothing set"). So the user's pick went to sub2api/gpt-6.1-sol, recorded as codex-turn. A "provider/model" id is never one of Codex's defaults, which are bare, so it is the user's pick and goes as it came, as codexFollowTo (the ChatGPT backend's path) already does. The same holds locally for a Codex on a profile or a CODEX_HOME of its own, whose config magpie doesn't read. A bare name that resolves still follows the conversation when the config here names no memory model (#4765 unchanged). Run (mote): go test ./internal/gateway -run 'TestCodexMemory|TestCodexSide|TestCodexMemories' -count=1: ok. Broken by hand: with the "/" check taken out, TestCodexMemoryOnAQualifiedModelKeepsIt fails with "memory_consolidation moved to "third/gpt-6-astra" (codex-turn)", the reporter's move. Not tried: a real Local -> Remote magpie pair with Sub2API; a bare memory model named in the config of a Codex on another computer still can't be seen by the remote. Reported-by: MariaMatrix (GitHub) Reported-by: mahiro233 (Discord) |
||
|
|
1493acb468 |
gui: Codex's memories default reads right on Codex 0.167.0 and before
Codex 0.167.0 (openai/codex#58091) moved its default memory models:
extraction from gpt-5.6-luna to gpt-6-luna, consolidation from
gpt-5.6-terra to gpt-6.1-terra. The memories square's unset text and the
Settings row's tooltip named the old pair. They now say "Codex's own
memory models", true on either version, in en, zh, zh-TW, ja and de.
The code comments (agent/codex.go, gateway/codex_memory.go,
gateway/codex_follow.go, the tests' headers) name both pairs with the
Codex version that uses them. No behaviour changes: magpie routes these
calls by kind (memgen, memory_consolidation), not by the model name.
Run on mote at the pre-rebase base
|
||
|
|
6de04a26e2 |
gateway: a Codex memory call on its own bare name follows the session when a provider serves a model under that name too (#4765)
raphael-y7: with magpie as Codex's model provider, the conversation on orbis/gpt-6.1-sol, Codex's memory consolidation — its own background request on its own default consolidation model, asked by its bare name gpt-5.6-terra — went to workbuddy-ai, the only provider of magpie's with a model under that name, and the account it landed on refused it: 400 "model [gpt-5.6-terra] is not allowed for user type [personal_free_user]", three tries, 8.5s, and the memory was never written. The bare name resolved, so codexMemoryStandIn (#742) left the call where it stood; a model of Codex's own asked by its bare name is not a pick of whichever provider has one under that name. Now a memory call whose bare name resolves still follows the conversation's model, as it does on the ChatGPT backend's path (codexFollowTo), when Codex's config names no model for its memories: codexMemoryStandIn asks codexMemorySession first and only falls through to the name's own resolution when there is none to follow. What keeps going as the name resolves: any other call, a model Codex's config names (the user's own pick, a full id or a bare name), a config magpie can't read, and a conversation magpie has no model of (on Codex's own, or nothing answered yet). What this doesn't change: the three tries on a capability refusal, and the model catalog's exposure of a model an account can't serve — the reporter's other two suggestions, both a bigger cut; the auto-review's codex-auto-review and the app's title, description and summary calls, whose as-Codex-sent default is deliberate (codexTitlesTo, codexSideTo; shruru counts a provider serving a luna-named model picking titles up as a feature, #4590). TestCodexMemoryOnACollidingBareNameFollowsTheSession: a provider with a model under gpt-5.6-terra, the conversation on another provider's — the memory call followed the conversation and the named provider got nothing (red before: it got the memory); the config's pick and a plain turn on the name still go to it. Run (darwin arm64, -tags nogui): - go test -tags nogui -run 'TestCodexMemoryOnACollidingBareNameFollowsTheSession|TestCodexMemoryCallsGoWhereItsTurnsGo|TestCodexMemoryStandInFollowsTheSwitch|TestCodexMemoriesFollowTheSession|TestCodexSideCallsKeepTheConfigsModel|TestCodexSideCallsBeforeTheFirstTurnFollowTheSwitch|TestCodexOwnModelOnMagpieThreadGoesOnSignIn' ./internal/gateway: ok (the new test was red before the fix, with the report's routing) Generated-by: GLM-5.3-Flash (ZCode) |
||
|
|
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
|
||
|
|
b7d5a97fec |
gateway: Codex's memories after a model switch wait for the new turn, as titles do
cybercaius (Discord) asked whether Codex's side calls (title, thread description, composer prediction, memory consolidation, auto-review) still go to the model the conversation was switched away from, and whether the first of each after a switch follows it as the title does since |
||
|
|
6e96903346 |
codex: auto-review follows the session on a ChatGPT Free plan (cybercaius)
cybercaius on Discord measured codex-auto-review spending a Free
account's allowance ("实测在 free 账号不免费"). magpie left an unset
auto-review to Codex (codex-auto-review), and held such a call by no
usage cap, on #1593's finding that OpenAI counts it in no window; that
was measured on a paid account.
Decision: with nothing picked and Codex signed in to a Free plan (the
ID token's chatgpt_plan_type is "free"), auto-review counts as "Same as
the session", as Codex's other side calls do, so the review stops
spending the free allowance when the session is on one of magpie's
models. On Codex's own model nothing changes (its entries keep OpenAI's
reviewer). A paid plan, or a plan magpie can't read, keeps Codex's pick;
a pick in Settings always wins.
- codexcat.AutoReviewModel is the setting in effect; the plan comes from
provider.CodexSignInPlan (liveLogin, keychain read cached), read once
per model list, and the list tag already re-stamps on auth.json.
- freeOnChatGPT no longer exempts a Free plan's codex-auto-review call
from usage caps (capHeld).
- GUI tooltip says it (en, zh, zh-TW, ja, de); docs updated.
Run at the pushed tree (on origin/main
|
||
|
|
d4c2512d2d |
usage: apps report their own calls with POST /v1/magpie/usage/requests, backfill included (#1874)
What changed
- POST /v1/magpie/usage/requests (internal/gateway/usage_ingest.go) takes
one record or an array, in usage.jsonl's shape:
- the post may carry up to 5000 records and 32 MiB;
- t, agent, provider, model and rid are required.
Each field is checked: unknown fields, quoted numbers, negative or absurd
counts, a status outside 100-599, a cost over 10000 USD, and a t more
than an hour ahead or before 2000-01-01T00:00:00Z. Any fault refuses the
whole post with a 400 that names error.index and error.param, and nothing
is written. A past t is otherwise taken as given, so history can be
backfilled. The reply gives accepted and skipped counts and each
record's index, rid and status.
- Access: lanGuard's rule (this machine, or another with a key while
shared, behind the Host check). A browser page also needs a key, since
corsGuard lets localhost pages and Origin null through. A held key is
refused.
- usage.IngestReported writes under usage.mu to the same file as
usage.Append. Rows carry source "reported" and no caller key. A rid
already reported is skipped, as is one repeated in the post. The set of
reported rids is read back from the log: one scan after a restart (lines
without the reported mark aren't parsed), then only what was appended.
- Pricing: a record with cost keeps it (Record.OwnCost, the rowOwnCost
flag; packed flags widened to uint16). Otherwise it is priced at
magpie's prices.
- Display:
- SourceReported is a source of its own: RequestPage.Reported,
?via=reported, and Ledger now honours via.
- The Requests tab gains a fourth cell "reported by apps", shown once
there are some, and a "Reported" badge (en, zh, zh-TW, ja, de).
- Nothing live: Record.IsReported keeps reported rows out of:
- a key's budget/spend limit (budget.counts);
- window holds, and the log start that decides whether a window can be
reckoned (logSnapshot.firstOwn);
- gateway sessions and Vias;
- Codex's sealed answers and remembered model.
There is no OTel span, rate limit, rest or alert for them.
- Docs: gateway-sessions.md, reference.md (with a curl), integrating.md,
site integrate.html (en, zh).
Why: the reporter's apps call vendors directly, and their usage (and
history) should show on the Usage page without becoming live traffic.
Run, in a worktree with sandbox HOME and a private GOCACHE
- gofmt -l: clean.
- go vet ./...: darwin, GOOS=linux -tags nogui, and GOOS=windows.
- go test internal/usage, usageapi, budget, gateway, gui: ok.
- -race -count=3 of the new usage/gateway tests: ok.
- GUI with playwright 1.62.0:
- usage-ledger-reported.test.cjs, 26/26 in chromium and webkit (5
languages, 1180 and 420 wide, light and dark);
- usage-ledger*.test.cjs, ledger-*.test.cjs, usage-sum-whole,
usage-unpriced-sum and i18n-keys: all pass.
- Timings with 200k reported rows (47 MB log, darwin):
- 40 posts of 5000 took 0.40 s (worst batch 18 ms);
- the first post after a restart took 0.45 s (rid rescan), a later one
1.6 ms;
- the cold index build took 2.1 s (as for gateway rows);
- page all took 27 ms warm, page 30d 39 ms, all via=reported 0.53 s;
- summary all took 215 ms, 30d 20 ms.
Broken by hand, each went red, then restored
- Go: dedupe against stored rids; the restart scan; CostAt ignoring own
cost; the block pricer overwriting own cost; the Reported split;
fromBrowser's key rule; skipping bad records instead of refusing; the
max-records and body limits; the ingest lock (race); both locks;
firstOwn -> first; the IsReported guards in windowHolds,
buildGatewaySessions, buildVias, budget.counts and loggedAnswers.
- GUI: the fourth cell, the --vias column count and the badge class.
Not shown red on its own: the remote-no-key and evil.example refusals come
from lanGuard and corsGuard before the handler, so breaking only the
handler's own check stays green. The codex_memory guard is not tested
alone: a reported row has no Requested there anyway. Not tried: a real
client against a live gateway, Windows/Linux runs of the tests, the full
GUI suite.
|
||
|
|
0e89b090c1 |
gateway: Codex's auto-review on codex-auto-review goes through a ChatGPT account past its usage cap, since OpenAI made it free (#1593, hywang1230)
An account past the usage cap set on it in magpie was held for every
model, so Codex's auto-review on codex-auto-review was refused with
"usage cap reached" once the account reached its cap. OpenAI made
Auto-review free for every ChatGPT sign-in on 2026-10-06: the reviewer's
calls are counted in no usage window, so the cap, which keeps a share of
a window unspent, has nothing to keep for them.
capHeld now leaves the user's caps out for a Codex (ChatGPT) account's
call on codex-auto-review (freeOnChatGPT). Credits set not to be spent
still hold it at 100% of a window, as nothing says the backend answers it
there. A review run on another model, or any other model, is held as
before.
Verified:
- TestAccountCapLetsAutoReviewThrough: an account at 92% with a 90% cap
takes codex-auto-review on Codex's backend path and as
codex/codex-auto-review, and still refuses gpt-5.5 on both. With the
exemption disabled it fails with the reporter's exact 429 ("usage cap
reached: every account that serves "codex/codex-auto-review" ...").
- go test -run 'TestAccountCap|TestCodexNoCredits|TestWindowCaps'
./internal/gateway, gofmt -l, GOOS=linux/windows go vet -tags nogui.
- Not tried against the real ChatGPT backend with a capped account.
|
||
|
|
f1fc8c65d3 |
gateway: Codex's auto-review reaches a model when its config names a group bare or Codex is on magpie through another provider table, instead of 404 "magpie knows no model codex-auto-review" (Adam on Discord)
Codex asks for its approval review on codex-auto-review whenever its model
list has that name or a model's entry names it as auto_review_model_override
(as a ChatGPT account's entries do). magpie stood that in with
config.toml's `model` (agent.StandIn,
|
||
|
|
987ce3d1b0 | codex: a memory call on a model of Codex's own goes where Codex's turns go, rather than a 404 (#742, congee949) — Codex writes and consolidates its memories on models of its own by their bare names (memories.extract_model and consolidation_model, gpt-5.6-luna and gpt-5.6-terra by default) whatever it is set to, so with magpie as its provider every memory_consolidation call was turned away as "magpie knows no model" before it was routed (28 in a week in the report, from Codex on two other computers with their own gateway keys, where the stand-in read from this computer's ~/.codex/config.toml can't reach). A Codex memory call (memory_consolidation, memgen, memory) on a model magpie can't resolve now goes to the model the same Codex (the agent and the gateway key it came with) last had a turn of its own answered on here, else the last such turn in the ledger a week back (so after a restart too), and is routed and recorded as the memory call it is. Any other call on an unknown model, and a memory call from a Codex with no turn answered, is turned away as before. Base instructions are untouched. TestCodexMemoryCallsGoWhereItsTurnsGo (terra and luna after a turn, after a restart from the ledger, unknown turn and review still 404) fails on the old code. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass. |