bitssly on X (tweet 2118722838249234609, v0.1.3177, Store Codex
26.1029.7803.0, app-server 0.166.0-alpha.6): when Codex's usage ran out
the Codex app flickered, showed "Hosted AppServerManager identity is not
ready" (fatal_error_broadcasted) and had to be quit and opened again,
four times in a day.
The page is the app's own bug after its app-server is ended (#4550), and
magpie ends it on purpose when it becomes Codex's provider for the
used-up account. 4f624241f reads the app's log for the page and reopens
the app, but on Windows it never saw it: codexLogFiles kept only files
whose fs.DirEntry Info() time was after the end, and on Windows that is
the folder listing's time, which NTFS brings up to date only as a handle
on the file is closed. The app keeps its day's log open, so the file the
page went to listed hours old and was skipped. On the Windows box the
Store app's own log listed 10:27Z (os.ReadDir and Get-ChildItem) while
the app wrote to it at 15:22Z (os.Lstat, File.GetLastWriteTimeUtc).
The same listing time judged Codex's session files, which the
app-server holds open: codexTurnOpen skipped a turn running in a thread
opened over 30 minutes before, and codexSessionsQuietFor counted such a
session quiet, so on Windows the app-server could be ended under a
running turn.
- agent/codex_app_crash.go: codexLogFiles reads os.Lstat per file.
- provider/codex_app_server.go: sessionFileInfo (os.Lstat) for
codexTurnOpen and codexSessionsQuietFor; a file gone between the
listing and the stat is skipped.
- The other readers that judge a file another program may hold open by
its listing time (sessions, claude_out_soon, subscription_usage,
claude_subscription's idle sweep) are #5549. magpie's first look after
its own restart ending an app-server that already started under the
takeover (one of bitssly's four pages came a minute after an
auto-update) is #5550.
Run:
- Windows box (win-run), Store Codex 26.1029.7803.0 installed there:
the two new tests red on the old code
(TestCodexAppCrashedReadsAFileTheAppHoldsOpen: crashed false;
TestCodexSessionHeldOpenReadAtItsOwnTime: "not open"), green with the
change; go test -run 'TestCodexApp|TestCodexSession|TestCodexTurn'
./internal/agent ./internal/provider ok. A Go probe on the box read
the live Store log at listing 15:22:00Z, own 15:32:02Z.
- Broken by hand on Windows: codexSessionsQuietFor back on e.Info()
makes TestCodexSessionHeldOpenReadAtItsOwnTime red ("quiet"); the
test checks quiet before the turn, since reading the file closes a
handle and Windows then brings the listing up to date.
- mote at this head on origin/main 80ae904c2: go test ./... -count=1
-timeout 45m: 86 packages ok, red only in internal/gui
TestMainWindowCorners (#3949, open, AppKit on mote's macOS 27).
- Rebased onto origin/main f9a88c4fb (1fd0bb967 update, f9a88c4fb wsl
touched agent and provider): at this head go test ./internal/agent
./internal/provider ./internal/netproxy ./internal/update
./internal/plugin ./internal/pii ok on mote, GOOS=windows go vet of
agent and provider ok.
- go vet ./... (darwin), GOOS=windows go vet ./... ok; GOOS=linux go
vet ./internal/agent ./internal/provider ok; gofmt -l clean.
- On macOS and Linux the listing already carries the file's own time,
so the tests pass there on old and new code alike.
Not tried: a real used-up ChatGPT account reaching the page and magpie
reopening the Store app (the reopen itself is #4550's, unchanged).
ysm119 on Discord: each Restart of Codex in magpie left the ChatGPT
desktop app on "ChatGPT 遇到了问题 / 请重试" till it was quit and opened
again. magpie ends the app's own app-server cleanly (code 0); a
signed-in ChatGPT 26.1021 then fails "Hosted AppServerManager identity
is not ready" on the one it starts, logs fatal_error_broadcasted and
shows the page. That is the app's bug; magpie now follows it up.
- provider/codex_app_crash.go: for 60s after every end magpie makes
(the watcher's step, RestartCodexApp, RestartSwitchedCodexApp) the
app's logs are read for a whole fatal_error_broadcasted line stamped
after the end. On one, with no request through magpie since or in
flight and no Codex turn opened since, the app is quit and opened
once. Otherwise it is left as it is and logged. Where it can't be
reopened (Linux, an app that didn't quit) the Agents row says
"The Codex app hit an error · quit it and open it again" (appSnag)
until the app-servers seen then are gone or the app is closed.
Unreadable logs reopen nothing.
- agent/codex_app_crash.go: the logs as the app's file logger writes
them (macOS ~/Library/Logs/com.openai.codex, Windows
%LOCALAPPDATA%\Codex\Logs and the Store package's LocalCache, Linux
$XDG_STATE_HOME/codex/logs; YYYY/MM/DD folders, tail-read, half
lines dropped). The relaunch is the Agents row's: on macOS
ChatGPT.app found by its bundle id, quit as ⌘Q does and opened once
it has ended, never forced; on Windows codexAppReopen.
- GUI line in en, zh, zh-TW, ja, de; docs/subsystems/agent-wiring.md.
Run on mote (macOS) at this head on origin/main 08982805e:
- go vet ./internal/agent ./internal/provider ./internal/gui (darwin
and GOOS=windows), GOOS=linux go vet ./internal/agent
./internal/provider; go build ./...; gofmt -l clean.
- go test ./internal/provider ok; go test -run
'TestCodexApp|Restart|Reopen' ./internal/agent ok.
- go test ./internal/gui: red only in TestMainWindowCorners (#3949) and
TestPanelHiddenByWailsMarksPageOutOfSight (#5322), AppKit window tests
red on mote's macOS 27 and filed before this change.
- win-run and wsl-run: go test -run TestCodexApp ./internal/agent
./internal/provider ok (the macOS relaunch test skips on Windows, as
TestWorkBuddySidecarOutlivesQuitOnMac does, #4115).
- node --test codex-app-snag, codex-app-out, codex-app-back, i18n-keys,
i18n-en-no-cjk: chromium and webkit, every language, 980 and 440px.
i18n-keys' "a plugin's words are its own" stays red for "View routing"
(#5327/#5332, red on main since 73c98ebc2); this change added a word
there and took it out again.
- Core script budget: under it, not raised.
Broken by hand, each red then restored:
- codexAppCrashStep's call removed: 4 provider tests red.
- the watch not armed in RestartSwitchedCodexApp:
TestCodexAppRestartsWatchForTheErrorPage red; in RestartCodexApp:
TestCodexAppRowRestartWatchesForTheErrorPage red.
- the turn and request checks off: TestCodexAppInUseAfterItsErrorPageIsLeft red.
- the snag not set: TestCodexAppSnagSaidTillTheAppRestarts red.
- the stamp's >= since check dropped, or a half-written last line kept:
TestCodexAppCrashedReadsItsOwnLogs red.
- a wrong Store package path: TestCodexAppCrashedReadsEachSystemsFolder red.
Not tried: a real signed-in ChatGPT app reaching the identity-not-ready
page, and a real quit and reopen of the user's ChatGPT.app (the relaunch
is tested with faked process listing, quit and open in a sandbox HOME).
The log line and folders are read from ChatGPT 26.1021's
file-based-logger and the reporters' logs; a later app that renames
them reopens nothing, as before this change.
A bug report by mail (11-04): after the ChatGPT allowance reset, Codex
was back on its account, but the Codex app still showed no account and
no usage. The app's app-server was the one it started while magpie
served Codex, and the app reads account/read only as that starts. With
"Restart the Codex app when magpie switches its account back" off (the
default, #4550), codexAppStep leaves it running, and nothing said so;
the takeover's hover even said "It all comes back on its own at the
reset". On Windows StaleCopies lists only the daemon, so no hint showed
there either.
- provider: codexAppStep remembers the app-servers it left running when
magpie gave Codex its account back (c.out && !out, not magpie's own
account switch, which codexAppLeft already says). CodexAppBack() is
true till they are gone (rechecked every 30s; a failed listing keeps
it), a route change clears it, and RestartSwitchedCodexApp clears it.
- gui: /api/state's Codex row carries appBack (not for a WSL Codex).
The Agents row says "Back on ChatGPT · restart the Codex app to see its
account" with a Restart, and the row opened says why, with the same
Restart; it posts codex/daemon/restart-app, as the Providers page's
"still signed in as" Restart does. The takeover text now says the
account and usage come back once the app-server restarts, and that
this row offers it.
- i18n: zh, zh-TW, ja, de for every new and changed string.
Run (on mote unless named; rebased on origin/main d892dd6a2, then 8b902e287 (checkin only; vet and CodexApp/Checkin tests ok there), the gui budget/i18n Go tests, CodexApp and i18n-keys, codex-app-back, codex-app-out ran again at this head: ok, 148 of 148):
- go test ./internal/provider -run CodexApp: ok; also ok on Windows
(win-run) and Linux (wsl-run, with go vet ./internal/provider).
- go test ./internal/gui: one red, TestMainWindowCorners/macOS_26_SDK,
which is #3949 (macOS 27 on mote), nothing else.
- GOOS=windows go vet ./internal/provider ./internal/gui: ok. Linux vet
of internal/gui needs gtk4/webkitgtk dev packages the WSL distro
lacks, so it was not run.
- gofmt -l internal/: nothing.
- GUI: every codex-*, agent*, ag-* and i18n* file (86 files), both
engines: 1484 of 1486. The two reds are codex-auto-reset webkit de
1100/420, red the same alone at origin/main e0ee9265e; #4790 (noted
there that macOS has it too). The new codex-app-back.test.cjs: 20 of
20, every language, both engines, 980 and 440 px, line and row opened.
- Broken by hand: leftBack forced false, TestCodexAppBackSaidTillItRestarts
went red ("the app left on the takeover's app-server isn't said");
restored.
Not tried: a real Codex app through a real reset; the state machine is
driven with stubbed app-server listings.
v0.1.2826 (1dead5dc7) added Restart the Codex app when magpie switches
its account, off by default, so that atom0964's ChatGPT app stopped
relaunching at every switch magpie made between two Plus accounts. Its
guard in codexAppStep left the app-server running for every change
magpie made by itself, and that covered too much:
- the takeover in, where magpie becomes Codex's provider for its used-up
account;
- the first look on a used-up account;
- magpie's switch off an account at 98% (SwitchWhenSpent).
The Codex app greys Send for every model while its signed-in account's
rate limit says not allowed, and reads the account only as its
app-server starts (ChatGPT.app 26.1013, 8b0132b3d). Left running, the
app stayed on the used-up account with Send grey, so neither magpie's
fallback nor the next account could serve it until the user restarted
it by hand. With the default off, that broke the takeover for every
user with a fallback.
Now those three restart the app-server tick or not (`needed` in
codexAppStep: `into || c.switched && c.spent`). The tick covers only
what the app works without: the switch back once the first account has
room, and Codex given its account back at the reset. The label, tooltip
and toasts say "switches its account back" in en, zh, zh-TW, ja and de.
The tooltip adds that a used-up account restarts the app anyway.
SwitchWhenSpent's stale-app log, RestartApp's comment and
agent-wiring.md say the same.
atom0964 will still see one restart when an account runs out. Send
needs it. The restarts at the switch back and at the reset are gone.
Run at the pushed head (on mote, rebased on c0d4f17a3):
- gofmt -l clean; GOOS=linux (-tags nogui) and GOOS=windows go vet of
provider and gui clean.
- go test -count=1 -timeout 45m ./internal/provider ./internal/davsync
./internal/backup: ok. ./internal/gui -run "Budget|I18n|Restart": ok
(the core script budget holds with the longer strings, no raise).
- GUI (chromium + webkit, narrow and wide, en/zh/ja/de): restart-app,
switch-only, i18n-keys, codex-accounts-via: 76/76.
Broken by hand: codexAppStep's guard without `!needed`:
TestCodexAppLeftRunningForMagpiesOwnChanges ("magpie switched off the
used-up account: ended [], want [60]") and
TestCodexAppFirstLookOnAUsedUpAccountRestarts go red.
Not tried: a real ChatGPT desktop app on a real used-up account (the
app-server end is stubbed); Windows, where an end is followed by
CodexAppReopen.
atom0964 on Discord (#help) has two ChatGPT Plus accounts in magpie, with
Codex always signed in to the first and Only switch Codex's sign-in both
off, on Smart routing. The Codex desktop app kept restarting by itself.
They tried several combinations of the ticks and it still did.
Why: with both off, SwitchWhenSpent signs Codex in to the next account at
98% and back to the first below 90%. Each switch was noted for the Codex
app (codexAppSpentSwitch), and KeepCodexAppOnItsProvider ended its
app-server once no turn ran; the ChatGPT app shows that as an error and
relaunches (#4550). With Codex kept on the first account there is no
switch, but the used-up takeover (magpie made Codex's provider for a
used-up account and given back once it has room; f37742e14 only limits
it to when another account can serve, which two accounts always can)
changed Codex's route, and that ended it too. So every combination
restarted the app.
What changed:
- Provider.RestartApp (restartApp), off by default, set by
provider/restartapp (SetRestartApp, Codex only). This computer's own,
like KeepLogin: Mirror keeps it and davsync's hash leaves it out.
- switchLoginBy(agent, user, byMagpie): SwitchWhenSpent marks its
switch magpie's own (codexApp.auto). In codexAppStep, a change that is
magpie's own (its switch, the takeover in or out, the first look at an
app on a used-up account) ends nothing unless RestartApp is on; it
logs why and the app follows once restarted. The switch notice's
Restart, the Agents row's Restart, and uninstall are unchanged.
- Still restarted: a switch the user makes (Switch, the Agents row, the
CLI), a Connect or Disconnect, failover written or taken out (any
route change while the takeover state is unchanged), and a user's
switch pending when magpie's comes.
- GUI: under Codex's accounts, with more than one on (or the tick set),
"Restart the Codex app when magpie switches its account", with a tip
and toasts in en, zh, zh-TW, ja and de. app.js paid for it with five
account-row comments cut; TestCoreScriptBudget is not raised.
- docs/subsystems/agent-wiring.md says which changes restart the app.
Known edge: a takeover flip in the same 3s tick as a Connect is taken
as the Connect's (restarted), since the route changed by the user.
Run at the pushed head (on mote, rebased on b967b1620; then rebased on 2a19043af, a Library change touching none of these files, with the core budget checked again: 160 bytes under):
- gofmt -l clean; GOOS=linux (-tags nogui) and GOOS=windows go vet of
provider, gui, davsync clean.
- go test -count=1 -timeout 45m ./internal/provider ./internal/davsync
./internal/backup: ok. ./internal/gui: ok except
TestMainWindowCorners/macOS_26_SDK, red alone on origin/main 694f4a6d6
too (#3949). ./internal/cli: ok except TestEveryRouteHasACommandOrIsNamed
on GET /api/context/reply (#5026).
- GUI (chromium + webkit, 1100 and 420 wide, en/zh/ja/de):
restart-app (new), switch-only, claude-switch-only, keep-login,
codex-accounts-via, account-arrange, i18n-keys: 110/110 and 94/94.
account-arrange's webkit case went red once in a 5-file run on an
aborted /api/lanes request; it passes alone on origin/main and at
this head.
Broken by hand:
- codexAppStep's guard turned off: TestCodexAppLeftRunningForMagpiesOwnChanges
and TestCodexAppFirstLookLeftRunning go red (ended [60]).
- SwitchWhenSpent marking its switch as the user's: TestCodexSwitchedWhenUsedUp
goes red ("magpie's own switch is counted the user's").
Not tried: a real ChatGPT desktop app on a real used-up account (the
app-server end is stubbed as before); Windows, where the app is quit and
reopened (CodexAppReopen runs only after an end, so leaving it running
skips it too); no CLI command for the tick (switch-only has none either).
xiaoq6285 on Discord (v0.1.2700): Codex on an official ChatGPT account
ran out of quota, and after switching to another account or provider in
magpie, the Codex app's Send button stayed grey. magpie has no chat
composer of its own; the button is the Codex app's, which greys Send for
every model while the app-server it runs is on a ChatGPT account the app
holds. magpie lifts that by restarting the app's app-server
(codexAppStep), but never while a Codex turn is open in its sessions, for
up to codexTurnWindow (30m). When quota runs out mid-turn the turn is
left open, so the restart, and the grey, waited.
cc81ad4ea let a quiet stuck turn be restarted past (codexTurnStuckAfter,
2m) only after SwitchWhenSpent's own switch. Two siblings that leave the
app-server on the same used-up account still waited the 30 minutes:
- a switch by hand (Accounts, CLI) off an account last read held:
noteCodexSwitch now marks it spent when the account's reading in hand
says Held (codexHeldKnown: cache only, no I/O; a failed read or none
is not held);
- magpie becoming Codex's provider for the used-up account (codex.out):
codexAppStep marks the change into out spent. The way back at the
reset still waits for any open turn, as a real one may run there.
A turn still writing its session or sending through magpie in the last
2 minutes holds the restart as before.
Tests, both red on the old code:
- TestCodexAppServerRestartedPastATurnStuckWhenMagpieTakesOver
- TestCodexHandSwitchOffAHeldAccountIsSpent
docs/subsystems/agent-wiring.md says so.
Run at this head on mote:
- go test -tags nogui ./internal/provider: ok (151s), at this head
after the rebase on 52195b6b0 (it changed provider_test.go and two
more provider files, so provider was run again).
- Before the rebase (on 07f4d46c5): provider ok, agent ok, gui ok;
gateway red on TestCodexPoolSaysTheClientsVersion alone (#4807, red in
a full package run, passes alone; -count=5 alone ok at this change);
cli red on TestEveryRouteHasACommandOrIsNamed (#4826), red the same
on origin/main 52195b6b0 just fetched.
- gofmt -l clean; GOOS=linux go vet -tags nogui, GOOS=windows go vet
and go vet of ./internal/provider ./internal/agent ok at this head.
- Not run: the full go test ./... (agent, gateway, gui, cli and provider
are what reach this code). No GUI change, so no GUI suite.
Broken by hand, each red, then restored:
- spent not set on the takeover (c.spent && into): the takeover test
failed "a turn stuck on the used-up account as magpie took over:
ended [], want [60]".
- noteCodexSwitch never marking spent: the hand-switch test failed
"switched off out@x: switched true, spent false, want true, true".
Not tried: the real Codex app with an account actually out of quota
(no such account to hand), and Windows/Linux runs of the package (the
change is OS-independent logic; GOOS vet run). Not confirmed with the
reporter that their case is a turn left open; their screenshot wasn't
seen here.
70d50254c (v0.1.2387) took the model list out of the route the Codex
app's app-server is ended on. The effort the app saves on each pick
went into the catalog, the next sync rewrote it, and the route's hash
of the catalog changed, so the app-server was ended every few minutes
and the ChatGPT app read that as a crash (goto_nozomi on Discord,
ggbdpq on #4550). This adds two things on top of that.
- codexAppStep logs each end with what made the app-server stale:
"codex: ended the Codex app's app-server [pid] for the app to start
another: <why>". The reason is the ChatGPT account switched, the
route changed, or the used-up takeover. Before this a successful end
logged nothing, so a reported crash couldn't be put down to magpie or
to the app (ggbdpq asked for it on #4550).
- TestCodexAppRouteKeepsThroughListFlaps runs in a sandbox HOME
through SyncCatalog. A relay's list drops a model and has it back,
the catalog is re-ranked in another order with other descriptions,
and the catalog is caught half-written. Each must leave the route as
it was. 70d50254c's tests cover an effort pick and a rename.
Product call, as 70d50254c made it: a list change alone never restarts
the app-server, not even once Codex has been idle for a while. The
restart is what crashes ChatGPT when an MCP server is slow, and idle
time doesn't make it safe. The new list is read at the app's next
launch, or on the Agents row's Restart (StaleCopies). Where requests
go (model_provider, openai_base_url, the magpie table's base_url,
requires_openai_auth, the used-up takeover) still restarts it, as
TestCodexAppRouteFollowsConnectAndDisconnect and
TestCodexAppRouteFollowsOpenAIAuth hold.
Run (mote):
- go vet, GOOS=linux go vet and GOOS=windows go vet of ./internal/agent
and ./internal/provider: clean.
- go test -count=1 -timeout 45m ./internal/agent ./internal/provider on
e484b1e93: ok. Rebased onto 5cc2eea2f (dsh in internal/agent), then
go vet and go test -count=1 -timeout 45m ./internal/agent again, and
-run CodexApp ./internal/provider: ok.
- gofmt -l on both packages: nothing.
Broken by hand:
- TestCodexAppRouteKeepsThroughListFlaps at 70d50254c^ (the route
still hashed the catalog) is red three ways: a model dropped (:119),
another order (:141) and a half-written catalog (:147) each changed
the route.
- With the used-up reason taken out of codexAppStep,
TestCodexAppEndSaysWhy is red ("... start another: where Codex's
config sends it changed", want "used up").
Not tried:
- The real ChatGPT/Codex app. Nothing here changes when the app-server
is ended, only what is logged.
- The whole ./... suite and the GUI suite. Neither package touches the
GUI.
- Whether goto_nozomi's crashes stop on v0.1.2387. #4550 stays open
for them to say, with the new log line asked for if any crash is
left.
pota on Discord: magpie switches the ChatGPT (Codex) desktop app's
account on macOS and Windows but not on Linux. OpenAI ships the app for
Linux since 08-11 (preview; learn.chatgpt.com/docs/linux/linux-app): a
deb, an rpm and an Arch package, which install /usr/lib/chatgpt. Its
app-server is /usr/lib/chatgpt/resources/codex ... app-server, run with
the user's HOME and no CODEX_HOME, so it reads ~/.codex like the CLI.
isCodexAppServer took only .app/Contents/ and Windows paths, so on Linux
nothing found the app: no "still signed in as" notice after a switch,
no restart of its app-server, and no version on the Agents row.
- provider: linuxCodexApp takes an absolute .../chatgpt/resources/codex
as the app's own app-server (findCodexApp, CodexAppStale, the switch's
restart all read it).
- agent: restartOnLinux; codexAppOpen knows on Linux whether the app is
open (any /usr/lib/chatgpt/ChatGPT process, not its codex alone or
another program's ChatGPT). desktopApps["codex"].linux reads the
version from resources/linux-package-metadata.json, HasApp/AppVersion
see it, and codexReaders counts the bundled codex's --version as a
reader of Codex's config. version() no longer stops at an empty store
read before the other sources.
Real run, WSL magpie-desktop (Ubuntu 24.04), OpenAI's chatgpt_amd64.deb
26.1027.30824 (bundled codex-cli 0.166.0-alpha.5.1) under Xvfb, sandbox
HOME, fake unsigned JWT accounts alice/bob (no real credentials), magpie
web on 127.0.0.1:3591:
- POST /api/login/switch alice: 200, auth.json alice; /api/providers
then says codexApp "bob@example.com" (the stale notice).
- POST /api/codex/daemon/restart-app: 200 in ~3s; the old app-server
ended (app log "Codex CLI process exited classifiedAsExpected=true
code=0"), a new one started with the sandbox HOME, the notice cleared.
- /api/agents/cli: "codex":{"app":"26.1027.30824"}.
- The same run with linuxCodexApp reverted: no notice, restart-app 400,
the app-server untouched (pota's case).
Run at 5b1709eee: go test -tags nogui -timeout 45m ./internal/agent
./internal/provider on mote, ok; gofmt -l clean; GOOS=linux go vet
-tags nogui and GOOS=windows go vet, ok; go build ./... ok. Full
go test -tags nogui -timeout 45m ./... on mote at cae01311c (the
earlier base; nothing under internal/agent, provider or proc changed
since): every package ok except two reds that are on main and filed,
TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestNoCommandBypassesProc (#4491, now child_unix.go too). WSL
./internal/agent ./internal/provider: provider ok; agent red only in
TestGrokInstalled, TestCursorFolderFromTheEditorIsNotTheCLI and
TestOmpDetectedWithPiDir, red the same alone at origin/main 5b1709eee
in WSL (#4033, #3548); the new Linux tests pass there.
Broken by hand: linuxCodexApp returning false turns TestFindCodexApp and
TestCodexAppOwnServer red; codexAppOpen's Linux case removed and
linuxVersion returning "" turn TestCodexLinuxAppOpen and
TestCodexLinuxAppVersion red; the old store early return turns
TestCodexLinuxAppVersion red; codexReaders' linux case removed turns
TestCodexLinuxAppReadsTheConfig red in WSL.
Not tried: the rpm and Arch packages (the Arch one has the same
usr/lib/chatgpt layout; the rpm's is assumed), a real ChatGPT account
(the app's own UI asks to sign in, since the fake tokens fail refresh),
and reopening the app when no app-server comes back (Windows only;
Linux says to quit and open it again, as macOS does). A switch made from
the CLI while magpie web runs elsewhere doesn't restart the app; the
notice says to, as on macOS.
After magpie switched Codex's account, the Windows Codex app answered
every send with "Codex app-server process is not available" until it
was quit and opened again. The report said the app doesn't reconnect
after a clean exit. That is half right. The app (MSIX OpenAI.Codex
26.1021, an Electron ChatGPT.exe that spawns codex.exe app-server over
stdio) does start another, but only once the old one's stdout reaches
EOF and its exit has fired. On Windows a child of the app-server (an MCP
server, a tool command) inherits that pipe handle. A child left running
keeps the pipe open, so the app never sees the close, starts none, and
its send() throws. Reproduced on the Windows box with the real codex.exe
0.164 app-server plus an MCP server: stdout ended only when the MCP
server did, and at once when the tree was ended.
magpie took "the old pid is gone" as done in each place it restarts the
app-server. None of them checked that a new one came:
- codexAppStep (the switch watcher) now records the pids it ended and
waits codexAppBackWait (30s) for another app-server. If none comes and
the app still runs (CodexAppOpen), it quits and opens the app as the
Agents row's Restart does (CodexAppReopen: restartWin by the
OpenAI.Codex_2p2nqsd0c76g0!App AUMID, Windows only). Where it can't,
the row says to (CodexAppStuck).
- RestartCodexApp (macOS Restart), RestartCodexAppWhenIdle (uninstall)
and the switch notice's Restart (RestartSwitchedCodexApp, 46aa7e6b8)
wait for a new app-server too, and reopen or say so the same way.
RestartSwitchedCodexApp's own 20s codexAppBackWait went into the
shared 30s one.
- recheckLeft no longer clears the "still on the old account" record
while the app is open with no app-server.
- A turn stuck open when quota ran out mid-task (蛋仔's follow-up) held
the restart for up to codexTurnWindow (30m), since an open turn in
Codex's sessions meant "a task runs". A switch off a used-up account
(SwitchWhenSpent) now marks it spent (codexAppSpentSwitch). After such
a switch, a turn that has written no session file and sent nothing
through magpie for codexTurnStuckAfter (2m) counts as stuck, and the
app-server is restarted past it. Its next request would be refused on
that account anyway. A tool still running in that turn is ended with
it. A switch for any other reason waits for the turn as before.
macOS is never reopened unasked (a reopen opens a new window,
yoshi037070, 10-27). WSL needs nothing: WSL Codex has no desktop app, and
the Windows app's app-server runs on the Windows side.
Run (at this head unless said):
- mote: go test -timeout 45m ./... at 4cf444bc4, this change on
origin/main 807048470. It was rebased on dca3e2d71 after (5 commits,
none in codex_app*/codex_switch/codex_daemon), and the -run below was
run again at the pushed head. Result: every package ok except gateway and gui, whose reds aren't this
change's (it touches neither package). gateway: TestAntigravityTurn*
x4 and TestCodexSpentGrokFailingIsTold, red the same on origin/main
46aa7e6b8 (#4362), and TestUnroutedUnknownHoldAnsweredSooner, which
passes alone 3 of 3 at this head (filed #4377). gui:
TestMainWindowCorners (#3949).
- mote: provider and agent -run 'CodexApp|CodexDaemon|RestartCodex|
RestartSwitched|CodexSwitched|CodexSessionsQuiet|Switch' ok; gofmt -l clean; GOOS=windows, linux,
darwin go vet ./internal/agent ./internal/provider ok.
- win-run, the same -run: everything of mine passes. Two tests are red,
TestCodexDaemonEnvIsTheTerminals and TestWorkBuddyRestartOnMac, the
same on origin/main (#4115).
- Broken by hand, each red, then restored: the step's no-app-server
branch, RestartCodexApp's not-back check, uninstall's reopen,
recheckLeft's open check (4 provider tests); RestartSwitchedCodexApp
without the reopen (TestRestartSwitchedCodexApp "reopened 0"); the
codexWinApp matcher widened to \WindowsApps\OpenAI.
(TestCodexAppReopenedOnWindows). The stuck-turn bypass taken out
("a turn stuck on the used-up account: ended []"), the spent mark not
set (TestCodexSwitchedWhenUsedUp), and the bypass without its spent
and quiet checks ("a turn open after a switch not for spend: ended
[60]").
- Real Codex app on Windows (xiaomi-gpu, OpenAI.Codex 26.1021.3705.0,
from a throwaway test, not committed, run as a scheduled task in the
console session):
- RestartCodexAppWhenIdle ended the real app-server, and the app
started another within ~0.6s. codexAppBack saw it (left false).
- codexAppReopen quit ChatGPT.exe 43832 and opened the app by its
AUMID in 3.7s (main now 70060). A new app-server came 9.6s after.
Not tried:
- The stuck state itself in the real app: an MCP child really holding
the app-server's stdout inside the Codex app. It was reproduced with
codex.exe outside the app, and the reopen was run on a working app.
- A signed-in real account switch on Windows.
- The quota-mid-task hang with a real used-up account. Why the app sat
on the turn wasn't reproduced. A plain usage_limit_reached refusal
closes the turn (task_complete, as dd9828f2b found), so this covers a
turn that stays open, whatever holds it.
- Whether a reopen loses an unsent draft.
- The macOS path with a real stuck app (it says to quit and reopen;
nothing is reopened there).
蛋仔 (danzi002 on Discord, 10-29 and 10-30) switched the Codex app's
used-up account in magpie, auth.json changed, and the app stayed grey
until it was quit and opened: "如果打开了 codex 再不点击任何会话的时候,
我手动切换账号它会重启,如果点了会话再切换账号就重启不了". dd9828f2b
made a switch restart every one of the app's own app-servers once no
Codex turn runs. This one never ran.
Why. Codex reads auth.json once; a 401 reloads it only for the same
account id (codex-rs/login/src/auth/manager.rs, reload_if_account_id_
matches), so only a new app-server takes up a switched account.
codexAppStep waits while any session file written to in the last 30
minutes ends in task_started. Tried with the real codex
0.164.0-alpha.11.1 (ChatGPT.app's), sandbox HOME/CODEX_HOME, a fake
Responses server holding a turn open:
- SIGTERM or stdin closed mid-turn: turn_aborted is written.
- SIGKILL (force quit, crash): the file ends in task_started for good.
- thread/resume in a new app-server, which is what opening the thread
in the app does, appends thread_settings_applied and moves the mtime
each time, nothing else changed.
- a 429 usage_limit_reached ends the turn with task_complete, so being
out of credit doesn't leave one open.
So a thread whose turn a killed app-server left open reads as running
for as long as the user keeps opening it, and the switch waits forever.
Change. proc.Started(pid) reads when a process started (darwin
kern.proc.pid P_starttime, Linux /proc/<pid>/stat starttime + btime,
Windows GetProcessTimes; ErrNoStart elsewhere). codexAppStep and
RestartCodexAppWhenIdle pass the oldest start of the app-servers they
would end; an open turn whose task_started line's timestamp is more
than 2s before it can't be running in them and no longer counts. A
start or a timestamp that can't be read counts the turn as running, as
before. A turn started in a running app-server still holds it: no turn
is cut short.
Run (mote-run unless said):
- gofmt -l internal/proc internal/provider: clean.
- go vet ./internal/proc ./internal/provider on darwin, GOOS=linux
-tags nogui, GOOS=windows: ok.
- go test -count=1 -timeout 45m ./internal/proc ./internal/provider:
ok (6.2s, 110s).
- wsl-run (magpie-desktop) and win-run (xiaomi-gpu): TestStarted,
TestCodexTurnOpen, TestCodexApp*: ok.
- The real killed-turn rollout above, copied into a temp test: open
with since unknown, not open with since after the kill, open with
since before the turn.
Broken by hand:
- codexAppStep passing a zero since (the old behaviour):
TestCodexAppSwitchPastATurnItsServerNeverRan red ("ended [], want
[60]").
- sessionTurnOpen ignoring since: TestCodexTurnOpen red too.
Not tried: the reporter's own app on a real account switch; whether
their app-server was in fact killed (force quit or crash) is not known.
A restarted app-server with the thread left open was not watched
ungreying Send in the real app.
danzi002 (Discord, Codex app on magpie API, several ChatGPT Plus accounts):
when the Plus account runs out the app greys Send; magpie signs Codex in to
the next account, but the app stays grey until it is quit and opened, and
only then is on the next account.
Cause: at the switch, noteCodexSwitch handed codexAppStep a single pid,
the first app-server-looking process (findCodexApp) of a 5-second ps
listing. That can be another program's `app-server --listen stdio://`
(ps lists by pid; on the owner's Mac Miyi Helper's runs beside the app's
own right now), which codexAppStep then drops as not the app's own, so
nothing is ended; and a ps slower than 5s dropped the switch for good.
Now the switch only marks codexApp.switched, and codexAppStep lists the
app's own app-servers on Codex's home with the same test and 30s bound a
route change uses, again at the next look if the listing fails, and ends
each once no Codex turn runs. findCodexApp (the "still on the old
account" notice) skips --listen ones too.
Also: a reply that says the active account is out (CodexMayBeUsedUp,
already reading the account at once) now runs SwitchWhenSpent too, so
the switch no longer waits for the account loop's next look, up to five
minutes when the last reading was under 90%. The app sends nothing once
it is grey, so no later request tells magpie.
Checked: a usage_limit_reached turn does not hold the restart back. Real
codex 0.164.0-alpha.11.1 (ChatGPT.app's bundled one) `codex exec` against
a fake 429 usage_limit_reached server in a sandbox CODEX_HOME writes
task_started then task_complete, so codexTurnOpen counts it ended.
Run (at 9f36d768d + this change, on mote):
- TestCodexAppSwitchRestartsTheAppsOwnServers (new): another program's
--listen app-server listed first, own one ended; ps failing at the
switch and at the first look, both own ones ended at the next.
- TestCodexReadNowSwitchesAtOnce (new): active account at 100%, the
other at 20%: codexReadNow signs Codex in to the other.
- Real processes in a sandbox HOME (temporary test, not committed): a
fake codex built at …/Helper.app/…/codex `app-server --listen stdio://`
started first and one at ChatGPT.app/…/CodexCLI.app/…/codex
`app-server --analytics-default-enabled`, real ps, real SwitchLogin
rewriting the sandbox auth.json, real proc.End: the app's own one
exits; on origin/main nothing is ended and it still runs.
- go test ./internal/provider: ok. go test -run Codex ./internal/gateway: ok.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok
(provider, gateway).
Broken by hand: on origin/main's codex_app_server.go, codex_daemon.go and
codex_app_out.go both new tests are red ("switched beside another
program's app-server: ended [], want [221]"; "Codex left on
new@example.com").
Not tried: the real Codex app with two real Plus accounts running out
(danzi002's setup is unknown to me: whether something else runs a
--listen app-server there, or ps was slow). Whether a restarted
app-server alone ungreys Send on the new account was tried for route
changes on ChatGPT.app 26.1013, not for an account switch.
Jevik_AI on X (Windows, portable magpie) deleted magpie's folders by hand.
~/.codex/config.toml kept openai_base_url on 127.0.0.1:3425, and every
Codex turn then failed with a 502, with nothing left that knew why.
Deleting magpie's files never puts an agent back, so there is now an
uninstall that does.
- internal/uninstall: Run goes in this order. System removes the
background service, opening at login, the Start menu shortcut
(shortcut.Remove, with its App Paths key), the magpie:// links and the
privacy model's helper. Agents ends Codex's account failover, then runs
each connected agent's own Disconnect, or its offline disconnect for an
app that is closed. That is the same code as the Agents page, so a value
the user changed by hand since Connect stays theirs (e7f21dba5 for
Codex). It then ports Codex's rollouts and restarts the Codex app's
app-server (provider.RestartCodexAppWhenIdle, which says whether one was left on
the old config). Data deletes magpie's folders, but keeps the Library's
folder while it holds skills, servers or hooks the user's agents use.
The executable is left where the user put it.
- `magpie uninstall [--yes]`: refuses while another magpie runs, and
says which one. On a terminal it lists what goes and asks [y/N]; with
no terminal, only --yes does it.
- Settings › About › Uninstall magpie: POST /api/uninstall runs System
and Agents. If anything failed, nothing else is removed and the sheet
offers Try again. Otherwise POST /api/uninstall/finish starts a
detached `magpie uninstall --data-after <pid>` (Setsid on unix,
DETACHED_PROCESS on Windows) and the app quits; the files go once it
has ended, since WebView2 holds its folder open until then. A Codex app
still on the old config is named before quitting. magpie web refuses
both routes. Strings go through t() in all five languages.
- --data-after refuses a pid that is no process (0, negative, its own):
kill(0) counts as alive, and a run given 0 waited out its 2 minutes.
Not done, and why:
- No restore on quit. Quitting keeps agents on magpie by design: the
service or the next start serves them.
- No Apps & Features entry or Windows uninstall hook. A portable copy
registers nothing with Windows, and an uninstaller that ran without
magpie's own disconnect would leave the configs as they are. The
`# magpie:` note above each line magpie writes (previous commit) is the
recovery path for a copy deleted by hand.
Run at this head (db75663a0's tree, on 5d24bc6cc), on mote:
- gofmt -l clean; go vet ./... on darwin (-tags nogui), GOOS=windows and
GOOS=linux -tags nogui: ok.
- go test -tags nogui -count=1 -timeout 45m on ., internal/uninstall,
cli, gui (TestCoreScriptBudget included), provider, shortcut, edit,
agent and proc: all ok.
- GUI at this head: mote was at load 100-120 with other sessions' GUI
runs. Chromium crashed (SIGBUS) mid-file in settings-search and
settings-sections after their en cases passed, WebKit failed to launch
within 180s in s3-sync, settings-search and settings-sections, and
fonts and title-bar-tools went red on unstable elements (#2984 has
fonts under load). uninstall-settings had not reported when this was
pushed.
- At the earlier base b3580c72c, on this machine: the full suite
(-timeout 45m), red only on #3884, #3632 (both since fixed on main) and
the core budget, which main's later move of Web search out (#4133) has
room for now. GUI: 104 Settings and i18n files in chromium and webkit,
uninstall-settings and i18n-keys green in both; the reds were #3797,
#3876 and the load reds above.
Tried for real, in a sandbox HOME: `magpie uninstall` end to end with
Codex connected and a sandbox Codex app running (config.toml back
without magpie's lines, magpie's data gone, the exe kept, the app's
app-server restarted onto the restored config); codex-cli 0.162.1
reading the noted config.toml. Other agents were covered by tests only.
Not tried: the GUI's Uninstall in a real app window, a real
--data-after run waiting on a live app's pid, and the Windows box.
Broken by hand: --data-after's pid guard removed ->
TestUninstallDataAfterNeedsAProcess red (0, -1 and its own pid
accepted); restored, green.
At the pushed head (rebased on 51f66fe8b; the uninstall call adapted to
EndCodexFailover's (bool, error) on the way), on mote:
- gofmt clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok;
go build ./... ok.
- go test -timeout 45m: internal/uninstall, edit, shortcut, cli, agent,
provider ok; internal/gui red only on TestMainWindowCorners/macOS_26_SDK
(#3949, macOS 27).
- GUI: uninstall-settings and i18n-keys, 30 pass 0 fail.
- WSL (magpie-desktop, CGO_ENABLED=0): uninstall, edit, shortcut,
provider ok; agent red on TestGrokInstalled, TestOmpDetectedWithPiDir,
TestZedAppPath, the same at origin/main 51f66fe8b (#4033, #3548).
TestEnvOfChild (internal/proc) and TestCodexAppServersOnHome
(internal/provider) are red on Linux since 8b0132b3, on ubuntu CI at
e056779a (run 40492644859): "EnvOf = map[], want map[CODEX_HOME:/sand
box/h/.codex HOME:/sand box/h]" and "HOME's .codex: not counted". Each
starts this test binary as a helper with a HOME (and CODEX_HOME) of its
own, and reads them back (proc.EnvOf, which codexAppHomeIs asks) the
moment cmd.Start returns. On Linux EnvOf reads /proc/<pid>/environ.
Start returns once the exec has put the new program's memory in place,
before the kernel has set where its environment lies in it, and environ
read in that window is empty. On macOS EnvOf runs ps -E, and macOS CI
has neither red.
Each helper now writes "running" to its stdout once its test runs, and
the tests read that line before anything else, as filelock's
TestLockAcrossProcesses waits for "locked". TestEndExitsClean waited
200ms for the same helper before ending it, "so the signal isn't taken
before its handlers"; it waits for the line too.
The wait has a cost the old timing hid. A helper is given no
testenv.Marker, so its TestMain makes a test home of its own in TMPDIR,
and once killed at its test's end it never removes it. At e056779a each
helper was killed before it got that far; waiting for it to run, every
helper would leave its home in the machine's temporary folder. Each
helper's TMPDIR is now a folder of its test's own (t.TempDir), removed
after the helper is ended. The other tests that start this binary again
hand it os.Environ(), testenv.Marker included, and make no home.
Not changed: EnvOf. magpie reads it of the Codex app-servers it finds
running; one read in that window would have no HOME, so codexAppHomeIs
says no and the app-server is left running, not restarted.
What was run (tree d20d0362, on origin/main e056779a, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- -count=100 -v: at e056779a TestEnvOfChild red 53 times and
TestCodexAppServersOnHome 95 (80 at HOME's .codex, 15 at CODEX_HOME),
TestEndExitsClean never. Here 300 PASS, in a TMPDIR of the run's own,
with no test home left in it.
- Broken by hand, the helpers' TMPDIR a folder of its own instead of the
test's, to count what they leave: -count=20 left 20 test homes from
TestEnvOfChild's helpers and 40 from TestCodexAppServersOnHome's. The
same at e056779a, without the wait: none, each helper killed before it
made one. Here: none.
- -race -count=30 over the three: ok.
- The window itself, outside magpie: a Go program starting a child with
a HOME and reading /proc/<pid>/environ the moment Start returns read
it empty 510 times in 1000 for /bin/sleep and 58 in 1000 for a
statically linked Go binary.
- internal/proc whole: ok (at e056779a TestEnvOfChild red).
internal/provider whole but TestUnreadLoginsWriteErrorsKeepCredentials
(#3632's crash), Bun 1.4.2: TestCodexAppServersOnHome passes, and
#3854's three tests are red, as at e056779a.
- go test -tags nogui -count=1 -timeout 45m ./... outside graftcp, umask
077, Bun 1.4.2 (log kept): 70 packages ok, internal/proc among them,
and 6 red, none in what this changes. In internal/provider
TestCodexAppServersOnHome passes before #3632's crash ends the
package. The reds: agent TestFolderVarsAreListed (#3884, main's CI
red), TestCodexDriftReached (#3398), TestInstalledVersion,
TestHowInstalled, TestCursorFolderFromTheEditorIsNotTheCLI,
TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
TestQoderSettingsFromAnIDEPluginIsNotTheCLI and
TestOmpDetectedWithPiDir (#3141),
TestReasonixCLIRequiresSupportedNativeVersion and
TestReasonixCLIRecoversAfterProbeTimeout (#3641); edit
TestWriteAtomicReadOnlyHardLink and testenv TestProgram (umask 077,
#3640); gateway TestPluginToldWhereTheAgentWorks (#3675); gui
TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie (#3649);
provider's "close of synctest channel from outside bubble" from
TestUnreadLoginsWriteErrorsKeepCredentials (#3632, main's CI red).
- gofmt -l clean. go vet -tags nogui and go build -tags nogui for linux,
windows and darwin, and go vet and go build for windows without the
tag: exit 0 each. go vet and go build without the tag on linux: exit 1
(this box has no GTK or WebKitGTK dev packages).
Not tried: Windows, where TestEndExitsClean wants code 0, and macOS.
Merged from JoeyWu-tech's branch, cherry-picked onto origin/main d6c459c79 with the other of #3906/#3854. Run on mote (macOS) at that tree:
- go test ./internal/proc/ ./internal/provider/: ok, both whole (provider's first whole pass since #3632).
- the six tests these two touch, -count=20: ok. Each was red on main before.
- GOOS=linux and GOOS=windows go vet ./internal/proc/ ./internal/provider/: ok.
Not run here: Linux, where #3906 was red; its record is the author's above and the CI run of this push.
yoshi037070 (Discord, 10-27): when magpie restarted Codex, a new Codex
window opened. The switch paths (Connect, Disconnect, failover) already end
only the app's own app-server (codexAppStep, proc.End: SIGTERM on macOS,
exit 0 on Windows), and the app starts another and keeps its window. The
Agents row's Restart beside a Codex app left on the old list did not: on
macOS ReopenCodexApp ran osascript "quit" and then `open` on the bundle,
and that open is what brought up a new window.
Now ReopenCodexApp keeps its check (only a bundle the row lists as left on
the old list) and calls provider.RestartCodexApp, which ends each process
whose command line starts with <bundle>/Contents/ and is the app's own
app-server (isCodexAppOwnServer: an app-server, not --listen), waits up to
10s for them to be gone, and errs when none ran. The app, its window and
another program's --listen server are left alone. The confirm says only the
app-server restarts and the window stays; the status says "Codex app-server
restarted" (zh, zh-TW, ja, de). app.js stays under its budget, with no raise (1,310,458 of 1,310,460
after rebasing on 97332140a): the "asked first" comment went and
appReopen's shrank. The
agent-wiring page says the same.
The model picker: the app's restart recovery doesn't refetch its models
query; it refetches on the next window focus once the list is over 5
minutes old (staleTime), or when the picker is mounted again.
Run (rebased on origin/main, at this commit's tree):
- go test ./internal/agent: ok (280s).
- go test ./internal/provider -run 'Codex|Restart': ok. Before the rebase,
the whole package with -skip TestUnreadLoginsWriteErrorsKeepCredentials
(#3632 crashes the binary) was ok except TestFetchAsksASharedBaseOnce and
its two siblings (#3854).
- go test ./internal/gui -run TestCoreScriptBudget: ok.
- GUI: agent-stale-copies in chromium and webkit, 5 languages, 980/440px:
80 pass. i18n-keys: its only red is #3897 ("Runs as"). Before the
rebase codex-app-stale passed too.
- gofmt -l clean; go vet darwin and windows for agent, provider, gui;
linux for agent and provider (gui's linux vet needs wails' cgo here).
- Real app: a clone of ChatGPT.app 26.1021.31345 (APFS clone in a sandbox
HOME, so the bundle is unique to it) run under that HOME. The real
RestartCodexApp ended its app-server 32922 in 3.1s; the same main
process (31894) started app-server 34143, and its one window (2273016)
stayed the only window. The user's own ChatGPT was untouched.
Broken by hand:
- reopenApp back to appQuit + appOpen: TestCodexAppReopen red ("did quit
…, open …").
- isCodexAppServer in place of isCodexAppOwnServer: TestRestartCodexApp…
red (ended [2 3], the --listen one too).
- the bundle prefix dropped: red (ended [2 4], another bundle's).
Not tried: the picker refreshing in a signed-in app (the sandbox app isn't
signed in); Windows has no such Restart (the row's Restart for the Codex
app is macOS only; Windows switches already end codex.exe with exit 0 and
the app keeps its window, 3aead9c62).
zhibukaixinyao (Discord #help, 10-27) asked when Windows gets the
"restart Codex" step: the Windows GUI has no Restart button, so after an
account switch the Codex app kept sending on, and showing the limits of,
the account it started with until the user quit and reopened it.
noteCodexSwitch now hands the app-server pid it recorded as left on the
old account to codexApp's stale set, the same set a route change fills.
KeepCodexAppOnItsProvider's step ends it once Codex is idle and no turn is
open, and the app starts another that reads auth.json afresh. This covers
a switch made in the gateway's process: the GUI's switch and
SwitchWhenSpent. Together with 3aead9c62 (the Windows app's app-server is
found at all) this needs no restart on Windows, macOS or Linux.
Run (at 9bfe68048 + this change):
- TestCodexAppServerRestartedOnAccountSwitch (new): nothing ended with no
switch, nothing while a turn is open, pid ended once idle after the
switch and only once, CodexAppStale "" afterwards.
- go test -race -count=3 -run TestCodexApp ./internal/provider: ok.
- go test ./internal/provider ./internal/agent ./internal/cli (skipping
#3632 and #3854's tests): provider ok, cli ok; agent red only on
TestFolderVarsAreListed, red on main since e4552cca9 (#3884).
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok.
Broken by hand: with the codexAppAccountLeft call removed the new test is
red ("switched, idle: ended [], want [60]").
Not tried: a real account switch on the Windows box (the box's Codex app
isn't signed in to two ChatGPT accounts). A switch made from the
CLI runs in its own process and still only sets the notice; the running
gateway doesn't hear of it.
zhibukaixinyao on Discord (#help, 10-27): on Windows there is no restart,
and Codex keeps the old provider until it is restarted by hand.
The cause: isCodexAppServer took the Windows app's codex to live under
WindowsApps\OpenAI.*, which was a guess. The real ChatGPT/Codex MSIX
(OpenAI.Codex 26.1021.3705.0, installed with winget OpenAI.ChatGPT)
runs it from %LOCALAPPDATA%\OpenAI\Codex\bin\<hash>\codex.exe
... app-server --analytics-default-enabled. So findCodexApp found
nothing, KeepCodexAppOnItsProvider never ended it, and the
"still signed in to the old account" notice never showed on Windows.
Now that path counts too (WindowsApps is kept); the npm, WinGet Links
and --listen app-servers still don't.
Run:
- go test ./internal/provider -skip TestUnreadLogins: ok except
TestFetchAsksASharedBaseOnce and two siblings, red on main and filed
as #3854; TestUnreadLoginsWriteErrorsKeepCredentials crashes the
package on main, filed as #3632. Neither is touched here.
- go test -run 'TestCodexApp|TestFindCodexApp|TestIsCodexClient'
./internal/provider ./internal/agent: ok.
- gofmt -l; go vet on darwin, linux -tags nogui and windows; go build
for darwin, windows and linux nogui: clean.
- On the Windows box (Windows 11, real Codex app 26.1021, sandbox
USERPROFILE/APPDATA/LOCALAPPDATA, gateway on :3491, a fake custom
provider): `magpie codex fakeai/fake-1` ended the app's app-server
and the app started a new one (pid 63320 -> 56692); `magpie codex
default` did it again (56692 -> 56216). The app logged the exit as
expected (code 0, app_server_restart_recovery_done) and kept its
window. The origin/main build left pid 56216 through both.
Broken by hand: with the old WindowsApps-only check,
TestCodexAppOwnServer and TestFindCodexApp go red on the real Windows
command line.
Not tried: a signed-in Windows app switching ChatGPT accounts, the
durable host, and the managed `codex app-server daemon` (winget's
portable codex 0.161 refuses to run it: "the CLI package does not match
this platform or executable").
JiangLiuer222 on X: after Disconnect the Codex app kept sending to
127.0.0.1:3425, now and then. The app's app-server reads config.toml only
as it starts, so one started while Codex was connected kept the gateway's
base URL until the user quit the app.
Now the gateway's watcher (KeepCodexAppOnItsProvider, from 8b0132b3d)
ends the app's own app-server whenever what it reads at start and magpie
writes changes: model_provider, openai_base_url, model_catalog_json, the
magpie table's base_url and the used-up takeover (codexAppRoute, through
the provider.CodexAppRoute hook, which replaces CodexAppOnMagpie). Same
guards as before: never while a Codex request is in flight or ended in
the last 10s, never with a turn open, only on magpie's Codex home, a
clean exit. At its first look only a used-up account's app-servers are
ended, as before.
Also checked: after Disconnect nothing writes the base URL back. Failover
and the stale-model rewire skip a disconnected Codex, and the takeover
paths in Sync need Codex joined or on magpie.
Run at this tree (on origin/main 32ea16c5a), private GOCACHE, sandbox HOME:
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
(internal/agent, internal/provider); go build darwin, windows, linux
nogui.
- go test -count=1 -run Codex ./internal/provider ./internal/agent: ok
(at 47175a68f); -run CodexApp again at 32ea16c5a: ok.
- Broken by hand: comparing only the takeover flag (the old condition)
made TestCodexAppServerRestartedOnDisconnect red ("disconnected, idle:
ended [], want [60]").
- Real app: ChatGPT.app 26.1013 under a sandbox HOME (CFFIXED_USER_HOME),
this build's magpie serve on 3492, Codex connected to a custom
provider by magpie codex fakeai/fake-1. magpie codex default: the
app's app-server 76497 ended within 5s, the app started 77343 and
logged "Codex CLI process exited classifiedAsExpected=true code=0";
window kept. Connect again: 77343 -> 79138. The owner's own app-server
(1902, HOME=~) was untouched.
Not tried: Windows and Linux real apps, a turn running during the
switch (unit-tested only), a signed-in sandbox app (it was signed out,
so no turn was sent to see the new route used).
Ethereal499 and Isdavexxx on X, MasterYi on Discord, #540. The Codex app greys
Send for every model, magpie's too, while the ChatGPT account it is signed in
to is used up. Its composer's gate (ChatGPT.app 26.1013) reads authMethod
"chatgpt" plus rate limit allowed=false, and it asks account/read only when its
app-server starts. ef37b6fb7 (v0.1.1381) could fail in practice:
- (a) The reopen was macOS-only, ran once per time out, only from the GUI
process. A Windows or Linux user, a magpie without its window, or a second
time out stayed greyed.
- Switch-back: the app stayed on magpie (authMethod null, no cloud tasks or
Log out) after the reset. Nothing restarted it.
- (c) Detection lag: the account was read every 5 minutes.
- The notice sat on the Providers page, not on Codex's Agents row.
Now:
- The gateway process (`provider.KeepCodexAppOnItsProvider`, every 3s, on
every OS) ends the Codex app's own app-server each time `Agent.AppOut`
flips, both ways. The app starts another at once and reads account/read
afresh. Its window, threads and drafts stay.
- It never ends an app-server while a Codex request is in flight through
magpie or ended in the last 10s (`Server.CodexBusy`, Codex's requests only),
or while a session under the Codex home has a turn open (`codexTurnOpen`).
- It ends only the app's own app-server. That one runs on stdio; one another
program starts with `--listen` is left alone (Miyi Helper runs one on this
Mac). It must also run on magpie's Codex home (`proc.EnvOf`: ps -E on macOS,
/proc on Linux; Windows can't tell).
- The exit is clean (`proc.End`: SIGTERM, or TerminateProcess with code 0 on
Windows). The app shows any other exit as a crash.
- A listing that fails is taken up again at the next look. One that outlives
3 ends, or is denied, makes the row say to quit and reopen.
- The active account is read every minute while it is held or a window is at
90% or more (`codexLookEvery`).
- Codex's Agents row says "On magpie until <reset> · ChatGPT allowance used
up". Hovering it, or opening the row, says what is off until then (cloud
tasks, the usage meter, Log out) and that it all comes back on its own. In
en, zh, zh-TW, ja and de.
- Removed: gui's keepCodexAppSending/codexAppOut, provider's episode
bookkeeping, and the Providers-page notice.
Not changed, by design:
- A Codex own model that no magpie account serves stays as it is: magpie
can't serve that turn.
- Account discovery off and "Only switch Codex's sign-in" (login=chatgpt) are
the user's own choices, and are left alone.
Full suite green at cff1a9686 (on origin/main 6ce0f14b9), below. At
4541b3e97 (rebased on 430e3050d, which touched gateway.go, app.js and
i18n.js beside this) ran: gofmt -l, go build ./..., go vet on darwin,
linux (-tags nogui ./...) and windows; go test -run Codex ./internal/provider
./internal/agent ok; GUI codex-app-out (22 ok) and codex-app-stale (20 ok),
chromium and webkit. Pushed rebased on b92cb2f59 (two more commits,
neither in these files), built, not rerun.
Run at this commit (cff1a9686, on origin/main 6ce0f14b9), with a private
GOCACHE (another session ran go clean -cache mid-run):
- gofmt -l: clean. go build ./...: ok.
- go vet: darwin (touched packages); GOOS=linux -tags nogui ./...;
GOOS=windows (touched packages).
- go test -count=1 -timeout 45m: internal/proc, internal/provider,
internal/agent, internal/gateway, internal/gui all ok, skipping four
tests red on main without this change, each already filed:
TestUnreadLoginsWriteErrorsKeepCredentials (#3632, a synctest crash
since 091153bf) and TestFetchAsksOneListOnceForTwoBasesOfIt,
TestFetchUnionsProtocolListsWithoutChat, TestFetchAsksASharedBaseOnce
(#3854, since 6eb510f78). All three of the latter fail the same at
origin/main 6ce0f14b9 and at 353519f55 without this commit.
- GUI at cff1a9686, chromium and webkit, 231 cases ok: codex-app-out (5 languages, 980 and 440px),
i18n-keys, gui-de/ja/zh-tw, codex-app-stale, codex-accounts-via,
agent-stale-copies, agent-app-restart, agent-failover, agent-connect,
agent-layout, agent-expand-steady, agent-connected-unfolded,
agent-notice-lang and codex-signin-always.
- Windows box (cross-built test binaries): proc and provider's Codex app
tests pass. TestEndExitsClean passes there and goes red with exit code 1.
- Broken by hand, each went red:
- Codex-only busy: TestCodexBusy.
- The 90% cadence: TestCodexLookEvery.
- The retry after a failed listing: TestCodexAppServerUnknown.
- The turn guard: TestCodexAppServerRestartedEachWay.
- The --listen exclusion: TestCodexAppOwnServer.
- Code 0 on Windows: TestEndExitsClean.
- The row's notice: codex-app-out.test.cjs, 4 of 4.
- Real app: ChatGPT.app 26.1013 in a sandbox HOME/CODEX_HOME, with this
build serving on 3492/3493. Codex was put on magpie as Sync does for a held
account (model_provider = "magpie", codex.out in stash.json). OpenAI's usage
reading to the app was never faked.
- The first listing ran out at load ~200, so the timeout is now 30s. The
next look ended the app-server, and the app started another 12s later.
Its profile went from "Pro · Usage · Log out" to "magpie" with no reopen,
and /api/state carried appOut.
- Undoing it ended the app-server again, and the profile came back to Pro,
Usage and Log out.
- The owner's own ChatGPT app (its app-server on ~/.codex) was never
touched.
- One webkit codex-app-out run at load 291 had one red subtest, name lost.
It passed 3 of 3 alone and in two full webkit runs.
Not tried:
- The Windows Store app (not installed on the box), and a real Codex app
on Linux.
- A real used-up account.
- A turn running in the real app while the switch happens (unit-tested
only).