ac4af582301a4e8a29245dbba767eba31334ddf9
17
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
77076eef47 |
agent: an npm update on Windows lets go of magpie's own claude and codex first
CLJY (Discord) had %APPDATA%\npm with only the 308-byte sh shim of claude: no claude.cmd, no claude.ps1 and no codex at all, and `npm i -g @anthropic-ai/claude-code` ended in "npm warn cleanup ... EPERM ... unlink ...\.claude-code-<rand>\...\claude-code-win32-x64\claude.exe". On Windows a running program's file can't be removed. npm moves the old package aside, takes the old shims away, and stops partway when a claude.exe of that package is still running; the sh shim is what is left. magpie keeps such processes running itself: - the Claude subscription bridge keeps up to 6 Claude Code runs waiting for their conversations' next turns, for up to an hour; - Codex's app-server daemon has no idle exit, and magpie restarts it. Its Update button ran npm with both still up. - agent.UpdateCLI, on Windows through npm, bun or pnpm, first lets go of them: gateway.LetGoIdleClaudeCode ends every waiting run (its session shelved for the next turn, as a run let go past idleMost is) and returns once each has exited; provider.StopIdleCodexDaemon stops the daemon when no codex session is on it. Runs in a turn and sessions are left. - An update on Windows that leaves the CLI's file gone fails, saying to quit it and reinstall, instead of "updated". - proc's toolIn (FindTool) and codexExecutable no longer take the bare extensionless file on Windows, which CreateProcess can't run. Beside name.exe and name.cmd, the sh shim alone stands for the .exe it runs (Claude Code's bin\claude.exe), read from cmd-shim's exec line and kept inside its folder; a node shim (codex) or any other script is skipped. The testdata shims are cmd-shim 7's bytes, made with cmd-shim@7 on the Windows box. Run at this head (rebased on origin/main; after the rebase, vet on all three systems and the changed tests again: ok on Windows and macOS): - gofmt -l internal/: clean. go vet of proc, agent, provider and gateway on macOS (mote), Windows (win-run) and Linux (wsl-run): ok. - Windows (win-run): internal/proc ok; TestToolInNPMShShimAlone, TestLetGoIdleClaudeCodeFreesTheExe and the TestClaudeIdle* tests pass. internal/agent, internal/provider and internal/gateway (-run "Claude|LetGo|Codex") have Windows reds, and the same run at origin/main |
||
|
|
1dead5dc7b |
provider: magpie's own Codex account switches leave the Codex app running unless Restart the app is ticked (atom0964)
atom0964 on Discord (#help) has two ChatGPT Plus accounts in magpie, with Codex always signed in to the first and Only switch Codex's sign-in both off, on Smart routing. The Codex desktop app kept restarting by itself. They tried several combinations of the ticks and it still did. Why: with both off, SwitchWhenSpent signs Codex in to the next account at 98% and back to the first below 90%. Each switch was noted for the Codex app (codexAppSpentSwitch), and KeepCodexAppOnItsProvider ended its app-server once no turn ran; the ChatGPT app shows that as an error and relaunches (#4550). With Codex kept on the first account there is no switch, but the used-up takeover (magpie made Codex's provider for a used-up account and given back once it has room; |
||
|
|
9f641daeab |
codex: a turn stuck on a used-up account no longer holds the Codex app's Send grey after a switch by hand or magpie's takeover (xiaoq6285)
xiaoq6285 on Discord (v0.1.2700): Codex on an official ChatGPT account ran out of quota, and after switching to another account or provider in magpie, the Codex app's Send button stayed grey. magpie has no chat composer of its own; the button is the Codex app's, which greys Send for every model while the app-server it runs is on a ChatGPT account the app holds. magpie lifts that by restarting the app's app-server (codexAppStep), but never while a Codex turn is open in its sessions, for up to codexTurnWindow (30m). When quota runs out mid-turn the turn is left open, so the restart, and the grey, waited. |
||
|
|
41357f3935 |
codex: the ChatGPT desktop app on Linux is found, and a switch reaches it
pota on Discord: magpie switches the ChatGPT (Codex) desktop app's account on macOS and Windows but not on Linux. OpenAI ships the app for Linux since 08-11 (preview; learn.chatgpt.com/docs/linux/linux-app): a deb, an rpm and an Arch package, which install /usr/lib/chatgpt. Its app-server is /usr/lib/chatgpt/resources/codex ... app-server, run with the user's HOME and no CODEX_HOME, so it reads ~/.codex like the CLI. isCodexAppServer took only .app/Contents/ and Windows paths, so on Linux nothing found the app: no "still signed in as" notice after a switch, no restart of its app-server, and no version on the Agents row. - provider: linuxCodexApp takes an absolute .../chatgpt/resources/codex as the app's own app-server (findCodexApp, CodexAppStale, the switch's restart all read it). - agent: restartOnLinux; codexAppOpen knows on Linux whether the app is open (any /usr/lib/chatgpt/ChatGPT process, not its codex alone or another program's ChatGPT). desktopApps["codex"].linux reads the version from resources/linux-package-metadata.json, HasApp/AppVersion see it, and codexReaders counts the bundled codex's --version as a reader of Codex's config. version() no longer stops at an empty store read before the other sources. Real run, WSL magpie-desktop (Ubuntu 24.04), OpenAI's chatgpt_amd64.deb 26.1027.30824 (bundled codex-cli 0.166.0-alpha.5.1) under Xvfb, sandbox HOME, fake unsigned JWT accounts alice/bob (no real credentials), magpie web on 127.0.0.1:3591: - POST /api/login/switch alice: 200, auth.json alice; /api/providers then says codexApp "bob@example.com" (the stale notice). - POST /api/codex/daemon/restart-app: 200 in ~3s; the old app-server ended (app log "Codex CLI process exited classifiedAsExpected=true code=0"), a new one started with the sandbox HOME, the notice cleared. - /api/agents/cli: "codex":{"app":"26.1027.30824"}. - The same run with linuxCodexApp reverted: no notice, restart-app 400, the app-server untouched (pota's case). Run at |
||
|
|
d99e213f5b |
codex: an account switch restarts nothing while Codex's provider takes no ChatGPT account
danzi002 on Discord: with requires_openai_auth = false on Codex's provider,
switching the Codex account in magpie still restarted the Codex app's
app-server and said the app and daemon were left on the old account.
Codex's provider with no requires_openai_auth = true goes by no ChatGPT
account: codex-rs ModelProviderInfo::account_state answers no account, and
resolve_provider_auth sends the table's key, never auth.json. So which
account auth.json holds is nothing a running Codex uses.
- provider.CodexNoAccount (set to agent.codexNoAccount): the config's top
model_provider is not openai, has a [model_providers] table, and the table
doesn't say requires_openai_auth = true. A profile, the built-in provider,
no table or an unreadable config count as false (may use the account).
- codexAppStep forgets a switch (and a spent switch) while it holds, so the
app-server is left running; a route change still restarts it.
- CodexAppStale / CodexDaemonStale say nothing, and `magpie accounts`'
switch line says nothing needs restarting.
- Kept: route-change restarts (model_provider, openai_base_url,
model_catalog_json, base_url, catalog hash: read only as the app-server
starts) and the daemon's model-list restarts; and switch restarts when
magpie writes requires_openai_auth = true (ChatGPT sign-in with room).
Run (mote-run; full suite at this change on
|
||
|
|
cc81ad4ea1 |
codex: a Windows Codex app that starts no app-server after a switch is reopened (蛋仔 on Discord)
After magpie switched Codex's account, the Windows Codex app answered every send with "Codex app-server process is not available" until it was quit and opened again. The report said the app doesn't reconnect after a clean exit. That is half right. The app (MSIX OpenAI.Codex 26.1021, an Electron ChatGPT.exe that spawns codex.exe app-server over stdio) does start another, but only once the old one's stdout reaches EOF and its exit has fired. On Windows a child of the app-server (an MCP server, a tool command) inherits that pipe handle. A child left running keeps the pipe open, so the app never sees the close, starts none, and its send() throws. Reproduced on the Windows box with the real codex.exe 0.164 app-server plus an MCP server: stdout ended only when the MCP server did, and at once when the tree was ended. magpie took "the old pid is gone" as done in each place it restarts the app-server. None of them checked that a new one came: - codexAppStep (the switch watcher) now records the pids it ended and waits codexAppBackWait (30s) for another app-server. If none comes and the app still runs (CodexAppOpen), it quits and opens the app as the Agents row's Restart does (CodexAppReopen: restartWin by the OpenAI.Codex_2p2nqsd0c76g0!App AUMID, Windows only). Where it can't, the row says to (CodexAppStuck). - RestartCodexApp (macOS Restart), RestartCodexAppWhenIdle (uninstall) and the switch notice's Restart (RestartSwitchedCodexApp, |
||
|
|
dd9828f2b8 |
codex: an account switch restarts every one of the Codex app's own app-servers, and a reply that says the account is out switches at once (danzi002 on Discord)
danzi002 (Discord, Codex app on magpie API, several ChatGPT Plus accounts):
when the Plus account runs out the app greys Send; magpie signs Codex in to
the next account, but the app stays grey until it is quit and opened, and
only then is on the next account.
Cause: at the switch, noteCodexSwitch handed codexAppStep a single pid,
the first app-server-looking process (findCodexApp) of a 5-second ps
listing. That can be another program's `app-server --listen stdio://`
(ps lists by pid; on the owner's Mac Miyi Helper's runs beside the app's
own right now), which codexAppStep then drops as not the app's own, so
nothing is ended; and a ps slower than 5s dropped the switch for good.
Now the switch only marks codexApp.switched, and codexAppStep lists the
app's own app-servers on Codex's home with the same test and 30s bound a
route change uses, again at the next look if the listing fails, and ends
each once no Codex turn runs. findCodexApp (the "still on the old
account" notice) skips --listen ones too.
Also: a reply that says the active account is out (CodexMayBeUsedUp,
already reading the account at once) now runs SwitchWhenSpent too, so
the switch no longer waits for the account loop's next look, up to five
minutes when the last reading was under 90%. The app sends nothing once
it is grey, so no later request tells magpie.
Checked: a usage_limit_reached turn does not hold the restart back. Real
codex 0.164.0-alpha.11.1 (ChatGPT.app's bundled one) `codex exec` against
a fake 429 usage_limit_reached server in a sandbox CODEX_HOME writes
task_started then task_complete, so codexTurnOpen counts it ended.
Run (at
|
||
|
|
4534561f6b |
codex: a thread open when magpie quits goes on through a relay, not a 503
idkatbro on X: a Codex session started while magpie was open keeps failing after magpie quits with "unexpected status 503 Service Unavailable: Unknown error, url: http://127.0.0.1:3425/backend-api/codex/responses", until magpie is opened again. Cause: Codex signed in to ChatGPT, with more of its accounts on in magpie, gets openai_base_url = the gateway's /backend-api/codex (failover). At quit EndCodexFailover takes it out of config.toml, but a thread already open, in the Codex app and its app-server above all, keeps the base URL it started with. Every turn after went to a closed port. With a system or env proxy in between, the proxy answers 503 with an empty body, which Codex shows as "Unknown error"; without one Codex says "Connection refused" and reconnects. Reproduced on mote with codex 0.162.1 and a proxy answering 503 for the closed port. Masking plays no part: it runs only in the gateway, is opt-in, and its own 503 carries a readable message. Fix: when quit really ends failover (EndCodexFailover now says so), the gateway is on loopback, and Codex processes run (provider.CodexPIDs), magpie starts a detached `magpie codex-relay` (internal/codexrelay). It waits up to 60s for the gateway's port, then passes /backend-api/codex/* on to the ChatGPT backend with the same transforms the gateway applies to Codex's own turns, signed by the caller's own Authorization; it adds no credential (gateway.CodexRelay). - Refused with a readable 400 (Codex retries a 5xx five times over): a magpie model, a turn naming one of magpie's Codex accounts, and a turn masking would have masked, which is never sent unmasked. - 403 for any Origin (null too) or a non-loopback Host, as corsGuard. - Any other path gets 503 "magpie isn't running", never readable as magpie by ServedBy. - It ends once every Codex process it was left for is gone and nothing is in flight. - The next magpie (GUI or `magpie serve`) calls codexrelay.Leave first: a POST with the token from a 0600 state file. The relay closes its listener at once, so the port is free when Leave returns, and finishes its streams (up to 30 minutes). No running turn is cut. Run (at 6df7dc287 on origin/main |
||
|
|
a312bf3e38 |
codex: switching the ChatGPT account restarts the Codex app's app-server once no turn runs
zhibukaixinyao (Discord #help, 10-27) asked when Windows gets the "restart Codex" step: the Windows GUI has no Restart button, so after an account switch the Codex app kept sending on, and showing the limits of, the account it started with until the user quit and reopened it. noteCodexSwitch now hands the app-server pid it recorded as left on the old account to codexApp's stale set, the same set a route change fills. KeepCodexAppOnItsProvider's step ends it once Codex is idle and no turn is open, and the app starts another that reads auth.json afresh. This covers a switch made in the gateway's process: the GUI's switch and SwitchWhenSpent. Together with |
||
|
|
3aead9c627 |
codex: the Windows Codex app's own app-server is found, so Connect, Disconnect and failover restart it there too
zhibukaixinyao on Discord (#help, 10-27): on Windows there is no restart, and Codex keeps the old provider until it is restarted by hand. The cause: isCodexAppServer took the Windows app's codex to live under WindowsApps\OpenAI.*, which was a guess. The real ChatGPT/Codex MSIX (OpenAI.Codex 26.1021.3705.0, installed with winget OpenAI.ChatGPT) runs it from %LOCALAPPDATA%\OpenAI\Codex\bin\<hash>\codex.exe ... app-server --analytics-default-enabled. So findCodexApp found nothing, KeepCodexAppOnItsProvider never ended it, and the "still signed in to the old account" notice never showed on Windows. Now that path counts too (WindowsApps is kept); the npm, WinGet Links and --listen app-servers still don't. Run: - go test ./internal/provider -skip TestUnreadLogins: ok except TestFetchAsksASharedBaseOnce and two siblings, red on main and filed as #3854; TestUnreadLoginsWriteErrorsKeepCredentials crashes the package on main, filed as #3632. Neither is touched here. - go test -run 'TestCodexApp|TestFindCodexApp|TestIsCodexClient' ./internal/provider ./internal/agent: ok. - gofmt -l; go vet on darwin, linux -tags nogui and windows; go build for darwin, windows and linux nogui: clean. - On the Windows box (Windows 11, real Codex app 26.1021, sandbox USERPROFILE/APPDATA/LOCALAPPDATA, gateway on :3491, a fake custom provider): `magpie codex fakeai/fake-1` ended the app's app-server and the app started a new one (pid 63320 -> 56692); `magpie codex default` did it again (56692 -> 56216). The app logged the exit as expected (code 0, app_server_restart_recovery_done) and kept its window. The origin/main build left pid 56216 through both. Broken by hand: with the old WindowsApps-only check, TestCodexAppOwnServer and TestFindCodexApp go red on the real Windows command line. Not tried: a signed-in Windows app switching ChatGPT accounts, the durable host, and the managed `codex app-server daemon` (winget's portable codex 0.161 refuses to run it: "the CLI package does not match this platform or executable"). |
||
|
|
8b0132b3d2 |
codex: the Codex app sends again on every system as soon as magpie takes a used-up ChatGPT account over, and gets it back at the reset
Ethereal499 and Isdavexxx on X, MasterYi on Discord, #540. The Codex app greys Send for every model, magpie's too, while the ChatGPT account it is signed in to is used up. Its composer's gate (ChatGPT.app 26.1013) reads authMethod "chatgpt" plus rate limit allowed=false, and it asks account/read only when its app-server starts. |
||
|
|
531b44a9a8 |
codex: the daemon magpie restarts asks macOS for folders in its own name, not magpie's (reformed9448 on Discord)
The first `codex --yolo` in a terminal had macOS say magpie wanted files
in the Desktop folder. magpie keeps Codex's managed app-server daemon
current (KeepCodexDaemonCurrent restarts it with `codex app-server daemon
restart` when no session is attached). On macOS a process is the TCC
"responsible process" of whoever started it, so the daemon that restart
leaves running answered to magpie. Every codex run in a terminal attaches
to that daemon, which works in the run's folder, so ~/Desktop was asked
for under magpie's name.
proc.CombinedOutputOwn runs a command through posix_spawn with
responsibility_spawnattrs_setdisclaim (looked up with dlsym, as it has no
header), so the command and what it leaves running answer for themselves.
Only stdio is passed on, stdin is /dev/null, signals are reset, and the
context's end kills it as CommandContext would. restartCodexDaemon uses it.
Elsewhere, and in a build without cgo (the CLI), it is cmd.CombinedOutput.
Run (darwin/arm64, Go 1.26.8, at
|
||
|
|
5b01938776 |
agent: the Codex app-server magpie restarts gets the terminal's proxy and PATH
guotianci6 on X (magpie 0.1.1566 on Linux, Codex 0.164.0, Codex not
wired to magpie): after signing in to ChatGPT in magpie, every `codex`
stopped at "account/read failed during TUI bootstrap: account/read
failed: workspace routing discovery timed out (code -32603)", and codex
logout / login didn't help.
codexDaemonCommand ran `codex app-server daemon restart` with magpie's
own environment. The daemon it starts outlives the restart and serves
every codex opened after it, so it ran with what magpie was opened
with. magpie opened from the desktop has no proxy and no shell PATH,
and with a proxy set in .zshrc that daemon goes to chatgpt.com
directly. codexDaemonEnv now gives it the login shell's proxy
variables (as a set: when the shell names any, magpie's own are
dropped) and PATH, as a daemon a terminal started would have. On
Windows, where a terminal's environment is the registry's as magpie's
is, nothing changes.
Not reproduced: that the timeout is the missing proxy is inferred from
the error, the restart magpie makes after a sign-in, and logout/login
not helping; the reporter is asked to run `codex app-server daemon
restart` from a terminal, which this makes magpie do the same way.
Run at this head (origin/main
|
||
|
|
12d3db7332 |
provider: the Codex daemon check lists processes only when a pid file is behind, not a PowerShell run every 15s on Windows (#2341)
KeepCodexDaemonCurrent runs every codexDaemonEvery (15s, internal/agent/
codex_daemon.go) for as long as magpie runs, and listed every process
first. On Windows that is `powershell Get-CimInstance Win32_Process`, a
cold start each time, which is the run the reporter saw over and over.
A daemon is only ever found behind through a pid file written before the
change (daemonStarted), so with no pid file, or only newer ones, the
answer was always "nothing to do". pidFileBehind checks that first, with
the same one-second slack, and processes are listed only when it can
matter.
Run: go test -p 1 -tags nogui -count=1 ./internal/provider
-run 'TestKeepCodexDaemon|CodexDaemon' (ok, macOS, sandbox HOME).
TestKeepCodexDaemonCurrentListsOnlyWhenBehind counts listProcesses calls:
none with no pid file or a newer one, one with an older one.
Broken by hand: codex_daemon.go put back to
|
||
|
|
4eb90b69f4 |
provider: after magpie switches Codex's account, Codex's accounts say the Codex app is still on the one before and to quit and reopen it (CavillZhang on X)
The Codex desktop app (ChatGPT.app 26.1007, bundled codex 0.162) reads auth.json once, as its app-server starts. codex-rs AuthManager only reloads it for the same account (reload_if_account_id_matches skips a different one; a full reload is the app's own login/logout). So after magpie's switch the running app keeps the spent account's token, its webview reads /wham/usage with it (straight to chatgpt.com, which magpie can't intercept), gets rate_limit.allowed=false, and hardBlocked stops the composer in every thread with "You're out of Codex and Work usage". Only quitting and reopening the app moves it. magpie now notes, like the managed daemon, the app's own app-server (…/CodexCLI.app/Contents/MacOS/codex … app-server, or the Windows Store app's codex.exe) running at a switch and the account it holds, until that process changes. Codex's accounts show "The Codex app is still signed in as …; quit it and open it again" with Got it; `magpie accounts` and the gateway log say the same. Run: go test ./internal/provider ./internal/gui (TestCodexAppStale goes red with the app not noted), the new GUI test in Chromium and WebKit, en zh zh-TW ja de, 900 and 480px; findCodexApp against the owner's running ChatGPT.app found its app-server; go vet darwin/linux(nogui)/windows, go build. |
||
|
|
e611fc65d6 |
codex: magpie restarts the codex app-server a change left on the old model list when no codex session is on it, and the Agents page offers Restart when one is (luci on Discord)
luci (Codex CLI 0.162, magpie 0.1.1150): after Codex was wired back to
magpie, codex in a new terminal listed Codex's own models although
config.toml was magpie's.
Cause, reproduced with real codex 0.162.0 in a sandbox CODEX_HOME:
codex sessions attach to a background app-server (the managed daemon)
that is per CODEX_HOME, not per terminal (socket under
$CODEX_HOME/app-server-control). It is detached, has no idle exit and
builds its model list once, at start. A daemon started while Codex was
off magpie keeps the official list for every later session, in this
terminal or a new one, until it restarts. magpie writes only PATH to
shell rc files and doesn't unwire Codex on quit, so nothing
per-terminal is involved. luci's "a new terminal fixed it" isn't
explained by the daemon. Codex's hourly updater restarting it is a
guess, not proven.
What changed:
- provider.KeepCodexDaemonCurrent(ctx, home, changed) compares the
daemon's start time with when magpie last changed what Codex reads at
start. The start time is the mtime of a pid file in that home that
names the running daemon's pid, so another home's daemon (ChatGPT.app,
other sandboxes) is never acted on.
- With no codex session attached, it runs
`codex app-server daemon restart` with CODEX_HOME set to that home.
- Otherwise it reports Behind and how many sessions are attached.
- isCodexClient leaves out apps' and editors' own codex, exec-server,
mcp-server and the daemon's own processes. It reads the whole ps line,
since ps leaves a path's spaces unquoted ("Codex Computer
Use.app/...").
- agent: Codex's Notice after a change runs this check first. It says
either that magpie restarted the daemon, or that the daemon is behind
and how to restart it (Agents page or the command).
- The GUI backend and `magpie serve` re-check every 15s. A session that
was open at the change is usually closed later, and that is when the
daemon can be restarted.
- Agents page: the stale "daemon" copy line has a Restart button that
POSTs /api/codex/daemon/restart (timeout now 2 min, as a running turn
is let finish). It reuses translated strings. On Windows, where
processes aren't listed on each look, the row shows the last check.
- Restarts are serialized by one mutex.
- WSL's Codex is not handled automatically. Its row keeps the advice
text, which names the restart command.
What was run:
- Real codex 0.162.0 in a sandbox CODEX_HOME, with a fake gateway, on
luci's sequence: the daemon started on the official config, then
magpie's config and catalog were written.
- With a TUI open, /model listed GPT-6.x. The check said Behind with
a session attached and did not restart.
- With the TUI quit, the check restarted the daemon. A new codex in
the same terminal listed Magpie Alpha and Beta.
- Earlier in the sandbox: a daemon restart under an idle attached 0.162
TUI reconnects, and /model then shows magpie's models. A running turn
is waited for up to 60s.
- New tests:
- TestKeepCodexDaemonCurrent(Fails), TestIsCodexClient (with the
space-in-path case from the real process list) and
TestCodexNoticeKeepsTheDaemonCurrent. They don't build or fail on
the old code. The space case failed before the ps-line fix.
- The GUI test "the daemon's line restarts it" times out on the old
app.js.
- Results:
- agent-stale-copies.test.cjs: 60/60 in Chromium and WebKit, in en,
zh, zh-TW, ja and de, at widths 980 and 440.
- go test (temp HOME) for ./internal/agent, ./internal/provider,
./internal/gui and the root package: ok.
- gofmt -l: clean.
- GOOS=linux and GOOS=windows go vet -tags nogui: ok.
- The Windows path is checked only by vet and not tried on a Windows
box.
|
||
|
|
03dbde12d0 | accounts: after a Codex switch, magpie says when Codex's background service is still on the account before, and restarts it when asked (vincentzhang on Discord) — Codex CLI can keep an app-server running (codex app-server --managed-daemon) that reads the sign-in once, when it starts, so sessions opened after a switch still ran on the account before. When a switch changes the account while such a daemon runs, Codex's account list shows that it is still signed in as the one before, with Later and Restart; Restart runs codex app-server daemon restart for the Codex home magpie signs in through, which ends the Codex sessions on it, so magpie never does it unasked. magpie accounts switch codex prints the same hint and the command. The notice goes when the daemon restarts or stops, or Codex is switched back. Only a codex program's app-server with --managed-daemon counts: the ChatGPT app's codex and other apps' app-servers don't. Tested with a fake codex and a fake daemon in a sandbox magpie web; the real codex 0.155 has the restart command |