Commit Graph
2 Commits
Author SHA1 Message Date
yetone 34b2dd9b70 gateway: a used-up Codex sign-in, the one account, is heard on its relayed turns and served without a restart
unsplashz on Discord: Codex beside its ChatGPT sign-in, one Codex
account in magpie. When the account ran out, Codex couldn't send until it
was restarted, after which its turns went through magpie.

Cause. With Codex's sign-in the only account on, an own-model turn is
relayed to ChatGPT as Codex sent it (codexUpstreamOn, no account). That
path never kept the reply's x-codex-* / codex.rate_limits windows
(heardCodexLimits) and never asked for the account to be read again on a
usage_limit_reached refusal (codexMayBeUsedUp). Only turns served through
magpie's accounts did. So magpie learned the account was out at the next
look, one to five minutes on, and until then wrote no codex.out and left
the Codex app's app-server alone, its Send greyed. A Codex started
before codex.out also kept sending own-model turns to its built-in
provider, each relayed to the same refusal, until it was restarted.

Fix.
- codexUpstreamOn: for a /responses relay on magpie's ChatGPT account
  (codexRelayedAccount: the account signed with, or Codex's sign-in when
  the request's chatgpt-account-id names it), the reply's windows are
  heard, and a quota refusal calls codexMayBeUsedUp. codexServed now uses
  the same lookup.
- codexAccounts: while the sign-in is known out (CodexUsedUpKnown, the
  cached reading only) and the request signs as it, an own-model turn
  goes through routing as codex/<model>, as a restarted Codex's does.
  Another sign-in (a Codex in WSL) still goes as it came.

Run:
- go test ./internal/gateway -run 'TestCodexUsedUp|TestCodexRelayedWindowsHeard|TestCodexHeldSignInServedWithoutRestart|TestCodexOwnModel|TestCodexPaused|OneAccount' (mote): ok.
- GOOS=darwin/linux/windows go vet ./internal/gateway (mote): clean. gofmt -l: clean.
- go test ./... -timeout 45m -count=1 at 25fbbd03e on the Linux VM (wsl-run,
  mote had another session's full suite): 73 ok, internal/gateway ok
  (738s). Reds: ., internal/cli and internal/gui don't build there (no
  gtk4/webkitgtk-6.0 dev packages); internal/agent TestInstalledVersion,
  TestGrokInstalled, TestOmpDetectedWithPiDir, TestZedAppPath, all #4033
  (and #3548). The first three are red the same on origin/main e61e10535
  there; TestZedAppPath passes 3 of 3 alone on this branch.
- go test . ./internal/cli ./internal/gui ./internal/agent -timeout 45m at
  25fbbd03e on mote (load ~300, other sessions' suites): ., cli, agent ok.
  internal/gui: 12 real-window AppKit tests killed at their deadlines
  (#2645, #4125). Alone, TestGatewayHeldByAContainer and
  TestGatewayFixQuitsOnlyAMagpie pass; the other 10 (TestDockJoinLeadsCommandTab,
  TestPanelCloseHidesIt, TestPanelJoinsFullScreenSpaces,
  TestPluginPageLoadsItsFilesInTheWindow, TestDockReopenKeepsTheWindowsSpace,
  TestMainWindowCorners, TestMainWindowRightToLeft,
  TestHandoverLeavesTheMenuBarIconForTheNextMagpie,
  TestTrayCellClickReleasedPanel, TestCoveredWindowStaysUp) are red the
  same on origin/main e61e10535 there. Nothing in gui is touched.
- Rebased on origin/main (12 commits, none in codex_backend.go):
  go test ./internal/gateway -run TestCodex at the pushed head on the
  Linux VM (mote stopped answering ssh): ok.

Broken by hand:
- codexMayBeUsedUp call removed: TestCodexUsedUpRelayedAsksAtOnce red
  (asked "", want me@example.com).
- heardCodexLimits call removed: TestCodexRelayedWindowsHeard red (heard []).
- held branch off in codexAccounts: TestCodexHeldSignInServedWithoutRestart
  red (held: "" false). Account-id guard removed: red (another sign-in
  routed as codex/gpt-5.5).

Not tried:
- A real used-up ChatGPT account, or the real Codex app. The real codex
  0.162.1 CLI in a sandbox CODEX_HOME against a fake backend never got
  past its workspace routing discovery (/wham/accounts/check), so no turn
  reached the fake.
- With one account and no fallbacks, the turn served through routing
  still ends in the account's 429 (worded by routing). It goes on only
  where routing has somewhere to send it, as for a restarted Codex.
2026-10-29 15:14:02 +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