netube's Codex Plus account showed a 922K context window on Routing. 922000 is models.dev's input limit for gpt-5.5, which is OpenAI's API's window. Codex holds a ChatGPT plan's conversation to the context_window its own list gives (272000). There were two causes: - codex_backend.go's end() took catalog.ContextOf(model) (models.dev) as the window for a turn Codex sent natively. It now takes provider.CodexWindow(user, slug), and falls back to models.dev's window only when no list says. CodexWindow checks, in order: the window the user set on the codex provider; the account's own live list; magpie's Codex subscription's list; Codex CLI's models_cache.json. - catalog.parseCodex dropped context_window, so until the live list was fetched, a Codex subscription's models (catalog.Codex) fell back to models.dev's 922K. That reached the Providers page and Routing (WindowOf), the Entry.Context agents are told, and siwcWithCodex. It now keeps Context. Only Codex is affected. A provider on OpenAI's API that serves the same id keeps models.dev's 922K, and both tests check that. Tests: - TestCodexNativeTurnTakesCodexWindow (gateway): a native turn's Prompt.Window is 272000 from models_cache.json, 258000 from the subscription's live list, and 400000 when the user sets it. An "oai" provider's gpt-5.5 stays at 922000. - TestCodexModelsTakeCodexWindow (provider): checks WindowOf, CodexWindow (and 0 for an unlisted slug), and the catalog entry's Context, with an OpenAI API provider kept at 922000. Broken by hand: - codex_backend reverted to ContextOf: the gateway test went red, with 922000 in all three cases. - parseCodex's Context removed: the gateway test went red on its first case, and the provider test went red on WindowOf 922000, CodexWindow 0 and the catalog entry 922000. - Restored: both green. Run: - gofmt -l: clean. - go vet: darwin, GOOS=linux -tags nogui, GOOS=windows -tags nogui. - go test -tags nogui -timeout 45m ./... at 7660399a1+this: 64 packages ok. internal/agent and internal/gateway hit the 45m timeout under a load average of ~270. The running tests were 1s and 6s old (TestReseatOff, TestClaudeCodeSeenOnAnyRoute), so this was slowness, not a hang. - Rerun at the rebased head with -timeout 90m: EXIT=0, 66 packages ok, none failed (agent 3761s, gateway 3105s), on cb05dc2d1+this. - Rebased then onto252bc61ce(84cd686afand252bc61ce, internal/agent only, none of these files): go build ./..., go vet of gateway, provider, catalog and agent, and both new tests green there.
72 lines
2.4 KiB
Go
72 lines
2.4 KiB
Go
package provider
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
// netube on Discord: a Codex Plus account's gpt-5.5 said 922K, models.dev's
|
|
// input limit for the id (OpenAI's API's), where Codex holds it to the 272K
|
|
// its ChatGPT list gives. Before the subscription's own list is fetched,
|
|
// its models are Codex CLI's models_cache.json's, and their window is that
|
|
// list's: on the Providers and Routing pages (WindowOf), in the catalog
|
|
// agents are told (Entry.Context) and in CodexWindow. A provider on
|
|
// OpenAI's API serving the same id keeps models.dev's.
|
|
func TestCodexModelsTakeCodexWindow(t *testing.T) {
|
|
home := signIn(t)
|
|
cache := catalog.CachePath()
|
|
os.MkdirAll(filepath.Dir(cache), 0o755)
|
|
if err := os.WriteFile(cache, []byte(`{"openai":{"id":"openai","models":{
|
|
"gpt-5.5":{"id":"gpt-5.5","limit":{"context":1050000,"input":922000,"output":128000}}}}}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
catalog.Reset()
|
|
t.Cleanup(catalog.Reset)
|
|
if err := os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), []byte(`{"etag":"\"e1\"","client_version":"0.159.0","models":[
|
|
{"slug":"gpt-5.5","display_name":"GPT-5.5","priority":1,"visibility":"list","context_window":272000,"max_context_window":272000}]}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ForgetAccounts()
|
|
t.Cleanup(ForgetAccounts)
|
|
|
|
p, ok := codexAccount(home)
|
|
if !ok {
|
|
t.Fatal("no Codex sign-in")
|
|
}
|
|
var got int
|
|
for _, m := range p.Available() {
|
|
if m.ID == "gpt-5.5" {
|
|
got = p.WindowOf(m)
|
|
}
|
|
}
|
|
if got != 272000 {
|
|
t.Errorf("Codex subscription's gpt-5.5 window %d, want Codex's 272000, not models.dev's 922000", got)
|
|
}
|
|
if n := CodexWindow("", "gpt-5.5"); n != 272000 {
|
|
t.Errorf("CodexWindow(gpt-5.5) = %d, want 272000", n)
|
|
}
|
|
if n := CodexWindow("", "gpt-unlisted"); n != 0 {
|
|
t.Errorf("CodexWindow(gpt-unlisted) = %d, want 0: no list says", n)
|
|
}
|
|
for _, e := range Catalog() {
|
|
if e.Provider.ID == "codex" && e.Model == "gpt-5.5" && e.Context != 272000 {
|
|
t.Errorf("catalog entry %s told agents %d, want 272000", e.ID, e.Context)
|
|
}
|
|
}
|
|
|
|
// the same id on OpenAI's API is models.dev's, as before
|
|
oai := Provider{ID: "oai", Name: "OAI", Key: "k", Catalog: "openai", Responses: "https://api.example.invalid/v1"}
|
|
got = 0
|
|
for _, m := range oai.Available() {
|
|
if m.ID == "gpt-5.5" {
|
|
got = oai.WindowOf(m)
|
|
}
|
|
}
|
|
if got != 922000 {
|
|
t.Errorf("OpenAI API gpt-5.5 window %d, want models.dev's 922000", got)
|
|
}
|
|
}
|