mrten_95615 on Discord: opening a Codex session from Sessions ran
`codex resume <id>` and Codex 0.166 stopped at "This chat uses custom,
but your current provider is magpie. Switch to custom to continue."
(modelProviderMismatch). Codex 0.166's app-server resumes a thread only
on the provider it was saved with (its state-database row, else its
session_meta), checked against the one config.toml (with -c) selects
(codex-rs app-server config_manager.rs load_for_resume); no flag lets a
resume go on another provider, and a provider config.toml no longer has
fails as modelProviderNotConfigured. Codex 0.165 resumed it on its own
provider without asking.
sessions.ResumeNow is the line that runs when the user opens a session
(GUI Terminal, TUI enter); the listed line is unchanged and nothing more
is read on a listing. For a Codex thread saved on a provider other than
the one Codex is on:
- config.toml still has that provider's table, or it is a Codex
built-in (openai, amazon-bedrock(-runtime), gcp, ollama, lmstudio):
`codex resume -c model_provider=<it> <id>`. Codex runs that embedded
(no shared daemon) on the thread's own provider.
- the provider is gone: MoveCodexProvider moves the thread to the
provider Codex is on (files copied to magpie's trash first, the state
row too) and it resumes there, the only way Codex resumes it at all. A
thread written to in the last minute or open in a Codex is left
(ErrActive) and the plain line runs.
A WSL distro's Codex session and every other agent are as listed.
Run at this head (mote):
- go test -count=1 -run 'TestCodexResume|TestMoveCodexProvider|TestCodexProviderIn' ./internal/sessions: ok
- go vet ./internal/{sessions,gui,tui}, GOOS=linux -tags nogui and GOOS=windows vet of them: ok; gofmt -l: clean
- At this head (rebased on origin/main bf05291e2): go test -count=1
./internal/sessions ./internal/tui: ok; ./internal/gui: ok but
TestMainWindowCorners/macOS_26_SDK (#3949, mote is macOS 27; this
change touches only gui/sessions.go's terminal route); go vet darwin,
GOOS=linux -tags nogui, GOOS=windows of the three: ok; gofmt -l clean.
- Full suite before the rebase (go test -tags nogui -timeout 45m ./...
on mote, at eb779ce92 + this change): 86 packages ok; internal/gateway
red on TestCodexPoolSaysTheClientsVersion alone (#4807, open, a full
package run's known red). Not re-run after the rebase.
Broken by hand: ResumeNow returning the listed line, TestCodexResumeOnItsProvider
fails "resume ... && codex resume 01a0bdc9-..., want ... codex resume -c
model_provider=custom 01a0bdc9-..."; with the move dropped it fails
"the thread's rollout wasn't moved to magpie".
Real Codex: codex-cli 0.166.0 (npm darwin-arm64) in a sandbox
CODEX_HOME with two fake Responses servers: a thread made on "custom",
config.toml switched to magpie. Plain `codex exec resume` failed with
the reporter's modelProviderMismatch; ResumeNow's line resumed it and the
turn reached custom's server. With custom's table removed, plain resume
failed with modelProviderNotConfigured; ResumeNow moved it and the turn
reached magpie's server. The TUI `codex resume -c model_provider=custom`
was also driven in tmux (resumed, turn on custom, "Running without the
shared background server" warning). Codex 0.165.0 resumes it plainly.
Not tried: a Codex profile that names its own model_provider (a -c
override may lose to it); the Codex desktop app's resume; Windows'
PowerShell line (same flag, not run there).
91 lines
3.6 KiB
Go
91 lines
3.6 KiB
Go
package sessions
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Codex 0.166 resumes a thread only on the provider it was saved with:
|
|
// `codex resume <id>` of a session CC Switch's "custom" made, with Codex
|
|
// on magpie now, stopped at modelProviderMismatch ("This chat uses custom,
|
|
// but your current provider is magpie", mrten_95615 on Discord). Opening
|
|
// it from Sessions names its own provider while config.toml has it, and
|
|
// moves the thread to the provider Codex is on when config.toml has it no
|
|
// longer, which nothing else gets Codex to resume.
|
|
func TestCodexResumeOnItsProvider(t *testing.T) {
|
|
_, codex := manageSetup(t)
|
|
main := filepath.Join(codex, "sessions", "2026", "09", "20", "rollout-2026-09-20T15-48-28-"+mgCX+".jsonl")
|
|
b, err := os.ReadFile(main)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
orig := bytes.Replace(b, []byte(`"model_provider":"openai"`), []byte(`"model_provider":"custom"`), 1)
|
|
old := time.Now().Add(-24 * time.Hour).Truncate(time.Second)
|
|
os.WriteFile(main, orig, 0o644)
|
|
os.Chtimes(main, old, old)
|
|
db := codexStateDB(t, codex, mgCX, "custom")
|
|
cfg := filepath.Join(codex, "config.toml")
|
|
magpie := "model = \"gpt-5.5\"\nmodel_provider = \"magpie\"\n\n[model_providers.magpie]\nname = \"magpie\"\nbase_url = \"http://127.0.0.1:1/v1\"\n"
|
|
custom := "\n[model_providers.custom]\nname = \"custom\"\nbase_url = \"http://127.0.0.1:2/v1\"\n"
|
|
|
|
// custom still in config.toml: resumed on it, nothing moved
|
|
os.WriteFile(cfg, []byte(magpie+custom), 0o644)
|
|
s, ok := Find("codex", mgCX)
|
|
if !ok || !strings.HasSuffix(s.Resume, "codex resume "+mgCX) {
|
|
t.Fatalf("listed %v, resume %q", ok, s.Resume)
|
|
}
|
|
got := ResumeNow(s)
|
|
if want := strings.TrimSuffix(s.Resume, "codex resume "+mgCX) + "codex resume -c model_provider=custom " + mgCX; got != want {
|
|
t.Fatalf("resume %q, want %q", got, want)
|
|
}
|
|
if b, _ := os.ReadFile(main); !bytes.Equal(b, orig) {
|
|
t.Fatal("a thread whose provider is there was changed")
|
|
}
|
|
|
|
// Codex on custom itself: as listed
|
|
os.WriteFile(cfg, []byte(strings.Replace(magpie, `model_provider = "magpie"`, `model_provider = "custom"`, 1)+custom), 0o644)
|
|
if got := ResumeNow(s); got != s.Resume {
|
|
t.Fatalf("on its own provider %q, want %q", got, s.Resume)
|
|
}
|
|
|
|
// custom gone: the thread moves to magpie and resumes there
|
|
os.WriteFile(cfg, []byte(magpie), 0o644)
|
|
if got := ResumeNow(s); got != s.Resume {
|
|
t.Fatalf("resume %q, want %q", got, s.Resume)
|
|
}
|
|
if b, _ := os.ReadFile(main); !bytes.Contains(b, []byte(`"model_provider":"magpie"`)) || bytes.Contains(b, []byte(`"model_provider":"custom"`)) {
|
|
t.Fatal("the thread's rollout wasn't moved to magpie")
|
|
}
|
|
if p, _, _ := threadProvider(t, db, mgCX); p != "magpie" {
|
|
t.Fatalf("thread row %q, want magpie", p)
|
|
}
|
|
if p, _, _ := threadProvider(t, db, "other"); p != "custom" {
|
|
t.Errorf("another thread became %q", p)
|
|
}
|
|
|
|
// the row is what Codex reads first: a row on custom over a file
|
|
// naming magpie still takes the override
|
|
os.WriteFile(cfg, []byte(magpie+custom), 0o644)
|
|
if _, err := moveCodexThread(db, mgCX, "custom"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := ResumeNow(s); !strings.Contains(got, "-c model_provider=custom ") {
|
|
t.Fatalf("row on custom: resume %q", got)
|
|
}
|
|
|
|
// a built-in Codex knows without a table
|
|
moveCodexThread(db, mgCX, "openai")
|
|
if got := ResumeNow(s); !strings.Contains(got, "-c model_provider=openai ") {
|
|
t.Fatalf("row on openai: resume %q", got)
|
|
}
|
|
|
|
// another agent's line is as listed
|
|
if cc := (Session{Agent: "claude", ID: "x", Resume: "claude --resume x", Path: main}); ResumeNow(cc) != cc.Resume {
|
|
t.Fatal("a Claude session's line changed")
|
|
}
|
|
}
|