Commit Graph
147 Commits
Author SHA1 Message Date
yetone bf0a1252fa codex: the chat open in the Codex app follows a provider switch (hubo31377762 on X)
Switching Codex between magpie and OpenAI left the chat that was open
unusable. The Codex app holds the writer lock of every chat it has loaded, so
no move touched that chat's row, and Codex 0.167 refuses to resume a chat whose
provider isn't the configured one (modelProviderMismatch openai to magpie,
modelProviderNotConfigured magpie to openai). Reopening it did not help.

Just before magpie ends the Codex app's app-server for the route change, the
held chats are now moved to the provider Codex is on: a paginated one by its
row, a legacy plain rollout in place at equal id length (openai and magpie),
packed legacy rollouts and other lengths left to the next sync
(provider.CodexBeforeAppEnd, agent.codexRetagOpenThreads,
sessions.RetagLoadedCodexThreads). The end is a clean SIGTERM and Codex writes
nothing back.

Run (mote-run): gofmt -l on the three packages; go vet for darwin, windows and
linux with nogui over ./internal/...; go test internal/sessions, provider and
agent. Real codex 0.167.1 app-server in a sandbox CODEX_HOME, both ways: no
retag gives modelProviderMismatch (openai to magpie) and
modelProviderNotConfigured (magpie to openai); with the row retagged and the
app-server SIGTERMed, thread/resume succeeds on the new provider in both.

Broken by hand: the hook call removed and the retag call emptied; both new
tests go red (open chat stays on the old provider, order is [end] only).

