codex: a switch of the preferred account leaves the Codex app running unless asked (Michael25651150 and ykj5353 on X)

After v0.1.3562 a switch of Codex's ChatGPT account made by hand in
magpie, between accounts that both had room, still ended the Codex
app's app-server with "Restart the Codex app when magpie switches its
account back" off. The app shows that as an error, relaunches, and
signs in as the new identity. ChatGPT.app 26.1103+ keeps its sidebar
projects per ChatGPT identity (electron-account-renderer-state-v1), so
on an identity that never had them it shows "没有项目" and every thread
under Recent: ykj5353's screenshot is the Codex app's sidebar, not
magpie's Sessions page.

codexAppStep no longer counts c.switched && !c.auto as by hand. Such a
switch is left running, logged, and the account rows' "still signed in
as" notice with its Restart is the way to follow, as for magpie's own
switch back. Still restarted with the tick off: a switch off a used-up
account (needed, the app greys Send there), Connect/Disconnect, the
takeover in and the takeover turned off by hand. RestartApp on restarts
on every switch as before.

Run (mote, at base 40ca0c88d; rebased onto bc0d9e873, whose provider changes touch no codex file): gofmt -l; go vet ./internal/provider for
darwin, GOOS=linux -tags nogui, GOOS=windows; go test -count=1
./internal/provider: ok (150.6s), vet ok on all three.

Broken by hand: putting `c.switched && !c.auto ||` back into byHand
turns TestCodexAppLeftRunningForMagpiesOwnChanges red ("switched by the
user after magpie: ended [101]").

Not tried: a real ChatGPT.app switch between two real accounts. Not
changed: during the takeover the app has no account and shows no
projects by its own rule; magpie can't fix that through the state file.
A user whose projects already went missing gets them back by quitting
the app fully and reopening it after ~30s, when carryCodexProjects
copies them to the current identity, if that identity has no project
list of its own yet.
This commit is contained in:
yetone
2026-11-10 18:26:39 +08:00
parent bc0d9e8739
commit 248268ce4c
3 changed files with 41 additions and 22 deletions
File diff suppressed because one or more lines are too long
+25 -15
View File
@@ -470,27 +470,37 @@ func codexAppStep(ctx context.Context, now time.Time, busy func() (int, time.Tim
// quota ran out mid-turn would hold their restart, and the app's grey
// Send, for up to codexTurnWindow (xiaoq6285 on Discord)
into := changed && out && (!c.seen || !c.out)
// what changed magpie changed by itself and the app works without:
// the switch back once the account has room, and the takeover out at
// the reset. The ChatGPT app shows the end of its app-server as an
// error and relaunches (#4550), so that waits for the user to restart
// it unless they asked magpie to (RestartApp; atom0964 on Discord: both
// of Codex's sign-in ticks off, and magpie still restarted the app to
// switch accounts). A switch the user made, a Connect or a Disconnect
// is theirs, and restarts it, and so does the takeover turned off by
// hand (CodexTakeoverOff). So does whatever leaves the app-server on
// a used-up account: the takeover in, the first look on one and a
// switch off one. The app greys Send for every model while that
// account's rate limit says not allowed and reads the account only as
// its app-server starts (8b0132b3d), so nothing magpie serves would
// reach it until a restart.
byHand := c.switched && !c.auto || c.seen && c.route != route && c.out == out || offByHand
// what the app works without: a switch among accounts with room,
// magpie's own switch back or one the user made, and the takeover out
// at the reset. The ChatGPT app shows the end of its app-server as an
// error and relaunches (#4550), and on its new account shows that
// account's projects, none for one that never had the app open (the
// app keeps them per ChatGPT identity, codex_projects.go): "switching
// the preferred account force-restarts the client, and the projects
// are lost" (Michael25651150 on X, after 15acba534). So that waits for
// the user to restart it unless they asked magpie to (RestartApp;
// atom0964 on Discord: both of Codex's sign-in ticks off, and magpie
// still restarted the app to switch accounts); the account rows say
// the app is still on the account before (CodexAppStale), with a
// Restart. A Connect or a Disconnect is the user's, and restarts it,
// and so does the takeover turned off by hand (CodexTakeoverOff). So
// does whatever leaves the app-server on a used-up account: the
// takeover in, the first look on one and a switch off one. The app
// greys Send for every model while that account's rate limit says not
// allowed and reads the account only as its app-server starts
// (8b0132b3d), so nothing magpie serves would reach it until a
// restart; an app-server left on an account that runs out later is
// restarted then (restartCodexAppLeftOnSpent).
byHand := c.seen && c.route != route && c.out == out || offByHand
needed := into || c.switched && c.spent
// left on the takeover: the app-servers it started while magpie was
// Codex's provider, which show no account till they restart
leftBack := false
if changed && !byHand && !needed && !codexRestartsApp() {
why := "magpie switched Codex's ChatGPT account back"
if c.switched && !c.auto {
why = "Codex's ChatGPT account was switched"
}
if !c.switched {
why = "magpie gave Codex back its ChatGPT account after the reset"
leftBack = c.out && !out
+15 -6
View File
@@ -1178,21 +1178,30 @@ func TestCodexAppLeftRunningForMagpiesOwnChanges(t *testing.T) {
s.on = false
none("magpie gave Codex back its account at the reset")
// a switch the user made, alone or after one of magpie's
// a switch the user made among accounts with room, alone or beside
// one of magpie's: the app's projects are kept per ChatGPT identity,
// and a restart onto the new one hid them (Michael25651150 on X)
codexAppSwitched(false, true)
codexAppAccountSwitched()
ends("switched by the user after magpie", 101)
none("switched by the user after magpie")
codexAppAccountSwitched()
codexAppSwitched(false, true)
ends("switched by the user, then magpie", 102)
none("switched by the user, then magpie")
codexAppAccountSwitched()
none("switched by the user")
// one off a used-up account: the app greys Send till it restarts
codexAppSpentSwitch()
ends("switched by the user off a used-up account", 101)
// a Connect: where Codex's config sends it changed, not by the takeover
s.route = "connected"
ends("connected", 103)
ends("connected", 102)
// ticked: magpie's changes the app works without restart it as well
// ticked: the changes the app works without restart it as well
restarts = true
codexAppSwitched(false, true)
ends("RestartApp on, magpie switched back", 104)
ends("RestartApp on, magpie switched back", 103)
codexAppAccountSwitched()
ends("RestartApp on, switched by the user", 104)
s.on = true
ends("RestartApp on, magpie took over", 105)
s.on = false