codex: an account that is out takes over for other models too (reverses f37742e14)
With one ChatGPT account out and nothing to serve Codex's own model on (provider.CodexServesWhileOut false),f37742e14left Codex on its sign-in to keep the account's menu. But the Codex app greys Send for every model while authMethod is chatgpt and /wham/usage says not allowed, so shamen (mac, banner "Codex 和工作使用额度已用完"), chenhan and xiaoq6285 could send nothing on GLM-5.3 or any other magpie model. A grey Send for every model costs more than the menu, so this is the owner's product call: sending on other models comes first. When joined, on ChatGPT and held, and magpie has a model on no ChatGPT account (codexOtherModel), Sync makes magpie the provider on that stand-in, keeps the user's model in codex.out_own and the stand-in in codex.out_stand, and at the reset puts Codex back joined on its own model (#540 way back). Once per held/unheld transition: on the stand-in the model is magpie's, so the branch is not met again. With nothing else to offer, Codex stays on its sign-in as inf37742e14. Nothing about identity, base_instructions or the account's state is changed or faked; magpie only becomes the provider, as for any held account. Run (mote-run, win-run, sandbox HOME, fake upstream; no real exhausted account was tried): - go test -tags nogui ./internal/agent -run Codex: ok; ./internal/provider -run CodexServes: ok; win-run ./internal/agent: see the tag notes. - gofmt -l, go vet linux/windows/native on internal/agent: clean. - New TestCodexOwnModelOneSpentAccountTakenOverForOtherModels: takeover, three more Syncs with no config write and no codexAppRoute change, the reset back once, a further Sync changing nothing. TestCodexOwnModel- OneSpentAccountStaysOnItsSignIn now covers only the nothing-else case (fake provider deleted). - Broken by hand: new branch disabled -> the new test red; the !isMagpie(m) one-shot guard removed -> red. Not tried: a real exhausted account in the Codex app; the stand-in picked by the user is indistinguishable from staying on it and gives way to the own model at the reset (documented in agent-wiring.md).
This commit is contained in:
File diff suppressed because one or more lines are too long
+37
-4
@@ -1467,7 +1467,7 @@ func codexIn(at place) *Agent {
|
||||
// left magpie the provider of one of Codex's own for good
|
||||
// (eddie.zhan on Discord, Always ChatGPT from the takeover)
|
||||
if asProvider() && stashShared()[at.key("codex.out")] == "1" && !out() {
|
||||
forget(at.key("codex.out"), at.key("codex.out_own"))
|
||||
forget(at.key("codex.out"), at.key("codex.out_own"), at.key("codex.out_stand"))
|
||||
if err := edit.DelTOMLTop(path, "model_provider", "model_catalog_json"); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1682,19 +1682,36 @@ func codexIn(at place) *Agent {
|
||||
return set(id)
|
||||
}
|
||||
}
|
||||
// magpie can't serve the model picked on that account, but the
|
||||
// Codex app greys Send for every model while the account is
|
||||
// out (shamen, chenhan, xiaoq6285 on Discord): with a model of
|
||||
// magpie's on no account of the held one, magpie becomes
|
||||
// Codex's provider on that one so the user can send at all.
|
||||
// This reverses f37742e14, which left Codex on its sign-in to
|
||||
// keep the account's menu: a grey Send for every model costs
|
||||
// more. Once per held/unheld transition: on the stand-in the
|
||||
// model is magpie's, so the branch is not met again; the
|
||||
// stand-in is kept (codex.out_stand) for the way back below.
|
||||
if m := get("model"); !isMagpie(m) && !api() && chatGPT() && joined() && out() && !provider.CodexServesWhileOut(m) {
|
||||
if id := codexOtherModel(); id != "" {
|
||||
stash(map[string]string{at.key("codex.out_own"): m, at.key("codex.out_stand"): id})
|
||||
return set(id)
|
||||
}
|
||||
}
|
||||
// put back before #540's way back, which would take
|
||||
// codex/<model> for a magpie model picked beside the sign-in
|
||||
if own := stashShared()[at.key("codex.out_own")]; own != "" {
|
||||
m := get("model")
|
||||
switch {
|
||||
case stashShared()[at.key("codex.out")] != "1" || !asProvider() || codexOwnOf(m) != own:
|
||||
case stashShared()[at.key("codex.out")] != "1" || !asProvider() ||
|
||||
codexOwnOf(m) != own && m != stashShared()[at.key("codex.out_stand")]:
|
||||
// moved since (another model picked, magpie API, a
|
||||
// disconnect): that stands
|
||||
forget(at.key("codex.out_own"))
|
||||
forget(at.key("codex.out_own"), at.key("codex.out_stand"))
|
||||
case !out():
|
||||
// back beside the sign-in on the one picked, as Join
|
||||
// leaves it: Codex's own sign-in, magpie's models joined
|
||||
forget(at.key("codex.out_own"), at.key("codex.out"))
|
||||
forget(at.key("codex.out_own"), at.key("codex.out"), at.key("codex.out_stand"))
|
||||
if err := edit.DelTOMLTop(path, "model_provider", "model_catalog_json"); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -2254,6 +2271,22 @@ func codexOwnViaMagpie(model string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// codexOtherModel is a model of magpie's that no ChatGPT account serves
|
||||
// (a provider's or a key's own), the one magpie takes Codex over on while
|
||||
// the account is out and cannot serve what was picked. "" when magpie has
|
||||
// none.
|
||||
func codexOtherModel() string {
|
||||
shown, _ := provider.CatalogFor("codex")
|
||||
for _, es := range [][]provider.Entry{shown, provider.Catalog()} {
|
||||
for _, e := range es {
|
||||
if a := e.Provider.Account; e.Group == "" && e.ID != "" && isMagpie(e.ID) && !provider.IsGroupRef(e.ID) && (a == nil || a.Agent != "codex") {
|
||||
return e.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// codexOwnOf is the model of Codex's own a catalog id serves on a ChatGPT
|
||||
// account (codexOwnViaMagpie's way back); "" for any other.
|
||||
func codexOwnOf(id string) string {
|
||||
|
||||
@@ -184,15 +184,19 @@ func TestCodexOwnModelGoesThroughMagpieWhileUsedUp(t *testing.T) {
|
||||
}
|
||||
|
||||
// One ChatGPT account, out, on one of Codex's own models joined beside the
|
||||
// sign-in, and nothing else in magpie to serve that model on: no fallback
|
||||
// on the Codex subscription and no other account (xiaoq6285 on Discord:
|
||||
// a Plus account in the Windows Codex app, the menu down to "magpie" with
|
||||
// no quota after the five-hour limit, the app erroring and restarting at
|
||||
// the limit and again at the reset). magpie leaves Codex on its sign-in:
|
||||
// every turn it took over would be refused on that same account, so the
|
||||
// sign-in, and nothing else in magpie to offer: no fallback on the Codex
|
||||
// subscription, no other account and no model of another provider
|
||||
// (xiaoq6285 on Discord: a Plus account in the Windows Codex app, the menu
|
||||
// down to "magpie" with no quota after the five-hour limit, the app
|
||||
// erroring and restarting at the limit and again at the reset). magpie
|
||||
// leaves Codex on its sign-in: no turn it took over could be sent, so the
|
||||
// app keeps the account, its usage and its reset, and nothing restarts.
|
||||
func TestCodexOwnModelOneSpentAccountStaysOnItsSignIn(t *testing.T) {
|
||||
home, read := codexHome(t, `{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`, "model = \"gpt-a\"\n")
|
||||
// codexHome's other provider is the one thing magpie could offer
|
||||
if err := provider.Delete("fake"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"),
|
||||
[]byte(`{"models":[{"slug":"gpt-a","display_name":"A","priority":1}]}`), 0o644)
|
||||
cx := codex(home)
|
||||
@@ -202,6 +206,9 @@ func TestCodexOwnModelOneSpentAccountStaysOnItsSignIn(t *testing.T) {
|
||||
if codexOwnViaMagpie("gpt-a") == "" {
|
||||
t.Fatal("magpie lists no codex/gpt-a: the test proves nothing")
|
||||
}
|
||||
if codexOtherModel() != "" {
|
||||
t.Fatalf("magpie has another model %q: the test proves nothing", codexOtherModel())
|
||||
}
|
||||
route, _, known := codexAppRoute()
|
||||
if !known {
|
||||
t.Fatal("route not known")
|
||||
@@ -235,6 +242,65 @@ func TestCodexOwnModelOneSpentAccountStaysOnItsSignIn(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The same account, with a model of another provider in magpie (fake/m1)
|
||||
// but nothing to serve Codex's own model on (CodexServesWhileOut false):
|
||||
// the Codex app greys Send for every model while the account is out, so
|
||||
// magpie takes Codex over on that model (shamen, chenhan on Discord),
|
||||
// once, and puts Codex back on its own model at the reset, once. A steady
|
||||
// held state writes nothing and ends no app-server. This reverses
|
||||
// f37742e14, which stayed on the sign-in.
|
||||
func TestCodexOwnModelOneSpentAccountTakenOverForOtherModels(t *testing.T) {
|
||||
home, read := codexHome(t, `{"tokens":{"access_token":"x","id_token":"x.e30.x"}}`, "model = \"gpt-a\"\n")
|
||||
os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"),
|
||||
[]byte(`{"models":[{"slug":"gpt-a","display_name":"A","priority":1}]}`), 0o644)
|
||||
cx := codex(home)
|
||||
if ok, err := cx.Join(); err != nil || !ok {
|
||||
t.Fatalf("join: %v %v", ok, err)
|
||||
}
|
||||
if provider.CodexServesWhileOut("gpt-a") {
|
||||
t.Fatal("magpie serves gpt-a while out: the test proves nothing")
|
||||
}
|
||||
if codexOtherModel() != "fake/m1" {
|
||||
t.Fatalf("other model %q", codexOtherModel())
|
||||
}
|
||||
codexUsedUp = func() bool { return true }
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := read()
|
||||
if !strings.Contains(cfg, `model_provider = "magpie"`) || !strings.Contains(cfg, `model = "fake/m1"`) || !cx.AppOut() {
|
||||
t.Fatalf("used up:\n%s", cfg)
|
||||
}
|
||||
route, _, _ := codexAppRoute()
|
||||
// steady: no write, no route change (an app-server end), however often
|
||||
for i := 0; i < 3; i++ {
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := read(); got != cfg {
|
||||
t.Fatalf("held, synced again (%d): config written:\n%s\nwas:\n%s", i, got, cfg)
|
||||
}
|
||||
if r, _, _ := codexAppRoute(); r != route {
|
||||
t.Fatalf("held, synced again (%d): route changed:\n%s\nwas:\n%s", i, r, route)
|
||||
}
|
||||
}
|
||||
codexUsedUp = func() bool { return false }
|
||||
if err := cx.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := read(); strings.Contains(got, "model_provider =") || strings.Contains(got, "model_catalog_json") ||
|
||||
!strings.Contains(got, `model = "gpt-a"`) || !strings.Contains(got, "openai_base_url") {
|
||||
t.Fatalf("reset:\n%s", got)
|
||||
}
|
||||
if cx.AppOut() || !cx.Joined() {
|
||||
t.Fatalf("reset: AppOut %v, Joined %v", cx.AppOut(), cx.Joined())
|
||||
}
|
||||
back := read()
|
||||
if err := cx.Sync(); err != nil || read() != back {
|
||||
t.Fatalf("reset, synced again: %v\n%s", err, read())
|
||||
}
|
||||
}
|
||||
|
||||
// Kept on ChatGPT, a used-up account on one of Codex's own models leaves
|
||||
// Codex as it is: the user chose the sign-in.
|
||||
func TestCodexOwnModelKeptOnChatGPT(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user