Qyburn3 on X ("为什么我每天好多次要重启"): the Agents row of a Codex
app already connected said 已接入 · 退出并重开 Codex 应用后生效 several
times a day.
Cause: StaleCopies counts a running copy as behind when a digest of
what magpie writes for Codex changed after it started. That digest took
magpie-desktop-models.json byte for byte. Beside the ChatGPT sign-in
(since add927e60) that file holds the ChatGPT backend's entries as
sent (base_instructions, comp_hash, available_in_plans...), asked for
again each hour, and each entry's details follow magpie's version and
models.dev, so a rewrite with the same models moved the digest and the
row asked for a reopen. The same digest drives KeepCodexDaemonCurrent,
so the CLI's app-server daemon was restarted for it too.
Fix: of Codex's two lists (magpie-models.json, magpie-desktop-models.json)
the digest takes which models they hold, slug and visibility in no
order (listedModels), beside the wiring keys and magpie's table as
before. A list that doesn't parse is still taken whole. A digest an older
magpie stashed is kept at its time when it matches the files as they are
(readsBefore), so the update itself doesn't ask every user to reopen
once more. Claude Desktop's reads already hash model ids only. The file
is still written only when its bytes differ (deskList); a running Codex
keeps working on its startup copy, and new details reach it on its next
start.
Run at this head (ccbefe2a2 + this), through mote-run:
- go vet ./internal/agent, GOOS=linux and GOOS=windows: ok
- go test ./internal/agent -count=1 -timeout 45m: ok (147.6s)
- wsl-run go test ./internal/agent -run 'TestCodexStale|TestChangedAt': ok
- the real ~/.codex/magpie-desktop-models.json (35 models) through
listedModels in a throwaway test, with every base_instructions,
priority and comp_hash changed and two entries swapped: same part.
Broken by hand: with the old byte-for-byte reads,
TestCodexStaleNotForAListsDetails is red at "the same models, other
details: 1 stale, want 0"; with the readsBefore carry-over off, red at
"an older magpie's stash, nothing changed since: 1 stale, want 0".
Not tried: a real Codex app beside a real ChatGPT sign-in watched over a
day; whether a list that flips between two model sets (a plugin's
listing failing and coming back) still asks for a reopen each flip (it
does: only the last digest is kept). No GUI change, so no GUI run.
TestCodexStaleOnlyForMagpiesChange, TestCodexStaleCopiesSayWhichIsLeft
and TestCodexDaemonHelperIsNoStaleCopy test copies told apart from the
process list. StaleCopies lists no processes on Windows (a PowerShell run
each look); there it returns codexDaemonBehind, the daemon as
KeepCodexDaemonCurrent last found it. So the three failed on Windows.
RaykieLee's f3e0672fd added Windows branches that seed codexDaemonSeen
with the answer and assert it back, so on Windows the tests named for
"only magpie's change" and "which copy is left" pass whatever those
guarantees do; its keepCodexDaemon mock is never called there, and one
branch leaves the seeded check behind for later tests. Taken instead:
the three skip on Windows and say why, and
TestCodexStaleOnWindowsIsTheDaemonsLastCheck drives the Windows path
itself, through codexDaemonCheck with keepCodexDaemon faked: none before
a check, none when not behind, the daemon (with its start) when behind,
none after CodexDaemonRestarted, none when magpie restarted it, none once
the check is older than three loops. It reads StaleCopies on Windows and
codexDaemonBehind elsewhere, and resets codexDaemonSeen when done.
Run: go test ./internal/agent on macOS green. Broken by hand, each red:
codexDaemonBehind ignoring Restarted, ignoring the check's age, and
CodexDaemonRestarted not clearing.
Windows box (Windows 11 x64, amd64 test binary of the whole package,
sandbox HOME/USERPROFILE/APPDATA/LOCALAPPDATA/TEMP): main plus the
series' base fails 21 tests; with the whole series only
TestInstallWithoutNodeParses (bash there is WSL's, whose default distro
has no /bin/bash) and the two TestReasonixCLI* (no Go on the box) fail,
both environmental and listed as untested by RaykieLee too. The three skip there
and TestCodexStaleOnWindowsIsTheDaemonsLastCheck passes.
Co-authored-by: RaykieLee <42793273+RaykieLee@users.noreply.github.com>
Codex keeps a long-lived helper next to the managed app-server (codex
app-server daemon pid-update-loop). It matches the codex startsWith
pattern, carries no --managed-daemon, sits under no app bundle or
Application Support folder, so codexCopyKind called it "cli": a helper
that started before magpie's last change to what Codex reads counted as
"A Codex in a terminal" forever, a daemon restart didn't end it, and the
only way to clear the row was killing a process the user can't name.
codexCopyKind now answers "helper" for an app-server daemon <sub>
command line, and StaleCopies skips it: it reads no list and there is no
Codex to quit. The daemon itself (--managed-daemon) is told apart
before, and a terminal Codex still counts.
Red/green: TestCodexDaemonHelperIsNoStaleCopy runs the helper alone from
before magpie's change — FAIL on the old code (one stale "cli" copy),
passes now; a terminal codex from before still counts 1.
Generated-by: GLM-5.3-Flash (ZCode)
Reviewed and landed by the maintainer (cherry-pick of b40a1dd0 from
ggbdpq:fix/codex-daemon-helper-1461, lychjck's report). Run on main at
c98160c0 with this commit on top, macOS arm64:
- On this Mac (ps, read only): the installed codex-cli 0.162.0 binary has
the subcommand `app-server daemon pid-update-loop` ("[internal] Run the
detached pid-backed standalone updater loop"): an updater, it reads no
model list. The managed daemons running here are
`codex app-server --listen unix:// --managed-daemon` and stay "daemon".
No pid-update-loop helper was running on this Mac at review time, so the
reporter's live row was not reproduced here; the fixture is the command
line from the report. provider's isManagedDaemon already names the same
helper as no daemon.
- TestCodexDaemonHelperIsNoStaleCopy with main's connectinfo.go: FAIL,
"the daemon's helper counted a stale copy: [{Kind:cli ...}], want none";
passes with the change.
- gofmt -l: clean. go vet -tags nogui ./internal/agent for darwin, linux
and windows; GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet
./...: clean. go build, GOOS=linux go build -tags nogui, GOOS=windows
go build: ok.
- go test -tags nogui -count=1 ./... under a scratch HOME with GOPATH,
GOMODCACHE and GOCACHE pinned: 44 packages ok, none failed.
- Not run: GUI tests (no GUI change), Windows or Linux hardware (the
stale-copy check doesn't run on Windows; Linux uses the same ps path).
Agent.Stale counted every process matching (^|/)codex( |$) that started
before magpie's last change, and the row only said "reopen Codex". Several
of those don't end when Codex is "reopened": ChatGPT.app's main process
registers window-all-closed so a packaged app on darwin doesn't quit
(read from /Applications/ChatGPT.app/Contents/Resources/app.asar), so
closing the window leaves its app-server (CodexCLI.app/.../codex
app-server) running; an editor extension's codex app-server, the CLI's
--managed-daemon (ppid 1) and a codex in another terminal run on through
a reopened app. One app also counted twice: its app-server and its
`codex exec-server --remote` both match (this Mac's ps).
Agent.StaleCopies gives each copy with its kind (app / ide / daemon /
cli, from the command line) and start, one app's processes as one copy;
Stale is its length. /api/state carries staleCopies, and the opened row
under "N running Codex still have the old list" says, per copy, what it is,
when it started and how to end it: ⌘Q for the app, the editor's window
reload, `codex app-server daemon restart` for the daemon, quit for a
terminal's. Strings in zh, zh-TW, ja, de.
TestCodexStaleCopiesSayWhichIsLeft (an app with its exec-server, VS
Code's Codex, this home's daemon, an old and a new terminal codex: app,
ide, daemon, cli; Stale 4) fails on the old logic (5 copies, no kinds).
agent-stale-copies.test.cjs (Chromium and WebKit, en/zh/zh-TW/ja/de,
980 and 440px) fails on the old app.js (no such lines).
Run: go vet -tags nogui (darwin, GOOS=linux, GOOS=windows) ./internal/agent
./internal/gui; go test -tags nogui ./internal/agent ./internal/gui (temp
HOME); node --test internal/gui/tests/agent-*.test.cjs gui-ja gui-de
gui-zh-tw i18n-keys codex-model-order: 202 pass, both engines. Not tried
with the reporter's Codex: which copy is left on their Mac isn't known.