codex: the ChatGPT app left on "hit a snag" after a switch off a used-up account is reopened without the Restart tick (RealZeroP27 on X)
RealZeroP27 (switch only, requests not through magpie, ChatGPT app on
macOS 27.2.1): when the account ran out and magpie signed Codex in to the
next one, the app showed "ChatGPT 遇到了问题 请重试" and only a manual
restart cleared it.
Cause: magpie did end the app-server (a switch off a used-up account
always does), and the signed-in ChatGPT app fails on the one it starts
next, a fault in the app (codex_app_crash.go, #4550). magpie reopens the
app on that page only with "Restart the Codex app" ticked, which ships
off (15acba534, Michael25651150), so the page stayed.
Now an end made for a used-up account (a switch off one, or the takeover
in; crashSpent) has the app quit and opened once on that page whatever the
tick says: the app was greyed on that account already and the page is all
its window shows. Every other end (route change, switch among accounts
with room) still waits for the tick. The page check (no composer, no turn
or request since) is unchanged. The Windows reopen when no app-server came
back (codexAppGotNone) is unchanged and stays tick-gated.
This partly reverses 15acba534's gate for the used-up case; a product
call. A quit of a working app is still never done unasked.
Run on mote at this head:
- go test -count=1 ./internal/provider ./internal/agent: ok.
- go vet ./internal/provider on darwin, GOOS=windows, GOOS=linux nogui;
gofmt -l clean.
- TestCodexAppReopenedAfterASpentEndUnasked (switch, takeover) is new;
TestCodexAppNotQuitUnasked now ends for a route change.
Broken by hand: spentEnd forced false -> the new test red in both subtests.
Not tried: the real ChatGPT app, the Windows box. No GUI file touched.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -24,12 +24,16 @@ import (
|
||||
// and no Codex turn has started since nor a request gone through magpie
|
||||
// (the page has no composer: one that ran means it came back), magpie
|
||||
// quits the app and opens it again, once (CodexAppRelaunch: ⌘Q's quit on
|
||||
// macOS, never forced; the Agents row's Restart on Windows), but only
|
||||
// with the user's "Restart the Codex app" on (RestartApp): unasked, a
|
||||
// quit of the user's app read as magpie force-restarting it whenever
|
||||
// quota ran out (Michael25651150 on X). Where that is off or can't be
|
||||
// done, or the app didn't quit, the Agents row says to (snag,
|
||||
// CodexAppSnagged) until the app-servers seen then are gone.
|
||||
// macOS, never forced; the Agents row's Restart on Windows). After an end
|
||||
// for a used-up account (crashSpent) that follows magpie's account switch
|
||||
// itself, with nothing to turn on: the page is all the window shows, the
|
||||
// switch is what the user asked magpie for, and only a quit and open
|
||||
// clears it (RealZeroP27 on X: "只能通过手动重启 codex 解决"). After any
|
||||
// other end it needs the user's "Restart the Codex app" (RestartApp):
|
||||
// unasked, a quit of a working app read as magpie force-restarting it
|
||||
// (Michael25651150 on X). Where it is off or can't be done, or the app
|
||||
// didn't quit, the Agents row says to (snag, CodexAppSnagged) until the
|
||||
// app-servers seen then are gone.
|
||||
|
||||
// CodexAppCrashed and CodexAppRelaunch are set by the agent package.
|
||||
// CodexAppCrashed says whether the Codex app logged the page it shows
|
||||
@@ -78,6 +82,7 @@ func codexAppCrashStep(ctx context.Context, now time.Time, busy func() (int, tim
|
||||
c := &codexApp
|
||||
c.Lock()
|
||||
since, by, snag, snagPids := c.crashSince, c.crashBy, c.snag, slices.Clone(c.snagPids)
|
||||
spentEnd := c.crashSpent
|
||||
c.Unlock()
|
||||
home := codexHome()
|
||||
if snag {
|
||||
@@ -108,14 +113,14 @@ func codexAppCrashStep(ctx context.Context, now time.Time, busy func() (int, tim
|
||||
if !now.Before(by) {
|
||||
c.Lock()
|
||||
if c.crashBy.Equal(by) {
|
||||
c.crashSince, c.crashBy = time.Time{}, time.Time{}
|
||||
c.crashSince, c.crashBy, c.crashSpent = time.Time{}, time.Time{}, false
|
||||
}
|
||||
c.Unlock()
|
||||
}
|
||||
return
|
||||
}
|
||||
c.Lock()
|
||||
c.crashSince, c.crashBy = time.Time{}, time.Time{}
|
||||
c.crashSince, c.crashBy, c.crashSpent = time.Time{}, time.Time{}, false
|
||||
c.Unlock()
|
||||
// the page has no composer: a request or a turn since means the app
|
||||
// came back (its Try again) and is in use, never cut short
|
||||
@@ -134,7 +139,7 @@ func codexAppCrashStep(ctx context.Context, now time.Time, busy func() (int, tim
|
||||
cancel()
|
||||
err := errNoRelaunch
|
||||
switch {
|
||||
case !codexRestartsApp():
|
||||
case !codexRestartsApp() && !spentEnd:
|
||||
// quitting the user's app and opening it again, unasked, takes
|
||||
// their window with it (Michael25651150 on X: "额度用尽时会强制重启
|
||||
// codex 客户端"); the Agents row says to, and its Try again or
|
||||
|
||||
@@ -279,11 +279,12 @@ func TestCodexAppRowRestartWatchesForTheErrorPage(t *testing.T) {
|
||||
}
|
||||
|
||||
// Michael25651150 on X: "额度用尽时会强制重启 codex 客户端". With the
|
||||
// user's "Restart the Codex app" off (as it ships), quota running out
|
||||
// still restarts the app's app-server, which the takeover needs, but the
|
||||
// app showing its error page after it is never quit and opened again
|
||||
// unasked: the Agents row says to, and the app's Try again or the row's
|
||||
// Restart is the user's. Nor is a Windows app that started no app-server.
|
||||
// user's "Restart the Codex app" off (as it ships), a change magpie makes
|
||||
// that isn't a used-up account's (where Codex sends its requests) still
|
||||
// restarts the app's app-server, but the app showing its error page after
|
||||
// it is never quit and opened again unasked: the Agents row says to, and
|
||||
// the app's Try again or the row's Restart is the user's. Nor is a Windows
|
||||
// app that started no app-server.
|
||||
func TestCodexAppNotQuitUnasked(t *testing.T) {
|
||||
signIn(t)
|
||||
s := stubCodexApp(t)
|
||||
@@ -293,9 +294,9 @@ func TestCodexAppNotQuitUnasked(t *testing.T) {
|
||||
idle := func() (int, time.Time) { return 0, now.Add(-time.Minute) }
|
||||
s.running = []int{60}
|
||||
codexAppStep(context.Background(), now, idle)
|
||||
s.on = true // the account used up: magpie serves it
|
||||
s.route = "other" // where Codex sends changed, no account used up
|
||||
if got := codexAppStep(context.Background(), now, idle); !slices.Equal(got, []int{60}) {
|
||||
t.Fatalf("ended %v, want [60]: the takeover needs the app-server's restart", got)
|
||||
t.Fatalf("ended %v, want [60]: the route change needs the app-server's restart", got)
|
||||
}
|
||||
c.page, c.at = true, now.Add(2*time.Second)
|
||||
now = now.Add(3 * time.Second)
|
||||
@@ -309,3 +310,50 @@ func TestCodexAppNotQuitUnasked(t *testing.T) {
|
||||
t.Fatalf("no app-server: reopened %d, stuck %v", reopened, stuck)
|
||||
}
|
||||
}
|
||||
|
||||
// RealZeroP27 on X (switch only, requests not through magpie): quota ran
|
||||
// out, magpie signed Codex in to the next account, ended the app's
|
||||
// app-server for the app to read it, and the ChatGPT app showed "hit a
|
||||
// snag" till the user quit and opened it. The account was used up, so the
|
||||
// app was greyed already and the page is all its window shows: it is
|
||||
// quit and opened once with "Restart the Codex app" off too, for a
|
||||
// switch off a used-up account and for the takeover in.
|
||||
func TestCodexAppReopenedAfterASpentEndUnasked(t *testing.T) {
|
||||
for _, name := range []string{"switch", "takeover"} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
signIn(t)
|
||||
s := stubCodexApp(t)
|
||||
c := stubCodexCrash(t)
|
||||
codexRestartsApp = func() bool { return false }
|
||||
now := time.Now()
|
||||
idle := func() (int, time.Time) { return 0, now.Add(-time.Minute) }
|
||||
s.running = []int{60}
|
||||
codexAppStep(context.Background(), now, idle)
|
||||
if name == "switch" {
|
||||
codexAppSwitched(true, true)
|
||||
} else {
|
||||
s.on = true
|
||||
}
|
||||
if got := codexAppStep(context.Background(), now, idle); !slices.Equal(got, []int{60}) {
|
||||
t.Fatalf("ended %v, want [60]", got)
|
||||
}
|
||||
c.page, c.at = true, now.Add(2*time.Second)
|
||||
now = now.Add(3 * time.Second)
|
||||
codexAppStep(context.Background(), now, idle)
|
||||
if c.relaunch != 1 || CodexAppSnagged() {
|
||||
t.Fatalf("relaunched %d, snag %v: want reopened once", c.relaunch, CodexAppSnagged())
|
||||
}
|
||||
// the next end, for a route change, is not a spent one's
|
||||
s.on = false
|
||||
s.running = []int{100}
|
||||
s.route = "other"
|
||||
codexAppStep(context.Background(), now, idle)
|
||||
c.at = now.Add(2 * time.Second)
|
||||
now = now.Add(3 * time.Second)
|
||||
codexAppStep(context.Background(), now, idle)
|
||||
if c.relaunch != 1 {
|
||||
t.Fatalf("relaunched %d after a later end that was not a used-up account's", c.relaunch)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,8 +322,12 @@ var codexApp struct {
|
||||
// the app showed that page and magpie couldn't reopen it, while the
|
||||
// app-servers in snagPids (those running then) run
|
||||
crashSince, crashBy time.Time
|
||||
snag bool
|
||||
snagPids []int
|
||||
// crashSpent: an end in that window was made for a used-up account
|
||||
// (spent), where the app was greyed already and what it shows after
|
||||
// is no working window to leave alone (codexAppCrashStep)
|
||||
crashSpent bool
|
||||
snag bool
|
||||
snagPids []int
|
||||
}
|
||||
|
||||
// codexAppBackEvery is how often the app-servers left on the takeover
|
||||
@@ -671,6 +675,7 @@ func codexAppStep(ctx context.Context, now time.Time, busy func() (int, time.Tim
|
||||
if len(ended) > 0 {
|
||||
log.Printf("codex: ended the Codex app's app-server %v for the app to start another: %s", ended, c.why)
|
||||
watchCodexAppCrashLocked(now)
|
||||
c.crashSpent = c.crashSpent || spent
|
||||
}
|
||||
return ended
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ func stubCodexApp(t *testing.T) *codexAppStub {
|
||||
codexApp.ended, codexApp.backBy, codexApp.spent, codexApp.why = nil, time.Time{}, false, ""
|
||||
codexApp.back, codexApp.backAt = nil, time.Time{}
|
||||
codexApp.crashSince, codexApp.crashBy, codexApp.snag, codexApp.snagPids = time.Time{}, time.Time{}, false, nil
|
||||
codexApp.crashSpent = false
|
||||
codexApp.Unlock()
|
||||
}
|
||||
oldCrashed, oldRelaunch, oldOff := CodexAppCrashed, CodexAppRelaunch, CodexTakeoverOff
|
||||
|
||||
Reference in New Issue
Block a user