diff --git a/internal/provider/account.go b/internal/provider/account.go index 3677b28ea..406866660 100644 --- a/internal/provider/account.go +++ b/internal/provider/account.go @@ -105,6 +105,11 @@ type Account struct { // is one the account was refused (copilot_refused.go); and on a ZCode // account on the Start Plan: whether it is one only the Coding Plan has. unusable func(model string) bool + // listedOnly is set on a ChatGPT account: the backend serves none of + // the models its list leaves out ("The 'gpt-5.5' model is not + // supported when using Codex with a ChatGPT account", #4772), so a + // pick the fetched list doesn't have isn't offered. + listedOnly bool // explain adds what the user can do about a refusal the account's // backend answered, "" when there is nothing to add (factory.go). explain func(status int, body []byte) string @@ -1049,6 +1054,7 @@ func codexAccount(home string) (Provider, bool) { } acct.body = codexBody acct.models = catalog.Codex + acct.listedOnly = true acct.fetch = func(ctx context.Context) ([]catalog.Model, error) { ms, err := codexModels(ctx, acct.sign) if err != nil { diff --git a/internal/provider/codex_gone_pick_test.go b/internal/provider/codex_gone_pick_test.go new file mode 100644 index 000000000..f0e2dce34 --- /dev/null +++ b/internal/provider/codex_gone_pick_test.go @@ -0,0 +1,94 @@ +package provider + +import ( + "net/http" + "net/http/httptest" + "path/filepath" + "slices" + "sync/atomic" + "testing" + "time" +) + +// #4772: the owner picked Codex's models while ChatGPT listed gpt-5.5. +// ChatGPT then stopped listing it on Plus and Pro alike, and its backend +// answers every request for it 400 "The 'gpt-5.5' model is not supported +// when using Codex with a ChatGPT account". The pick stayed, and agents +// (Cindy) were offered codex/gpt-5.5 first. A pick the account's list +// doesn't have is not offered; it comes back when the list has it again. +func TestCodexPickTheListDroppedNotOffered(t *testing.T) { + isolate(t) + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + newFetches.Lock() + newFetches.m = map[string]time.Time{} + newFetches.Unlock() + + var dropped atomic.Bool + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/backend-api/codex/models" { + w.WriteHeader(404) + return + } + if dropped.Load() { + // the Pro account's list on 11-01 + w.Write(codexListOf("gpt-6.1-sol", "gpt-6-astra", "gpt-6-sol", "gpt-5.6-luna")) + return + } + w.Write(codexListOf("gpt-5.5", "gpt-6-astra", "gpt-6-sol", "gpt-5.6-luna")) + })) + defer srv.Close() + codexListedAt(t, srv.URL) + codexSignedIn(t, home) + + offered := func() []string { + t.Helper() + p, err := Find("codex") + if err != nil { + t.Fatal(err) + } + var out []string + for _, m := range p.ExposedOf(p.Available()) { + out = append(out, m.ID) + } + return out + } + refetch := func() { + t.Helper() + p, err := Find("codex") + if err != nil { + t.Fatal(err) + } + if _, err := p.fetch(t.Context()); err != nil { + t.Fatal(err) + } + forgetAccountCaches() + } + + refetch() + if err := SetModels("codex", []string{"gpt-5.5", "gpt-6-astra", "gpt-6-sol"}); err != nil { + t.Fatal(err) + } + if got := offered(); !slices.Equal(got, []string{"gpt-5.5", "gpt-6-astra", "gpt-6-sol"}) { + t.Fatalf("picks while listed: %v", got) + } + + dropped.Store(true) + refetch() + if got := offered(); slices.Contains(got, "gpt-5.5") || !slices.Equal(got, []string{"gpt-6-astra", "gpt-6-sol"}) { + t.Fatalf("after ChatGPT stopped listing gpt-5.5, offered %v; want gpt-6-astra and gpt-6-sol", got) + } + // the user's pick is kept, only not offered + if p, _ := Find("codex"); !slices.Contains(p.Models, "gpt-5.5") { + t.Fatalf("the pick itself was dropped: %v", p.Models) + } + + dropped.Store(false) + refetch() + if got := offered(); !slices.Contains(got, "gpt-5.5") { + t.Fatalf("listed again, gpt-5.5 not offered: %v", got) + } +} diff --git a/internal/provider/models.go b/internal/provider/models.go index 65013366c..3a3170f2b 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -1574,11 +1574,14 @@ func (p Provider) ExposedOf(avail []catalog.Model) []catalog.Model { return out } picks := p.Models - if _, _, ok := p.live(); ok && p.Account != nil && p.Account.unusable != nil { + if _, _, ok := p.live(); ok && p.Account != nil && (p.Account.unusable != nil || p.Account.listedOnly) { // A Copilot account is served what its list offers it, less what // it was refused: a pick its list doesn't have (#371: gpt-6-luna, // not in a Student plan's) or that it was refused is left out; - // with none left, as if none were picked. + // with none left, as if none were picked. A ChatGPT account's + // too: a pick made while its list had gpt-5.5 stayed offered after + // the list dropped it, and the backend refused every request for + // it (#4772). It comes back when the list has it again. picks = slices.DeleteFunc(slices.Clone(picks), func(id string) bool { _, ok := byID[id]; return !ok }) } else if p.Account != nil && p.Account.unusable != nil { // with no list fetched, a pick the account can't be served (a