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.
This commit is contained in:
+25
-2
@@ -1163,7 +1163,7 @@ func codexIn(at place) *Agent {
|
||||
if !through && (!onSignIn || codexFailover()) {
|
||||
return append(own, viaMagpie("codex", "")...)
|
||||
}
|
||||
return append(own, viaMagpieFor("codex", "")...)
|
||||
return append(own, codexViaMagpieFor(own)...)
|
||||
}
|
||||
// unroute takes magpie out as the way Codex reaches its models and puts
|
||||
// back what the stash kept from before magpie was wired in (its
|
||||
@@ -2010,7 +2010,7 @@ func ownCodex() []catalog.Model {
|
||||
|
||||
// codexInMagpie marks Served those of Codex's own models that magpie's list
|
||||
// shows Codex on a ChatGPT account of the user's (codex/gpt-5.5): its
|
||||
// pickers leave out magpie's codex/… as only a hop (viaMagpieFor), so these
|
||||
// pickers leave out magpie's codex/… as only a hop (codexViaMagpieFor), so these
|
||||
// are how they are offered, and the agent's own models switched off
|
||||
// (provider.OwnModelsHidden) never takes them out. It did once a routing
|
||||
// group gave the picker a catalog entry, and Codex's picker was the group
|
||||
@@ -2029,6 +2029,29 @@ func codexInMagpie(own []Option) []Option {
|
||||
return own
|
||||
}
|
||||
|
||||
// codexViaMagpieFor is viaMagpieFor("codex") keeping the models magpie
|
||||
// serves on a ChatGPT account that own, Codex's own list, leaves out: one
|
||||
// Codex hides from its picker (gpt-6.1-terra) but the user ticked on the
|
||||
// subscription was offered nowhere (ysm119 on Discord), as the hop is all
|
||||
// that reaches it.
|
||||
func codexViaMagpieFor(own []Option) []Option {
|
||||
in := map[string]bool{}
|
||||
for _, o := range own {
|
||||
in[o.Value] = true
|
||||
if m := codexOwnOf(o.Value); m != "" {
|
||||
in[m] = true
|
||||
}
|
||||
}
|
||||
var out []Option
|
||||
for _, o := range viaMagpie("codex", "") {
|
||||
if strings.HasPrefix(o.Value, "codex/") && in[codexOwnOf(o.Value)] {
|
||||
continue
|
||||
}
|
||||
out = append(out, o)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// codexOwnViaMagpie is the catalog id magpie serves one of Codex's own
|
||||
// models by on a ChatGPT account of the user's ("codex/gpt-5.5"), those
|
||||
// shown to Codex first; "" when none serves it.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// A model Codex hides from its own picker (gpt-6.1-terra) but the user
|
||||
// ticked on the Codex subscription is still offered in Codex's picker,
|
||||
// via magpie, while one Codex lists is offered once, as Codex's own
|
||||
// (ysm119 on Discord: 4 ticked, 3 to pick from).
|
||||
func TestCodexHiddenTickedModelOffered(t *testing.T) {
|
||||
claims := func(m map[string]any) string {
|
||||
b, _ := json.Marshal(m)
|
||||
return "h." + base64.RawURLEncoding.EncodeToString(b) + ".s"
|
||||
}
|
||||
me, _ := json.Marshal(map[string]any{"auth_mode": "chatgpt", "tokens": map[string]any{
|
||||
"id_token": claims(map[string]any{"email": "me@example.com"}),
|
||||
"access_token": claims(map[string]any{"exp": time.Now().Add(time.Hour).Unix()}),
|
||||
"refresh_token": "r", "account_id": "acct-1"}})
|
||||
home, _ := codexHome(t, string(me), "model = \"gpt-a\"\n")
|
||||
os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), []byte(`{"models":[
|
||||
{"slug":"gpt-a","display_name":"A","priority":1},
|
||||
{"slug":"gpt-h","display_name":"H","priority":2,"visibility":"hide"}]}`), 0o644)
|
||||
if err := provider.Save(provider.Provider{ID: "codex", Models: []string{"gpt-a", "gpt-h"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seen := map[string]int{}
|
||||
var all []string
|
||||
for _, o := range codex(home).Fields[0].Options(nil) {
|
||||
all = append(all, o.Group+":"+o.Value)
|
||||
m := o.Value
|
||||
if own := codexOwnOf(o.Value); own != "" {
|
||||
m = own
|
||||
}
|
||||
seen[m]++
|
||||
}
|
||||
if seen["gpt-h"] != 1 || seen["gpt-a"] != 1 {
|
||||
t.Fatalf("want gpt-a and gpt-h once each: %v", all)
|
||||
}
|
||||
}
|
||||
@@ -114,18 +114,6 @@ func listLabels(agent string) map[string]string {
|
||||
return out
|
||||
}
|
||||
|
||||
// viaMagpieFor is viaMagpie without the agent's own account: Codex CLI going
|
||||
// through magpie to its own ChatGPT login would only add a hop.
|
||||
func viaMagpieFor(agentID, prefix string) []Option {
|
||||
var out []Option
|
||||
for _, o := range viaMagpie(agentID, prefix) {
|
||||
if !strings.HasPrefix(o.Value, prefix+agentID+"/") {
|
||||
out = append(out, o)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// isMagpie reports whether a model value is a catalog reference.
|
||||
func isMagpie(v string) bool {
|
||||
if pid, _, ok := strings.Cut(v, "/"); ok && dryProviders[pid] {
|
||||
|
||||
@@ -298,7 +298,8 @@ var wslKinds = []wslKind{
|
||||
if codexFailover() {
|
||||
return append(group("OpenAI", options(ownCodex(), "")), viaMagpie("codex", "")...)
|
||||
}
|
||||
return append(codexInMagpie(group("OpenAI", options(ownCodex(), ""))), viaMagpieFor("codex", "")...)
|
||||
own := codexInMagpie(group("OpenAI", options(ownCodex(), "")))
|
||||
return append(own, codexViaMagpieFor(own)...)
|
||||
}
|
||||
case "effort":
|
||||
return func(cur map[string]string) []Option {
|
||||
|
||||
Reference in New Issue
Block a user