Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

codex: Disconnect keeps an effort or model list the user set by hand after Connect

yetonee7f21dba5eae
diff --git a/internal/agent/codex.go b/internal/agent/codex.go
index 7dc88bd25..2299c213a 100644
--- a/internal/agent/codex.go
+++ b/internal/agent/codex.go
@@ -426,9 +426,12 @@ func codexIn(at place) *Agent {
ms := models()
model, effort := get("model"), get("model_reasoning_effort")
if e := catalog.Efforts(ms, model); len(e) > 0 && effort != "" && !contains(e, effort) {
- if err := edit.SetTOMLTop(path, edit.KV{Path: "model_reasoning_effort", Value: codexcat.ModelDefault(e, effort)}); err != nil {
+ to := codexcat.ModelDefault(e, effort)
+ if err := edit.SetTOMLTop(path, edit.KV{Path: "model_reasoning_effort", Value: to}); err != nil {
return err
}
+ // magpie's own change, which Disconnect undoes while it stands
+ stash(map[string]string{at.key("codex.effort_set"): to})
if err := relist(); err != nil {
return err
}
@@ -524,7 +527,12 @@ func codexIn(at place) *Agent {
if !asProvider() {
return nil
}
- if err := edit.DelTOMLTop(path, "model_provider", "model_catalog_json"); err != nil {
+ // a model list of the user's own, put in by hand since, stays
+ keys := []string{"model_provider"}
+ if c := get("model_catalog_json"); c == "" || ownCatalog(c) {
+ keys = append(keys, "model_catalog_json")
+ }
+ if err := edit.DelTOMLTop(path, keys...); err != nil {
return err
}
dropList()
@@ -1078,16 +1086,33 @@ func codexIn(at place) *Agent {
return "", err
}
was := unstash(at.key("codex.model"))
+ // what was there before magpie is put back only where magpie's
+ // change still stands: a key the user set by hand since keeps
+ // theirs (yhwangl on X)
var back []edit.KV
- if p := unstash(at.key("codex.provider")); p != "" && p != magpieID {
+ if p := unstash(at.key("codex.provider")); p != "" && p != magpieID && get("model_provider") == "" {
back = append(back, edit.KV{Path: "model_provider", Value: p})
}
// the catalog of the user's own put back while its file is there:
// one removed since would keep Codex from loading its config
- if c := unstash(at.key("codex.catalog")); c != "" && !ownCatalog(c) && !theirListGone(c) {
+ if c := unstash(at.key("codex.catalog")); c != "" && !ownCatalog(c) && !theirListGone(c) && get("model_catalog_json") == "" {
back = append(back, edit.KV{Path: "model_catalog_json", Value: c})
}
- if e := unstash(at.key("codex.effort")); e != "" {
+ // the effort, where it is still one magpie set: picked on the
+ // Agents page, or moved to one its model has. One taken out
+ // reads the same however it was, and comes back.
+ id := at.id
+ if id == "" {
+ id = "codex"
+ }
+ ours := map[string]bool{"": true}
+ if set := unstash(at.key("codex.effort_set")); set != "" {
+ ours[set] = true
+ }
+ if r := appliedOf(id).Fields["effort"]; r != "" {
+ ours[r] = true
+ }
+ if e := unstash(at.key("codex.effort")); e != "" && ours[get("model_reasoning_effort")] {
back = append(back, edit.KV{Path: "model_reasoning_effort", Value: e})
}
if len(back) > 0 {
@@ -1116,7 +1141,7 @@ func codexIn(at place) *Agent {
return err
}
dropList()
- forget(at.key("codex.model"), at.key("codex.effort"), at.key("codex.provider"), at.key("codex.catalog"), at.key("codex.out"), at.key("codex.joined"), at.key("codex.beside"))
+ forget(at.key("codex.model"), at.key("codex.effort"), at.key("codex.effort_set"), at.key("codex.provider"), at.key("codex.catalog"), at.key("codex.out"), at.key("codex.joined"), at.key("codex.beside"))
return nil
}
// magpie API: magpie stays Codex's provider whichever model is the
@@ -1255,7 +1280,7 @@ func codexIn(at place) *Agent {
return err
}
dropList()
- forget(at.key("codex.model"), at.key("codex.effort"), at.key("codex.provider"), at.key("codex.catalog"))
+ forget(at.key("codex.model"), at.key("codex.effort"), at.key("codex.effort_set"), at.key("codex.provider"), at.key("codex.catalog"))
// its threads go on without magpie: the compactions magpie made
// in them written as Codex's own (a distro's Codex locks its
// files where this machine's locks can't reach)
diff --git a/internal/agent/codex_hand_edit_test.go b/internal/agent/codex_hand_edit_test.go
new file mode 100644
index 000000000..4e5917e68
--- /dev/null
+++ b/internal/agent/codex_hand_edit_test.go
@@ -0,0 +1,68 @@
+package agent
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+)
+
+// Disconnect puts back only what magpie changed: a key the user edited by
+// hand while Codex was on magpie keeps the user's value, though magpie had
+// saved what was there before it connected (yhwangl on X).
+func TestCodexDisconnectKeepsHandEdits(t *testing.T) {
+ home, read := codexHome(t, "", "model = \"gpt-5.5\"\nmodel_reasoning_effort = \"low\"\nmodel_catalog_json = \"/x/old-list.json\"\n")
+ theirs := filepath.Join(home, "my-list.json")
+ os.WriteFile(theirs, []byte(`{"models":[]}`), 0o644)
+ cx := codex(home)
+ if err := cx.Fields[0].Set("fake/m1"); err != nil {
+ t.Fatal(err)
+ }
+ cfg := read()
+ if !strings.Contains(cfg, "model_provider = \"magpie\"") {
+ t.Fatalf("not magpie's provider:\n%s", cfg)
+ }
+ // by hand, with magpie connected: an effort and a model list of their own
+ cfg = strings.Replace(cfg, "model_reasoning_effort = \"low\"", "model_reasoning_effort = \"high\"", 1)
+ lines := strings.Split(cfg, "\n")
+ for i, l := range lines {
+ if strings.HasPrefix(l, "model_catalog_json") {
+ lines[i] = "model_catalog_json = " + quoteTOML(theirs)
+ }
+ }
+ os.WriteFile(filepath.Join(home, ".codex", "config.toml"), []byte(strings.Join(lines, "\n")), 0o644)
+ if err := codex(home).Disconnect(); err != nil {
+ t.Fatal(err)
+ }
+ cfg = read()
+ for _, want := range []string{"model_reasoning_effort = \"high\"\n", "model_catalog_json = " + quoteTOML(theirs) + "\n", "model = \"gpt-5.5\"\n"} {
+ if !strings.Contains(cfg, want) {
+ t.Errorf("missing %q after Disconnect:\n%s", want, cfg)
+ }
+ }
+ if strings.Contains(cfg, "model_provider = \"magpie\"") {
+ t.Errorf("still on magpie:\n%s", cfg)
+ }
+}
+
+// What magpie changed and the user didn't is put back as it was.
+func TestCodexDisconnectPutsBackWhatMagpieChanged(t *testing.T) {
+ home, read := codexHome(t, "", "model = \"gpt-5.5\"\nmodel_reasoning_effort = \"low\"\n")
+ if err := codex(home).Fields[0].Set("fake/m1"); err != nil {
+ t.Fatal(err)
+ }
+ if err := codex(home).Disconnect(); err != nil {
+ t.Fatal(err)
+ }
+ cfg := read()
+ for _, want := range []string{"model_reasoning_effort = \"low\"\n", "model = \"gpt-5.5\"\n"} {
+ if !strings.Contains(cfg, want) {
+ t.Errorf("missing %q after Disconnect:\n%s", want, cfg)
+ }
+ }
+ if strings.Contains(cfg, "model_catalog_json") || strings.Contains(cfg, "model_provider =") {
+ t.Errorf("magpie's keys left:\n%s", cfg)
+ }
+}
+
+func quoteTOML(s string) string { return "\"" + strings.ReplaceAll(s, `\`, `\\`) + "\"" }