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)
This commit is contained in:
File diff suppressed because one or more lines are too long
+44
-22
@@ -941,35 +941,53 @@ func codexIn(at place) *Agent {
|
||||
// CC Switch 4 moves them back to "openai" itself (#7948). Codex 0.166
|
||||
// resumes a thread only on the provider it is on now, so one of them
|
||||
// reopened beside magpie said "This chat uses cc-switch-official, but
|
||||
// your current provider is openai" (AcMilan on Discord). None moves
|
||||
// while config.toml or a profile picks that id, whose threads they
|
||||
// are then, and none from a distro's Codex. A copy of each is kept
|
||||
// your current provider is openai" (AcMilan on Discord). So do the
|
||||
// threads of CC Switch's OpenAI mirror (isCCSwitchMirror: "custom",
|
||||
// name OpenAI, the sign-in, no base_url of its own), which are the
|
||||
// ChatGPT account's as much: the Codex app names a provider by its
|
||||
// table's name, and refused them with "This chat uses OpenAI, but your
|
||||
// current provider is OpenAI" (Chris on Discord), Codex on the built-in
|
||||
// OpenAI and the thread on the mirror. None moves while config.toml or
|
||||
// a profile picks that id, whose threads they are then (lendOwn brings
|
||||
// OpenAI's to a mirror at the top), and none from a distro's Codex. A
|
||||
// mirror magpie took down from the top (stash codex.provider) is left
|
||||
// to bringBeside and bringOver, which give its threads back at the
|
||||
// Disconnect that puts it back. A copy of each is kept
|
||||
// (MoveCodexThreads); config.toml is left as it is.
|
||||
bringOfficial := func() {
|
||||
if at.spell != nil || !routed() {
|
||||
return
|
||||
}
|
||||
to := sessions.CodexProviderIn(dir)
|
||||
if to != "openai" && to != magpieID || get("model_provider") == ccSwitchOfficial {
|
||||
if to != "openai" && to != magpieID {
|
||||
return
|
||||
}
|
||||
names, _ := edit.TOMLTables(path)
|
||||
if profileNamed(names)[ccSwitchOfficial] {
|
||||
return
|
||||
named := profileNamed(names)
|
||||
ids := []string{ccSwitchOfficial}
|
||||
for _, n := range names {
|
||||
if id, ok := strings.CutPrefix(n, "model_providers."); ok && !strings.Contains(id, ".") && id != ccSwitchOfficial && isCCSwitchMirror(id) {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
retagged, err := sessions.RetagPagedCodexThreads(dir, ccSwitchOfficial, to)
|
||||
if len(retagged) > 0 {
|
||||
log.Printf("codex: %d paginated thread(s) of CC Switch's official route moved to %s, where Codex resumes them", len(retagged), to)
|
||||
}
|
||||
if err != nil {
|
||||
log.Println("codex: moving CC Switch's official paginated threads:", err)
|
||||
}
|
||||
moved, err := sessions.MoveCodexThreads(dir, ccSwitchOfficial, to)
|
||||
if len(moved) > 0 {
|
||||
log.Printf("codex: %d thread(s) of CC Switch's official route moved to %s, where Codex resumes them", len(moved), to)
|
||||
}
|
||||
if err != nil {
|
||||
log.Println("codex: moving CC Switch's official threads:", err)
|
||||
for _, from := range ids {
|
||||
if from == to || get("model_provider") == from || named[from] || from != ccSwitchOfficial && from == stashShared()[at.key("codex.provider")] {
|
||||
continue
|
||||
}
|
||||
retagged, err := sessions.RetagPagedCodexThreads(dir, from, to)
|
||||
if len(retagged) > 0 {
|
||||
log.Printf("codex: %d paginated thread(s) of CC Switch's official route %s moved to %s, where Codex resumes them", len(retagged), from, to)
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("codex: moving CC Switch's official paginated threads of %s: %v", from, err)
|
||||
}
|
||||
moved, err := sessions.MoveCodexThreads(dir, from, to)
|
||||
if len(moved) > 0 {
|
||||
log.Printf("codex: %d thread(s) of CC Switch's official route %s moved to %s, where Codex resumes them", len(moved), from, to)
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("codex: moving CC Switch's official threads of %s: %v", from, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
// brought are the threads bringBeside moved onto OpenAI, and the
|
||||
@@ -1002,7 +1020,7 @@ func codexIn(at place) *Agent {
|
||||
return
|
||||
}
|
||||
from := stashShared()[at.key("codex.provider")]
|
||||
if from == "" || from == "openai" || from == magpieID || from == ccSwitchOfficial || isCCSwitchMirror(from) {
|
||||
if from == "" || from == "openai" || from == magpieID || from == ccSwitchOfficial {
|
||||
return
|
||||
}
|
||||
names, _ := edit.TOMLTables(path)
|
||||
@@ -1392,7 +1410,11 @@ func codexIn(at place) *Agent {
|
||||
// provider's onto OpenAI: in place when the id is OpenAI's length, the
|
||||
// last 30 days of them rewritten with a copy kept otherwise, a
|
||||
// paginated one by its row. Each one moved is kept (codex.lent) for
|
||||
// giveLent to give back once Codex is on OpenAI again. None while a
|
||||
// giveLent to give back once Codex is on OpenAI again. CC Switch's
|
||||
// OpenAI mirror at the top is such a provider too: the Codex app
|
||||
// names both by the name "OpenAI" and refused OpenAI's threads with
|
||||
// "This chat uses OpenAI, but your current provider is OpenAI" (Chris
|
||||
// on Discord). None while a
|
||||
// profile is chosen (Codex lists that one's threads) or names OpenAI,
|
||||
// none once the user disconnected Codex from magpie, and none from a
|
||||
// distro's Codex.
|
||||
@@ -1401,7 +1423,7 @@ func codexIn(at place) *Agent {
|
||||
return
|
||||
}
|
||||
to := get("model_provider")
|
||||
if to == "" || to == "openai" || to == magpieID || to == ccSwitchOfficial || isCCSwitchMirror(to) || sessions.CodexProviderIn(dir) != to {
|
||||
if to == "" || to == "openai" || to == magpieID || to == ccSwitchOfficial || sessions.CodexProviderIn(dir) != to {
|
||||
return
|
||||
}
|
||||
names, _ := edit.TOMLTables(path)
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
)
|
||||
|
||||
// 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, and CC Switch's OpenAI mirror ("custom": name OpenAI, the
|
||||
// ChatGPT sign-in, no base_url) is named OpenAI as the built-in is. Codex
|
||||
// 0.166 and 0.167 resume a thread only on the provider id it is on now,
|
||||
// and magpie left the mirror out of every move: its threads stayed on it
|
||||
// while Codex was on the built-in OpenAI beside magpie, and OpenAI's
|
||||
// stayed on OpenAI while Codex was on the mirror. Both are the ChatGPT
|
||||
// account's threads, so they follow whichever of the two Codex is on.
|
||||
const ccSwitchMirrorTable = "[model_providers.custom]\nname = \"OpenAI\"\nrequires_openai_auth = true\nsupports_websockets = true\nwire_api = \"responses\"\n"
|
||||
|
||||
// Codex on OpenAI beside its sign-in with a magpie model, the mirror a
|
||||
// table left from CC Switch: its threads move to OpenAI; a profile's
|
||||
// mirror keeps its own.
|
||||
func TestCodexMirrorThreadsFollowOpenAI(t *testing.T) {
|
||||
const (
|
||||
mirror = "019a0000-0000-7000-8000-0000000000a1"
|
||||
profile = "019a0000-0000-7000-8000-0000000000a2"
|
||||
)
|
||||
cfg := "model = \"gpt-5.4\"\n\n" + ccSwitchMirrorTable +
|
||||
"\n[model_providers.cc-switch-3]\nname = \"OpenAI\"\nrequires_openai_auth = true\nwire_api = \"responses\"\n" +
|
||||
"\n[profiles.p]\nmodel_provider = \"cc-switch-3\"\n"
|
||||
home, read := codexHome(t, chatGPTAuth, cfg)
|
||||
dir := filepath.Join(home, ".codex")
|
||||
codexThreadOn(t, dir, mirror, "custom")
|
||||
codexThreadOn(t, dir, profile, "cc-switch-3")
|
||||
cx := codex(home)
|
||||
if err := cx.Fields[0].Set("fake/m1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p, _ := edit.GetTOMLTop(filepath.Join(dir, "config.toml"), "model_provider"); p != "" {
|
||||
t.Fatalf("model_provider %q, want Codex on OpenAI beside its sign-in:\n%s", p, read())
|
||||
}
|
||||
for id, want := range map[string]string{mirror: "openai", profile: "cc-switch-3"} {
|
||||
if p := codexRowOn(t, dir, id); p != want {
|
||||
t.Errorf("thread %s on %q, want %q", id, p, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The mirror at the top when a magpie model is picked: magpie takes it
|
||||
// down and Codex goes on OpenAI, so its threads go to OpenAI, and back to
|
||||
// the mirror at the Disconnect, which puts it back on top.
|
||||
func TestCodexMirrorAtTopJoinsWithItsThreads(t *testing.T) {
|
||||
const (
|
||||
theirs = "019a0000-0000-7000-8000-0000000000a3"
|
||||
own = "019a0000-0000-7000-8000-0000000000a4"
|
||||
)
|
||||
home, read := codexHome(t, chatGPTAuth, "model_provider = \"custom\"\nmodel = \"gpt-5.4\"\n\n"+ccSwitchMirrorTable)
|
||||
dir := filepath.Join(home, ".codex")
|
||||
cfgPath := filepath.Join(dir, "config.toml")
|
||||
codexThreadOn(t, dir, theirs, "custom")
|
||||
codexThreadOn(t, dir, own, "openai")
|
||||
cx := codex(home)
|
||||
if err := cx.Fields[0].Set("fake/m1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p, _ := edit.GetTOMLTop(cfgPath, "model_provider"); p != "" {
|
||||
t.Fatalf("model_provider %q, want the mirror taken down:\n%s", p, read())
|
||||
}
|
||||
for id, want := range map[string]string{theirs: "openai", own: "openai"} {
|
||||
if p := codexRowOn(t, dir, id); p != want {
|
||||
t.Errorf("beside: thread %s on %q, want %q", id, p, want)
|
||||
}
|
||||
}
|
||||
if err := cx.Unwire(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p, _ := edit.GetTOMLTop(cfgPath, "model_provider"); p != "custom" {
|
||||
t.Fatalf("model_provider %q after the Disconnect, want the mirror back:\n%s", p, read())
|
||||
}
|
||||
if p := codexRowOn(t, dir, theirs); p != "custom" {
|
||||
t.Errorf("after the Disconnect: the mirror's thread on %q, want custom", p)
|
||||
}
|
||||
}
|
||||
|
||||
// Codex on the mirror at the top (CC Switch's official card of that
|
||||
// kind): OpenAI's threads move to it, and back once Codex is on OpenAI.
|
||||
func TestCodexMirrorAtTopTakesOpenAIThreads(t *testing.T) {
|
||||
const id = "019a0000-0000-7000-8000-0000000000a5"
|
||||
home, read := codexHome(t, chatGPTAuth, "model_provider = \"custom\"\nmodel = \"gpt-5.4\"\n\n"+ccSwitchMirrorTable)
|
||||
dir := filepath.Join(home, ".codex")
|
||||
cfgPath := filepath.Join(dir, "config.toml")
|
||||
codexThreadOn(t, dir, id, "openai")
|
||||
cx := codex(home)
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p, _ := edit.GetTOMLTop(cfgPath, "model_provider"); p != "custom" {
|
||||
t.Fatalf("model_provider %q, want the mirror kept:\n%s", p, read())
|
||||
}
|
||||
if p := codexRowOn(t, dir, id); p != "custom" {
|
||||
t.Fatalf("thread on %q, want custom, the provider Codex is on", p)
|
||||
}
|
||||
if err := edit.DelTOMLTop(cfgPath, "model_provider"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if p := codexRowOn(t, dir, id); p != "openai" {
|
||||
t.Fatalf("back on OpenAI: thread on %q, want openai", p)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user