codex: turning the takeover off restarts the Codex app, so its ChatGPT projects come back

Herzz____ on X, the Windows Codex app: with Codex through magpie the
sidebar's project list is empty; they use magpie only when their
subscription runs out, and want to switch between magpie and the native
sign-in with the projects whole each way.

What happens. When the ChatGPT account is used up, magpie becomes
Codex's provider (codex.out) without requires_openai_auth: on that
account the app's composer gate greys Send for every model, magpie's
too (#540). Checked again in ChatGPT.app 26.1029's bundle: the gate
picks the account's own snapshot (limitName null) whenever it is
blocked, before any per-model additional_rate_limits, so keeping the
account during the takeover would still grey Send. The app-server then
answers account/read with no account and the app hides its ChatGPT
projects and chats (72ca3d593). magpie never touches projects,
project_roots or a thread's cwd: its thread moves only rewrite
threads.model_provider (sessions/codex_provider.go), so path case or
backslashes on Windows play no part.

What was wrong. Turning the takeover off by hand (the takeover note's
Keep on ChatGPT, the sign-in's Always ChatGPT, or Disconnect) looked
the same to codexAppStep as the reset, magpie's own end of it: with
Restart the Codex app to follow off (the default) the app's app-server
was left running on no account, so the projects stayed gone after the
user switched back to have them, until they restarted the app (the
Windows app has no Restart of its own).

Now Agent.AppOutOff (Always ChatGPT, or Codex not routed through
magpie) reaches the step through provider.CodexTakeoverOff, asked only
as out goes false, and a takeover ended so counts as the user's change:
the app-server is restarted once no Codex turn runs, as for a Connect,
and the Windows app reopened if none comes back (existing path). The
reset itself still leaves the app running and says so (CodexAppBack);
that note now names the ChatGPT projects and chats it lacks (en, zh,
zh-TW, ja, de). agent-wiring.md says the same.

Switching back to native is already in magpie: Agents > Codex > sign-in
> Always ChatGPT (`magpie codex login chatgpt`), or Keep on ChatGPT on
the takeover note; ChatGPT (the default) lets magpie take over again.

Tests: TestCodexAppRestartedWhenTheTakeoverIsTurnedOff (turned off with
a request in flight: held, then restarted; CodexAppBack not said; the
hook asked once; the reset still left running and said);
TestCodexOwnModelOutThenKeptOnChatGPT and
TestCodexOwnModelGoesThroughMagpieWhileUsedUp assert AppOutOff for Keep
on ChatGPT, Disconnect and the reset; codex-app-back.test.cjs checks
the note names the projects in every language.
Broken by hand: offByHand out of byHand, the provider test red (ended
[], want [100]); the login half of AppOutOff false, the Keep on ChatGPT
test red; the routed half false, the Disconnect check red.

Run (mote-run at b87783fbb (this change's tree) on origin/main 547585cd9): gofmt -l clean;
go build ./...; go vet linux -tags nogui ./... and windows ./...,
darwin ./internal/agent ./internal/provider ./internal/gui;
go test -tags nogui ./internal/provider ./internal/agent ok;
GUI codex-app-back, codex-app-out, i18n-keys, i18n-en-no-cjk, gui-ja,
Chromium and WebKit, every language, 155 of 155 pass.
Windows (win-run on xiaomi-gpu): the provider and agent Codex app tests
ok; the box's running Windows Codex app (26.1029) app-server command
line has the shape TestCodexAppOwnServer already holds.
Not run: a real used-up ChatGPT account (none at hand), so the restart
after Keep on ChatGPT is tried with the stubbed step, not the real app;
the full go test ./... waits behind mote's suite lock and runs after the
push, any red filed.
This commit is contained in:
yetone
2026-11-10 04:14:40 +08:00
parent 547585cd9c
commit b3a57b3d8f
10 changed files with 151 additions and 17 deletions
File diff suppressed because one or more lines are too long
+5
View File
@@ -201,6 +201,11 @@ type Agent struct {
// its sign-in only as it opens, sends nothing on it till it is opened
// again (MasterYi on Discord).
AppOut func() bool
// AppOutOff reports the user has turned the takeover (AppOut) off:
// Codex's sign-in set to Always ChatGPT, or Codex not connected. The
// takeover ending so is the user's change, not the reset's, and the
// Codex app's app-server is restarted for it (CodexTakeoverOff).
AppOutOff func() bool
// HoldMatters reports Codex takes magpie's models beside a ChatGPT
// sign-in, so that magpie is its provider while the Codex app holds
// the account (out), or is that already: what the app holds is read
+7
View File
@@ -56,6 +56,13 @@ func init() {
// but not when Codex's account is switched while its provider takes
// no ChatGPT account: the app-server goes by none
provider.CodexNoAccount = codexNoAccount
// and whether the takeover was turned off by the user rather than
// ended by the reset (Keep on ChatGPT, Always ChatGPT, a Disconnect)
provider.CodexTakeoverOff = func() bool {
home, _ := homes()
a := codex(home)
return a.AppOutOff != nil && a.AppOutOff()
}
// and when none starts in place of the one ended, the app is
// reopened on Windows, where its stdout was held open
provider.CodexAppOpen = codexAppOpen
+3 -2
View File
@@ -1939,8 +1939,9 @@ func codexIn(at place) *Agent {
// mark stays for Sync to put it back beside the sign-in: the
// Agents row said "its own models stay in /model" while the Codex
// app was meant to be in its API state (#2267)
Joined: func() bool { return joined() && !asProvider() },
AppOut: func() bool { return asProvider() && !api() && chatGPT() && stashShared()[at.key("codex.out")] == "1" },
Joined: func() bool { return joined() && !asProvider() },
AppOut: func() bool { return asProvider() && !api() && chatGPT() && stashShared()[at.key("codex.out")] == "1" },
AppOutOff: func() bool { return stashShared()[at.key("codex.login")] == "chatgpt" || !routed() },
HoldMatters: func() bool {
return stashShared()[at.key("codex.login")] == "" && chatGPT() &&
(viaBase() || asProvider() && stashShared()[at.key("codex.out")] == "1")
+28
View File
@@ -165,6 +165,10 @@ func TestCodexOwnModelGoesThroughMagpieWhileUsedUp(t *testing.T) {
if cx.AppOut() || !cx.Joined() {
t.Fatalf("allowance back: AppOut %v, Joined %v", cx.AppOut(), cx.Joined())
}
// the reset ended the takeover, not the user (CodexTakeoverOff)
if cx.AppOutOff() {
t.Fatal("allowance back: the takeover reads as turned off by the user")
}
// a model the user picked while out stays theirs when room comes back
codexUsedUp = func() bool { return true }
@@ -181,6 +185,22 @@ func TestCodexOwnModelGoesThroughMagpieWhileUsedUp(t *testing.T) {
if cfg := read(); !strings.Contains(cfg, `model = "fake/m1"`) {
t.Fatalf("picked while out, allowance back:\n%s", cfg)
}
// taken over again, then Codex disconnected: the user's end of it
codexUsedUp = func() bool { return true }
t.Cleanup(func() { codexUsedUp = func() bool { return false } })
if err := cx.Sync(); err != nil {
t.Fatal(err)
}
if !cx.AppOut() || cx.AppOutOff() {
t.Fatalf("taken over again: AppOut %v, AppOutOff %v:\n%s", cx.AppOut(), cx.AppOutOff(), read())
}
if err := cx.Disconnect(); err != nil {
t.Fatal(err)
}
if cx.AppOut() || !cx.AppOutOff() {
t.Fatalf("disconnected: AppOut %v, AppOutOff %v:\n%s", cx.AppOut(), cx.AppOutOff(), read())
}
}
// One ChatGPT account, out, on one of Codex's own models joined beside the
@@ -351,9 +371,17 @@ func TestCodexOwnModelOutThenKeptOnChatGPT(t *testing.T) {
if !cx.AppOut() {
t.Fatalf("used up: not AppOut:\n%s", read())
}
if cx.AppOutOff() {
t.Fatal("taken over: the takeover reads as turned off")
}
if err := cx.Field("login").Set("chatgpt"); err != nil {
t.Fatal(err)
}
// the user's own end of the takeover, which restarts the Codex app's
// app-server so its ChatGPT projects come back (CodexTakeoverOff)
if !cx.AppOutOff() {
t.Fatal("kept on ChatGPT: the takeover doesn't read as turned off by the user")
}
onSignIn := func(when string) {
t.Helper()
if cfg := read(); strings.Contains(cfg, "model_provider =") || strings.Contains(cfg, "model_catalog_json") || !strings.Contains(cfg, `model = "gpt-a"`) {
+1 -1
View File
@@ -2041,7 +2041,7 @@ function appOutSaid(a) {
// still on the app-server it started while magpie was its provider, which
// reads the account only as it starts (a bug report by mail, 11-04)
function appBackSaid(a) {
return t("magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT side until that restarts. Restart does it now; its window stays.", { agent: a.name });
return t("magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT projects or chats until that restarts. Restart does it now; its window stays.", { agent: a.name });
}
// appBackRestart: the Codex app's app-server restarted, so it reads its
+4 -4
View File
@@ -2276,7 +2276,7 @@ const I18N = {
"Till then the {agent} app's ChatGPT side is off: its ChatGPT chats and projects, browser use (its Chrome control), cloud tasks, its account, its usage meter and Log out. They come back after the reset, once the app's app-server restarts: this row offers the restart then.": "在此之前,{agent} 应用的 ChatGPT 功能暂时关闭:ChatGPT 聊天和项目、浏览器操作(Chrome 控制)、云端任务、账号、用量显示和退出登录。额度重置后,等应用的 app-server 重启就会恢复;届时这一行会提供重启按钮。",
"The {agent} app hit an error · quit it and open it again": "{agent} 应用出错了 · 请退出后重新打开",
"Back on ChatGPT · restart the {agent} app to see its account": "已回到 ChatGPT · 重启 {agent} 应用才能看到账号",
"magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT side until that restarts. Restart does it now; its window stays.": "额度重置后,magpie 已把 ChatGPT 账号还给 {agent}。但 {agent} 应用仍在用 magpie 接管期间启动的 app-server,所以在它重启前看不到账号、用量和其他 ChatGPT 功能。点“重启”即可立即重启;窗口保持不变。",
"magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT projects or chats until that restarts. Restart does it now; its window stays.": "额度重置后,magpie 已把 ChatGPT 账号还给 {agent}。但 {agent} 应用仍在用 magpie 接管期间启动的 app-server,所以在它重启前看不到账号、用量以及 ChatGPT 项目和对话。点“重启”即可立即重启;窗口保持不变。",
"Only its app-server restarts, for its ChatGPT account; its window stays. A running turn stops.": "只重启它的 app-server,以读取 ChatGPT 账号;窗口保持不变。正在运行的回合会停止。",
"Keep on ChatGPT (its sign-in's Always ChatGPT) leaves {agent} on its ChatGPT account instead: it shows its own limit message till the reset, and magpie no longer takes it over.": "点「保持 ChatGPT」(即登录方式里的「始终 ChatGPT」)可让 {agent} 留在它的 ChatGPT 账号上:额度重置前它会显示自己的额度用尽提示,magpie 不再接管。",
"Keep on ChatGPT": "保持 ChatGPT",
@@ -7070,7 +7070,7 @@ const I18N = {
"Till then the {agent} app's ChatGPT side is off: its ChatGPT chats and projects, browser use (its Chrome control), cloud tasks, its account, its usage meter and Log out. They come back after the reset, once the app's app-server restarts: this row offers the restart then.": "在此之前,{agent} 應用的 ChatGPT 功能暫時關閉:ChatGPT 聊天和專案、瀏覽器操作(Chrome 控制)、雲端任務、帳號、用量顯示和登出。額度重設後,等應用的 app-server 重新啟動就會恢復;屆時這一行會提供重新啟動按鈕。",
"The {agent} app hit an error · quit it and open it again": "{agent} 應用程式出錯了 · 請結束後重新開啟",
"Back on ChatGPT · restart the {agent} app to see its account": "已回到 ChatGPT · 重新啟動 {agent} 應用才能看到帳號",
"magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT side until that restarts. Restart does it now; its window stays.": "額度重設後,magpie 已把 ChatGPT 帳號還給 {agent}。但 {agent} 應用仍在使用 magpie 接管期間啟動的 app-server,所以在它重新啟動前看不到帳號、用量和其他 ChatGPT 功能。點「重啟」即可立即重新啟動;視窗保持不變。",
"magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT projects or chats until that restarts. Restart does it now; its window stays.": "額度重設後,magpie 已把 ChatGPT 帳號還給 {agent}。但 {agent} 應用仍在使用 magpie 接管期間啟動的 app-server,所以在它重新啟動前看不到帳號、用量以及 ChatGPT 專案和對話。點「重啟」即可立即重新啟動;視窗保持不變。",
"Only its app-server restarts, for its ChatGPT account; its window stays. A running turn stops.": "只重新啟動它的 app-server,以讀取 ChatGPT 帳號;視窗保持不變。正在執行的回合會停止。",
"Keep on ChatGPT (its sign-in's Always ChatGPT) leaves {agent} on its ChatGPT account instead: it shows its own limit message till the reset, and magpie no longer takes it over.": "點「保持 ChatGPT」(即登入方式裡的「始終 ChatGPT」)可讓 {agent} 留在它的 ChatGPT 帳號上:額度重設前它會顯示自己的額度用盡提示,magpie 不再接管。",
"Keep on ChatGPT": "保持 ChatGPT",
@@ -11840,7 +11840,7 @@ const I18N = {
"Till then the {agent} app's ChatGPT side is off: its ChatGPT chats and projects, browser use (its Chrome control), cloud tasks, its account, its usage meter and Log out. They come back after the reset, once the app's app-server restarts: this row offers the restart then.": "それまで {agent} アプリの ChatGPT 機能(ChatGPT のチャットとプロジェクト、ブラウザ操作(Chrome の操作)、クラウドタスク、アカウント、使用量の表示、ログアウト)はオフになります。リセット後、アプリの app-server が再起動すると戻ります。そのときこの行に再起動ボタンが出ます。",
"The {agent} app hit an error · quit it and open it again": "{agent} アプリでエラーが発生しました · 終了してもう一度開いてください",
"Back on ChatGPT · restart the {agent} app to see its account": "ChatGPT に戻りました · アカウントを表示するには {agent} アプリを再起動",
"magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT side until that restarts. Restart does it now; its window stays.": "リセット後、magpie は {agent} に ChatGPT アカウントを戻しました。ただし {agent} アプリは magpie が代わりに応答していた間に起動した app-server のままなので、再起動するまでアカウント、使用量、その他の ChatGPT 機能は表示されません。「再起動」ですぐに再起動します。ウィンドウはそのままです。",
"magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT projects or chats until that restarts. Restart does it now; its window stays.": "リセット後、magpie は {agent} に ChatGPT アカウントを戻しました。ただし {agent} アプリは magpie が代わりに応答していた間に起動した app-server のままなので、再起動するまでアカウント、使用量、ChatGPT のプロジェクトとチャットは表示されません。「再起動」ですぐに再起動します。ウィンドウはそのままです。",
"Only its app-server restarts, for its ChatGPT account; its window stays. A running turn stops.": "app-server だけを再起動して ChatGPT アカウントを読み込ませます。ウィンドウはそのままです。実行中のターンは止まります。",
"Keep on ChatGPT (its sign-in's Always ChatGPT) leaves {agent} on its ChatGPT account instead: it shows its own limit message till the reset, and magpie no longer takes it over.": "「ChatGPT のまま」(サインインの「常に ChatGPT」)を選ぶと {agent} は ChatGPT アカウントのままになります。リセットまではそのアプリ自身の上限メッセージが表示され、magpie は引き継ぎません。",
"Keep on ChatGPT": "ChatGPT のまま",
@@ -16641,7 +16641,7 @@ const I18N = {
"Till then the {agent} app's ChatGPT side is off: its ChatGPT chats and projects, browser use (its Chrome control), cloud tasks, its account, its usage meter and Log out. They come back after the reset, once the app's app-server restarts: this row offers the restart then.": "Bis dahin ist die ChatGPT-Seite der {agent}-App aus: ihre ChatGPT-Chats und -Projekte, Browser-Nutzung (ihre Chrome-Steuerung), Cloud-Aufgaben, ihr Konto, ihre Nutzungsanzeige und Abmelden. Nach dem Zurücksetzen kommt sie wieder, sobald der App-Server der App neu startet: Diese Zeile bietet dann den Neustart an.",
"The {agent} app hit an error · quit it and open it again": "Die {agent}-App hat einen Fehler · beende sie und öffne sie erneut",
"Back on ChatGPT · restart the {agent} app to see its account": "Wieder bei ChatGPT · {agent}-App neu starten, um das Konto zu sehen",
"magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT side until that restarts. Restart does it now; its window stays.": "magpie hat {agent} nach dem Zurücksetzen sein ChatGPT-Konto zurückgegeben. Die {agent}-App läuft noch auf dem App-Server, den sie startete, während magpie sie bediente, und zeigt darum kein Konto, keine Nutzung und nichts von ihrer ChatGPT-Seite, bis dieser neu startet. „Neu starten“ erledigt das jetzt; das Fenster bleibt offen.",
"magpie gave {agent} back its ChatGPT account after the reset. The {agent} app still runs on the app-server it started while magpie served it, so it shows no account, no usage and none of its ChatGPT projects or chats until that restarts. Restart does it now; its window stays.": "magpie hat {agent} nach dem Zurücksetzen sein ChatGPT-Konto zurückgegeben. Die {agent}-App läuft noch auf dem App-Server, den sie startete, während magpie sie bediente, und zeigt darum kein Konto, keine Nutzung und keine ihrer ChatGPT-Projekte oder -Chats, bis dieser neu startet. „Neu starten“ erledigt das jetzt; das Fenster bleibt offen.",
"Only its app-server restarts, for its ChatGPT account; its window stays. A running turn stops.": "Nur sein App-Server startet neu, um sein ChatGPT-Konto zu lesen; das Fenster bleibt offen. Ein laufender Turn wird angehalten.",
"Keep on ChatGPT (its sign-in's Always ChatGPT) leaves {agent} on its ChatGPT account instead: it shows its own limit message till the reset, and magpie no longer takes it over.": "„Bei ChatGPT bleiben“ (bei der Anmeldung „Immer ChatGPT“) lässt {agent} stattdessen bei seinem ChatGPT-Konto: Bis zum Zurücksetzen zeigt es seine eigene Limit-Meldung, und magpie übernimmt nicht mehr.",
"Keep on ChatGPT": "Bei ChatGPT bleiben",
+7 -5
View File
@@ -22,11 +22,11 @@ const codex = (appBack) => ({
});
const words = {
en: { line: "Back on ChatGPT", why: "no usage", restart: "Restart", done: "Codex app-server restarted" },
zh: { line: "已回到 ChatGPT", why: "用量", restart: "重启", done: "Codex 的 app-server 已重启" },
"zh-TW": { line: "已回到 ChatGPT", why: "用量", restart: "重啟", done: "Codex 的 app-server 已重新啟動" },
ja: { line: "ChatGPT に戻りました", why: "使用量", restart: "再起動", done: "Codex の app-server を再起動しました" },
de: { line: "Wieder bei ChatGPT", why: "keine Nutzung", restart: "Neu starten", done: "App-Server von Codex neu gestartet" },
en: { line: "Back on ChatGPT", why: "no usage", proj: "projects", restart: "Restart", done: "Codex app-server restarted" },
zh: { line: "已回到 ChatGPT", why: "用量", proj: "项目", restart: "重启", done: "Codex 的 app-server 已重启" },
"zh-TW": { line: "已回到 ChatGPT", why: "用量", proj: "專案", restart: "重啟", done: "Codex 的 app-server 已重新啟動" },
ja: { line: "ChatGPT に戻りました", why: "使用量", proj: "プロジェクト", restart: "再起動", done: "Codex の app-server を再起動しました" },
de: { line: "Wieder bei ChatGPT", why: "keine Nutzung", proj: "Projekte", restart: "Neu starten", done: "App-Server von Codex neu gestartet" },
};
function serve(lang, posts) {
@@ -91,6 +91,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await said.waitFor();
const s = await said.textContent();
assert.ok(s.includes(w.why), "the row opened says why: " + s);
// what the reporter missed: the app's ChatGPT projects (Herzz____ on X)
assert.ok(s.includes(w.proj), "the row opened names the projects: " + s);
assert.doesNotMatch(s, /\{\w+\}/);
go = page.locator(`${row} .ag-app-back + .ag-vl button`);
await page.waitForFunction(() => {
+20 -2
View File
@@ -70,6 +70,19 @@ var CodexAppRoute func() (route string, out, known bool)
// switch restarts none of them. false when it can't be told.
var CodexNoAccount func() bool
// CodexTakeoverOff is set by the agent package: whether the user has
// turned off magpie's takeover of Codex's used-up account (AppOutOff):
// its sign-in set to Always ChatGPT, as the takeover note's Keep on
// ChatGPT does, or Codex not connected. The takeover ending while it says
// so is the user's change, and the Codex app's app-server is restarted
// for it as for a Connect, Restart the Codex app to follow off too: the
// one the takeover started answers account/read with no account, so the
// app shows none of its ChatGPT projects or chats till it restarts, which
// the user who turned the takeover off to have them back can't tell
// (Herzz____ on X, the Windows app's project list empty). Asked only as
// the takeover ends; false while it isn't set.
var CodexTakeoverOff func() bool
// codexNoAccount is CodexNoAccount, false while it isn't set.
func codexNoAccount() bool {
return CodexNoAccount != nil && CodexNoAccount()
@@ -427,7 +440,11 @@ func codexAppStep(ctx context.Context, now time.Time, busy func() (int, time.Tim
c := &codexApp
c.Lock()
switched := c.switched
wasOut := c.seen && c.out
c.Unlock()
// the takeover ending now: by the user's hand (CodexTakeoverOff), or
// by the reset, which is magpie's own change
offByHand := wasOut && !out && CodexTakeoverOff != nil && CodexTakeoverOff()
// an account switch is nothing to an app-server on a provider that
// takes no ChatGPT account (CodexNoAccount): it is forgotten, and a
// route change later restarts it all the same
@@ -453,13 +470,14 @@ func codexAppStep(ctx context.Context, now time.Time, busy func() (int, time.Tim
// 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. So does whatever leaves the app-server on
// 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
byHand := c.switched && !c.auto || 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
+75 -2
View File
@@ -51,11 +51,12 @@ func stubCodexApp(t *testing.T) *codexAppStub {
codexApp.crashSince, codexApp.crashBy, codexApp.snag, codexApp.snagPids = time.Time{}, time.Time{}, false, nil
codexApp.Unlock()
}
oldCrashed, oldRelaunch := CodexAppCrashed, CodexAppRelaunch
oldCrashed, oldRelaunch, oldOff := CodexAppCrashed, CodexAppRelaunch, CodexTakeoverOff
CodexTakeoverOff = nil
t.Cleanup(func() {
CodexAppRoute, codexAppServersOn, endCodexAppServer, codexTurnRunning = oldOn, oldList, oldEnd, oldTurn
CodexAppOpen, CodexAppReopen, codexSessionsQuiet, codexRestartsApp = oldOpen, oldReopen, oldQuiet, oldRestarts
CodexAppCrashed, CodexAppRelaunch = oldCrashed, oldRelaunch
CodexAppCrashed, CodexAppRelaunch, CodexTakeoverOff = oldCrashed, oldRelaunch, oldOff
reset()
})
// the app's logs as tests find them: no error page, and never reopened
@@ -1288,3 +1289,75 @@ func TestCodexAppBackSaidTillItRestarts(t *testing.T) {
t.Fatal("a failed listing read as the app-server gone")
}
}
// The takeover turned off by the user (the takeover note's Keep on
// ChatGPT, the sign-in's Always ChatGPT, a Disconnect) restarts the Codex
// app's app-server with Restart the Codex app to follow off too, once no
// Codex turn runs: the one the takeover started shows no account, so the
// app's ChatGPT projects and chats stayed gone after the user turned it
// off to have them back (Herzz____ on X, the Windows app). The reset,
// magpie's own end of it, still leaves the app running and says so
// (CodexAppBack). Whether it was turned off is asked only as the takeover
// ends, not at every look.
func TestCodexAppRestartedWhenTheTakeoverIsTurnedOff(t *testing.T) {
signIn(t)
s := stubCodexApp(t)
codexRestartsApp = func() bool { return false }
off, asked := false, 0
CodexTakeoverOff = func() bool { asked++; return off }
now := time.Now()
idle := func() (int, time.Time) { return 0, now.Add(-time.Minute) }
step := func(busy func() (int, time.Time)) []int { return codexAppStep(context.Background(), now, busy) }
s.running = []int{60}
for range 3 {
if got := step(idle); got != nil {
t.Fatalf("on its account: ended %v", got)
}
}
s.on = true
if got := step(idle); !slices.Equal(got, []int{60}) {
t.Fatalf("the takeover: ended %v, want [60]", got)
}
step(idle)
if asked != 0 {
t.Fatalf("asked whether the takeover is off %d times while it ran", asked)
}
// Keep on ChatGPT, with a Codex request in flight: held till it ends
off, s.on = true, false
if got := step(func() (int, time.Time) { return 1, now.Add(-time.Minute) }); got != nil {
t.Fatalf("a Codex request in flight: ended %v", got)
}
if got := step(idle); !slices.Equal(got, []int{100}) {
t.Fatalf("the takeover turned off by hand: ended %v, want [100]", got)
}
if CodexAppBack() {
t.Fatal("restarted, and still said to be left on the takeover")
}
if asked != 1 {
t.Fatalf("asked %d times, want once as the takeover ended", asked)
}
for range 3 {
if got := step(idle); got != nil {
t.Fatalf("after: ended %v", got)
}
}
if asked != 1 {
t.Fatalf("asked %d times after the takeover ended, want once in all", asked)
}
// taken over again, and ended by the reset: left running, and said
off = false
s.on = true
if got := step(idle); !slices.Equal(got, []int{101}) {
t.Fatalf("the takeover again: ended %v, want [101]", got)
}
s.on = false
if got := step(idle); got != nil {
t.Fatalf("the reset with Restart off: ended %v", got)
}
if !CodexAppBack() {
t.Fatal("the app left on the takeover's app-server at the reset isn't said")
}
}