"为什么codex在触发自动更换账号后侧边栏已有的项目文件夹会消失呢".
v0.1.3600 (10bef5fe0) shares every account's projects while the Codex app
is closed. A switch while the app runs can't be helped by a file: the
app (ChatGPT.app 26.1103, early-bootstrap-133 selectRendererOwner, run on
every principal change) parks the old identity's projects and loads the
new one's from memory, and writes its memory over the file. An app open
since before the sharing, or a project added since it was last closed,
shows the new account's empty list. magpie does not quit the app unasked
(15acba534, 248268ce4); the owner chose a hint instead.
codexProjectsLook, from codexProjectsStep's loop while the app is open,
reads the state file: the owner's local projects' folders against those
parked under the other identities. When the owner changed since the last
look and the owner lacks a folder, /api/providers says codexProjects, and
Codex's accounts show "The Codex app shows fewer projects than you have:
quit and open it again" (Got it hushes it; dismiss-projects). A project
removed on the account the user is on is no switch and says nothing. A
closed app clears it: the share runs and the app loads every list as it
opens. The notice is in codexprojects.js, loaded when the state says so,
so the core's budget is unchanged. i18n in zh, zh-TW, ja, de.
Run (mote refused ssh all session; so wsl-run on the Linux box):
- go test -tags nogui -run 'TestCodexApp|TestCodexProjects' ./internal/provider: ok.
TestCodexAppProjectsShortAfterALiveSwitch drives the repo's app
simulator through a live switch to an unshared account and, after
shareCodexProjects, to a shared one. Broken by hand (every look counts as
a switch) TestCodexAppProjectsRemovedByHandIsNoHint went red.
- node --test codex-app-projects-short.test.cjs (new), codex-app-stale,
i18n-keys, i18n-en-no-cjk: all pass, chromium and webkit, 5 languages,
900 and 480px (70 tests for the first two).
- TestCoreScriptBudget ok; gofmt clean; go vet -tags nogui and GOOS=windows
of internal/provider and internal/gui ok.
- old-webkit.test.cjs: "compat.js is the first of the page's own scripts"
and "the styles hold up in Safari 15.0" are red on origin/main
4ddc150c6 too, same names. GOOS=darwin vet of internal/gui fails at
traywindows_darwin_test.go:30 (trayImagePNG) on origin/main too, from
WSL without cgo.
Not tried: the real Codex app switching live (the simulator follows the
bundle's selectRendererOwner, not a launched app); the whole GUI suite
before the push (started after the tag); mote.
The reporter wants the Codex app's projects kept however magpie switches
ChatGPT accounts. v0.1.3559 (15acba534) copied the longest list only to
an identity with no list yet, so an account with a list of its own (an
empty one too) never got the others' projects, and a project added on
one account never reached an account that had any.
Now, while the app is closed (the same moments as before: the 3s loop
once the state file or logins changed, and between a reopen's quit and
open), shareCodexProjects gives every identity the file has and every
saved Codex login one list: each identity's local-projects together,
the signed-in identity's copy first, with the ties the other
codexProjectKeys have to them (thread-project-assignments,
project-order, pins, appearances, the app-server id maps one level
down). A folder is one project: the app gives a new project a random id
per account (randomUUID in 26.1103's bundle), so a project of a folder
an identity already has maps onto that one, its threads renamed to it.
Removals: codex-projects.json (beside logins.json) keeps each
identity's project ids and folders as the last look left them. A
project a look saw on an identity that the next doesn't have was
removed there; it goes from every identity with every tie, as do other
projects of its folders, unless the user added that project or folder
again since. No record yet removes nothing. A record that can't be
read or parsed means what was removed is unknown: nothing is written.
The record is written after the state file, and not when the app's
start overtook the write, so that look is taken again. The state file
is still written through temp + rename, only when it is byte-for-byte
what was read, with the first-write backup beside it.
Checked against ChatGPT.app 26.1103.60933's own bundle (downloaded from
its appcast into a scratch dir, unpacked there): the renderer state
schema {owner, inactive:{<hash>:{atoms, globals}}}, selectRendererOwner
parking/loading Object.values of the global-state key table (the
account-scoped keys, codexProjectKeys among them), the local project
schema (id, name, rootPaths, backings, createdAt, updatedAt) and
randomUUID ids for new projects. The live ~/.codex was not touched.
Run (mote refused ssh all session, kex reset; so on xiaomi-gpu):
- wsl-run go vet -tags nogui, GOOS=darwin CGO_ENABLED=0 go vet and
GOOS=windows go vet of ./internal/provider: ok
- wsl-run go test -tags nogui ./internal/provider: ok (281s)
- wsl-run go test -run 'TestCodexProjects|TestCodexRendererOwner|
TestCodexApp' ./internal/provider ./internal/agent: ok
- win-run go test -run 'TestCodexProjects|TestCodexRendererOwner'
./internal/provider: ok
- gofmt -l: clean.
Red on the old code (origin/main's codex_projects.go with a 3-arg
shim): TestCodexProjectsShared (shared with 1, want 2),
TestCodexProjectsRemovalRemembered (0, want 3),
TestCodexProjectsRecordUnreadable (written).
Broken by hand: removals never gone -> RemovalRemembered red; no
folder dedupe -> Shared red; no graft of ties -> FollowASwitch and
Shared red; a tie not renamed to the folder's project -> Shared red;
no MkdirAll for the record -> StepWaitsForTheAppToClose red.
Not tried: the real Codex app switching real accounts (it would share
Electron's userData with the user's running app); the switch is played
by the tests' Go port of 26.1103's selectRendererOwner. No macOS run
(mote down). The first look after this release has no record, so a
project the user removed on one account before it comes back there.
"切换账号 codex 添加的项目丢了 发生过好几次了 另外额度用尽时会强制重启 codex 客户端"
Projects. The Codex app (ChatGPT.app 26.1103 and on) keeps its sidebar's
projects per ChatGPT identity in $CODEX_HOME/.codex-global-state.json,
under electron-account-renderer-state-v1 ({owner, inactive:{<sha256 of
JSON.stringify([chatgpt_user_id, chatgpt_account_id])>: {atoms, globals}}}).
On an account change it parks the old identity's account-scoped globals
and loads the new one's, so magpie's switch (auth.json, then the
app-server's restart) showed an account that never had the app open with
no projects (#5497, #5602, #5702, #5874). Read from the app's own bundle
(early-bootstrap-133 selectRendererOwner, -815's owner hash). The app reads
the file only at launch and writes its memory over it, so magpie writes
it only while the app is closed (codex_projects.go): from the 3s loop once
the file, auth.json or logins.json changed (process listing at most every
30s), and between the quit and the open of every reopen (appQuitDone in
reopenBundle and restartWin). Each identity of auth.json and the saved
Codex logins whose snapshot has no local-projects key gets the project
keys of the identity with the most; an own list (an emptied one too) is
left; g-p- ChatGPT project mirrors and their ties aren't carried, and a
backing naming another account is dropped (the app refuses those). A
file without the key or that doesn't parse is not written; the first
write keeps the file as it was beside it (.magpie-before-projects).
Restart. When quota runs out magpie restarts the app's app-server (the
takeover needs it: the app reads its account only as its app-server
starts, else Send stays grey). A ChatGPT app can then show "hit a snag",
and magpie quit and reopened the whole app (CodexAppRelaunch), and on
Windows reopened an app that started no app-server (codexAppGotNone).
Both now happen only with "Restart the Codex app when magpie switches its
account back" ticked (codexRestartsApp, off by default); otherwise the
Agents row says to quit and reopen, as it did where a relaunch failed.
Run (mote unreachable all session: ssh kex reset on every try; so on the
Linux box and Windows box instead):
- wsl-run: go vet -tags nogui, GOOS=darwin CGO_ENABLED=0 go vet and
GOOS=windows go vet of internal/provider and internal/agent: ok.
- wsl-run go test -tags nogui ./internal/provider ./internal/agent:
provider ok; agent red only on TestGrokInstalled (#3548, WSL binfmt).
- win-run go test -run 'TestCodexProjects|TestCodexRendererOwner|
TestCodexApp|Restart' ./internal/provider ./internal/agent: provider ok;
agent red on TestWorkBuddyRestartOnMac (#4115) and
TestOpenMausBotRestartOnMac (added to #4115), neither touched.
- gofmt -l: clean.
- The owner hash checked against node's crypto (TestCodexRendererOwner).
Broken by hand: carryCodexProjects returning at once -> the four
TestCodexProjects* red; the snag gate removed -> TestCodexAppNotQuitUnasked
red (relaunched 1); the Windows gate removed -> red (reopened 1); the
backing strip removed -> TestCodexProjectsFollowASwitch red.
Not tried: the real Codex app. This Mac's ~/.codex state has no
per-identity key (read-only check), so the switch is reproduced against a
Go port of the app's selectRendererOwner on the issues' layout, not the
app itself. No macOS test run (mote down). The takeover (no account)
still shows no projects in the app, by the app's own rule; they come back
with the account. Projects added while the app runs reach other accounts
once it is closed.