Commit Graph
6 Commits
Author SHA1 Message Date
yetone 247794c613 codex: an account that is out takes over for other models too (reverses f37742e14)
With one ChatGPT account out and nothing to serve Codex's own model on
(provider.CodexServesWhileOut false), f37742e14 left Codex on its sign-in
to keep the account's menu. But the Codex app greys Send for every model
while authMethod is chatgpt and /wham/usage says not allowed, so shamen
(mac, banner "Codex 和工作使用额度已用完"), chenhan and xiaoq6285 could send
nothing on GLM-5.3 or any other magpie model. A grey Send for every model
costs more than the menu, so this is the owner's product call: sending on
other models comes first.

When joined, on ChatGPT and held, and magpie has a model on no ChatGPT
account (codexOtherModel), Sync makes magpie the provider on that
stand-in, keeps the user's model in codex.out_own and the stand-in in
codex.out_stand, and at the reset puts Codex back joined on its own model
(#540 way back). Once per held/unheld transition: on the stand-in the model
is magpie's, so the branch is not met again. With nothing else to offer,
Codex stays on its sign-in as in f37742e14. Nothing about identity,
base_instructions or the account's state is changed or faked; magpie only
becomes the provider, as for any held account.

Run (mote-run, win-run, sandbox HOME, fake upstream; no real exhausted
account was tried):
- go test -tags nogui ./internal/agent -run Codex: ok; ./internal/provider
  -run CodexServes: ok; win-run ./internal/agent: see the tag notes.
- gofmt -l, go vet linux/windows/native on internal/agent: clean.
- New TestCodexOwnModelOneSpentAccountTakenOverForOtherModels: takeover,
  three more Syncs with no config write and no codexAppRoute change, the
  reset back once, a further Sync changing nothing. TestCodexOwnModel-
  OneSpentAccountStaysOnItsSignIn now covers only the nothing-else case
  (fake provider deleted).
- Broken by hand: new branch disabled -> the new test red; the
  !isMagpie(m) one-shot guard removed -> red.
Not tried: a real exhausted account in the Codex app; the stand-in picked
by the user is indistinguishable from staying on it and gives way to the
own model at the reset (documented in agent-wiring.md).
2026-11-04 10:05:32 +08:00
yetone f37742e14d agent: a used-up ChatGPT account magpie can't serve past leaves the Codex app on its sign-in (xiaoq6285)
xiaoq6285 on Discord (magpie 0.1.2798, the Windows Codex app, one
ChatGPT Plus account, Codex on its own model joined beside the sign-in):
at the five-hour limit the app showed an error and had to be restarted,
then its account menu showed only "magpie" with no quota; at the reset
it restarted by itself and the account came back.

Cause. When the active account was held (used up, no credits), Sync's
own-model takeover made magpie Codex's provider on codex/<model>
whenever magpie's catalog listed that model on any Codex account -- the
same used-up one included. With one account and no fallback every turn
it took over is refused on that account anyway, while the takeover:
- has account/read answer no account, so the menu drops the user, Plus
  and the usage meter until the reset;
- changes the route twice (into it, back at the reset), and
  KeepCodexAppOnItsProvider ends the app's app-server each time, which
  ChatGPT desktop 26.1027.x shows as "ChatGPT 遇到了问题" and relaunches
  (#4550, still open, the app's own reaction to an ended app-server).
Separately, magpie's [model_providers.magpie] requires_openai_auth
follows the account out and back (openaiAuth), and codexAppRoute
counted it even when that table was not Codex's model_provider, so
staying beside the sign-in would still have ended the app-server at
the limit and at the reset.

Change.
- provider.CodexServesWhileOut(model): the Codex subscription has
  fallbacks for codex/<model> (FallbackModels), or another ChatGPT
  account is not known held and not lapsed.
- Sync's own-model takeover runs only when that holds. Otherwise Codex
  stays on its sign-in: the app keeps the account, its quota and reset,
  and shows its own limit message. With a fallback set it moves as
  before (affa979d5 serves the fallback through the gateway too).
- codexAppRoute counts magpie.requires_openai_auth only while
  model_provider is magpie; the table is still written as before.
- docs/subsystems/agent-wiring.md says both.

Tests.
- TestCodexOwnModelOneSpentAccountStaysOnItsSignIn (new): one account,
  no fallback, held: config stays on the sign-in, codexAppRoute and
  AppOut unchanged across two Syncs and the reset.
- TestCodexServesWhileOut (new): one account none; another not known
  out yes; every account out none; a codex fallback yes.
- TestCodexOwnModelGoesThroughMagpieWhileUsedUp and
  TestCodexOwnModelOutThenKeptOnChatGPT now set a codex fallback, the
  case where the takeover still serves something.

Broken by hand: the CodexServesWhileOut gate taken out -> the new agent
test red (Codex moved to model_provider = "magpie", codex/gpt-a);
codexAppRoute counting requires_openai_auth always -> red (route
changed with model_provider empty). Each put back, green.

Run on mote at this head (rebased on e41ef6288), -tags nogui -timeout 45m:
- internal/agent ok (381s), internal/provider ok (254s);
- internal/cli FAIL in TestEveryRouteHasACommandOrIsNamed alone: GET
  /api/context/reply has no command, from 0872bc2a0, filed as #5026,
  nothing of this change;
- gofmt -l clean; go vet of both packages, GOOS=linux go vet -tags
  nogui ./... and GOOS=windows go vet ./... ok.
- internal/gateway ok (1152s) at the earlier base 3088872e6, not run
  again after the rebase (it imports provider; this change adds a
  function there and changes nothing it calls).

Not tried: the real Windows Codex app signed in to a used-up Plus
account (the Windows box's app is not signed in; #4550's crash was not
reproduced there); a real codex app-server against a fake 429 upstream.
Users with a fallback or a second account still get the takeover and
its two app-server restarts, which #4550 tracks.
2026-11-03 15:46:42 +08:00
yetone c544789047 agent, gui: the Codex takeover names browser use and offers Keep on ChatGPT
eddie.zhan on Discord (10-27): once Codex's allowance ran out, magpie
took it over and "many features stop working, browser use is blocked,
the agent says it has no permission".

Cause, from openai/codex 5a361b5: under the takeover magpie is Codex's
model provider without requires_openai_auth, so app-server's
getAuthStatus hands the app no auth token. The Codex app's Chrome
control needs that token, so browser use is off till the reset, with
cloud tasks, the usage meter and Log out. Image generation (actor
authorization header) and web search (provider default) stay. Bringing
requires_openai_auth back would bring back the greyed Send the takeover
exists to avoid, so it can't be kept by config.

The off switch existed (sign-in > Always ChatGPT, `magpie codex login
chatgpt`) but nothing under the takeover pointed to it. The default is
kept; the opened Codex row's takeover note now names browser use and has
a Keep on ChatGPT button (login=chatgpt) on its own line. In every
language.

Also fixed: Always ChatGPT picked while Codex was taken over on one of
its own models left model_provider = "magpie" for good. set now puts it
back on the sign-in as Join leaves it.

Run (on mote, at this tree):
- go test ./internal/agent ./internal/gui: ok except
  TestWSLColdPlaceOpensNothing (#3924) and TestMainWindowCorners/macOS_26
  (#2645), both red on origin/main f2b4b9894 too.
- TestCoreScriptBudget ok; app.js 1,310,432 under 1,310,460, not raised.
- GUI codex-app-out, codex-signin-always, i18n-keys in chromium and
  webkit at 980 and 440, every language: 95 pass, 1 red is #3897
  (i18n-keys plugin words, red on main).
- gofmt -l clean; go vet darwin, linux (nogui), windows on internal/agent
  and internal/gui.
Broken by hand: TestCodexOwnModelOutThenKeptOnChatGPT red on the old
set (model_provider = "magpie" left); codex-app-out red with origin's
app.js/i18n.js (no browser use in the note).
Not tried: the real Codex app, a real used-up account, the Windows box
and the Linux app.
2026-10-28 03:36:13 +08:00
yetone ef37b6fb76 gateway: an exhausted ChatGPT account no longer greys Codex app's Send while magpie can serve the turn (MasterYi on Discord)
MasterYi (#help, 1563467829687222343): with magpie wired into the Codex
app, a used-up ChatGPT account greys the Send button, so the third-party
models joined in Codex's picker can't be used either.

Cause, as far as the app's bundled code (ChatGPT.app 26.1013.40934,
read-only) shows: Send is gated in the app itself. It needs
authMethod == "chatgpt", the /wham/usage reading (fetched by the app
straight from chatgpt.com, not through magpie) saying not allowed, and
no credits. authMethod is read as the app opens or on account/updated,
which the app-server sends only on login/logout, not on a config change.
So the gate lifts only when model_provider is magpie AND the app has been
opened again. #540 already made magpie the provider while out, but only
when a magpie model was the default; on one of Codex's own models
(joined), nothing changed.

What changed:
- A (agent/codex.go Sync): joined on one of Codex's own models and the
  account out (not Always ChatGPT, not magpie API), magpie becomes the
  provider on that model as magpie serves it (codex/<model>), the model
  kept in codex.out_own. Once the account has room, Codex is put back
  joined on that model. A model picked meanwhile stays the user's. With
  no ChatGPT account in magpie to serve it, nothing changes. New
  Agent.AppOut says magpie is the provider for a used-up sign-in.
- C (provider/codex_app_out.go): a usage_limit_reached rest on the
  active Codex account (gateway routing) or an x-codex-* window heard at
  100% (NoteCodexLimits) has the account read again at once
  (CodexMayBeUsedUp: active account only, at most every 20s, only
  while a KeepOnAnAccountWithRoom loop has made its first reading and
  still runs), not only on the 5-minute look. A first cut turned this
  on for good as the loop started; every gateway test's Serve starts
  it, so later gateway tests had accounts read again behind them, and
  TestCodexOwnModelMovesToNextAccount and
  TestCodexSpentMovesToNextGroupMember went red in the package run
  (green alone 3 of 3). Now a counter, up after the first minute's
  reading, down as the loop ends; the package run is green with it.
- B (gui/codex_app_out.go): the app open when the account ran out is kept
  by its app-server's pid (provider.CodexAppOut; a new pid means it
  reopened and read the provider, standing in for "authMethod is still
  chatgpt"). On macOS, every 10s, magpie reopens it through the Agents
  row's ReopenCodexApp when: AppOut, the account still out, the app is a
  copy from before the config change, no turn in flight through the
  gateway and none ended in the last 30s. At most once per time the
  account runs out, success or not.
  Drafts: the app's code keeps composer drafts in a persisted store
  (composer-prompt-drafts-v2, 250ms debounce, flushed on quit), and
  threads are server-side, so an unsent draft and open threads should
  survive the quit. Not watched in a real app.
- D (GUI): Codex's accounts say "The Codex app can't send on {user}'s
  used-up account": on macOS that magpie reopens it once no turn runs;
  off macOS (no reopen path) or once tried, to quit and reopen it.
  en, zh, zh-TW, ja, de.

Tests (each red on the code without its part, broken by hand):
- TestCodexOwnModelGoesThroughMagpieWhileUsedUp: red at "used up" with
  the out case off, at "allowance back" with the restore off.
  TestCodexOwnModelKeptOnChatGPT: Always ChatGPT stays.
- TestCodexMayBeUsedUpReadsAtOnce: red at "a window full: not read"
  with the NoteCodexLimits hook off. TestCodexAppOutEpisode.
- TestCodexUsedUpReplyAsksAtOnce (gateway): red, asked [], with the
  routing hook off.
- TestCodexAppOutReopenedOnce (gui, reopen stubbed): red at "a turn in
  flight" with the idle check off, and at "again" with the once checks
  off.
- codex-app-out.test.cjs: 40 of 40 (chromium, webkit; 900/480; five
  languages; both texts); 2 of 2 red with the notice's call site off.

What was run, at this tree:
- gofmt -l: none. go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: exit 0.
- go test -tags nogui -timeout 45m: internal/agent ok (414s, before a
  comment-only reorder in Sync); internal/gateway ok (534s),
  internal/gui ok (78s), internal/provider ok (137s), after the
  live-check fix, at this tree before the previous commit's JS-only
  move (then with a budget raise since taken back); internal/gui
  again after the move.
- GUI (chromium, webkit), at this tree: codex-app-out, codex-app-stale,
  i18n-keys, gui-de, gui-ja, gui-zh-tw and the files reaching the
  previous commit's move: 164 of 164. Before the trim, every codex-*
  and account-* file: 447 of 448; the red, codex-predictions chromium
  ja 420 "picking a model scrolled the page", is #2624 and is red alone
  on origin/main 5a85a2a91 too (1 of 2); one codex-app-out case timed
  out launching chromium at load ~100 and passed on the rerun.
- TestCoreScriptBudget with the budgets unchanged: ok. The three Codex
  notices now share one box builder (codexNote), and the previous
  commit moved ledSaid out of app.js.

Not tried:
- No real Codex app was quit or reopened (the owner's live app is left
  alone); the reopen path is stubbed. Whether the reopened app's Send
  comes back, and whether a draft survives, is from reading its code.
- No real used-up account; the move was run in a sandbox HOME.
- The full suite: no suite lock on this machine, load ~75.
- A gateway served by another magpie process: the episode lives in the
  process that serves the gateway, so a GUI that doesn't serve it never
  reopens the app or shows the notice.
2026-10-24 17:38:50 +08:00
forever 7f45f45cb5 codex: a sign-in kept on ChatGPT when its account is used up (#981)
Codex's sign-in, ChatGPT, keeps Codex signed in to ChatGPT with magpie's
models beside its own, but once the ChatGPT account is used up magpie
makes itself Codex's provider (#540): the Codex app sends nothing at all
on an account it knows is out, a magpie model's turn included. That move
went unsaid, and a user who chose ChatGPT expected Codex to stay there.

ChatGPT now says it, and a third way, Always ChatGPT (login "chatgpt"),
never makes the move, by a pick or by Sync; choosing it puts a Codex moved
before back beside the sign-in. What it costs is said beside it: the Codex
app may send nothing till the account has room, while Codex CLI's turns
still reach magpie by the base URL, its routing and other accounts serving
them.
2026-10-06 13:31:16 +08:00
yetone 27f0e4ebdd codex: when the ChatGPT account runs out of its allowance after a magpie model was picked, magpie becomes Codex's provider, and goes back beside the sign-in when the allowance is back (#540: once the Codex 5-hour/weekly quota is used up, a third-party model through magpie sends nothing in new or old sessions; Dazzle-sys: the session was on the magpie model all along, the quota went elsewhere) — the Codex desktop app refuses to send for a ChatGPT account that is out of its allowance before any request is made, whichever model the turn is on, so a magpie model beside the sign-in (openai_base_url, ChatGPT mode) is blocked with it; Codex's open-source core and TUI only report a usage limit after a response, the block is the app's, keyed on the account. bd5bf422 made magpie the provider (model_provider = "magpie", model_catalog_json; the app-server's getAuthStatus then answers requires_openai_auth false, the app's API state) only when a model was picked while the account was already out, so an allowance running out later left Codex as it was. KeepOnAnAccountWithRoom now also looks, every 5 minutes, whether the active Codex account is out (CodexUsedUp, now read through LoginUsage's cache, fetched at most once a minute, as the agents' sync asks it on every catalog sync) and tells the agents' sync when that changes (noteCodexUsedUp → catalog.Touched); Codex's Sync then sets the magpie model again, which wires it as the provider while the account is out, marked codex.out in the stash, and puts it back beside the sign-in once the allowance is back, only where it was moved for that (a provider asked for with sign-in "api" stays). Threads started on Codex's own provider and reopened may still be held by the app; the Codex app may need a restart to take the new config. agent's TestMain stubs codexUsedUp so no test asks OpenAI. TestCodexRunsOutAfterPick (ChatGPT mode, then out: provider; out again: stays; back: beside the sign-in; api stays) fails without the change; TestNoteCodexUsedUp checks only a change is told. No request was made to OpenAI. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-02 16:48:26 +08:00