Not tried: the Codex app GUI itself, Windows runs, a packed legacy thread held
open (left to the next sync). A resumed thread's sandbox falling back to
config.toml's default happens with no provider change and is #6028.
2026-11-11 07:33:20 +08:00
yetone 418bb6c9e1 codex: Show Codex's own models off leaves them out of Codex's own picker (iiiiiimone on X)
The switch (#1642) only narrowed the Agents page's pickers. Codex's own list,
which the gateway hands it beside its sign-in and as the Codex app's list
file, kept every model of the ChatGPT account, also with the Codex provider
switched off. codexMerged now leaves the sign-in's visible models out when the
switch is off (provider.CodexOwnLeftOut); the model Codex is set to, models
magpie serves on a ChatGPT account and hidden jobs stay, and the list's ETag
carries the switch so Codex asks again. Codex has one openai_base_url for every
model, so one it is still set to goes through the gateway to OpenAI on its own
sign-in; a model of it can't be sent direct beside magpie's models.

Run: TestCodexListWithOwnModelsOff, red with the filter turned off (own models
all listed, ETag unchanged); gateway, provider tests at this tree.
Not tried: a real Codex app against the list.
2026-11-11 01:54:05 +08:00
yetone bc0d9e8739 agent: magpie's own Claude work folder isn't Claude Code bypassing magpie (ifccod7391564 on X)
The bridge runs Claude Code in os.TempDir()'s magpie-claude-work(-<uid>),
and on the user's own home those prompts go into ~/.claude/history.jsonl
too. LastUsed read them as Claude Code used with none of its requests
reaching magpie, and the Agents page warned "Claude Code 最近绕过了
magpie". The owner's own history.jsonl has 1594 such lines, project
/private/var/folders/.../T/magpie-claude-work-501. LastUsed now passes
over lines whose project is that folder (inMagpieWork: the last path
element, either slash, so a Mac's /private/var, C:/…, C:\… and a WSL
mount all match; magpie-claude-workshop does not). lastJSONLTime takes a
skip; Codex's history.jsonl has no project and passes nil.

Run (wsl-run, magpie-desktop; mote refused SSH the whole time):
- go test -count=1 -timeout 45m ./internal/provider ./internal/agent:
  provider ok; agent ok but TestGrokInstalled, the known WSL2 binfmt
  red (#3548), unrelated
- TestClaudeBridgePromptsArentBypass, TestDriftBypassed on Windows: ok
- cross-OS go vet as in the provider commit; gofmt -l clean
Broken by hand: LastUsed with skip nil: the new test is red with the
reporter's bypassed drift.
Not tried: the GUI (no GUI change), the macOS run (mote down).
2026-11-10 18:21:32 +08:00
yetone 720200092e agent: turn off an agent's own telemetry from its settings (OipsAnthony on X)
An agent with a documented telemetry switch has a Telemetry row in its
Settings on the Agents page (opened row and settings sheet). Off writes
that switch into the agent's own config the way magpie writes it already:

- Codex: [analytics] enabled = false in config.toml (feedback left alone)
- Claude Code: env DISABLE_TELEMETRY and DISABLE_ERROR_REPORTING = "1"
- Gemini CLI, Qwen Code: privacy.usageStatisticsEnabled = false

Nothing is written until the user turns it off. Off writes only keys the
file lacks and records them in the stash; a key the user set on refuses
Off and names it; one they set off stays, and the row says so. On takes
out only the keys magpie wrote that still hold magpie's value. An
unreadable config is unknown: the row says so and can't be pressed.
Agent.Telemetry is not a Field, so profiles never carry it and Unwire
leaves it. Only agents on this computer (no WSL distro, #3896).
POST /api/agents/telemetry/{id}; strings in zh, zh-TW, ja, de.

The row is paid for in the core budget with sixteen Agents-page comments
cut in app.js (core 1,532,840 of 1,533,802 after the rebase), no raise.

Run (mote, at this head on origin/main 1ad9d157f; vet, the three packages and agent-telemetry, i18n-keys, agent-details-ready, click-scroll again there, 98 of 98):
- go test -run Telemetry ./internal/agent, then go test -count=1
  ./internal/agent ./internal/gui ./internal/cli: ok
- go vet ./..., GOOS=linux -tags nogui, GOOS=windows: ok; gofmt clean
- GUI, chromium and webkit: agent-telemetry (34 pass: every language at
  1100 and 640px, no scroll on click, no select, the user's own off,
  a refusal, the sheet), and 104 agent-*, i18n-*, click-scroll,
  settings-search, panel-agent and agent-settings files: reds only in
  page-width-steady and mobile-web (red the same at origin/main
  5a347ca8c, #5013, #4541) and agent-compact once under concurrency 6
  (passes alone, 8 of 8; #5607; its fixture has no telemetry)
- internal/cli failed once in the first run with its name lost to a
  tail of mine; it passed on a rerun at this head and at origin/main

Broken by hand: skipping the user-on check, dropping the "still ours"
check before a delete, and removing the WSL gate each turned
TestCodexTelemetryLeavesTheUsers, TestClaudeTelemetryChangedSince,
TestUsageStatsTelemetrySwitch and TestTelemetryOnlyHere red. The tests
don't compile on the old code (no Agent.Telemetry).

Not tried: real Codex, Claude Code, Gemini CLI or Qwen Code reading the
written keys (the keys come from their source); Crush (left for later),
OpenCode (no switch); WSL agents; the whole GUI suite (the agent-*,
i18n and agent-settings files only); the full go suite runs after the tag.
2026-11-10 17:28:15 +08:00
yetone e4197144a8 perf: every package's package-level regexps compile on first use
v0.1.3516 made gateway's and redact's patterns lazy. The other 299
package-level regexp.MustCompile calls, in 148 files across agent,
provider, gui, library, codexcat, sessions, usage, plugin and the rest,
now go through lazyre.New too, so a launch that never reaches them
(`magpie statusline`, run by Claude Code on every message) doesn't
compile them. Fields, maps and params that held them are *lazyre.RE.

Measured on mote (M5 Pro), sandbox HOME, v0.1.3516-equivalent build
(t42) against this one (t43):
- GODEBUG=inittrace=1 sum: 7.39 MB / 69,837 allocs -> 4.62 MB / 46,765
- `magpie statusline`, 3 runs each: instructions retired ~212M -> ~176M,
  peak memory footprint 19.2-19.4 MB -> 16.8-17.0 MB

Run: go vet ./... (darwin) ok; GOOS=windows go vet on each of the 30
changed packages ok; GOOS=linux go vet ok except ., internal/cli and
internal/gui, which stop in wails v3's cgo files when cross-compiled
(the same at main). New TestAllLazyPatternsCompile at the root compiles
all 574 registered patterns (ok), so a bad pattern fails a test rather
than a first use.
Not run before push: the changed packages' own test suites; they run
on mote after it.
2026-11-10 12:54:39 +08:00
yetone 1b078d404b gui: a state poll encodes into buffers kept from the last one, and Codex's own models are read without a copy
Each /api/state poll json.Marshal'd the state without its agents twice
(to send it and for keepState's sum) into fresh slices, and made a new
32KB writer; ownCodex cloned Codex's whole model list for a caller that
only reads it. One set of buffers and the writer is now kept between
polls (an atomic slot, not a sync.Pool, which a GC between polls
empties; a poll that finds it taken makes its own, and buffers over
4MB are dropped), and ownCodex reads catalog.CodexShared.

Run on mote at this tree: go vet ./internal/gui ./internal/agent;
go test -run "State|Settings|Allow" ./internal/gui, the same -race for
StateWritten, -run "Codex|OwnCodex|Pick" ./internal/agent: ok.
TestStateWrittenAsEncoded now writes big after small and small after
big; with encodeTo's Reset taken out by hand it is red (a stale tail).
Real accounts, 40 polls of /api/state, alloc_space: 27.8 and 26.1 MB
before, 18.4 and 22.7 MB after.
Not tried: Windows and Linux runs (no OS-specific code).
2026-11-10 09:23:47 +08:00
yetone 079da3a785 perf: a state poll lists dsh profiles once, and skips work for Codex's models and gateway base
Each /api/state poll redid work for each agent row. That work is now done
once, or skipped:
- dsh's profile list is held for the request (dshProfilesHeld). dshModern,
  Joined and dshLead each globbed profiles/*/cordis.patch.yml again.
  Writers still call dshProfiles.
- CodexSignInGone reads the record first. With nothing on record for the
  home, the usual case, it no longer parses auth.json and hashes the
  refresh token on each look. A record that can't be read answers as
  before.
- Codex's effort field reads catalog.CodexShared(), which doesn't copy.
  With both lists, they are joined into one presized slice.
- codexViaMagpieFor builds one presized slice instead of two that grow
  and are then joined.
- onAnotherMachine answers a plain loopback base (localhost, 127.0.0.1,
  [::1], digits-only port, no user info) without url.Parse. Anything
  else still goes through url.Parse.

Measured on mote with the real-account sandbox, allocations over 40
/api/state polls, two alternating pairs:
- before (216ac6f85): 34.6 and 36.2 MB
- after: 26.8 and 23.7 MB

Run on mote:
- go vet on agent, provider and catalog.
- go test, all of internal/catalog.
- go test, internal/provider -run "Gone|SignIn|Codex".
- go test, internal/agent -run "OnAnother|Codex|Dsh|DSH|ZCode|Zcode|Loopback".
All ok.

New test: TestOnAnotherMachineQuickLookAgrees compares the quick look with
the url.Parse logic over 21 bases (user info, a port with letters,
uppercase, [::1], %2f) and requires 0 allocations for the gateway base.

Not tried: the full internal/agent suite (about 50 min).
2026-11-10 08:12:56 +08:00
yetone b3a57b3d8f codex: turning the takeover off restarts the Codex app, so its ChatGPT projects come back
Herzz____ on X, the Windows Codex app: with Codex through magpie the
sidebar's project list is empty; they use magpie only when their
subscription runs out, and want to switch between magpie and the native
sign-in with the projects whole each way.

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

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

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

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

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

Run (mote-run at b87783fbb (this change's tree) on origin/main 547585cd9): gofmt -l clean;
go build ./...; go vet linux -tags nogui ./... and windows ./...,
darwin ./internal/agent ./internal/provider ./internal/gui;
go test -tags nogui ./internal/provider ./internal/agent ok;
GUI codex-app-back, codex-app-out, i18n-keys, i18n-en-no-cjk, gui-ja,
Chromium and WebKit, every language, 155 of 155 pass.
Windows (win-run on xiaomi-gpu): the provider and agent Codex app tests
ok; the box's running Windows Codex app (26.1029) app-server command
line has the shape TestCodexAppOwnServer already holds.
Not run: a real used-up ChatGPT account (none at hand), so the restart
after Keep on ChatGPT is tried with the stubbed step, not the real app;
the full go test ./... waits behind mote's suite lock and runs after the
push, any red filed.
2026-11-10 04:14:40 +08:00
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