Commit Graph
139 Commits
Author SHA1 Message Date
yetone fc8e98ba47 edit: Codex's thousands of [projects] tables are left out of the reads that don't want them (#2278)
Codex writes a [projects."…"] table for every project it is trusted in;
the owner's config.toml has 10,933 of them in 1.5 MB. go-toml's decoder
checks each table against its siblings one at a time, so every decode
of the file cost ~0.3s of CPU, and six readers decoded it again each
time Codex wrote it, plus a whole-file check before each write magpie
made to it.

- edit.TOMLWithout drops [projects…] tables in a single unstable.Parser
  pass. The agent's codexTopOf, sessions' readCodexConfig, provider's
  readCodexStoreSetting, library's rtk sandbox, hooks rekey and MCP
  entries read through it. None of them reads projects. A file that
  doesn't parse is passed through unchanged, so it still fails.
- validateTOML checks definitions with the rest of the file and the
  projects decoded apart, 128 projects to a decode. A bare [projects]
  table, a dotted projects.… key outside the tables, or any error
  decodes the whole file, so the error is the one it gives.

Run on mote (M5 Pro):
- BenchmarkCodexConfigDecode (10,933 projects): 283ms -> 7.6ms a decode.
- BenchmarkValidateCodexConfig: 52ms (the whole decode was 283ms).
- Startup CPU profile, first 70s, the real-account copy (the real
  1,524,099-byte config.toml): 2.76s -> 2.26s of samples; go-toml
  0.32s -> none sampled.
- go test ./internal/edit ./internal/sessions ./internal/provider
  ./internal/library ./internal/agent: all ok.
- go vet of the same five on darwin, GOOS=linux and GOOS=windows; gofmt -l clean.

Broken by hand:
- Decoding the batches into struct{} instead of a map:
  TestValidateTOMLDefinitionsInGroups went red ("a key twice", "a
  subtable then its key"), so the check keeps maps.

Not tried:
- the whole suite. Only the five packages that read the file were run.
- Now that projects is left out, a project table defined twice no longer
  fails these readers' decode. Codex itself refuses such a file.
2026-11-09 19:07:06 +08:00
yetone 56f0956044 codex: switching Codex off gives a relay's table its own base_url back
Switching Codex off on the Agents page left a provider table of the
user's own (a relay, not CC Switch's) pointed at magpie's gateway, and
forgot the relay's URL for good. takeTables points such a table at
magpie while a Codex thread names it, and keeps its base_url in the
stash (codex.tables). bringOver then moves that thread onto magpie, so
by the Disconnect no thread names the table any more: giveTables asked
ccSwitchTables for the tables on magpie, which skips a table no thread
names, put nothing back, and dropped the stash. Codex was left on the
user's provider again, with that provider sending to 127.0.0.1:3425.
giveTables now reads each stashed table as it is and puts the URL back
where it still says magpie's; one the user changed since stays.

The report ("all of Codex's configuration was reset to defaults" after
the switch and a Codex restart) is not reproduced as such: every other
line of a full config.toml survives the Disconnect, an edit made while
connected too, in each auth and provider case. The new test is the
guard for all of it. TestCodexOffKeepsAppsOwnConfig guards the other
writer the switch sets off (agent.Rewired starts the library's Sync,
which gives Codex its MCP servers one way on magpie and another off it):
what the Codex app writes for its browser, Chrome and computer use
(plugins, marketplaces, node_repl with its env table and env_vars, a
server kept off, shell_environment_policy.set, [desktop]) stays through
on and off, node_repl imported into the library or not. It passed on the
old code too.

Run (mote, then the Linux box once mote's disk filled up): go test -run TestCodexOffKeepsUsersConfig ./internal/agent
(10 subtests: ChatGPT, API key, no auth, relay, relay + ChatGPT, each
with and without an edit while connected), go test -run Codex
./internal/agent ok 37s, go vet for darwin, linux and windows; on Linux (wsl-run) go test -run
'TestCodexOffKeepsAppsOwnConfig|TestRunCodexEntry|TestRunDirectServerIsCodexsCommand'
./internal/library and TestCodexOffKeepsUsersConfig ok, go vet for all
three systems of internal/agent and internal/library. The
config.toml each subtest leaves was loaded by the real Codex CLI
0.164.0-alpha.11.1 (codex mcp list, sandbox CODEX_HOME): all ten load
and list the user's MCP servers.
Broken by hand: the old giveTables back, the four relay subtests go red
with "lost base_url = https://relay.example.com/v1".
Not tried: the Codex app (ChatGPT.app) itself switched off and
restarted; the reporter's own config, version and OS (not known).

Reported-by: darwish4021 (Discord)
2026-11-07 20:57:30 +08:00
yetone e9bde2520d codex: OpenAI's threads follow Codex onto magpie from a provider of the user's, and a move the budget stopped asks for the next sync (Lice9735 on X)
Lice9735 on X, Windows, magpie 0.1.3233, Codex app 26.1104: an old chat
(10-13) answered "模型提供商不匹配 — 此聊天使用的是 OpenAI,但你当前
的提供商是 magpie。请切换至 OpenAI 以继续", only a new chat worked,
after d620ff6b5 and d2c29abe7. Their config.toml has a provider table
of their own, openai-http.

Cause. The banner is the app-server's modelProviderMismatch on
thread/resume (app 26.1103: providerBlock is set only from that error;
codex 0.167 load_for_resume compares the stored thread's provider, the
row for a paginated thread, the rollout's session_meta for a legacy
one, with config.toml's). With Codex on a provider of the user's at the
takeover, the stash's codex.provider is that provider, and bringOver
moved only its threads: OpenAI's stayed on openai by design ("whose
threads bringBack would hand them to"). The Codex app lists them and
refuses each one on magpie. A second gap on the same path: the
rewriting moves (MovePackedCodexThreads, MoveRecentCodexThreads) go
128 MB a sync, newest first, and the rest waited for a sync nothing
asked for, which can be hours away.

- bringOver, with Codex on a provider of the user's before magpie (not
  OpenAI, magpie or cc-switch-official, and no profile naming OpenAI),
  moves OpenAI's threads to magpie too: in place, a paginated one by its
  row, the last 30 days rewritten. They are recorded in codex.lent with
  that provider as To, as lendOwn records its own: the Disconnect gives
  every magpie thread to that provider (bringBack), where Codex resumes
  them, and giveLent gives these back to OpenAI once Codex is on OpenAI
  again. One the app holds open waits (codexThreadsLater on openai).
- MovePackedCodexThreads and MoveRecentCodexThreads say more when the
  budget stopped them with a thread left, and bringOver, bringBeside and
  lendOwn ask for the next sync at once (codexThreadsAgain). The three
  share one mover now (codexOnto); bringBeside also waits on a held
  thread as the other two do. packedBudget is a var, for the test.
- Tests: TestCodexOpenAIThreadsFollowMagpieFromOwnProvider (new: an
  openai-http table named "OpenAI", a plain and a packed OpenAI thread,
  moved, lent, to openai-http at the Disconnect, back to OpenAI after;
  none while a profile names openai), TestCodexThreadsLeftByTheBudgetAskAgain
  (new), TestMovePackedCodexThreads checks more. TestCodexThreadsFollowMagpieIn's
  two user-provider subtests now expect OpenAI's thread on magpie, then
  on that provider after the Disconnect.
- docs/subsystems/agent-wiring.md says so.

Run:
- Real codex-cli 0.166.0 on mote, sandbox HOME and CODEX_HOME, a fake
  Responses server: a thread started on the built-in openai (API key,
  openai_base_url), a second after switching to model_provider
  openai-http (name "OpenAI"); both paginated. On openai-http the first
  was refused ("This chat uses openai, but your current provider is
  openai-http"). A throwaway test (not committed) ran magpie's takeover
  (Set fake/m1, Sync) on a copy of that home: with origin/main's code
  the openai row stayed and `codex exec resume` on magpie (the copy's
  base URLs pointed at the fake) failed with exactly "This chat uses
  openai, but your current provider is magpie"
  (modelProviderMismatch); with this change the row was magpie,
  codex.lent {"to":"openai-http",...}, and the resume answered.
- New and changed tests red on origin/main 191f3c0af (the openai thread
  on "openai", want "magpie"; after the Disconnect "openai", want the
  user's provider).
- Broken by hand: bringOver's `if more` dropped ->
  TestCodexThreadsLeftByTheBudgetAskAgain red ("0 sync(s) asked for");
  `more = true` turned false -> TestMovePackedCodexThreads red.
- mote: gofmt -l clean; GOOS=windows go vet and GOOS=linux go vet
  -tags nogui of internal/agent and internal/sessions ok;
  go test ./internal/sessions ./internal/agent ok at this head
  (this change on e6cdeac9c; rebased after onto 5dbdfc1bd, which
  changes internal/provider only), agent 292.2s, sessions 47.4s. Pushed and tagged
  without waiting for the full `go test -timeout 45m ./...`, per the
  owner's rule to ship each verified fix at once; it runs on mote after
  another session's suite, and a red it shows is filed or fixed in a
  follow-up.
- win-run (xiaomi-gpu), go test ./internal/sessions ./internal/agent
  (at the commit's parent before a rebase onto abe7b0063, which touches
  neither package): every test this change adds or touches passes; 29
  reds, 28 of them red the same at origin/main 191f3c0af run alone
  there. The 29th, TestHermesProfilesFollowMagpieModel, passes alone
  3/3 on this tree and is in #4115.

Not tried: the Codex app itself (the CLI's app-server gives the same
error the app shows); Windows with a real Codex; a legacy (non-paginated)
thread with a real Codex, covered by the unit tests only; a history
over 128 MB with real files. The chat the app has loaded at the switch
goes on once the app lets it go: fully quit the Codex app and reopen it
after magpie updates.
2026-11-07 18:08:39 +08:00
yetone a9667daad5 codex: CC Switch's OpenAI mirror's threads follow OpenAI, and OpenAI's follow the mirror
Chris on Discord (the Codex app on a Mac): "Model provider mismatch.
This chat uses OpenAI, but your current provider is OpenAI. Switch to
OpenAI to continue." The Codex app names a provider by its table's
name. CC Switch's OpenAI mirror ([model_providers.custom], name
"OpenAI", requires_openai_auth, no base_url) is named OpenAI as the
built-in openai is, and Codex up to 0.167 resumes a thread only on the
provider id it is on now (app-server config_manager.rs load_for_resume
and check_thread_model_provider_for_input: ModelProviderMismatch;
0.168.0-alpha drops that check). magpie left the mirror out of every
thread move: bringBeside skipped it as the provider it took down,
lendOwn skipped it at the top, and bringOfficial took only
cc-switch-official. So a thread on the mirror stayed refused with Codex
on OpenAI beside magpie, and OpenAI's threads with Codex on the mirror.

Both are the ChatGPT account's threads, so they follow whichever of the
two Codex is on:
- bringOfficial moves every mirror table's threads to the provider
  Codex is on with magpie (openai or magpie), unless the mirror is at
  the top, a profile names it, or it is the provider magpie took down
  (stash codex.provider);
- bringBeside takes that one, recorded, and giveBeside gives its
  threads back at the Disconnect that puts the mirror back on top;
- lendOwn moves OpenAI's threads to a mirror at the top, and giveLent
  back once Codex is on OpenAI.
Existing threads: each sync moves them, "custom" in place (OpenAI's
length), a paginated one by its row, any age; others' ids the last 30
days with a copy kept, as before. Config.toml and the provider ids
magpie writes are unchanged.

Run: real codex 0.167.0 in a sandbox CODEX_HOME, `codex exec resume`
of a thread on custom with Codex on openai: "This chat uses custom, but
your current provider is openai" (modelProviderMismatch), resumed past
the check after the relabel to openai; the reverse (custom at the top,
thread on openai) refused the same way.
mote (go 1.26.8): go test -count=1 ./internal/agent/ ./internal/sessions/
ok (408s, 58s); go vet ./internal/agent/ native, GOOS=windows, GOOS=linux
ok; gofmt -l clean.
Broken by hand: the three old exclusions back, all three new tests red
(thread left on custom / on openai); bringOfficial without the stash
skip, TestCodexMirrorAtTopJoinsWithItsThreads red (the mirror's thread
left on openai after the Disconnect).
Not tried: the Codex desktop app itself (not on any test box), and
Chris's config.toml wasn't seen, so which way round his threads were is
inferred from the two ids that name "OpenAI". A thread on a mirror with
a profile naming it stays; after the Disconnect, OpenAI's own threads
stay on OpenAI as before.

Reported-by: Chris (Discord)
2026-11-07 03:00:10 +08:00
yetone fb4632ee0c agent, provider: Codex's polls and the usage quotas read what is kept
Heap profile diff of the live magpie (v0.1.2906, /v1/magpie/heap, two
idle minutes with the window open: 269 MB allocated):
- ownCodex found the codex provider through provider.All, a copy of every
  provider, on each look (~9 MB). Its picks are now kept per stamp
  (codexPicks, stampedLists), read only.
- Codex's model and effort fields copied magpie's whole model list on
  each Options call, every poll of the effort field (~11 MB). They read
  sharedModels, the list kept, which they only read.
- visibleQuotas built every provider's offered models to narrow Gemini's
  and Antigravity's quotas (~20 MB). exposedIDs builds the providers
  asked only.

Run (mote, at this tree):
- gofmt -l internal, go vet ./..., GOOS=windows and GOOS=linux go vet
  ./internal/agent/ ./internal/provider/: clean
- go test -count=1 -timeout 45m ./... (all three commits' tree): 85
  packages ok, internal/gateway 748s, internal/provider 193s. Two red:
  internal/gui's TestMainWindowCorners/macOS_26_SDK, mote's macOS 27
  (#3949, filed before, untouched here), and internal/agent's
  TestCodexEffortOptionsReadTheKeptList, whose bar counted the
  environment's copy (see the effort test's comment), fixed in its test.
- then go test -count=1 -timeout 45m ./internal/agent/ with that fix:
  ok (200.1s)

Broken by hand:
- codexPicks through provider.Find again: 285 allocations, red
  (TestCodexOwnModelsFollowPicks, bar 20).
- the effort field on magpieModels again: 199896 bytes a look past
  its StampNow's 1712, red (TestCodexEffortOptionsReadTheKeptList, bar
  20000). The test takes the look's StampNow off: os.Environ copies the
  environment, and each t.Setenv before it in the package made that
  longer (an Unsetenv leaves its slot), ~56 KB a look in the whole
  package; run alone it is 1.7 KB.
- exposedIDs without the ids check: "other" built, red
  (TestExposedIDsBuildsOnlyTheProvidersAsked).

Not tried: the numbers on the live app after this build; that profile
is taken once it is released.
2026-11-06 12:48:51 +08:00
yetone d2c29abe73 codex: a chat the Codex app had open as magpie became its provider moves once the app lets it go (crypto0xfish on Discord)
crypto0xfish on Discord, the Codex app: "Model provider mismatch. This
chat uses OpenAI, but your current provider is magpie. Switch to OpenAI
to continue."

magpie makes itself Codex's provider (model_provider = "magpie") when
Codex has no ChatGPT sign-in, is signed in with an API key, the user
picks magpie API, or the ChatGPT account is used up (the takeover).
bringOver then moves OpenAI's threads to magpie, a paginated one by its
row (RetagPagedCodexThreads), skipping any a Codex holds open (its
writer lock) or wrote to in the last minute, "for the next sync". The
Codex app holds the lock of every thread it has loaded, the chat on
screen among them, however long ago it was written (tried below), and
nothing asked for that next sync: Sync runs on catalog changes, which
can be hours away. So the chat open at the switch stayed on OpenAI;
the app refuses it while loaded (app-server
check_thread_model_provider_for_input compares the loaded thread's
provider with config.toml at each turn), and after the app let it go it
was refused again on resume by its row, until something else synced.
681a472ca fixed the same gap for bringBack by time alone and named the
held-lock case as not tried.

- sessions.CodexThreadsBusyOn also counts a thread on the provider
  whose writer lock a Codex holds (codexLockedIDs: the lock files in
  thread-writer-locks, each tried and let go under Codex's coordination
  lock, none made or removed).
- codexThreadsLater(dir, p) now looks every 15s, for up to 12h, and asks
  for the Sync once nothing on p is busy or held; one wait per home and
  provider. bringBack keeps calling it for magpie; bringOver calls it
  for the provider it moved from, and lendOwn for openai (the same skip,
  OpenAI's threads onto a provider of the user's).
- Tests: TestCodexOpenThreadFollowsMagpieOnceLetGo (new: a paginated
  OpenAI thread held open stays at the takeover, no Sync is asked while
  held, one is once let go, and that Sync moves it to magpie);
  TestCodexTakeoverThreadComesBackOnceQuiet now expects the Sync only
  after the thread is quiet. TestMain turns the wait off so no goroutine
  outlives a test; the two tests end theirs in Cleanup.
- docs/subsystems/agent-wiring.md says so.

The chat loaded at the moment of the switch can't be helped from
outside: the app goes on with it once it reloads it (quit and reopen).
Codex's identity line, base_instructions and every value of the user's
are untouched.

Run on mote at this tree (base cff530079):
- gofmt -l: clean; go build ./...: ok;
- go vet ./internal/agent ./internal/sessions for darwin, linux -tags
  nogui and windows: clean;
- the two tests with -race -count=3: ok;
- go test ./internal/agent ./internal/sessions: ok.
On Windows (win-run): the two tests and TestCodexPagedThreadsFollowByRow: ok.

Broken by hand: bringOver's call turned off (`if false &&`), the new test
fails "no later Sync asked for"; the lock check in CodexThreadsBusyOn
turned off, it fails the same way. Restored, both pass.

Real Codex: codex-cli 0.165.0's app-server in a sandbox CODEX_HOME, a
thread started and a turn sent (to a dead fake provider). With the thread
loaded and its rollout quiet 73s, its lock was held, a probe built from
this tree said CodexThreadsBusyOn true and RetagPagedCodexThreads moved
nothing; after the app-server exited and a quiet minute, busy was false
and the retag moved the row.

Not tried: the real Codex desktop app (whether leaving a chat for another
lets its lock go within a minute, or only quitting does), and a live
switch with a real used-up or API-key account. The reporter's own setup
(why Codex was on magpie for them) is not known.

Reported-by: crypto0xfish
2026-11-06 11:26:41 +08:00
yetoneandggbdpq 429f9317d2 uninstall: Codex's base URL at magpie's gateway goes even with magpie's notes gone (#3866)
Uninstalling disconnected only the agents that read as connected. A
Codex whose config still had openai_base_url at magpie's gateway (or
model_provider = "magpie") but whose notes in magpie's folder were gone
(the folder deleted by hand, a fresh install beside an old config, a
magpie older than the notes) read as not connected, so the uninstall
left it pointing at a port nothing answers: every Codex turn then failed
with a connection error that never names magpie.

Uninstall's Agents step now ends with Codex's leftovers pass
(agent.TakeCodexLeftovers, the Agent's TakeLeftovers): the base URL goes
by viaBase()/dropBase and magpie as provider by asProvider()/dropProvider,
the same gates and drops a Disconnect uses, notes or not. Codex's own
model, its own provider and keys stay, and so does
[model_providers.magpie], which threads started on magpie name. Taking
anything shows "Codex's leftover settings" in the report and restarts
the Codex app's app-server. docs/subsystems/agent-wiring.md says so.

Not changed: deleting magpie.exe by hand runs no code, so the reporter's
Windows case is covered only through Settings > About > Uninstall magpie
or `magpie uninstall`. The pass is this machine's Codex only, like
EndCodexFailover; a WSL distro's config is left as it was. viaBase
matches any loopback port with /backend-api/codex, as Disconnect does.

Run on mote, base origin/main 4e7661adc:
- gofmt -l on the touched files: nothing
- go vet -tags nogui ./internal/agent/ ./internal/uninstall/,
  GOOS=linux go vet -tags nogui, GOOS=windows go vet: clean
- go test -tags nogui -count=1 ./internal/uninstall/: ok
- go test -tags nogui -run 'Uninstall|Run|Keep|Data' ./internal/cli/: ok
- go test -tags nogui -run Codex ./internal/agent/: ok (44s)

Broken by hand: TakeLeftovers returning false at once and Agents not
calling endLeftovers: TestCodexLeftoversGoAtUninstallWithoutTheMarks and
TestCodexProviderLeftovers... FAIL "took false, err <nil>"; TestRunOrder,
TestKeepData and TestRunTakesCodexLeftovers FAIL (no "leftovers" step,
the Codex app not restarted, a failed pass not reported).

Not tried: a real `magpie uninstall` (it removes the login service, which
a sandbox HOME doesn't isolate), the Codex app, Windows.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:44:24 +08:00
yetone 1493acb468 gui: Codex's memories default reads right on Codex 0.167.0 and before
Codex 0.167.0 (openai/codex#58091) moved its default memory models:
extraction from gpt-5.6-luna to gpt-6-luna, consolidation from
gpt-5.6-terra to gpt-6.1-terra. The memories square's unset text and the
Settings row's tooltip named the old pair. They now say "Codex's own
memory models", true on either version, in en, zh, zh-TW, ja and de.
The code comments (agent/codex.go, gateway/codex_memory.go,
gateway/codex_follow.go, the tests' headers) name both pairs with the
Codex version that uses them. No behaviour changes: magpie routes these
calls by kind (memgen, memory_consolidation), not by the model name.

Run on mote at the pre-rebase base 4e7661adc, both engines:
node --test codex-memories, codex-memories-settings, agent-prefs,
codex-sheet-providers, settings-general, i18n-keys, i18n-en-no-cjk:
127 of 128 ok. The one red is i18n-keys "a plugin's words are its own"
("No session ID", "View routing"), red on main before this change and
filed as #5327, #5332 and #5426. go vet of internal/agent and
internal/gateway for darwin, linux and windows, and gofmt -l: clean.
Not broken by hand: text-only change; codex-memories.test.cjs asserts
the new en and zh strings, so the old text fails it.
Not tried: a real Codex 0.167.0 writing memories through magpie.
2026-11-06 09:59:56 +08:00
yetone 1d704f8190 codex: OpenAI's threads follow a provider of the user's at the top, where Codex resumes them
harris on Discord (the Codex app, after switching from CC Switch):
"This chat uses openai, but your current provider is custom. Switch to
openai to continue." CC Switch left its "custom" as config.toml's
model_provider, which magpie keeps since #4347, and Codex 0.166 resumes
a thread only on the provider it is on now. Every thread started on
OpenAI before was refused, and switching to OpenAI would refuse
custom's threads instead, so the user was stuck. Nothing moved them:
bringOver moves only onto magpie, bringBeside only from such a provider
onto OpenAI.

lendOwn (each Sync) moves OpenAI's threads onto that provider, as
bringBeside does the other way: in place at OpenAI's length, by the row
for a paginated thread, the last 30 days rewritten with a copy kept
otherwise. The ids go in stash codex.lent; giveLent returns exactly
those to OpenAI once Codex is on it again (CC Switch's official card),
keeps the record while Codex is on that provider or on magpie, and
drops it on any other. Nothing moves while a profile names openai,
after the user disconnected Codex, or from a distro's Codex.
TestCodexThreadsComeBackOffMagpie/by_hand expected an OpenAI thread to
stay on OpenAI with custom set by hand at the top, the stuck state
itself; it now expects it on custom. docs/subsystems/agent-wiring.md
says so.

Run (mote, go 1.26.8): go test -count=1 ./internal/agent/ ok (250s);
GOOS=windows, GOOS=linux and native go vet ./internal/agent/ ok;
gofmt -l clean.
Broken by hand: Sync without lendOwn, TestCodexOwnProviderTakesOpenAIThreads
red (thread left on "openai", rollout not on custom); without the
disconnected and profile guards, TestCodexOwnProviderLeavesOpenAIThreads
red for both cases.
Not tried: a real Codex app resuming a moved thread on a real relay;
harris's config.toml wasn't seen, so the "custom" here is CC Switch's
relay table as it writes it. A thread moved from the ChatGPT backend to
a relay carries its encrypted reasoning, which a relay on another
account may not accept; the thread then fails on the relay as a
switch to it by hand would.
2026-11-06 00:51:01 +08:00
yetone d620ff6b54 codex: an old OpenAI thread follows Codex onto magpie by its row, and back at the Disconnect (Parry_Moody, Cyrus)
Parry_Moody and Cyrus on Discord: Codex on OpenAI through an API key
before magpie, and for two days the Codex app answered every older
conversation "继续聊天未成功: This chat uses openai, but your current
provider is magpie. Switch to openai to continue."

Cause, from Codex's source (rust-v0.167.0-alpha.3.1, same in 0.166.0):
every thread Codex 0.166 starts is paginated (history_mode 'paginated'
in its state-DB row), and for those thread-store read_thread takes the
provider from the row, never the rollout ("Paginated history may contain
only a suffix, so its display metadata lives in SQLite"). The app sends
thread/resume with modelProvider null (ChatGPT.app 26.1021, Kct in
app-shared), so the row alone decides, and load_for_resume refuses a row
other than the current provider. bringOver moved threads by rewriting
files: plain ones in place, packed ones only from the last 30 days and
128 MB a sync. An older or packed OpenAI thread kept an openai row.

Now sessions.RetagPagedCodexThreads moves every paginated thread on a
provider by its row alone: any age, packed or not, an id of any length,
no file read, written or copied. Each thread is held by its writer lock
(an open one stays: its writer would write the provider back), one
written to in the last minute waits, 200 rows a transaction. It runs
after the in-place relabel in bringOver, bringBack (so a Disconnect no
longer copies a whole paginated history to the trash), bringOfficial and
bringBeside, and giveBeside by ids (RetagPagedCodexThreadIDs). Legacy
threads keep the file path. The Sessions page lists a paginated thread
on its row's provider (codexPagedProviders, memoised on the DB and WAL
stamp), so it isn't offered a Move it had.

Run:
- real codex-cli 0.166.0 (npm latest) on mote in a sandbox CODEX_HOME,
  a fake Responses server: a thread started with OpenAI (API key,
  openai_base_url) is paginated, row openai; with model_provider magpie
  `codex exec resume` failed with exactly "This chat uses openai, but
  your current provider is magpie" (modelProviderMismatch). After
  magpie's RetagPagedCodexThreads on that home (a throwaway test calling
  it, not committed) it resumed and answered; the rollout still names
  openai. Reversed (magpie -> openai) with config back on OpenAI, it
  resumed again. The first retag try moved nothing: the rollout had been
  written <1 minute before, the ActiveWindow skip, as intended.
- mote: gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
  for ./internal/sessions ./internal/agent; go test ./internal/sessions
  ./internal/agent: ok (sessions 20.1s, agent 194.4s) on mote, plus go vet on darwin, linux -tags nogui and windows

Broken by hand:
- RetagPagedCodexThreads returning nil (the old behaviour):
  TestCodexPagedThreadsFollowByRow red (250 packed 90-day-old threads
  "on openai, want magpie"), TestRetagPagedCodexThreads red.
- the writer-lock hold skipped: TestCodexPagedThreadsFollowByRow red,
  the open thread moved to magpie.

Not tried: the Codex app GUI itself (the app goes through the same
app-server thread/resume, whose modelProvider it sends null); Windows
and Linux runs (vet only). Codex rebuilds a row from its rollout when a
search listing reconciles it, which puts a retagged thread back on its
file's provider until the next sync; not seen, read from the source.
A legacy thread packed over 30 days still waits for Sessions' Move.
2026-11-05 16:11:14 +08:00
yetone 681a472cab agent: a Codex thread started during the takeover comes back to OpenAI once it is quiet, not hours later (nb5p on Discord)
nb5p on Discord (v0.1.3001, Codex app): after Send greyed out, Retry in
Codex did nothing. The model picker and Send spun, the same dialog came
back a few seconds later, and the model field read "model unavailable".

With the ChatGPT account Codex is signed in to used up, magpie makes
itself Codex's provider (codex.out), so a turn sent then starts a thread
saved with model_provider "magpie". When the account has room again,
Sync puts Codex back on OpenAI, and its deferred bringBack moves magpie's
threads to OpenAI. It skips a thread written to in the last minute,
which is the one the user was in, and leaves it "for the next Sync".
Nothing schedules one, though: Sync runs on a catalog change, which can
be hours away. The app then can't resume that thread on the provider it
is now on ("This chat uses magpie, but your current provider is
openai", the string still in the Codex the app bundles), so each Retry
failed the same way.

bringBack now asks whether a thread is still on magpie because it was
being written to (sessions.CodexThreadsBusyOn: the state databases' rows
on magpie whose rollout changed within ActiveWindow). If one is, it asks
for one more Sync after ActiveWindow+5s. Only one wait is pending at a
time.

docs/subsystems/agent-wiring.md says so beside bringBack.

Test: TestCodexTakeoverThreadComesBackOnceQuiet. The takeover is on, and
a thread on magpie is written to now. The account comes back, and the
thread stays on magpie while it is written to. A later Sync is asked
for, and that Sync, with the thread quiet, moves it to openai. No other
Sync is asked for after that.

Broken by hand: with the bringBack hook turned off (`if false && ...`),
it fails with "no later Sync asked for" (5.3s). Restored, it passes.

Run on mote at this tree (base 8eb219354, origin/main fetched, nothing
new):
- the new test with -race -count=3: ok;
- go vet ./internal/agent ./internal/sessions for darwin, for linux
  -tags nogui and for windows: clean;
- go build ./...: ok;
- gofmt -l: clean;
- go test ./internal/agent ./internal/sessions: ok.
The full suite at the pushed head is in the report.

Not tried: the real Codex app at the moment an account runs out and
comes back. The resume failure is read from the Codex source and the
string in the app's bundled codex, not seen live. A thread the app keeps
writing to for minutes on end waits one more round each time; that case
was not timed. Nor was a thread the app keeps open with its writer lock
held after it goes quiet: MoveCodexThreads refuses that one too, and
CodexThreadsBusyOn looks at the time only, so no further Sync is asked
for it.
2026-11-05 08:23:05 +08:00
yetone 8eb2193540 agent: Codex's own models are drawn by their names in its picker, as every other list's are (nb5p on Discord)
nb5p's screenshot of the Agents page: Codex's model picker drew each of
Codex's own models by its slug (gpt-6-astra · 经 magpie · GPT-6-Astra in
grey). Every other list in magpie, magpie's catalog included, draws the
model's name. options() gives a model its name only as the grey note;
Codex's own were the one list built straight from it, and on magpie API or
with magpie Codex's provider the label was set to the slug outright.

codexNamed gives each of Codex's own models its name (the display_name
Codex lists it by) as the label, for the picker of this machine's Codex
and of a WSL distro's (wsl.go, both of its lists), and the magpie-API
branch no longer writes the slug over it. The value is the slug, as
before: what Codex is set to and sends is unchanged (codex/gpt-… on
magpie API, gpt-… otherwise). The Codex app's own picker was not the
cause: magpie's catalog file already gives it the names.

Test: TestCodexOwnModelsNamedInPicker (beside the ChatGPT sign-in, and
magpie the provider) checks each own model is labelled by its name and
valued by its slug. TestCodexAPIKeepsMagpieOnOwnModel and
TestCodexProviderOwnModelSaysItsPath now check the name too.

Run on mote at this tree: go test ./internal/agent ok (176s); go vet for
darwin, linux -tags nogui and windows on internal/agent; go build ./...;
gofmt -l clean.
Broken by hand: codexNamed left without the label, all three tests red
("gpt-6-astra is offered as "" ... want it named "GPT-6-Astra"").
Not tried: the GUI suite (no GUI file changed; the picker already draws
a label when there is one), a real Codex in WSL.
2026-11-05 08:14:57 +08:00
yetone 387b386c84 codex: threads of the provider an older beside wiring took down move to OpenAI (yikelizi9438 on Discord)
yikelizi9438 (Windows, the Codex app): models wouldn't load, "This chat
uses custom, but your current provider is openai. Switch to custom to
continue", and "Model unavailable" in the composer. "custom" is CC
Switch's provider id; magpie never names one so. Before #4347
(e02bc8c49, v0.1.2652) a magpie model picked beside the ChatGPT sign-in
took the user's model_provider down, kept in stash codex.provider for
the Disconnect, leaving Codex on OpenAI by openai_base_url. Codex 0.166
resumes a thread only on the provider it is on now
(modelProviderMismatch), so every thread started on custom was refused.
#4347 stopped new configs reaching that state, and d6e3a36ff moves such
threads only when magpie is Codex's provider, so a config already left
so stayed broken after the update.

Now Sync's bringBeside: with Codex on OpenAI routed by the base URL, no
top-level model_provider, and a provider of the user's in the stash
(not openai, magpie, cc-switch-official or a CC Switch OpenAI mirror,
none a profile names), that provider's threads move to openai as
bringOver moves them onto magpie: in place at OpenAI's length, the last
30 days rewritten with a copy kept otherwise. The ids moved are kept
(codex.brought). The Disconnect, which puts the provider back, returns
exactly those (sessions.MoveCodexThreadIDs, only ones still on openai);
OpenAI's own threads stay. If magpie becomes Codex's provider instead,
they go on to magpie (followBeside), where bringBack returns them at the
Disconnect. A reset forgets the record (Codex stays on OpenAI).

Run: TestCodexBesideBringsTakenProvidersThreads red on origin/main
f280b12e5 ("thread ... on \"custom\", want \"openai\""), green here
(mote-run). Broken by hand: with Unwire's giveBeside("") commented out
the test goes red at the Disconnect ("on \"openai\", want \"custom\"").
mote-run: gofmt -l clean; GOOS=windows and GOOS=linux go vet -tags nogui
of internal/agent and internal/sessions; go test -tags nogui
./internal/agent/ ./internal/sessions/ ./internal/gui/ ok (agent 282s, sessions 31s, gui 95s).
win-run (xiaomi-gpu): TestCodexBeside|TestCodexThreads|
TestMoveRecentCodexThreads|TestMovePackedCodexThreads ok.

Not tried: a real Windows Codex app with the reporter's config (their
magpie version and config.toml are unknown; if CC Switch itself switched
them to its official card, the stash has no provider and nothing moves:
the Sessions page's "Move to openai" does it by hand). The followBeside
path has no test of its own.
2026-11-04 23:16:23 +08:00
yetone d6e3a36ffc codex: threads of the provider Codex was on before magpie follow it onto magpie (hxy920830 on X)
hxy920830 on X: "magpie希望codex接入的时候自定义供应商名称,我现在名称被替换成了
magpie,原来的会话可以看到,但是加载不出来模型了". Codex had been on a
provider of the user's own (a relay's [model_providers.<id>] table, or CC
Switch's "custom"). Wired with no ChatGPT sign-in, magpie sets
model_provider = "magpie". bringOver moved only OpenAI's threads onto
magpie, so the relay's threads stayed on their provider. From Codex 0.166
(codex-rs app-server config_manager.rs load_for_resume) a thread resumes
only on the provider Codex is on now. The app lists them (thread/list
with model_providers [] lists every provider) but opening one stops at
modelProviderMismatch: "This chat uses <id>, but your current provider is
magpie". Nothing a user can set changes that, so a setting to rename the
provider wouldn't be needed. The threads should just open.

bringOver now moves the threads of the provider Codex was on before magpie
(stash codex.provider, "openai" when none was set), not only OpenAI's:
- an id of magpie's length ("custom") is relabelled in place
  (RelabelCodexThreads), then packed ones from the last 30 days
  (MovePackedCodexThreads), as OpenAI's already were;
- any other id ("myrelay") can't be written in place, so the threads of
  the last 30 days, plain or packed, are rewritten with a copy kept in
  the trash, newest first, 128 MB a sync (new
  sessions.MoveRecentCodexThreads, sharing MovePackedCodexThreads' body
  with packedOnly off). Older ones are left for Sessions' Move/Resume.
#887's guarantee still holds where it matters. Threads of any other
provider stay put. OpenAI's stay when Codex was on another provider. No
threads move for a provider a profile names (the user picks it with -p),
for cc-switch-official (bringOfficial handles it), or for a distro's
Codex. The Disconnect puts the user's model_provider back and bringBack
returns the threads to it, and CC Switch switching back to that provider
does the same. If Codex leaves magpie for a different provider,
bringBack hands them to that one, as it already did with OpenAI's moved
threads. profileNamed moved up so bringOver can use it.
docs/subsystems/agent-wiring.md says so.

Tests:
- TestCodexThreadsFollowMagpieIn "on a provider of the user's before"
  used to assert that the custom thread stays. Now it moves to magpie in
  place, with no copy, and goes back to custom at Unwire, with
  model_provider custom restored.
- New subtest "on a relay's table of another length": myrelay's plain
  and packed threads move with a copy kept, a 40-day-old one stays,
  OpenAI's stays, and everything goes back at Unwire.
- New subtest "on a provider a profile names": the thread stays.
- New TestMoveRecentCodexThreads: newest first, a copy each, an old
  thread and another provider's stay, and the packed-only move still
  leaves a plain thread.

Run at this tree (on origin/main 823e7c250), on mote through mote-run:
- gofmt -l internal/agent internal/sessions: clean.
- GOOS=windows go vet, GOOS=linux go vet -tags nogui and go vet (darwin)
  of ./internal/agent ./internal/sessions: ok.
- go test -count=1 -timeout 45m ./internal/agent ./internal/sessions: ok
  (296s, 85s). An earlier run before the last tweak (plain file must be
  regular) was ok as well.

Broken by hand:
- bringOver back to OpenAI-only plus packedOnly forced: three of the four
  new assertions in TestCodexThreadsFollowMagpieIn and
  TestMoveRecentCodexThreads fail ("thread ...c3 on "custom", want
  "magpie"", "moved [only the packed one], want the plain then the packed
  one").
- the profileNamed guard dropped: "on a provider a profile names" fails.

Not tried: a real Codex 0.166 app or CLI resuming a moved relay thread
(this reasons from the codex-rs source for rust-v0.166.0, and earlier
commits record real 0.166 resuming moved threads); a real CC Switch
switch; the whole ./... suite (mote was at load ~75-100 with two other
sessions' full suites); a Windows or WSL run.
2026-11-04 22:52:05 +08:00
yetone 0ee424e3ee codex: a thread Codex 0.166 won't resume for its provider moves with Codex (毅, AcMilan on Discord)
Codex 0.166 (openai/codex#57840) refuses to resume a thread whose saved
provider isn't the configured one: "This chat uses openai, but your
current provider is magpie. Switch to openai to continue." (毅), and
"This chat uses cc-switch-official, but your current provider is
openai" (AcMilan). The rollout's session_meta provider wins over the
state DB row, and no -c override gets past it (openai/codex#58865).

Cause on magpie's side: bringOver relabelled only plain rollouts in
place. A thread Codex had packed to .jsonl.zst (a week after its last
turn) stayed on openai, so with magpie as provider it can't resume.
cc-switch-official is the id CC Switch 3.17-3.20 gave the official
account; CC Switch 4 moves those threads back to openai itself (#7948
there), but a user who left CC Switch keeps them stranded.

- sessions.MovePackedCodexThreads: packed threads on `from` updated in
  the last 30 days, newest first, up to 128 MB per sync, each moved by
  the existing packed rewrite with its copy kept in the trash. Rows
  are checked against the file (plain absent, .zst present, meta on
  `from`, same home). A state DB without updated_at moves nothing.
- bringOver calls it after RelabelCodexThreads; bringBack already
  moves packed threads back.
- bringOfficial: while magpie wires Codex and Codex is on openai or
  magpie, cc-switch-official threads move there, unless the user's
  top-level model_provider or a profile names cc-switch-official.
- Other providers and packed threads older than 30 days are left; the
  Sessions page's Move or Resume takes them.

Run (mote, at the pushed base c7bbd3faf):
- gofmt -l clean; go vet darwin, GOOS=linux, GOOS=windows on
  internal/agent and internal/sessions: ok.
- go test ./internal/agent ./internal/sessions: ok.
- Real codex-cli 0.166.0 app-server in a sandbox CODEX_HOME with a
  fake Responses server: an openai thread packed, Codex on magpie,
  thread/resume gave 毅's error word for word; RelabelCodexThreads
  alone left it; after MovePackedCodexThreads the resume said
  provider magpie and a turn started. A cc-switch-official thread with
  Codex on openai gave AcMilan's error; after the move it resumed on
  openai and a turn started.

Broken by hand (each red, then restored):
- budget check off: TestMovePackedCodexThreads red (both moved).
- the packed call in bringOver removed: TestCodexThreadsFollowMagpieIn
  red (packed thread stayed on openai).
- defer bringOfficial removed: TestCodexMovesCCSwitchOfficialThreads red.

Not tried: the Codex App GUI itself; agent Sync against a real Codex
(unit tests only); Windows and Linux runs; threads on other provider
ids, which 0.166 also refuses (left to the Sessions page).
2026-11-04 15:12:08 +08:00
yetone 247794c613 codex: an account that is out takes over for other models too (reverses f37742e14)
With one ChatGPT account out and nothing to serve Codex's own model on
(provider.CodexServesWhileOut false), f37742e14 left Codex on its sign-in
to keep the account's menu. But the Codex app greys Send for every model
while authMethod is chatgpt and /wham/usage says not allowed, so shamen
(mac, banner "Codex 和工作使用额度已用完"), chenhan and xiaoq6285 could send
nothing on GLM-5.3 or any other magpie model. A grey Send for every model
costs more than the menu, so this is the owner's product call: sending on
other models comes first.

When joined, on ChatGPT and held, and magpie has a model on no ChatGPT
account (codexOtherModel), Sync makes magpie the provider on that
stand-in, keeps the user's model in codex.out_own and the stand-in in
codex.out_stand, and at the reset puts Codex back joined on its own model
(#540 way back). Once per held/unheld transition: on the stand-in the model
is magpie's, so the branch is not met again. With nothing else to offer,
Codex stays on its sign-in as in f37742e14. Nothing about identity,
base_instructions or the account's state is changed or faked; magpie only
becomes the provider, as for any held account.

Run (mote-run, win-run, sandbox HOME, fake upstream; no real exhausted
account was tried):
- go test -tags nogui ./internal/agent -run Codex: ok; ./internal/provider
  -run CodexServes: ok; win-run ./internal/agent: see the tag notes.
- gofmt -l, go vet linux/windows/native on internal/agent: clean.
- New TestCodexOwnModelOneSpentAccountTakenOverForOtherModels: takeover,
  three more Syncs with no config write and no codexAppRoute change, the
  reset back once, a further Sync changing nothing. TestCodexOwnModel-
  OneSpentAccountStaysOnItsSignIn now covers only the nothing-else case
  (fake provider deleted).
- Broken by hand: new branch disabled -> the new test red; the
  !isMagpie(m) one-shot guard removed -> red.
Not tried: a real exhausted account in the Codex app; the stand-in picked
by the user is indistinguishable from staying on it and gives way to the
own model at the reset (documented in agent-wiring.md).
2026-11-04 10:05:32 +08:00
yetone 1e1068c86c codex: "Same as the lead" holds every subagent to the lead's model (cleverpigo on X)
cleverpigo (Windows, Codex App 26.1027.6604.0) had Codex's lead on
WorkBuddy's DeepSeek-V4.1-Flash, the subagent model on what the GUI called
"Same as the lead", and the Routing page still showed a subagent on
gpt-5.6-sol through Codex's own sign-in.

Cause: that setting, unset, never held a subagent to anything. Since
67c8f562c (mengxiao) a subagent keeps the model its lead names in
spawn_agent (codexFollowTo leaves subagents alone; codexSubagentPick
returns nil with nothing set), and Codex lists its own models first under
spawn_agent's model overrides, so the DeepSeek lead named gpt-5.6-sol.
Codex's side calls use luna, terra or codex-auto-review, not sol, so it
was the subagent, not a side call.

Now:
- "lead" (settings.CodexSubagentLead / provider.CodexSubagentLead) is a
  value of CodexSubagentModel: every Codex subagent goes on the model the
  lead's own turns last went on (codexLeads.lookup), whatever it names.
  The trace says so (SubagentPick.Lead) and Routing tells it as "the
  model its lead is on".
- A lead on one of Codex's own models is followed on the ChatGPT backend
  route only; in serve such a lead leaves the request as asked. With no
  lead turn seen, a subagent goes as asked.
- The GUI's picker offers "Lead's pick" (unset, mengxiao's case, as
  before) and "Same as the lead" (the new value); the texts say which one
  holds the subagents. en, zh, zh-TW, ja and de.
- No prompt text sent to a vendor changes.

Users who had it unset stay on Lead's pick; the label now says what it
does, and they pick Same as the lead to hold their subagents.

Docs: agent-wiring.md (subagent model field), gateway-routing.md
(CodexSubagentModel paragraph).

Ran, on mote through mote-run at this tree (base origin/main 50265256b):
- go test -tags nogui ./internal/gateway (whole package, -timeout 45m): ok
- go test -tags nogui ./internal/provider ./internal/settings
  ./internal/settingsapi: ok; -run Codex ./internal/agent ./internal/gui:
  ok; -run Budget ./internal/gui (TestCoreScriptBudget): ok
- go vet ./..., GOOS=windows go vet ./..., GOOS=linux go vet -tags nogui
  ./... (and -tags nogui darwin/windows): clean; gofmt -l: nothing
- node --test, both engines: codex-subagent-model (now picks Same as the
  lead and back, sheet row, Routing story of a lead-moved subagent, five
  languages), codex-subagents-lead, i18n-keys, routing-request-model,
  routing-sealed-task: pass. routing-story-shrinks is red in WebKit (4
  subtests, "held while under way"), the same alone at origin/main
  50265256b: #3954.

Broken by hand (in mote's copy only):
- lead lookup turned off in codexSubagentPick: both new tests red
  (TestCodexSubagentFollowsTheLeadWhenSet: "ChatGPT was asked for
  [gpt-5.6-sol]", the reporter's case).
- codexBackend's gate back to bare models only:
  TestCodexSubagentFollowsALeadOnCodexsOwnModel red.
- On the old code the tests don't build (no "lead" value), and
  SetCodexSubagentModel refused "lead".

Not tried: a real Codex App/CLI with a DeepSeek lead spawning a subagent,
and nothing on Windows (the change has no OS-specific path). The whole GUI
suite wasn't run: mote had two other sessions' full GUI suites going.
2026-11-03 23:12:33 +08:00
yetone f37742e14d agent: a used-up ChatGPT account magpie can't serve past leaves the Codex app on its sign-in (xiaoq6285)
xiaoq6285 on Discord (magpie 0.1.2798, the Windows Codex app, one
ChatGPT Plus account, Codex on its own model joined beside the sign-in):
at the five-hour limit the app showed an error and had to be restarted,
then its account menu showed only "magpie" with no quota; at the reset
it restarted by itself and the account came back.

Cause. When the active account was held (used up, no credits), Sync's
own-model takeover made magpie Codex's provider on codex/<model>
whenever magpie's catalog listed that model on any Codex account -- the
same used-up one included. With one account and no fallback every turn
it took over is refused on that account anyway, while the takeover:
- has account/read answer no account, so the menu drops the user, Plus
  and the usage meter until the reset;
- changes the route twice (into it, back at the reset), and
  KeepCodexAppOnItsProvider ends the app's app-server each time, which
  ChatGPT desktop 26.1027.x shows as "ChatGPT 遇到了问题" and relaunches
  (#4550, still open, the app's own reaction to an ended app-server).
Separately, magpie's [model_providers.magpie] requires_openai_auth
follows the account out and back (openaiAuth), and codexAppRoute
counted it even when that table was not Codex's model_provider, so
staying beside the sign-in would still have ended the app-server at
the limit and at the reset.

Change.
- provider.CodexServesWhileOut(model): the Codex subscription has
  fallbacks for codex/<model> (FallbackModels), or another ChatGPT
  account is not known held and not lapsed.
- Sync's own-model takeover runs only when that holds. Otherwise Codex
  stays on its sign-in: the app keeps the account, its quota and reset,
  and shows its own limit message. With a fallback set it moves as
  before (affa979d5 serves the fallback through the gateway too).
- codexAppRoute counts magpie.requires_openai_auth only while
  model_provider is magpie; the table is still written as before.
- docs/subsystems/agent-wiring.md says both.

Tests.
- TestCodexOwnModelOneSpentAccountStaysOnItsSignIn (new): one account,
  no fallback, held: config stays on the sign-in, codexAppRoute and
  AppOut unchanged across two Syncs and the reset.
- TestCodexServesWhileOut (new): one account none; another not known
  out yes; every account out none; a codex fallback yes.
- TestCodexOwnModelGoesThroughMagpieWhileUsedUp and
  TestCodexOwnModelOutThenKeptOnChatGPT now set a codex fallback, the
  case where the takeover still serves something.

Broken by hand: the CodexServesWhileOut gate taken out -> the new agent
test red (Codex moved to model_provider = "magpie", codex/gpt-a);
codexAppRoute counting requires_openai_auth always -> red (route
changed with model_provider empty). Each put back, green.

Run on mote at this head (rebased on e41ef6288), -tags nogui -timeout 45m:
- internal/agent ok (381s), internal/provider ok (254s);
- internal/cli FAIL in TestEveryRouteHasACommandOrIsNamed alone: GET
  /api/context/reply has no command, from 0872bc2a0, filed as #5026,
  nothing of this change;
- gofmt -l clean; go vet of both packages, GOOS=linux go vet -tags
  nogui ./... and GOOS=windows go vet ./... ok.
- internal/gateway ok (1152s) at the earlier base 3088872e6, not run
  again after the rebase (it imports provider; this change adds a
  function there and changes nothing it calls).

Not tried: the real Windows Codex app signed in to a used-up Plus
account (the Windows box's app is not signed in; #4550's crash was not
reproduced there); a real codex app-server against a fake 429 upstream.
Users with a fallback or a second account still get the takeover and
its two app-server restarts, which #4550 tracks.
2026-11-03 15:46:42 +08:00
ggbdpq e02bc8c49b fix(agent/codex): keep the user's model_provider over a takeover or reset (#4347)
What changed: the beside wiring of a Codex takeover took the top-level
model_provider down silently whenever a magpie model was picked beside
the ChatGPT sign-in — a provider of the user's (CC Switch's custom, an
older takeover's) went with it, and every Codex thread saved with that
provider stopped resuming (modelProviderMismatch: Codex falls back to
its built-in openai, the threads name the provider they were started
on, #4347). The wiring now steps beside only from a provider magpie
puts back itself (its own, none, CC Switch's mirror of OpenAI, as Join
already has it); over a provider of the user's the takeover names
magpie instead and keeps the user's spelling in the stash, for Unwire
to put back, as any takeover does. A reset leaves the line where the
user put it too: it takes magpie's keys out, not theirs.

Run: go test -tags nogui -run 'TestCodexTakeoverKeepsUserProvider|TestCodexResetKeepsUserProvider' ./internal/agent/ (both fail on the parent, pass here); go test -tags nogui ./internal/agent/ passes.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-02 05:38:11 +08:00
yetone cdfdb62c69 agent: a model field's list is joined with the catalog once while neither changed
Each agent's model field returned append(its own models,
viaMagpieShared(...)...), a copy of the whole catalog's options for
each field of each agent on every poll: Picks was 94.7 MB of 496 MB
over forty polls of the Agents page with real accounts. withVia keeps
the joined list per agent and prefix while the own models read the same
(sameOption, field by field) and the catalog's list is the very one
kept (same array), and joins it again when either changed. The list is
read only and clipped, as viaMagpieShared's is; every caller of a
field's Options reads it, Picks clones it before it drops anything.
The 52 `return append(own, viaMagpieShared(...)...)` sites call it.
omp's and Reasonix's planner edit the joined list after the append, and
Grok's writes Same into its copy, so they keep their own copies.

TestWithViaKeepsTheJoinedList: the same own models give the same array,
own models changed in a value or only an icon are joined anew, a
provider saved since is listed, and nothing joined is the catalog's own
list. TestSameOptionReadsEveryField sets each field of Option alone and
fails when sameOption doesn't see it. Broken by hand: never answering
from the kept list ("the same own models joined the catalog again"),
and FastFor left out of sameOption ("sameOption doesn't read
Option.FastFor").

Run on mote: both tests alone 3 of 3; internal/agent, internal/tui and
internal/cli ok; internal/gui red only on TestSettingsSaveKeepsWhatItDoesNotSend
(#4514) and TestMainWindowCorners (#3949); gofmt, vet and GOOS=windows
and linux vet clean. Real accounts in a sandbox HOME, forty polls:
Picks 94.7 MB -> 51.2 MB, state 190.8 MB -> 154.0 MB, state and drift
replies byte for byte the same as before. Footprint peak 136 MB.
2026-11-01 07:54:54 +08:00
yetone 6712e367e8 agent: a look at the stash shares one read of it
Each /api/state and /api/drift poll asked the stash (stash.json) for one
value hundreds of times, through Detected, Drift and the agents' wiring
checks, and each ask read the file and parsed it again. In a real-account
heap profile (20 rounds of drift, state and providers) stashLoad was
24-34 MB of what was allocated.

stashShared reads it through filememo.Read, so every look shares one
parse until the file changes, by magpie or by another process. Every
read-only caller uses it now, the 24 files here and QwenPaw's
unstashPeek. stashLoad, which callers change and write back, still gives
each its own map, cloned from the same parse.

Real use: the owner's real-account sandbox, offline (proxy to :9),
20 warm rounds of /api/drift, /api/state and /api/providers:
- allocated 477 MB (d307aa648) -> 411 MB; stashLoad is out of the
  profile.
- /api/state and /api/drift bytes identical to d307aa648's (cmp).

Run on mote (mote-run, Go 1.26.8), at this head rebased on d307aa648:
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestStashLooksShareOneRead alone, 3 times: ok.
- Broken by hand (stashShared reading through stashLoad): red, "a look
  at the stash read and parsed it again".
- go test -timeout 45m ./internal/agent ./internal/gateway: ok (263s,
  691s).
2026-11-01 05:32:29 +08:00
yetone dd7442f283 agent: a look at the via-magpie options shares the kept list
viaMagpie handed every caller its own copy of the options list it keeps
per stamp, and a window poll asks for it from most agents' fields and
pickers. In a real-account sandbox (abr.sh, 20 polls of drift, state and
providers on v0.1.2463) those copies were 33.7 MB of slices.Clone, plus
~8 MB more on the way, of the 713 MB the polls allocated.

viaMagpieShared returns the kept list itself, clipped, so an append
makes the caller's own array. The 58 callers that only read it, or
append onto it, now take it; viaMagpie (a copy) stays for the ones that
change it.

TestKeptListSharedWithoutACopy checks that 20 shared looks return the
kept array, and that an append onto a shared look and a write into
get's copy leave the kept list as it was.

Run on mote at this tree:
- gofmt, go vet (darwin, GOOS=windows, GOOS=linux with gateway),
  go build ./...: ok.
- Broken by hand (shared returns slices.Clone): the test is red, "a
  shared look copies the kept list".
- go test -count=1 ./internal/agent: ok (480s).

Not run: internal/gateway and internal/gui packages on this tree.
2026-11-01 04:25:59 +08:00
yetone 2597c96365 agent: Codex's config.toml is decoded once a read for a sync's own looks
A sync to Codex decoded the whole config.toml again for each thing it
checked: codexMultiAgentV2On, putThreadTables, codexEnableEfforts and
codexAsyncNow each ran toml.Unmarshal over the file. Codex writes a
[projects."…"] table for every folder it was opened in; the owner's
config is 1.5 MB with 10,932 tables, and with 10,000 such tables one
sync allocated 21 MB.

codexTopOf decodes only the top tables these look at (features,
model_providers, desktop, profile, profiles) and keeps the result in
filememo by the file's mod time and size, so a sync and the polls
after it share one decode until the file changes. A missing file is
an empty config, as before.

TestCodexSyncDecodesTheConfigOnce: 10,000 project tables, one sync
to settle, then five more; each must allocate under 12x the file and
leave config.toml unwritten. Now ~5 MB a sync. Red on the old code:
51,257 KB a sync over an 868 KB file, past the 10,421 KB bound.

Run at this head on mote: gofmt clean; go vet (darwin, GOOS=windows,
GOOS=linux) ok; go test -timeout 45m ./internal/agent
./internal/gateway ok.
2026-11-01 04:06:09 +08:00
yetone 2e9df9b1be agent: which of Codex's models magpie serves is kept while the catalog stays
codexInMagpie marks Codex's own models that magpie serves on the
user's ChatGPT account. Codex's options are asked per field of its
Drift on every drift poll, and each time it built Codex's whole
catalog (provider.CatalogFor) for these few names: 0.2 GB of the
2.6 GB a real config allocated over 20 polls.

The names are now kept in a stampedLists, as magpieModels and
viaMagpie are: built again when provider.StampNow moves, or a minute
after they were.

TestCodexServedKeptWhileCatalogStays: a signed-in account beside a
300-model relay; gpt-5.5 is marked served and the relay's model is
not, a kept answer takes under a twentieth of a build's bytes, and
the account's models picked since are followed at once. Red with the
set found each time ("a set already found took 9948425 bytes, finding
it 9954954").

Run on mote at this tree (0fe9f97c1 + this commit): go vet ./... for
darwin, windows and linux (internal/gui skipped on linux, wails cgo),
gofmt -l clean, go test -timeout 45m ./internal/agent (ok 402s) and
./internal/gateway (ok 963s).
2026-11-01 02:22:17 +08:00
JoeyWu-tech bec9df0888 sessions: a provider move leaves a thread a Codex has open (#3751)
#3751's second half; 67b12956 fixed the half about lengths. A Codex
thread moved to another provider, by the Sessions page's Move
(MoveCodexProvider, #887) or as Codex steps off magpie (bringBack's
MoveCodexThreads), has each of its rollouts written whole into a temp
file that then takes its place. The move took no Codex lock and left
alone only a thread written to in the last minute. A Codex that resumed
the thread (the app-server, as run below; a resumed TUI too, by Codex's
source) keeps its rollout open to append to for as long as it has the
thread, so what it wrote after a move went into the file the rename had
put aside: a turn the upstream answered was in neither the rollout nor
what Codex sent after its next resume.

moveCodexPaths now holds the thread as Codex holds one it writes to,
archives or deletes (rollout/src/writer_lock.rs, acquire; thread-store
holds it through a whole archive, unarchive or delete): under
thread-writer-locks/.coordination.lock it makes and locks
thread-writer-locks/<thread>.lock, then lets the coordination lock go
and keeps the thread's lock from before a file is copied to the trash
until the thread's row in the state database has moved. Letting go takes
the lock file away under the coordination lock, as Codex's guard does. A
Codex that resumes the thread meanwhile is turned away by Codex itself
("already has an active writer"), so the files and the row move together
and a rollback is written under no Codex. A thread a Codex has open is
left as it was: its files, their time and its row, with no copy kept.

Its error, "a Codex has the session open", is ErrActive too, so it goes
where a thread written to in the last minute goes: MoveCodexThreads
leaves it for its next call, and the Sessions page's reply marks it
active, so the page says "{title} is still being written to; close it in
Codex and try again in a minute" ("{n} sessions ..." for several), in
en, zh, zh-TW, ja and de. No new words and no GUI file changed: app.js
grows 0 bytes. There is no CLI for the move. The minute is the page's
own: codex exec lets the thread go as it exits (the interactive TUI
wasn't tried), but Codex 0.164.0's app-server keeps a thread loaded, and
held, until 30 minutes after it went idle with nothing showing it
(thread_unload_delay_secs, 1800 by default), or until it ends. So a
thread the Codex app has shown can be refused for up to half an hour
after it is closed there, or until the app quits. Those words are left
as they are (#3986).

A Codex home without thread-writer-locks (a Codex from before them)
has no lock to take, and its threads move as before, with the
last-minute check alone. None is made there: PortCodexRollouts reads a
home with one as one whose Codex holds its threads, and would then
rewrite rollouts under a Codex that doesn't. A lock folder that can't
be read, or a lock file that can't be opened, refuses the move with
its error. The coordination lock is waited for at most 10s
(filelock.Wait), under storeMu and mu as the row's 5s busy_timeout
already is; not had by then, the thread counts as held, as in
editRollout.

editRollout, the port's writer, isn't used: it publishes one file under
the coordination lock alone, while a thread's files (a revert's, a
packed twin) and its row move together, and its edit can't refuse a
longer id in a paginated rollout as 67b12956's rewriteCodexProvider
does. rewriteCodexProvider is unchanged, so the padding and that
refusal stay as they were.

A thread bringBack leaves keeps its row on magpie, so the next bringBack
picks it again (codexThreadsOn) and moves it once its Codex has let go:
it isn't left for good. bringBack runs at Disconnect and in Codex's
Sync, which SyncCatalog runs: at the GUI's start, after a provider,
plugin or model list is saved or fetched, and when the catalog is
fetched again (catalog.KeepFresh, at least daily in the GUI and in
magpie serve). Until then the thread stays on magpie, as one written to
in the last minute does now, so for up to about a day while magpie runs.
At a Disconnect magpie also restarts the Codex app's app-server
(KeepCodexAppOnItsProvider, every 3s), which lets the thread go; when
that comes after bringBack's move, the thread waits for the next Sync.
When Codex goes back to openai, or another id of magpie's length,
RelabelCodexThreads first writes a plain rollout's provider in place,
held or not; MoveCodexThreads meets a held thread there only for what
that skips, a packed rollout mostly. For an id of another length it
moves them all.

RelabelCodexThreads takes no lock either. It writes the id over in the
first line, in place, so a Codex appending to the file loses nothing:
tried below, the turn after it was kept and the row stayed as it wrote
it. It is left as it is.

The port's paragraph in docs/subsystems/gateway-routing.md, where
67b12956 put the move's lengths, says so, and so do the comments of
MoveCodexProvider, MoveCodexThreads and bringBack.

What was run (tree d652ce94, on origin/main 74dcf40a, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- TestMoveCodexProviderLeavesAnOpenThread (new): a thread's writer lock
  held as a resumed Codex holds it. The Move is refused with ErrActive;
  the file, its time and the row are as they were, nothing is kept in
  the trash and no temp file is left. With the lock let go (its file
  left behind, as a Codex that ended leaves it), the Move goes through
  and the lock file is gone.
- TestMoveCodexProviderHoldsTheThread (new): looked at from a trigger
  on the row's update, as the Move writes the row, the thread's lock is
  held and the file names the new provider already; the lock file is
  gone after.
- TestMoveCodexThreadsLeavesAnOpenThread (new): two threads on magpie,
  one held. The other moves; the held one keeps its file and row, with
  no copy and no error, and the next call moves it once let go. A home
  without thread-writer-locks moves its thread as before, and gets
  none.
- The three with 74dcf40a's codex_provider.go: red, "err <nil>, want
  ErrActive", "as the row was written: no lock file", and both threads
  moved.
- -race -count=10, the three and every move and port test of
  internal/sessions (TestCodexProviderIn, TestMoveCodexProvider,
  TestMoveCodexProviderPacked, TestMoveCodexProviderKeepsBytePlaces,
  TestMoveCodexThreads, TestMoveCodexThreadsNone,
  TestPortCodexRollouts and its KeepsBytePlaces, LeavesAnOpenThread,
  LongerLine and RepairsForks, TestPortLineDropsClaudeBlocks,
  TestPortLineLeavesOthers): 16 tests, 10 runs each, ok. -race
  -count=3: internal/agent's TestCodexThreadsComeBackOffMagpie and
  TestCodexThreadsFollowMagpieIn (bringBack, bringOver) and
  internal/gateway's TestPortedCompactionReadsTheSame, ok.
- Broken by hand, each alone in a scratch worktree at this tree, the
  eight move tests run, each red:
  - no lock taken: all three new tests, as at 74dcf40a.
  - the row written for a thread left: both LeavesAnOpenThread tests
    ("its row moved to ..., its files didn't"), and MoveCodexThreads
    never finds the thread again ("after its Codex let go: [] <nil>").
  - the lock taken after the copy to the trash: both
    LeavesAnOpenThread tests ("a copy kept of a thread left as it
    was").
  - the lock let go after the files, before the row:
    TestMoveCodexProviderHoldsTheThread.
  - the error not ErrActive: TestMoveCodexProviderLeavesAnOpenThread
    ("err a Codex has the session open, want ErrActive") and
    TestMoveCodexThreadsLeavesAnOpenThread (the held thread's error
    returned, "thread ...: a Codex has the session open").
  - the lock file left when the move lets go: both
    TestMoveCodexProvider tests.
  - thread-writer-locks made in a home without one:
    TestMoveCodexThreadsLeavesAnOpenThread.
  The other move tests stayed green under each.
- Codex CLI 0.164.0, real, with gw-c's #3616 move-open harness: a
  sandbox HOME and CODEX_HOME, loopback only, a fake Responses
  upstream, and MoveCodexThreads from fake-provider to fake through a
  test binary built from each tree. Two turns on a thread T; a codex
  app-server resumes T (T's lock file appears in thread-writer-locks),
  waits 80s and has a turn; at 70s, the move.
  - 74dcf40a: the move moved T, file and row. The turn completed and
    the upstream got it, but the rollout has it 0 times, and Codex
    resuming T on fake sent turns 1 and 2 without it.
  - here: the move moved nothing, file and row on fake-provider. The
    turn is in the rollout (2 lines). With the app-server gone (its
    lock file gone) and the rollout a minute old, the move moved T
    (files 1, db 1), and thread-writer-locks had only
    .coordination.lock after it. Codex resuming T on fake sent turns 1
    and 2 and the turn the app-server had.
  Each tree ran twice: in the first runs the move after the app-server
  came within the minute after its turn, which left T here; the script
  now waits the minute out.
- Codex CLI 0.164.0, the same sandbox: with T's lock file made and
  flocked under the coordination lock by another process, as
  holdCodexThread does, codex exec resume T exits 1 with "thread/resume
  failed: thread ... already has an active writer" and sends nothing;
  once it is let go and the file taken away, the resume runs.
- Codex CLI 0.164.0, the move-open run with RelabelCodexThreads from
  fake to fak2 (one length) at 70s: T relabelled at once, the turn in
  the rollout (2 lines), the row still fak2 after it, and Codex
  resuming T on fak2 sent the turn.
- gofmt -l clean. tools/vetset.sh: go vet -tags nogui for linux,
  windows and darwin, go vet for windows, go build -tags nogui for
  linux and darwin, and go build for windows, exit 0 each; untagged
  linux vet and build exit 1 (no GTK or WebKitGTK dev packages on this
  box).
- go test -tags nogui -count=1 -timeout 45m ./... (log kept), Bun
  1.4.2: 68 packages ok and 8 red, sessions ok; each red on the list of
  reds already filed: agent (#3141, #3398, #3641, and
  TestWSLColdPlaceOpensNothing, #3924), davsync TestSync (#3420), edit
  and testenv (umask 077, #3640), gateway
  TestPluginToldWhereTheAgentWorks (#3675), gui
  TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie
  (#3649), provider TestCodexAppServersOnHome (#3906), then "close of
  synctest channel from outside bubble" (#3632), tui
  TestTUIFetchesSubscriptionModels/agent (#3919)
- On origin/main 1a804859 with this commit cherry-picked (a scratch
  worktree, not this tree): go test ./internal/sessions ok; go test -run
  Codex ./internal/agent, only TestCodexDriftReached red (#3398)
Not run: the GUI tests, i18n-keys among them; no GUI file changed.

Not tried: Windows, where magpie's lock is LockFileEx on one byte and
Codex's on the whole file (as for the port), and macOS; the Codex app
itself, whose app-server was driven over stdio here as the app drives
one; a thread of a Codex in a WSL distro moved from Windows, where the
lock taken may not be the distro's; a file system without locks, where
the move is refused as held.

Review (yetone, at this commit on origin/main bb5e68cea, go1.26.8):
- Checked against Codex's codex-rs/rollout/src/writer_lock.rs: acquire
  takes thread-writer-locks/.coordination.lock, creates and try-locks
  <thread_id>.lock and lets coordination go; its guard's drop takes
  coordination again, closes the file, removes it and lets go. The move
  does the same, and leaves a home without the folder alone.
- On main, the three new tests red on macOS (mote): "err <nil>, want
  ErrActive", "as the row was written: no lock file", both threads
  moved. With this change, ok.
- Broken by hand, each red: letGo called at once (HoldsTheThread);
  os.Remove dropped ("lock file is left", both MoveCodexProvider
  tests); threadOpen's Is false (LeavesAnOpenThread x2); the lock
  folder always made (MoveCodexThreads, "thread-writer-locks made where
  Codex keeps none").
- macOS (mote): go test -tags nogui ./internal/sessions
  ./internal/filelock ./internal/agent ok; -race -count=10 -run
  'TestMoveCodex|TestPortCodex' ./internal/sessions ok (at d0a61b856);
  gofmt -l clean; go vet darwin, GOOS=linux -tags nogui and
  GOOS=windows for sessions and agent ok.
- Windows (xiaomi-gpu, win-run) and Linux (WSL magpie-desktop,
  wsl-run): go test -run 'TestMoveCodex|TestPortCodex'
  ./internal/sessions ok (at d0a61b856).
Not tried by the review: a real Codex CLI or app holding a thread
during a move, on any system; a WSL distro's Codex moved from Windows.

At the pushed tree (rebased on origin/main 7e0fe83d4), macOS (mote):
gofmt clean; go vet darwin, GOOS=windows and GOOS=linux -tags nogui for
sessions ok; go test -tags nogui ./internal/sessions ./internal/agent
ok; -run Budget ./internal/gui ok.
2026-10-31 18:52:01 +08:00
yetone 47173f593a sessions: a Codex thread left magpie keeps no reasoning OpenAI didn't seal
hentulong on X: after routing Codex through WorkBuddy and switching back,
Codex couldn't connect, and a fork said "Persisted response contains
hosted-tool, compaction, or unverifiable hidden reasoning state that
Rustponses cannot replay".

Cause: while Codex is routed through magpie to another vendor, the
reasoning items magpie hands it stay in the thread's rollout. After the
switch back Codex talks to chatgpt.com itself, and OpenAI refuses every
reasoning item it didn't seal. On the owner's real account:
- summary only, no encrypted_content: unsupported_persisted_item_context
  (the reporter's Rustponses error) on a previous_response_id
  continuation;
- with content (reasoning_text, what Codex 0.165 writes for DeepSeek via
  magpie): 400 array_above_max_length "Invalid 'input[5].content'";
- foreign encrypted_content: invalid_encrypted_content.
Codex treats each as fatal, so that thread and its forks fail while new
threads work. No stale config: Unwire/EndFailover drop openai_base_url.

Fix: when Codex is no longer routed or failing over (Unwire, quit,
uninstall and the periodic pass), PortCodexRolloutsLeft rewrites, in
threads begun on openai/magpie, every reasoning item (and every one in a
compacted line's replacement_history) whose encrypted_content isn't an
OpenAI Fernet token ("gAAAA") into type "magpie_reasoning", without id
and encrypted_content. Codex reads an unknown type as Other and never
sends it; magpie's sessions readers still show it. The edit keeps member
order and line length (same fitLine/lock path as the existing port),
has its own state entry, and starts at 2026-09-21. A survey of 150 live
rollouts found 340 of 340 OpenAI reasoning items in the gAAAA shape.

Run (mote, at f1d0c0bfd + this): go vet ./... for darwin, linux and
windows; go build for the three; go test -tags nogui -timeout 45m ./...:
every package ok but internal/gui, whose one red is
TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll), open on main as #4514; gofmt -l clean.
Broken by hand: with the retire step off, and with Unwire passing false,
TestPortCodexRolloutsLeftRetiresUnsealedReasoning,
TestPortCodexRolloutsLeftKeepsItsOwnState and
TestCodexDisconnectRetiresMagpieReasoning go red.
Real Codex 0.165, sandbox CODEX_HOME, owner's account: a turn via magpie
with auto/deepseek-flash, then `codex exec resume` on gpt-6-sol direct
failed with array_above_max_length; after the left port the same resume
answered. The summary-only Rustponses refusal was reproduced with a
websocket probe against chatgpt.com and is retired by the same rule.

Not tried: the reporter's exact case in the interactive TUI (exec
resume doesn't warm up, so it never sends previous_response_id). A
thread Codex holds open keeps its in-memory history until reopened; a
switch not made through Unwire is caught by the periodic pass within
10 minutes.

Rebased after the full run onto 9551fadcb (5174c0970 GUI assets,
9551fadcb gateway/usage; no file here). At the pushed head:
go test -tags nogui -run Codex ./internal/sessions ./internal/agent ok,
go vet ./internal/sessions ./internal/agent ok.
2026-10-31 17:47:20 +08:00
yetone a5ba5f23bd agent: a requires_openai_auth = false the user wrote in magpie's Codex table stays
蛋仔 on Discord wanted the Codex app wholly on magpie, with no ChatGPT
account of its own, and set requires_openai_auth = false in
[model_providers.magpie] by hand. While their ChatGPT sign-in had room,
the next Sync (authStale) set it back to true, and putProvider's
SetTOMLTable replaced the table without it. magpie only ever writes true
or nothing, so a false is the user's: openaiAuth now reports it as not
known (no rewrite, no drift), and putProvider carries it into the table
it writes.

Run (mote, at this head):
- go test ./internal/agent -count=1 (whole package, rebased on 819aad1bc): ok
- GOOS=linux and GOOS=windows go vet ./internal/agent: ok
- Broken by hand (ownNoAuth always false): the new subtest "user's own
  false kept" goes red ("used up false: ... kept").
Not tried: the real Codex app with false set (the reporter's case).
2026-10-30 18:02:42 +08:00
yetone fb2e11e288 agent: a Codex sign-in OpenAI refused to refresh for good counts as none (#4308)
jjt on Discord: Codex's ChatGPT sign-in was revoked, and magpie's
models were gone from Codex until they signed in again.

Cause: Codex keeps a revoked sign-in's auth.json as it was and remembers
the permanent refresh failure in memory alone (codex-rs
login/src/auth/manager.rs). magpie read auth.json alone
(codexChatGPTKnown), counted the sign-in and wired Codex beside it
(openai_base_url, requires_openai_auth). There, Codex's /models went to
the gateway, which passed OpenAI's 401 token_revoked through, so the
picker had no magpie model; and every turn, magpie's models too, failed
at Codex 0.162.1's workspace routing discovery
(/backend-api/wham/accounts/check, 401).

Change:
- provider: codexRefresh tells a refusal Codex takes as permanent
  (request_chatgpt_token_refresh: refresh_token_expired, _reused or
  _invalidated, a 400 invalid_grant, or a 401 - here only a 401 that
  carries an error code, read as oauth/error.rs reads it). When magpie's
  own refresh of Codex's sign-in (codexTokenRenewing, from the usage read
  that KeepOnAnAccountWithRoom runs) is refused that way, and the store
  still holds that refresh token, codex-signin-gone.json keeps the Codex
  home -> sha256 of the refused refresh token (no token stored). A
  successful refresh forgets it. Writes Touch the catalog so the agents
  resync; the loop's noteCodexGoneNow notices a sign-in made again
  elsewhere within minutes.
- agent: codexChatGPTKnown reads such a sign-in as none
  (provider.CodexSignInGone), as v0.1.2087 did for forced_login_method =
  "api": magpie is Codex's provider without requires_openai_auth, the
  user's auth.json stays. A record that can't be read is unknown (as
  magpie last wired it). Signing in again gives another refresh token,
  which the record doesn't name: Sync writes requires_openai_auth back.
- gateway: codexModels doesn't pass a revoked /models answer
  (provider.SignInRevoked) through: it lists Codex's cached models and
  magpie's. The desk file does the same while the live list says revoked
  (CodexListRevoked). Any other refusal (token_expired, 5xx) is as before.
- docs: agent-wiring and gateway-routing.

Run:
- real codex 0.162.1 (app-server over stdio, and exec) on mote, sandbox
  HOME/CODEX_HOME, fake OpenAI (chatgpt_base_url,
  CODEX_REFRESH_TOKEN_URL_OVERRIDE, provider.CodexBase) answering 401
  token_revoked and refresh_token_invalidated; no real network.
  - Old wiring beside the dead sign-in, old gateway: model/list had no
    magpie model (jjt's case). With the gateway change: fake/m1 listed,
    but exec -m fake/m1 fails at workspace routing discovery (401), and
    account/read errors too - why the wiring change is needed.
  - Uncommitted e2e in the agent package with magpie's own written
    config: Set("fake/m1") wrote it beside the sign-in; magpie's
    LoginUsage("codex") then heard the refresh refused, Sync rewrote it
    to model_provider = "magpie", model_catalog_json, no
    requires_openai_auth. account/read: {"account":null,
    "requiresOpenaiAuth":false}; model/list: fake/m1 plus Codex's
    models; exec -m fake/m1 answered "hi from magpie"; auth.json byte
    for byte the same.
- Red on the old code (broken by hand): without the codexChatGPTKnown
  check TestCodexGoneSignInIsNoChatGPT is red; without the
  noteCodexSignInGone call TestCodexSignInGoneWhenRefusedForGood is red;
  with codexRefreshGone true for every failure TestCodexRefreshGoneRule
  is red; TestCodexModelListRevokedSignIn and
  TestCodexDesktopCatalogRevokedSignIn are red on the old gateway.
  Taking out the store re-check in noteCodexSignInGone leaves the tests
  green: a token Codex rotated meanwhile is already held by the hash
  comparison, and the re-check only saves a needless record, log line
  and resync. Not guarded on its own.
- via mote-run, at this commit rebased on origin/main 1f03d7546:
  gofmt -l clean; go vet ./internal/provider ./internal/agent
  ./internal/gateway for darwin, linux (-tags nogui) and windows ok;
  go test -timeout 45m -p 1 of the three: provider ok (92.3s), agent ok
  (192.1s), gateway ok (530.9s). The first full run had the new provider
  test red: run after the other Codex tests it read their cached logins
  and listed none; it now has the resetRevoked/rememberLogins setup its
  siblings use.
  Rebased after the run onto 05a6087e1 (access: key model scope) and
  8cbd0a9c9 (GUI loading bird); neither touches the Codex paths, and
  this push wasn't run again on them.

Not tried: the real Codex desktop app (ChatGPT.app); signing in again
with the real binary (the unit test writes a new auth.json); the
keychain credential store; magpie's left-alone mode, where magpie
doesn't refresh Codex's sign-in, so nothing is recorded there;
Codex homes on Windows and in WSL.
2026-10-30 01:40:48 +08:00
yetone f5806ed21e agent: Codex's forced_login_method = "api" counts as no ChatGPT sign-in (Tiger)
Tiger on Discord: after restarting Codex the Codex app showed a sign-in
screen whose only option was "Sign in with an API key", and they couldn't
get back in.

Cause: a top-level forced_login_method = "api" in ~/.codex/config.toml.
Other tools and guides write it; magpie never has (git log -S). With it,
Codex won't use a ChatGPT sign-in: the TUI logs it out as it starts
(codex-rs login/src/auth/manager.rs enforce_login_restrictions) and the
app server reads no account (load_auth). The app takes its allowed
methods from configRequirements/read, which then says ["api"]. magpie
read auth.json alone (codexChatGPTKnown), counted the sign-in, and wired
Codex beside it: the built-in provider, which requires OpenAI auth. The
app asked for a sign-in that only an API key could give.

Fix: codexChatGPTKnown reads forced_login_method = "api" as no ChatGPT
sign-in. magpie is then Codex's provider without requires_openai_auth,
and Codex needs no sign-in for magpie's models. The user's line stays
(magpie's default never overrides the user's value). Taking it out
brings the ChatGPT account back: Sync writes requires_openai_auth = true
again. connectinfo's codexChatGPT gets the same answer.

Run:
- real codex app-server 0.162.1 on mote in sandbox CODEX_HOMEs (stdio
  JSON-RPC: account/read, getAuthStatus, config/read,
  configRequirements/read). Beside a ChatGPT sign-in with forced api:
  account null, requiresOpenaiAuth true, allowedLoginMethods ["api"] —
  Tiger's screen. magpie as the provider, no requires_openai_auth, same
  auth.json: requiresOpenaiAuth false, and auth.json kept.
- TestCodexForcedAPILoginIsNoChatGPT is red on the old codex.go (it
  wrote openai_base_url and requires_openai_auth = true beside the
  sign-in) and green with the fix.
- via mote-run: gofmt -l; go vet ./internal/agent for darwin, linux
  (-tags nogui) and windows; go test -timeout 45m ./internal/agent ok
  (150.6s); ./internal/provider ok earlier on the same codex.go change.

Not tried: the real Codex app (ChatGPT.app) against a running magpie
built with this; managed requirements.toml / MDM allowed_login_methods
and forced_chatgpt_workspace_id, which this doesn't read; a revoked
ChatGPT sign-in (jjt's report): magpie still counts its tokens as a
sign-in and wires Codex beside it, and the /models 401 there comes from
OpenAI, passed through.
2026-10-30 00:19:43 +08:00
yetone adc618bbf9 codex: a Codex switched off in magpie still has its held ChatGPT account read, so the Codex app sends magpie's models (sherlock_23333 on X)
sherlock_23333 on X: once the ChatGPT account Codex is signed in to ran
out, the Codex app's Send stayed greyed even on a magpie model, through
restarts and reconnects.

The gate is the Codex app's own (ChatGPT.app 26.1021, composer gM):
Send is blocked while its authMethod is chatgpt and its own /wham/usage
says rate_limit.allowed false with no credits. magpie's one lever is
the takeover (codex.out): magpie becomes Codex's provider without
requires_openai_auth, so the app-server reports no ChatGPT account and
the gate lifts. That runs only when provider.CodexUsedUp says the
account is held, and CodexUsedUp read LoginUsage, which returns nothing
for a provider switched off or removed in magpie (leftAlone). So a user
who turned Codex off in magpie once its allowance ran out never got the
takeover, and one already taken over was put back on the held account.

Now, with Codex left alone, CodexUsedUp reads the active account alone
(codexHoldReading) while Codex takes magpie's models beside its sign-in
or magpie is its provider for the held account (Agent.HoldMatters, via
the new provider.CodexHoldMatters hook). At most once a minute (the
loginReading cache), with the token as Codex keeps it, never renewed or
written (codexTokenAsKept); the Usage page still shows nothing of it.
Codex's prompts and base_instructions are untouched.

Run at f41b63232 + this change, on mote via mote-run:
gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...; go build ./... all ok.
go test -count=1 -timeout 45m ./internal/provider ./internal/agent: ok
(219s, 340s).
Rebased on 9f25de56c (a Cursor mover min and a GUI test), then at 9f25de56c +
this change: go vet and go test -count=1 -timeout 45m of
./internal/provider ./internal/agent again: ok (178s, 273s).
8c63c5b78 (plugin speech models; no file in common) landed on main
after that run and this is rebased onto it; the two packages were not
run again with it.

Broken by hand: without the leftAlone branch in CodexUsedUp,
TestCodexHoldReadLeftAlone fails ("switched off: CodexUsedUp = false on
a held account"); with the left-alone token read sent back through
codexToken, it fails with the expired sign-in refreshed once.

Not tried: the reporter's own config (whether their Codex was off in
magpie is inferred, not confirmed); the real Codex app against a held
account; internal/gateway's suite (no gateway code changed); Linux and
Windows test runs (vet only).
2026-10-29 18:20:50 +08:00
yetone 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 4d9058a98, on mote):
- go vet of the six touched packages; gofmt -l clean.
- go test ./internal/codexrelay and the CodexRelay, CodexFailover,
  CodexProxy, RelayOpenCodex and CodexPIDs tests: ok.
- codexrelay tests on Windows (win-run) and Linux (wsl-run,
  magpie-desktop): ok.
- Windows smoke of the real binary (nogui build): `codex-relay`
  answers / with the readable 503, stays while its watched process
  lives, ends after it.
- Real codex 0.162.1 e2e on mote, sandbox CODEX_HOME, API-key sign-in,
  fake upstream: the relay waited out a port held 2s, then turn 1
  completed (RELAYED-OK); a turn on openrouter/kimi-k2 showed the
  refusal's message; turn 2 was mid-stream when Leave ran, the port
  was free at once, the turn completed, and the relay ended.
- GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... and a
  Windows build: ok.
- Full suite, go test -count=1 -timeout 45m ./... on mote: every
  package ok but internal/gui, where 10 real-window AppKit tests
  (dock, panel, tray, titlebar, covered window, plugin page) are
  killed at their 20-80s bars. The same 10 fail the same way at
  origin/main 4d9058a98 on mote, run alone: mote's AppKit hang, #4125
  (and #2645, #1936). None of them touches the quit path changed here.
- Rebased on origin/main 1198cff60 to push. Still running there when
  pushed: go vet ./..., Windows and Linux vet of the touched packages,
  and go test of codexrelay, gateway, agent, provider and cli. A red
  it shows gets its own issue.

Broken by hand, each red, then restored:
- Leave without ln.Close(), with a 1s delay before Shutdown injected:
  "the port isn't free after Leave" (with ln.Close: green).
- No pid watch: "relay outlived the Codex it was left for".
- Leave without the token check: an empty token got 204.
- No Origin/Host guard: Origin null got 200.
- No masking refusal, no magpie-model refusal: 200, sent upstream.
- An empty 503 at "/": TestCodexRelayIsNotMagpie red.
- RelayOpenCodex starting nothing: "no relay for the open Codex".
- EndCodexFailover never saying ended: TestCodexFailoverEndsWithMagpie.
- CodexPIDs missing "codex": the Codex app and CLI not found.

Not tried:
- the real Codex desktop app, and a real ChatGPT account. With a fake
  ChatGPT token codex 0.162.1 stops at its own "workspace routing
  discovery" against chatgpt.com before sending a turn, so the
  ChatGPT path is covered by unit tests only;
- a Codex in a WSL distro, and a connected (not failover) Codex: both
  left as they were;
- a magpie that ends without quitting (killed, crashed): still leaves
  failover in place and no relay;
- the relay's memory use as the full binary.
2026-10-29 17:13:05 +08:00
yetone fae438b4a5 agent: Codex switched on again is joined, and its own models say where a pick goes
NancyTom18 on X: Codex on a routing group, Disconnect and restore, switched
on again, then an OpenAI model picked: every OpenAI row said 直连. After a
routing group again they said 经 magpie.

Reproduced in a sandbox HOME (ChatGPT sign-in, a group): reconnect put the
group back by Apply alone, so Codex was beside its sign-in and not joined
(codex.joined went with the Disconnect). Picking one of its own models then
took magpie out (set → unroute, #940): config.toml had no openai_base_url
and no model_provider, so Codex went straight to OpenAI and the 直连 tags
were true. Back on the group, the rows said via magpie from routed(), while
a pick would again go straight to OpenAI, with no ask: that label was false.

- reconnect calls Join first where the agent has one, so a Codex switched
  on again comes back as the switch first connects it: joined, its own
  models staying through magpie.
- modelOptions: beside its sign-in, not joined (with ChatGPT), and failover
  off, Codex's own models say Direct "OpenAI", so the picker tags them
  直连 and asks before a pick takes Codex off magpie.

Tests: TestCodexReconnectStaysJoined (red on the old applied.go: "connected
again, not joined"), TestCodexBesideOwnModelsSayDirect (red on the old
codex.go: "gpt-5.5 says via"). Each fix reverted by hand, its test went red.

Run on mote at this tree: go test -timeout 45m ./... all ok except
internal/gui TestMainWindowCorners/macOS_26_SDK, mote's macOS 27 red filed
as #3949 (window chrome, untouched here). go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./..., go build ./..., gofmt -l
clean. GUI files unchanged; agent-leave-magpie and agent-path-same pass in
Chromium and WebKit (4/4 each).

Not tried: a real Codex binary with a real ChatGPT sign-in sending a turn;
the route is read from config.toml as Codex's own provider rules read it.
A Codex already beside a group from before this release stays so: its
OpenAI rows now say 直连 and ask; switching it off and on joins it.
2026-10-29 07:32:05 +08:00
yetone 72ca3d593b codex: magpie as Codex's provider keeps the Codex app's ChatGPT account while it has room, so its Work chats and projects stay
Qyburn3 on X: with magpie taking Codex over, the Codex app's "Work"
sessions don't load while the model still answers; turned off, they
come back.

Cause: [model_providers.magpie] had no requires_openai_auth, so Codex's
app-server answers account/read and getAuthStatus with no account and no
token whenever magpie is Codex's provider (magpie API, or the codex.out
takeover). ChatGPT.app 26.1021 then switches to an identity of no
account: onboarding again with no name, ChatGPT mode's projects and
chats ("Work") empty, no avatar, no Chrome control (#1824).

Now putProvider writes requires_openai_auth = true while Codex has a
ChatGPT sign-in with room (openaiAuth: codexChatGPTKnown and not
codexUsedUp), and takes it out otherwise:
- API key alone: left out. With it Codex drops image_gen (captured: 11
  tools without, 10 with), and there is no account to keep.
- No sign-in: left out (the app would ask for a sign-in).
- A sign-in the Codex app holds (codex.out, or magpie API while used
  up): left out, since the app's composer gate (authMethod chatgpt +
  allowed false, #540) would grey Send for magpie's models again. The
  takeover's note now names "its ChatGPT chats and projects" among what
  is off till the reset, beside Keep on ChatGPT.
- An unknown sign-in read leaves the table as it is.
Sync rewrites the key on any table that disagrees (authStale), an older
magpie's included, and the key joins codexAppRoute, so the Codex app's
app-server is restarted onto its account with nothing for the user to
do. The magpie API note no longer says Chrome control needs ChatGPT (en,
zh, zh-TW, ja, de); agent-wiring.md says why.

Real app (mote, ChatGPT.app 26.1021 with its codex 0.164.0-alpha.11,
sandbox CODEX_HOME, copied real ChatGPT auth, auth.json unchanged after):
- native config: the account's projects and recent chats listed.
- magpie table without the key: onboarding, "ChatGPT Work" with no
  projects, no chats. app-server: account null, authMethod null.
- magpie table with requires_openai_auth = true (the keys this commit
  writes): every project and chat back; account/read chatgpt pro,
  getAuthStatus authMethod chatgpt with a token.
- Model requests to a capturing server, with and without the key:
  Bearer is magpie's experimental_bearer_token, no ChatGPT-Account-ID,
  15 tools both ways with a ChatGPT sign-in (image_gen kept).

Tests: TestCodexMagpieProviderKeepsChatGPTAccount (ChatGPT + magpie API,
used up and back; taken over and the reset; an older magpie's table from
live config bytes; API key and no sign-in, fresh and after ChatGPT) and
TestCodexAppRouteFollowsOpenAIAuth. Broken by hand: on the old codex.go
5 of 7 subtests red; without the Sync re-derive 3 red; with the key kept
while used up 2 red; agents.go without the route key, the route test red.

Run (mote-run, at this tree on origin/main 157d575c3; the build and the
agent run again after the rebase onto e5e2aa58e, ok; 5a85a9836 after it touches redact only,
no agent
or GUI file, ok): gofmt -l clean;
go build ./...; go vet linux (-tags nogui) and windows ./..., darwin
./internal/agent; go test -tags nogui -run 'Codex|Agents|Sync|Disconnect|Route'
./internal/agent ok; GUI codex-signin-always, codex-app-out, i18n-keys
and the i18n files, Chromium and WebKit, 96/96.
Not run before the push: the full go test ./... (mote had three other
sessions' full suites at load ~100); it runs after, and any red gets an
issue. Not tried: the used-up case on the real app with the key (the
composer gate is from #540's reading of 26.1013), Windows and Linux
Codex apps.
2026-10-29 01:18:59 +08:00
yetone 67c8f562cd codex: a subagent named a model goes on it with "Same as the lead" (mengxiao on Discord)
mengxiao left Codex's subagent model at "Same as the lead" in magpie,
asked the lead for a subagent on GPT-6.1 Terra, and magpie put the
subagent on the lead's model anyway. The cause was codexFollowTo
(internal/gateway/codex_follow.go): on the ChatGPT-sign-in path, a
collab_spawn request asking for one of Codex's bare models, with nothing
set in magpie or [agents] default_subagent_model, was moved onto the
model the conversation's own turns go on (a1174674d, cybercaius).

Codex starts a spawn that names no model on its lead's model (codex-rs
core/src/agent/child_config.rs: build_agent_spawn_config sets the
child's model to the step's slug; apply_requested_spawn_agent_model_
overrides takes spawn_agent's model, else default_subagent_model; a
role's config can set one too). So under a lead on a magpie model, a
bare model in a subagent's request was always named by the lead, the
config or a role: the user's or the lead's pick. The GUI already says
"Same as the lead" means "the lead's model, or another the lead picks".

- codexFollowTo now handles memory calls only; a subagent is moved only
  by the model set for Codex's subagents in magpie (codexSubagentPick,
  unchanged). codex_backend.go no longer builds a pick from it.
- Dead code out: codexSessionOf, codexLeads.of, and CodexSideSet's
  "subagent" case (its doc moved onto servedSession).
- docs/subsystems/gateway-routing.md says a subagent never follows.
- Sibling checked: Claude Code writes no CLAUDE_CODE_SUBAGENT_MODEL
  while following the main model, and Claude Code takes the Agent call's
  model first; Claude Desktop's pick acts only when a model is set.
  Neither overrides a named model under "same as lead".
- Who relied on a1174674d (a lead's own pick of a Codex model following
  the session): pick the session's model as Codex's subagent model in
  magpie, which puts every subagent on it.

Ran (mote, -tags nogui -count=1, this change on 7fd77a944; rebased after onto a57c95513, which adds only docs, LESSONS and GUI test files):
- TestCodexSubagentKeepsTheModelItWasNamed on the old code (b01193ef9
  with only the new test): FAIL, "ChatGPT was asked for []".
- go test -run 'TestCodex(Subagent|Side|Memor|AppSide|Title|Prediction)'
  ./internal/gateway ./internal/agent: ok.
- go vet (darwin nogui, GOOS=linux, GOOS=windows) on internal/gateway
  and internal/agent: ok. gofmt -l: clean.
Not run: the full go test ./... suite (started on mote, not waited on);
staticcheck (not installed on mote); a real Codex spawn_agent with a
ChatGPT sign-in and a lead on a magpie model.
2026-10-28 16:16:02 +08:00
yetone f201183047 tune: the compact window is Long conversations, one value for both agents
7eleven (Discord #help): the Usage page's "Tuned for you" compaction
value and the agents' sheet "Long conversations" window were two values
that could disagree. Codex's tune wrote model_auto_compact_token_limit
into config.toml beside the catalog's context_window that Long
conversations writes; Claude's read its own env.

One source of truth: settings.CompactAt / FullContext. Tune's compact
row for Codex and Claude Code now has source "long": its Current is
settings.Compact(), Use calls provider.SetCompactAt (Sync writes Codex's
catalog and Claude's CLAUDE_CODE_AUTO_COMPACT_WINDOW as before), Undo
puts back the CompactAt/Full it stashed under tune.long.compact. So a
value set on either page shows on the other and writes the same config.
writeCompact marks claude.compact_long when the env value came from
settings, so Claude's row reads it as ours, not as the user's.

Migration (Codex Sync, local place): an old tune.codex.compact stash
whose limit is still the one tune wrote moves into Long conversations.
At default or Full it takes tune's value; with a value the user set it
takes tune's only when smaller. config.toml gets the user's earlier
limit back or loses the key; the stash is forgotten. A limit the user
changed after tune wrote it, or wrote themselves, stays and reads
Locked. A provider's Compact at or the user's own Claude env stays
Locked too.

Run (mote, at this tree):
- go vet on agent, provider, gui, tune; GOOS=linux go vet -tags nogui
  ./...; GOOS=windows go vet ./...; go build ./... and -tags nogui: ok
- go test -tags nogui ./internal/agent ./internal/provider
  ./internal/tune ./internal/gui: ok (TestCoreScriptBudget within the
  budget, not raised; context.js is 33 bytes smaller)
- GUI: compact-one-value.test.cjs (new; Chromium and WebKit, en zh
  zh-TW ja de) and context-tune: 104/104 at the rebased head
Broken by hand: the Codex long branch, the Claude long env check and
the Sync migration call each turned red TestClaudeCompactAt,
TestCodexHomeEnvTakesThePick, TestTuneCodexCompact,
TestTuneCodexOwnLimit, TestTuneCodexMigrate (4 subtests),
TestTuneClaudeLong and TestTuneCodexMigrateOnSync. Old context.js and
i18n.js turn compact-one-value red ("You set 272K").
Not run: full suite, Go or GUI (shipped at once per owner; the GUI suite
is still running on mote, reds get their own issues).
Not tried: a real Codex or Claude Code session reading the written
config; the migration on Windows/WSL places (it runs for the local
place only).
2026-10-28 13:52:08 +08:00
yetone c544789047 agent, gui: the Codex takeover names browser use and offers Keep on ChatGPT
eddie.zhan on Discord (10-27): once Codex's allowance ran out, magpie
took it over and "many features stop working, browser use is blocked,
the agent says it has no permission".

Cause, from openai/codex 5a361b5: under the takeover magpie is Codex's
model provider without requires_openai_auth, so app-server's
getAuthStatus hands the app no auth token. The Codex app's Chrome
control needs that token, so browser use is off till the reset, with
cloud tasks, the usage meter and Log out. Image generation (actor
authorization header) and web search (provider default) stay. Bringing
requires_openai_auth back would bring back the greyed Send the takeover
exists to avoid, so it can't be kept by config.

The off switch existed (sign-in > Always ChatGPT, `magpie codex login
chatgpt`) but nothing under the takeover pointed to it. The default is
kept; the opened Codex row's takeover note now names browser use and has
a Keep on ChatGPT button (login=chatgpt) on its own line. In every
language.

Also fixed: Always ChatGPT picked while Codex was taken over on one of
its own models left model_provider = "magpie" for good. set now puts it
back on the sign-in as Join leaves it.

Run (on mote, at this tree):
- go test ./internal/agent ./internal/gui: ok except
  TestWSLColdPlaceOpensNothing (#3924) and TestMainWindowCorners/macOS_26
  (#2645), both red on origin/main f2b4b9894 too.
- TestCoreScriptBudget ok; app.js 1,310,432 under 1,310,460, not raised.
- GUI codex-app-out, codex-signin-always, i18n-keys in chromium and
  webkit at 980 and 440, every language: 95 pass, 1 red is #3897
  (i18n-keys plugin words, red on main).
- gofmt -l clean; go vet darwin, linux (nogui), windows on internal/agent
  and internal/gui.
Broken by hand: TestCodexOwnModelOutThenKeptOnChatGPT red on the old
set (model_provider = "magpie" left); codex-app-out red with origin's
app.js/i18n.js (no browser use in the note).
Not tried: the real Codex app, a real used-up account, the Windows box
and the Linux app.
2026-10-28 03:36:13 +08:00
yetone 6c063ac1b2 agent: a model Codex hides joins Codex's own group in the picker
v0.1.1737 offered a model the user ticked but Codex's bundled catalog
hides (GPT-6.1 Terra) under a "Codex" section of its own, beside the
provider's group. ysm119 asked on Discord why one provider's ticked
models showed up as two groups. codexViaMagpieFor now gives such a
model the group and icon of the provider's own entries and lists it
first among them.

Run: go test -run 'Codex|WSL|Wsl|Via|Magpie' ./internal/agent ok;
go vet ./internal/agent for darwin, windows and linux (nogui) ok;
gofmt clean.
Broken by hand: with the group assignment removed,
TestCodexHiddenTickedModelOffered fails ("gpt-h in \"Codex\", gpt-a in
\"OpenAI\"").
Not tried: the GUI picker with a real Codex account.
2026-10-27 23:30:37 +08:00
yetone c80b32c936 agent: a model Codex hides but the user ticked is offered in Codex's picker
ysm119 (Discord) ticked four models on the Codex subscription and Codex's
picker offered three. GPT-6.1 Terra is "visibility": "hide" in Codex's
models_cache.json, so catalog.Codex() leaves it out of Codex's own list,
and viaMagpieFor dropped every codex/… entry as only a hop, so it was
offered nowhere. codexViaMagpieFor now drops a codex/… entry only when
Codex's own list already has its model; the rest stay, via magpie. Both
pickers (live Codex and Codex in WSL) take it; viaMagpieFor had no other
caller and is gone.

Run: TestCodexHiddenTickedModelOffered is red with the codex/… entries
dropped as before ([OpenAI:gpt-a]) and green with the fix;
go test ./internal/agent -run 'Codex|WSL|Wsl|Via|Magpie' ok; go vet
darwin and GOOS=windows; gofmt clean.
Not tried: picking gpt-6.1-terra with a real ChatGPT account.
2026-10-27 22:56:58 +08:00
yetone add927e604 codex: the Codex app beside the ChatGPT sign-in lists magpie's models too
laddieyao (Discord #general, 10-27): with Codex joined to magpie beside
its ChatGPT sign-in, the Codex desktop app's model picker showed OpenAI's
GPT models alone, while the Codex CLI listed magpie's. The /models
request does reach magpie's gateway and its answer holds magpie's
models. ChatGPT.app 26.1013's picker then narrows app-server model/list
to the models a Statsig config (107580212, use_hidden_models /
available_models) names, while Codex is on its built-in provider, unless
Codex reads its list from a file (model_catalog_json,
hasConfiguredModelCatalog) or names a provider of its own. The CLI has
no such filter.

Where the Codex app is installed (codexReaders has an "app"), and only
joined/beside the sign-in (not magpie as Codex's provider, not account
failover alone), magpie writes the list it hands Codex at
/backend-api/codex/models to ~/.codex/magpie-desktop-models.json and
names it with model_catalog_json. Codex is still on its built-in
provider. With a catalog named Codex asks for no list, so magpie asks
the backend itself, with Codex's live sign-in (provider.CodexLiveList):
its entries go in verbatim, base_instructions and all, merged as the
gateway merges them (codexMerged, factored out of codexModels: picked,
hidden, window, V1, AutoReview edits), magpie's models after them.

- A list not known (not asked yet, or the backend failing) is unknown:
  the file as it was stays, never an empty list; a key naming a file
  that is gone goes, as Codex loads no config then.
- Written via temp+rename at Join, set, settle and every Sync (so a
  change of magpie's models, picks or hidden models rewrites it, as
  SyncCatalog runs on them); the backend list is asked again hourly
  (5 min after a failure) and a change syncs again.
- A model_catalog_json of the user's own stands; none is written beside.
- magpie API, the app gone, or unwire take the key and the file out;
  unroute never restores the desk file as the user's catalog.
- connectinfo counts the file, so a running app on an old list reads
  as needing a restart.
- CLI-only machines: unchanged, the live /models path as before.

Run:
- Real account, sandbox HOME (copy of auth.json, chatgpt Pro; live
  ~/.codex untouched): Join wrote model_catalog_json and the file with
  the real backend's 10 entries (gpt-6.1-sol ... codex-auto-review, each
  with base_instructions) plus relay/claude-opus-5.5 and
  relay/claude-sonnet-4-5. Then the real app-server bundled in
  ChatGPT.app (codex 0.163.0-alpha.10.2, CODEX_HOME sandbox, base URL
  pointed at a dead port) model/list returned all 12, relay models
  visible, and config/read showed model_catalog_json set, which is what
  the app's picker checks to skip its filter.
- New tests: TestCodexDesktopListBesideSignIn, ...CLIOnly,
  ...KeepsTheirs (internal/agent), TestCodexDesktopCatalog
  (internal/gateway).
- Broken by hand, each went red: deskList a no-op (all three agent
  tests), the user's-own branch removed (KeepsTheirs), the gone-file
  branch removed (KeepsTheirs), the keep-last-good rule broken in
  codexDeskRefresh (TestCodexDesktopCatalog).
- go test -tags nogui -timeout 45m ./internal/agent ./internal/gateway
  ./internal/provider ./internal/cli at bc0a99bb6 (on 68bbcc01c):
  agent, gateway, cli ok; provider red on TestUnreadLogins...
  (synctest crash, #3632) and three TestFetch* tests (#3854), both red
  the same at origin/main 68bbcc01c / 5a3292354 run alone, both filed.
- Rebased over e7f21dba5 (Disconnect keeps a hand-set catalog): the
  conflict in unroute merged (the desk key counts as no catalog of the
  user's), and -run 'CodexDesktop|Disconnect|Unwire|Catalog'
  ./internal/agent ok. The packages' run at the final head could not
  build: the machine's disk was full (other sessions).
- gofmt -l clean; go vet ./... on darwin, GOOS=linux, GOOS=windows ok.

Not tried: clicking the real desktop app's picker (the app-server
answer and config were checked, not the GUI); the Windows Store app
(its readers get no version but count as the app; not run there); a
backend list change rewriting the file while the app runs (the app
needs reopening to read a new file, which connectinfo's restart notice
covers).
2026-10-27 18:38:27 +08:00
yetone 28f3c4d7fd codex: the Codex app's first 100 models hold the ones used, hidden ones last
@ZhenLuoTTAWDTT on X: with Codex on magpie the model list stops short,
and the models past it can't be chosen.

Cause, from the clients' own code: the Codex app (ChatGPT.app
26.1013.40934, app-initial-90eb42395b7d.js) and the VS Code extension
(openai.chatgpt 26.51021.22027, model-queries-667cf4bd657d.js) both ask
their app-server for model/list with includeHidden, cursor null and
limit 100 (e?.limit??100) and never ask for nextCursor. codex-rs's
list_models pages the list sorted by priority, hidden entries counted,
so anything past the 100th is in no picker there. The CLI's /model
(tui model_popups.rs) lists every preset in a scrolling popup and has no
cap. magpie truncated nothing; its models are numbered after the
account's own, so a user with many models lost everything past ~100 in
the app, while hidden entries (codex-auto-review and the like) took
slots at the top.

Fix: codexcat.Fit ranks the list last of all, on every route magpie
hands Codex a list (/backend-api/codex/models after the user's own
order, /v1/codex/models before its 1 MiB cut, and the
model_catalog_json file via CatalogUsed): hidden entries go after every
listed one, and with more than 100 listed, the models Codex used in the
last 30 days (usage.CodexUsed, most recent first, at most 100; on
/v1/codex/models only the asking key's, CodexUsedBy) are brought into
the first 100 in the order they stood. The rest keep their order. The
list's ETag and X-Models-Etag carry a tag of the used set
(codexcat.UsedTag), so Codex asks again when it uses a model it hadn't;
CodexUsed is read at most once a minute, or at once when Append writes a
Codex call to a model it doesn't hold. Documented in
docs/subsystems/gateway-routing.md.

Tests (each red on the old code, broken by hand: Fit a no-op, the gateway
calls and the used tag removed, Append's codexUsedNew removed):
TestFitKeepsUsedModelsWhereTheCodexAppReads, TestFitLeavesAShortListsOrder,
TestCatalogUsedFits, TestUsedTagIsTheSet (codexcat), TestCodexUsed
(usage), TestCodexModelListKeepsUsedModelsInTheAppsHundred and
TestCodexCatalogKeepsTheKeysUsedModelsFirst (gateway).

Real run: codex-cli 0.162.1's app-server in a sandbox CODEX_HOME (never
~/.codex) with a model_catalog_json of 3 hidden entries at priority 1-3
and 150 listed models, driven over stdio with the app's own request
(model/list includeHidden, limit 100). Before: page 1 held 100 of 153,
3 of them hidden, the last many/model-096, nextCursor "100". The same
catalog put through Fit with many/model-140 used: page 1 has no hidden
entry and ends with many/model-140. The TUI's /model scrolled to all
150 (tmux).

Run with this change on e4ca47b0f: gofmt -l clean; go vet
-tags nogui with GOOS=linux and GOOS=windows on codexcat, usage, gateway
and agent clean. go test -count=1 -timeout 45m: codexcat ok, usage ok;
-run 'Codex|Fit|Used|ModelList|Catalog' on gateway, usage and agent ok
(122s, 11s, 80s). The whole gateway and agent packages ran too, but the
machine's disk was full under other sessions' runs (209M to 2.5G free),
and 959 lines of that log are "no space left on device". Of the reds,
three are not that: TestFolderVarsAreListed is #3884 (CARGO_HOME, red on
main since e4552cca9); TestHistoryKeepsDaysAndDropsOld (gateway) and
TestSuffixModesReachAgentFiles (agent) failed beside half-written
settings files and pass alone 3 of 3 at this commit. Not run: the full
./... suite (no room on the disk); the Codex app and VS Code extension
themselves against a magpie with this change (their request was read
from their bundles and replayed against a real app-server).

Rebased on ca8a6f346 (agent rename and Codex app route, claude_runs in
gateway) and run again: GOOS=windows go vet on agent
and gateway clean; -run 'Codex|Fit|Used|ModelList|Catalog' ok on
codexcat, usage and gateway (75s), and with |Rename ok on agent (68s).
Then rebased on 94c2aaecb (usage rename) and usage run whole again: ok
(88s).
2026-10-27 18:37:16 +08:00
yetone e7f21dba5e codex: Disconnect keeps an effort or model list the user set by hand after Connect
@yhwangl on X asked that putting an agent's config back never write
over what the user changed by hand after magpie took it over: only the
keys magpie changed go back, and a key magpie wrote that the user has
changed since keeps the user's value.

Codex's Disconnect put back the pre-connect model_reasoning_effort and
model_catalog_json whatever they were by then. An effort the user set
by hand to high after connecting went back to the low it was before,
and a model list of their own put in by hand was deleted.

Now:
- the effort goes back only while it is still one magpie set: the one
  settle moved it to (stashed as codex.effort_set), the one picked on
  the Agents page (the applied record), or none;
- dropProvider takes model_catalog_json out only when it is magpie's
  list (or empty), and unroute puts the old list back only where the
  key is empty;
- model_provider is put back only where the key is empty.
Other agents' fields already clear only a value still magpie's, and
put the pre-connect backup only into a field left empty.

Run, at this commit's tree (HEAD df8374921 plus this change), sandbox
HOME, private GOCACHE:
- gofmt -l internal/agent: clean; go vet ./internal/agent: ok
- go test -tags nogui -count=1 -run Codex ./internal/agent: ok (121.7s)
- broken by hand (the effort and catalog checks taken out of unroute):
  TestCodexDisconnectKeepsHandEdits went red, green again with them.
Not run: the full suite (runs with the uninstall change).
2026-10-27 17:02:55 +08:00
yetone 508911e431 agent, gui: Codex's ChatGPT models stay in its picker with a routing group on and its own models switched off (shiqi_40904 on Discord)
shiqi_40904 on Discord: "开启路由组后,agent 设置页面-codex-模型列表里不会显示
codex 模型,关闭路由组后才会显示".

Cause: the switch "Show Codex's own models" (#1642, provider.
OwnModelsHidden) has agent.Picks drop every option of the agent's own
(no catalog Ref) from a picker that offers one of magpie's models. On a
ChatGPT sign-in, Codex's picker offers its own models and leaves out
magpie's codex/... (viaMagpieFor: only a hop), so with no routing group
it has no Ref option and the switch did nothing; a group gives it one
(group/mygpt) and the switch then took out every Codex model but the one
it was set to. The picker was Default, gpt-5.5 and the group; turned
off, the group took the Ref away and they were back. The list's switch
itself shows only while a group is on (OwnModels), so with the group off
nothing on screen said why.

Fix: Option.Served marks one of the agent's own that magpie's list shows
it too, on the account it is signed in to. Codex's own models a ChatGPT
account in magpie serves (codex/<model> in CatalogFor("codex")) are
marked so (codexInMagpie, live and WSL Codex), and agent.Own leaves them
out, so the switch never takes them out; the list's tick decides them
(one taken out there is the switch's again). With all of them served,
OwnModels is false and the list has no switch for Codex. The GUI's
filter on closing the list (closeAgentModels) keeps o.served the same
way. Codex on a relay of its own (model_provider of the user's) is
unchanged: those go straight to the relay, the switch's to take out.

Sibling check: Claude Code offers magpie's models on its own account as
catalog options (Same, with Ref), so the switch leaves them; DeepSeek
Harness's own are not served by magpie; the TUI and the tray panel take
their options from agent.Picks (server); WSL Codex's options marked too.

Reproduced first in a sandbox HOME (fake ChatGPT auth.json,
models_cache.json, catalog.SaveLive codex with 5 models, group MyGPT of
codex/gpt-5.5 + codex/gpt-5.4, own models switched off): agent.Picks
gave [gpt-5.5 group/mygpt] with the group, all five without it. Then
drove the real GUI (Handler on 127.0.0.1:3719, Playwright chromium):
Codex connected, its picker with the fix lists Default, Disconnect,
gpt-5.5, MyGPT, gpt-5.4, gpt-5.4-mini, gpt-5.3-codex, gpt-5.2; the list
shows Routing groups 1/1, Codex 5/5 and no own-models switch.

Run at this head (rebased on origin/main 3a89dd53c):
- go test ./internal/gui ./internal/tui: ok (202s, 38s);
  ./internal/agent: ok (406s) on a second run, the first ran out of
  disk ("no space left on device" in TempDir, the machine at 100%)
- new TestCodexOwnModelsStayWithGroupOn: red with agent.Own back to
  ignoring Served ("group on: gpt-5.4 not in Codex's picker [gpt-5.5
  group/mygpt]", the reporter's case), green with it
- GUI: agent-models-own-served.test.cjs (new; chromium + webkit, en +
  zh, 420 and 1100) red 4/4 in chromium with o.served dropped from the
  close filter, green 8/8 with it; all agent-models*, i18n-keys,
  claude-picker*, picker-rail-current, editor-picker-clicks: 66 pass
  before the rebase; at this head agent-models-own, -own-served,
  -group-on, -picker and i18n-keys: 40 pass
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build

Not tried: a real ChatGPT account (the sign-in is faked in the sandbox),
the Windows box and WSL Codex (its options are built the same way), the
whole GUI suite (the change is the list's close filter, not the shared
picker).
2026-10-27 13:43:28 +08:00
yetone de54b4ff99 codex: threads started on OpenAI are listed while magpie is Codex's provider
notnico64 on Discord (Linux, magpie desktop): with Codex connected to
magpie, `codex resume` said "No sessions yet". Codex's resume picker
(tui/src/resume_picker.rs picker_provider_filter) lists only threads
whose model_provider is the one Codex is on now, with no opt-out, and
the filesystem scan checks each rollout's session_meta, not just the
state DB row. With no ChatGPT sign-in (also an API key, magpie API, an
account out of allowance, another machine/WSL) magpie writes
model_provider = "magpie", so every thread started on "openai" vanished
from the list. Nothing in it is Linux-only; macOS does the same.

Now, when magpie becomes Codex's provider and Codex was on OpenAI
before (not on a provider of the user's), the threads on "openai" move
to "magpie": the state DB row and the rollout's session_meta, rewritten
in place (both ids are 6 bytes), the file's mtime kept so the picker's
order holds, with no trash copy. At the Disconnect bringBack relabels
them back the same way before its usual mover. Threads Codex has
already packed (.zst, a week after the last turn) are left alone:
rewriting gigabytes of history at a switch isn't worth it (the owner's
~/.codex/sessions is 51GB, 11,591 of 12,255 rollouts packed). Files
written within ActiveWindow, outside this Codex home, or without their
id in the name are skipped too.

Run:
- Real Codex 0.162.1 in a sandbox HOME/CODEX_HOME (never ~/.codex):
  without model_provider the picker listed only the openai thread;
  with model_provider = "magpie" only the magpie one (the report).
  After RelabelCodexThreads(home, "openai", "magpie") the same picker
  listed both threads.
- TestCodexThreadsFollowMagpieIn (new) is red on the old code:
  "connected: thread ...c1 on "openai", want "magpie"".
- go test -tags nogui -timeout 45m ./internal/agent ./internal/sessions
  at this head: ok agent 480s, ok sessions 41s (rebased on 9298d2a7c)
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on
  both packages clean.

Broken by hand: dropping the prior-provider guard turns the
"provider of the user's" subtest red; dropping the Chtimes turns the
mtime check red.

Not tried: the reporter's own machine and why magpie became their
provider; Linux itself; the Codex desktop app's thread list; a full
`go test ./...`. Packed threads stay out of the list while magpie is
the provider.
2026-10-26 22:38:57 +08:00
yetone 4e3078ee47 agents: a Codex thread started on any provider table goes through magpie when reopened, not only CC Switch's
A report the owner relayed from WeChat (10-26): in Codex, with apikeyfan's
gpt-6.1-sol on, an old thread failed every turn with "unexpected status 404
Not Found: Model "apikeyfan/gpt-6.1-sol" is not supported by any configured
account in this group, url: https://slb.apikey.fan/responses". A new thread
worked, and updating magpie didn't help. The url is Codex's own call: Codex
reopens a thread on the provider it was started on, and that thread's table
pointed straight at the relay (no /v1, so not a table magpie wrote), so the
magpie model id went to the relay. 6c5ed2acf pointed only CC Switch's
"custom"/"cc-switch-N" tables at magpie; a table of the user's own, or one
named after a CC Switch card, kept going to the relay.

Now any [model_providers.<id>] table a Codex thread was started on (the
state database's threads) goes through magpie while a magpie model is on,
the same way: base_url to magpie's /v1, the old URL kept in the stash and
given back with Codex's own model or a reset, the table's other keys as they
were. Left alone: tables no thread names, tables a profile names, magpie's,
Codex's built-ins and CC Switch's OpenAI mirror. The state database is read
only when a table outside CC Switch's ids has a base_url, once per check.

Run at this head (4a33cf0a9 + this):
- TestCodexTakesThreadTables (new) is red on the old codex.go: "thread's
  table not through magpie". TestCodexWritesTablesThreadsName, changed to
  expect the user's thread table through magpie, is red on the old code too.
- go test -tags nogui ./internal/agent -run Codex: ok.
- gofmt -l, go vet (darwin, GOOS=windows), go build (darwin, GOOS=linux): ok.

Not tried: the reporter's own config.toml (its table's id isn't known, so a
quoted header or a profile-named table would still be left alone), the full
suite, and a real Codex app reopening a thread.
2026-10-26 22:02:03 +08:00
yetone a1174674da codex: subagents and memories follow the session's magpie model; auto-review can too (cybercaius on Discord)
Codex's side calls ask for one of Codex's own models by its bare name
whatever the conversation is on: a subagent goes on the model the lead
names in spawn_agent, memories on gpt-5.6-luna/terra, auto-review on
codex-auto-review. With Codex signed in to ChatGPT and the conversation
routed onto one of magpie's models, each of those went to the ChatGPT
account instead (cybercaius: "can't pick follow the main model").

- gateway (codexFollowTo, codexLeads): a collab_spawn or memory call
  that asks for a bare model, with nothing set for it (no magpie
  subagent model, no [agents] default_subagent_model, no [memories]
  extract/consolidation_model in Codex's config), goes on the model its
  conversation's own turns go on (parent thread, own thread, else the
  key's last turn), when that is a magpie model the key may use. A task
  the ChatGPT backend sealed stays on ChatGPT. The trace shows a
  subagent's pick as {asked -> to}.
- agent.CodexSideSet reads Codex's config.toml for those keys; an
  unreadable config counts as set (leave as sent).
- Auto-review gets "Same as the session" (settings value "session"):
  codexcat writes each magpie entry's own id as its
  auto_review_model_override. Not the default: codex-auto-review runs
  free on a ChatGPT sign-in (#1593).
- GUI: the option in all languages; Memories' default text says it
  follows the session. app.js stays under its budget by folding five
  identical writingPrefs then/catch chains into prefWrite.

Ran (sandbox HOME, -tags nogui -count=1 -timeout 45m):
- go test ./internal/gateway ./internal/agent ./internal/codexcat
  ./internal/settings ./internal/cli ./internal/gui: ok.
  ./internal/provider: FAIL with "close of synctest channel from outside
  bubble" in filememo.Forget (TestUnreadLoginsWriteErrorsKeepCredentials),
  which is #3632 on main; this change touches nothing there.
- TestCodexSubagentFollowsTheSession and TestCodexMemoriesFollowTheSession
  go red with codexFollowTo returning "" (broken by hand).
  TestCodexSideCallsKeepTheConfigsModel, TestCodexSideCallsStayOnChatGPT,
  TestCodexSideSet, TestCodexAutoReviewFollowsTheSession pass.
- GUI (playwright 1.62.0, chromium + webkit): codex-auto-review (en, zh,
  zh-TW, ja, de), codex-memories, codex-memories-settings, codex-titles,
  codex-predictions, codex-descriptions, settings-general, agent-prefs,
  i18n-keys: 120/120 pass. TestCoreScriptBudget passes, budget unchanged.
- gofmt -l clean; go vet -tags nogui for linux, windows and darwin ok.

Again after rebasing on origin/main 49f15d124 (25341b4ca on top touches
only internal/redact; rebuilt): nogui builds (darwin, linux,
windows), TestCoreScriptBudget, the tests above, and the GUI files 120/120.

Not tried: a real Codex with a real ChatGPT account and a relay model.
2026-10-26 15:35:12 +08:00
yetone 7b1faf99f2 agent: a Codex auth.json caught mid-rewrite leaves Codex beside its ChatGPT sign-in (lucy)
lucy on Discord (v0.1.1394, Codex app, signed in in Codex, not in
magpie): on and off, Codex's account menu showed "magpie" instead of the
ChatGPT account, and the model picker listed magpie's catalog ("6.1 Sol
· Codex" ...) instead of Codex's own models.

Cause. codexChatGPT (internal/agent/codex.go:2022 on 0d2a10116) took any
failed read or parse of auth.json as "not signed in to ChatGPT". Codex
rewrites auth.json in place when it refreshes its tokens (codex-rs
login/src/auth/storage.rs FileAuthStorage::save: OpenOptions
truncate(true), then write_all), so a read in that moment finds it empty
or cut off; a keychain read that fails for a moment is the same. Sync
(codex.go:1306, run from every SyncCatalog) then took a Codex on a magpie
model beside its sign-in for one "with no ChatGPT sign-in" and called
set, which (codex.go:1079) made magpie Codex's provider with no codex.out
mark. Nothing put it back: Sync returns it beside the sign-in only from
codex.out, so it stayed until the next pick or group switch. A pick in
that moment (a group switch, the Agents page) did the same, and while
the account was held (codex.out) it forgot the mark.

Fix. provider.CodexSignInKnown says whether the read says anything: no
auth.json, no keychain item, or a store magpie doesn't read is known;
a read error, an auth.json that isn't valid JSON (empty, cut off), or a
keychain read that failed is unknown. codexChatGPTKnown builds on it,
and Codex's chatGPT closure takes an unknown read as magpie last wired
it (joined, beside, or codex.out). A sign-in really gone (codex logout)
or one with no ChatGPT token (an API key) still moves Codex onto magpie
as its provider, as before. codexChatGPT keeps its bool for connectinfo.

Tests (red on the old code, by putting the old answer back by hand in
the closure: every subtest of the first and the second failed):
- TestCodexHalfWrittenAuthKeepsSignIn: beside the sign-in, auth.json
  empty / cut off / not JSON, then Sync and a pick: stays beside; on the
  old code it went to model_provider = "magpie" and stayed there after
  auth.json was whole again and Sync ran.
- TestCodexHalfWrittenAuthKeepsOut: held (codex.out), a pick while
  auth.json is empty keeps the mark, and Sync puts it back beside the
  sign-in once the account has room.
- TestCodexSignInGoneStillKnown: logged out, or an API key: magpie its
  provider, as before.
- TestCodexSignInKnown (provider): signed in, empty, half, removed,
  keyring with no item, keyring refusing, ephemeral.
docs/subsystems/agent-wiring.md says the rule.

Run at the pushed head (this commit on origin/main 761904b5a):
go test -tags nogui -count=1 ./internal/agent -run Codex: ok (26s);
./internal/provider -run Codex: ok (19s); gofmt -l: none; GOOS=linux
and GOOS=windows go vet -tags nogui ./...: ok.
Full suite (go test -tags nogui -timeout 45m ./..., sandbox HOME): still
queued behind other sessions' suites at push time, pushed without
waiting per the owner's rule; a red from this change gets a follow-up,
an unrelated one an issue.

Not tried: the real Codex app through a real token refresh; the race
was reproduced with auth.json written empty / cut off by the test, and
Codex's in-place write was read from codex-rs main's source, not traced
on lucy's machine. Whether lucy's flips were this or the held-account
move (codex.out, CodexUsedUp: allowance out and no credits) isn't known
from the report; this one is the one that sticks after the account is
fine.
2026-10-25 01:49:13 +08:00
yetone 0d2a101160 gateway: the Codex app's titles, descriptions and summaries go to the magpie model picked, not ChatGPT (atom_Ray on X)
atom_Ray on X: with a third-party model picked in the Codex app through
magpie, an hour of use still took 2% of the ChatGPT account's 5-hour
window, and at 0% left it could not be used at all.

The cause is the app's hidden side turns. ChatGPT.app 26.1013.40934 asks
for a thread's title, description and one-line summary
(ThreadMetadataGenerationService.generateTitle/generateDescription/
generateSummary in .vite/build/main-CLu1A25j.js; R0/z0/B0 via H0 and Jq
in src-DsLVGakC.js) on ephemeralGenerationModel, gpt-6-luna by default,
whatever model the conversation is on. A summary is asked after each
user and assistant message (bAu in app-initial). With magpie's model
beside the ChatGPT sign-in (openai_base_url), these reach
/backend-api/codex as gpt-6-luna. codexTitlesTo and codexDescriptionsTo
left an unset setting on the model Codex asked for, and thread_summary
had no route at all, so all three went to ChatGPT on the user's sign-in.

Now, with Codex's config model one of magpie's and magpie not Codex's
provider (agent.CodexSideModel, through gateway.CodexSideModel),
codexSideTo sends titles, descriptions and summaries on the Codex
backend path to that model. On Codex's own model nothing changes, and a
model the Titles or Descriptions setting names still wins. Summaries get
the same wrapper as descriptions (codexShaped): the plain answer is
handed back as the {"summary": ...} the schema asks for, with
compactSummary filled and cut to its maxLength (summaryJSON). This also
covers a summary on magpie's own API, where a Chat model's plain answer
was dropped by the app. No prompt, instructions or base_instructions are
changed: the request is sent to another model as Codex wrote it.

Run (this change on origin/main e57e78563 for the full suite; rebased
onto 3a47e377e, which touches internal/gateway, for the packages run
again; then onto 0e643b14e, internal/sessions only, built):
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows for
  internal/gateway, internal/agent and internal/cli: clean.
- New tests: TestCodexSideTurnsOnThePickedModel,
  TestCodexSummaryOnMagpieProvider, TestSummaryJSON (gateway) and
  TestCodexSideModel (agent). Also the existing title, description and
  #540 used-up tests: ok.
- Full suite (go test -tags nogui -timeout 45m ./..., one suite on the
  machine, log tee'd): 70 packages ok, 19 without tests, no FAIL, exit 0
  (gateway 594s, agent 449s, provider 220s, cli 151s).
- Rebased onto 3a47e377e: gofmt and vet (nogui) of gateway, agent and
  cli clean; go test -tags nogui -timeout 45m of internal/gateway,
  internal/agent, internal/cli and internal/usage: all ok.
- Rebased onto 0e643b14e (internal/sessions only): go build ./... ok;
  not run again.

Broken by hand:
- codexSideTo's side-model branch turned off: TestCodexSideTurnsOn-
  ThePickedModel red (the title went to ChatGPT, 0 magpie calls).
- Both codexSummariesTo call sites turned off: TestCodexSideTurnsOn-
  ThePickedModel red on thread_summary, and
  TestCodexSummaryOnMagpieProvider red (plain text came back).
- SideModel without the !asProvider() check: TestCodexSideModel red.

Not tried: the real Codex App with a real ChatGPT account (live ~/.codex
and the running magpie were left alone), Windows and Linux. The app's
ambient suggestions (ambientSuggestionsModel), safety recourse and
commit/PR message turns are not moved; they are asked rarely or only by
user action. Not changed: what ef37b6fb7 does at 0% (Send greyed in the
app until it is reopened). On macOS magpie reopens the app once when it
is idle. On Windows and Linux it only shows a notice
(internal/gui/codex_app_out.go:78). With account discovery off,
readLogins returns nil (internal/provider/logins.go:208), so a used-up
account is never known.
2026-10-25 01:41:23 +08:00
yetone 1cdc3a59fe gui: Codex has one subagent model, Same as the lead or one model for every subagent
The owner, looking at Codex's New sessions line: two squares, subagents
and subagent model, read alike and nobody could tell them apart ("这两个
用户压根分辨不出来区别"). One was Codex's own [agents]
default_subagent_model, a model a subagent starts on only when its lead
names none; the other magpie's, which puts every subagent on one model
whatever the lead asks for. They are one setting now:

- Codex's card shows the subagent model alone. Unset it says "Same as
  the lead" (跟主代理一样): each subagent runs on the lead's model, or on
  another the lead picks for it. A model picked: every subagent runs on
  it, whatever the lead asks for. Its picker opens on Same as the lead,
  the lead's model in the note. With no model of magpie's to pick there,
  Codex's own square stays as it was.
- Codex's sheet has the same setting as a row with a name, Codex
  subagent model, beside Codex subagents on any model, as the memories
  model got one when its square wasn't found (Hu9956).
- A model Codex's config still has in [agents] default_subagent_model
  is said on the square, which is lit: "Codex's config still starts
  subagents on {model} when the lead names none; picking here replaces
  it."

For users who set default_subagent_model themselves: a pick in the
subagent model, Same as the lead too, removes it from Codex's config
(and a subagent effort the subagents' model no longer has), so the one
setting shown is the one that holds. Until they pick, it stays and is
said on the square. The CLI and profiles keep the subagents field.
Claude Code's, omp's and Claude Desktop's subagent squares are unchanged.

Every new string has zh, zh-TW, ja and de. app.js grows 4,011 bytes,
the Agents page's, which the tray panel draws too: the core budget is
raised to it, with no room added, and says why.
2026-10-24 23:40:44 +08:00
yetone 1184862583 agent: Codex background compaction writes the bare async_compaction = true where a Codex older than 0.163 reads the config (多喝热水)
多喝热水 (Discord #help, Windows, v0.1.1384, Codex desktop with ChatGPT
sign-in): Codex wouldn't open, "config.toml:154:1: invalid type: map,
expected a boolean". That line is the [features.async_compaction] table
1978eabe5 (#2490/#2493) writes.

Codex versions, from codex-rs source and the real binaries:
- up to 0.163.0-alpha.5 (0.160.0, 0.162.1 included) FeaturesToml is a
  flattened BTreeMap<String, bool>: any table under [features] fails the
  whole config; an unknown bool key is only a warning.
- from 0.163.0-alpha.8, async_compaction is FeatureToml<…>, bool or
  table, and model_async_compact_threshold_percent is read only from the
  table (the bool gives Codex's default 65).
- the provider table's capabilities = {...} is safe: 0.161 and older
  ignore unknown provider keys (schemars-only deny_unknown_fields),
  0.162 parses it. 0.160.0 and 0.162.1 load a config holding it.
- ChatGPT.app 26.1013.40934 bundles Codex 0.163.0-alpha.10.2
  (Contents/Resources/codex-cli/codex-package.json); the reporter's
  Windows app rejects the table, so it bundles one before alpha.8.

Fix: the table is written only when every Codex found here that reads
this config (the CLI on PATH, the desktop app's bundled codex on macOS,
the Store app on Windows, the editor extension, Codex in WSL) has a
version at or after 0.163.0-alpha.8. Otherwise, or when a version can't
be read (the Windows app, the extension), magpie writes the bare
[features] async_compaction = true with no share. A table magpie wrote
before is taken back through its stash (only the keys the stash names
as magpie's; an emptied table goes), so a config already broken opens
again on the next sync. A table or bool the user wrote stays. The stash
records a bool it wrote (`bool`), and the table comes back once every
reader is new enough. Settings' state carries codexAsyncHeld, and the
Codex row says which Codex holds the share back and that it needs
0.163. The note costs app.js 390 bytes; its budget and the core's are
raised by exactly that, the agent's own row in the core.

Run:
- real binaries, sandbox CODEX_HOME/HOME, `codex features list` on the
  config magpie writes (TestCodexAsyncConfigLoadsInRealCodex,
  MAGPIE_TEST_CODEX_BINS): 0.162.1, 0.163.0-alpha.8 and 0.164.0 load it;
  alpha.8 and 0.164.0 report async_compaction true. By hand before the
  fix: 0.160.0 and 0.162.1 exit 1 on the table ("invalid type: map,
  expected a boolean"), load the bool and nothing; alpha.8 and 0.164.0
  load all three.
- broken by hand (table always allowed): the real-binary test is red
  for 0.162.1 with Codex's own error, OldCodexGetsTheBareKey red in all
  four cases, TableTakenBackForOldCodex red ("magpie's table not
  mended"). Green again with the fix.
- go test -tags nogui ./internal/agent ./internal/gui ./internal/edit
  ./internal/settings: ok (gui after the budget, re-run alone: ok).
- GUI (node --test, chromium + webkit): codex-async-compact,
  agent-prefs, settings-general, segs-glide, i18n-keys: 100 pass, 0 fail.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...; go build for darwin, linux (nogui),
  windows: ok.

Not tried: the Windows box (Store-app detection, reading its bundled
codex's version, a non-Store install), a WSL distro, a real Codex run
past the share, the whole GUI suite. The full go test ./... is queued
behind other sessions' suites (one per machine) and wasn't waited for.
2026-10-24 22:02:49 +08:00
yetone ef37b6fb76 gateway: an exhausted ChatGPT account no longer greys Codex app's Send while magpie can serve the turn (MasterYi on Discord)
MasterYi (#help, 1563467829687222343): with magpie wired into the Codex
app, a used-up ChatGPT account greys the Send button, so the third-party
models joined in Codex's picker can't be used either.

Cause, as far as the app's bundled code (ChatGPT.app 26.1013.40934,
read-only) shows: Send is gated in the app itself. It needs
authMethod == "chatgpt", the /wham/usage reading (fetched by the app
straight from chatgpt.com, not through magpie) saying not allowed, and
no credits. authMethod is read as the app opens or on account/updated,
which the app-server sends only on login/logout, not on a config change.
So the gate lifts only when model_provider is magpie AND the app has been
opened again. #540 already made magpie the provider while out, but only
when a magpie model was the default; on one of Codex's own models
(joined), nothing changed.

What changed:
- A (agent/codex.go Sync): joined on one of Codex's own models and the
  account out (not Always ChatGPT, not magpie API), magpie becomes the
  provider on that model as magpie serves it (codex/<model>), the model
  kept in codex.out_own. Once the account has room, Codex is put back
  joined on that model. A model picked meanwhile stays the user's. With
  no ChatGPT account in magpie to serve it, nothing changes. New
  Agent.AppOut says magpie is the provider for a used-up sign-in.
- C (provider/codex_app_out.go): a usage_limit_reached rest on the
  active Codex account (gateway routing) or an x-codex-* window heard at
  100% (NoteCodexLimits) has the account read again at once
  (CodexMayBeUsedUp: active account only, at most every 20s, only
  while a KeepOnAnAccountWithRoom loop has made its first reading and
  still runs), not only on the 5-minute look. A first cut turned this
  on for good as the loop started; every gateway test's Serve starts
  it, so later gateway tests had accounts read again behind them, and
  TestCodexOwnModelMovesToNextAccount and
  TestCodexSpentMovesToNextGroupMember went red in the package run
  (green alone 3 of 3). Now a counter, up after the first minute's
  reading, down as the loop ends; the package run is green with it.
- B (gui/codex_app_out.go): the app open when the account ran out is kept
  by its app-server's pid (provider.CodexAppOut; a new pid means it
  reopened and read the provider, standing in for "authMethod is still
  chatgpt"). On macOS, every 10s, magpie reopens it through the Agents
  row's ReopenCodexApp when: AppOut, the account still out, the app is a
  copy from before the config change, no turn in flight through the
  gateway and none ended in the last 30s. At most once per time the
  account runs out, success or not.
  Drafts: the app's code keeps composer drafts in a persisted store
  (composer-prompt-drafts-v2, 250ms debounce, flushed on quit), and
  threads are server-side, so an unsent draft and open threads should
  survive the quit. Not watched in a real app.
- D (GUI): Codex's accounts say "The Codex app can't send on {user}'s
  used-up account": on macOS that magpie reopens it once no turn runs;
  off macOS (no reopen path) or once tried, to quit and reopen it.
  en, zh, zh-TW, ja, de.

Tests (each red on the code without its part, broken by hand):
- TestCodexOwnModelGoesThroughMagpieWhileUsedUp: red at "used up" with
  the out case off, at "allowance back" with the restore off.
  TestCodexOwnModelKeptOnChatGPT: Always ChatGPT stays.
- TestCodexMayBeUsedUpReadsAtOnce: red at "a window full: not read"
  with the NoteCodexLimits hook off. TestCodexAppOutEpisode.
- TestCodexUsedUpReplyAsksAtOnce (gateway): red, asked [], with the
  routing hook off.
- TestCodexAppOutReopenedOnce (gui, reopen stubbed): red at "a turn in
  flight" with the idle check off, and at "again" with the once checks
  off.
- codex-app-out.test.cjs: 40 of 40 (chromium, webkit; 900/480; five
  languages; both texts); 2 of 2 red with the notice's call site off.

What was run, at this tree:
- gofmt -l: none. go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: exit 0.
- go test -tags nogui -timeout 45m: internal/agent ok (414s, before a
  comment-only reorder in Sync); internal/gateway ok (534s),
  internal/gui ok (78s), internal/provider ok (137s), after the
  live-check fix, at this tree before the previous commit's JS-only
  move (then with a budget raise since taken back); internal/gui
  again after the move.
- GUI (chromium, webkit), at this tree: codex-app-out, codex-app-stale,
  i18n-keys, gui-de, gui-ja, gui-zh-tw and the files reaching the
  previous commit's move: 164 of 164. Before the trim, every codex-*
  and account-* file: 447 of 448; the red, codex-predictions chromium
  ja 420 "picking a model scrolled the page", is #2624 and is red alone
  on origin/main 5a85a2a91 too (1 of 2); one codex-app-out case timed
  out launching chromium at load ~100 and passed on the rerun.
- TestCoreScriptBudget with the budgets unchanged: ok. The three Codex
  notices now share one box builder (codexNote), and the previous
  commit moved ledSaid out of app.js.

Not tried:
- No real Codex app was quit or reopened (the owner's live app is left
  alone); the reopen path is stubbed. Whether the reopened app's Send
  comes back, and whether a draft survives, is from reading its code.
- No real used-up account; the move was run in a sandbox HOME.
- The full suite: no suite lock on this machine, load ~75.
- A gateway served by another magpie process: the episode lives in the
  process that serves the gateway, so a GUI that doesn't serve it never
  reopens the app or shows the notice.
2026-10-24 17:38:50 +08:00