danzi002 on Discord: with requires_openai_auth = false on Codex's provider,
switching the Codex account in magpie still restarted the Codex app's
app-server and said the app and daemon were left on the old account.
Codex's provider with no requires_openai_auth = true goes by no ChatGPT
account: codex-rs ModelProviderInfo::account_state answers no account, and
resolve_provider_auth sends the table's key, never auth.json. So which
account auth.json holds is nothing a running Codex uses.
- provider.CodexNoAccount (set to agent.codexNoAccount): the config's top
model_provider is not openai, has a [model_providers] table, and the table
doesn't say requires_openai_auth = true. A profile, the built-in provider,
no table or an unreadable config count as false (may use the account).
- codexAppStep forgets a switch (and a spent switch) while it holds, so the
app-server is left running; a route change still restarts it.
- CodexAppStale / CodexDaemonStale say nothing, and `magpie accounts`'
switch line says nothing needs restarting.
- Kept: route-change restarts (model_provider, openai_base_url,
model_catalog_json, base_url, catalog hash: read only as the app-server
starts) and the daemon's model-list restarts; and switch restarts when
magpie writes requires_openai_auth = true (ChatGPT sign-in with room).
Run (mote-run; full suite at this change on e0ad48641):
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
./..., go build for darwin/linux(nogui)/windows: ok.
- go test -tags nogui -timeout 45m ./...: 81 packages ok, no FAIL.
- New tests: TestCodexNoAccountSwitchRestartsNothing (provider),
TestCodexNoAccountFollowsRequiresOpenAIAuth and
TestCodexNoAccountOfEachConfig (agent).
- Broken by hand: codexNoAccount returning false in provider made
TestCodexNoAccountSwitchRestartsNothing red (ended the app-servers);
agent's codexNoAccount returning false made both agent tests red.
- Real codex-cli 0.165.0 in a sandbox CODEX_HOME with a provider table at
requires_openai_auth = false: app-server account/read and getAuthStatus
answered no account before and after auth.json was switched from a@x to
b@x, and `codex exec` against a loopback capture server sent
`Authorization: Bearer <the table's key>` with no chatgpt-account-id for
both accounts.
After rebasing onto origin/main (2 commits: gateway desktop probe,
usage purposes): go vet ./... and go test of internal/agent, provider,
cli, usage and gateway at the pushed head: ok.
Not tried: the real Codex desktop app (macOS or the Windows MSIX) through
a switch; a daemon with live sessions through a switch; the GUI suite
(no GUI asset changed; the switch notice reads CodexAppStale).
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).
After an account switch, Codex's accounts say the Codex app is still on
the account before. A user asked for a button that does the restart for
them. The notice now has Restart: magpie's own dialog asks first, then
magpie ends the app's own app-server (POST /api/codex/daemon/restart-app,
provider.RestartSwitchedCodexApp), waits for it to be gone and for the
app to start another, which reads auth.json and the new account. The
window stays, as the owner chose on 10-27 (quit and reopen opened a new
window). It ends the app-server now even mid-turn, after the confirm says
a running turn stops.
The app-server is ended as a clean exit (proc.End), never killed: the app
shows a killed app-server as a crash, so there is no force fallback. Each
failure says so in the notice, in the reader's language: the app isn't
running, the app-server couldn't be ended, the app didn't start another
within 20s, or the listing failed ("couldn't tell", not success).
Only the Codex desktop app gets the button (macOS ChatGPT.app/Codex.app,
the Windows Codex app). CLI agents in a terminal get none: restarting
them would lose the user's session. The text stays as it was.
app.js is 457 bytes smaller than main (comments cut), no budget raise.
The button and the confirm and four notices are in zh, zh-TW, ja and de.
Run:
- mote (darwin): gofmt -l clean; go vet agent, provider, gui on darwin
and GOOS=windows; GOOS=linux go vet agent and provider (gui needs
WebKitGTK headers, which neither mote nor magpie-desktop has).
- mote: go test provider -run 'TestRestartSwitchedCodexApp|TestCodexApp|
TestRestartCodexApp' ok; agent TestRestartSwitchedCodexAppSays,
TestEveryNotice ok; gui TestCoreScriptBudget etc. ok.
- win-run: the same provider tests ok, with real helper processes ended
by proc.End (TerminateProcess) and a new one started.
- mote GUI: codex-app-stale + i18n-keys, chromium and webkit, en zh
zh-TW ja de, 900 and 480px: 54/54.
- Broken by hand: TestRestartSwitchedCodexApp and ...Real go red when
the wait for a new app-server always holds ("none back: <nil>").
- Real app: on mote, the real ChatGPT.app 26.1021 opened under the
test's sandbox HOME (not signed in), its app-server 5232 ended, the
app started 5901 within 3s, no diagnostic report; the app was quit.
(A throwaway test, not committed.)
Not tried: a signed-in Codex app switching between two real accounts
(whether its window shows the new account's limits after this); the real
Windows Codex app; the Restart clicked in the real magpie GUI.
蛋仔 (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).
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.
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).