copilot: the window is the prompt Copilot takes, and Codex's entries say effective_context_window_percent (codealc on X)

Copilot's /models says capabilities.limits.max_prompt_tokens per account
(936000 for gemini-4-carbon); magpie dropped it and told agents models.dev's
1048576 for the id, so Codex sent prompts Copilot answered 400 to. The
window of a Copilot model is now that limit (models whose list says none keep
models.dev's); other vendors are unchanged, the field being read only in
copilotModels.

The model catalog magpie writes for Codex lacked
effective_context_window_percent, which every entry of Codex's own catalog
has (95); Codex 0.166 worked out no limit from such an entry and never
compacted. Magpie's entries now say 95, and a vendor-listed entry that
omitted it gets it.

Run: TestCopilotWindowIsThePromptItTakes, TestCodexCatalogSaysEffectivePercent
and the codexcat/provider tests via mote-run. Broken by hand: window set to 0,
and the percent left out; each new test goes red.
Not tried: Codex 0.166 itself against the catalog (Codex 0.165 is on this
machine; the live config was not touched).
This commit is contained in:
yetone
2026-11-12 14:17:12 +08:00
parent 28b8244d47
commit 4f38882c4c
4 changed files with 108 additions and 2 deletions
+13 -1
View File
@@ -270,6 +270,11 @@ type model struct {
// the model's whole window, which Codex shows (95% of it) as the
// context the conversation has
Context *int `json:"context_window,omitempty"`
// the share of the window Codex counts as the conversation's room, as
// every entry of its own catalog says (95): an entry without it left
// a newer Codex with no limit to compact against, so a long
// conversation ran into the vendor's "too long" (codealc on X)
EffectivePct int `json:"effective_context_window_percent"`
// where Codex compacts the conversation when that is before the
// window: the threshold set on the model or its provider, else
// Long conversations' (settings.Working). Codex compacts at the
@@ -383,7 +388,7 @@ func entriesAt(ms []catalog.Model, after int, effort string) []any {
Shell: "unified_exec", Visibility: "list", InAPI: true, Priority: after + i + 1,
ApplyPatch: "freeform", Tools: []string{}, Modalities: []string{"text"},
Tiers: []tier{}, SearchTool: true, Parallel: true,
AutoReview: autoReview,
AutoReview: autoReview, EffectivePct: effectivePct,
}
if e.AutoReview == settings.CodexAutoReviewSession {
e.AutoReview = m.ID
@@ -1032,6 +1037,10 @@ func Remember(entries []any) {
// ChatGPT sign-in: its entry as Codex has it (images, context window, tools,
// instructions), under magpie's id. The start-up notice and the upgrade
// prompt are left out; they name slugs the catalog does not have.
// effectivePct is the effective_context_window_percent of Codex's own
// entries.
const effectivePct = 95
func ownEntry(raw map[string]any, id, name string, priority int) map[string]any {
e := make(map[string]any, len(raw))
for k, v := range raw {
@@ -1039,6 +1048,9 @@ func ownEntry(raw map[string]any, id, name string, priority int) map[string]any
}
delete(e, "availability_nux")
delete(e, "upgrade")
if _, ok := e["effective_context_window_percent"]; !ok {
e["effective_context_window_percent"] = effectivePct
}
e["slug"], e["display_name"], e["priority"], e["visibility"] = id, name, priority, "list"
if s, _ := e["base_instructions"].(string); s == "" {
// an entry with model_messages alone carries its instructions
+42
View File
@@ -0,0 +1,42 @@
package codexcat
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// Every entry of Codex's own catalog says effective_context_window_percent
// (95); magpie's lacked it (codealc on X: Codex 0.166 on a Copilot Gemini
// worked out no limit and never compacted), for a model with no window
// known as for one with, and for a vendor-listed entry that omitted it.
func TestCodexCatalogSaysEffectivePercent(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", os.Getenv("HOME"))
t.Setenv("XDG_CONFIG_HOME", filepath.Join(os.Getenv("HOME"), ".config"))
var got struct {
Models []map[string]any `json:"models"`
}
json.Unmarshal(Catalog([]catalog.Model{
{ID: "copilot/gemini-4-carbon", Name: "Gemini 4 Carbon", Context: 936000},
{ID: "x/nowindow", Name: "none"},
{ID: "x/listed", Name: "listed", Context: 200000, Codex: json.RawMessage(`{"slug":"listed","base_instructions":"p"}`)},
}), &got)
n := 0
for _, e := range got.Models {
slug, _ := e["slug"].(string)
if slug != "copilot/gemini-4-carbon" && slug != "x/nowindow" && slug != "x/listed" {
continue
}
n++
if e["effective_context_window_percent"] != float64(95) {
t.Errorf("%s: effective_context_window_percent %v; want 95", slug, e["effective_context_window_percent"])
}
}
if n != 3 {
t.Fatalf("%d of 3 entries found", n)
}
}
+8 -1
View File
@@ -1817,6 +1817,9 @@ func copilotModels(ctx context.Context, app copilotApp) ([]catalog.Model, error)
Supports struct {
Efforts []string `json:"reasoning_effort"`
} `json:"supports"`
Limits struct {
Prompt int `json:"max_prompt_tokens"`
} `json:"limits"`
} `json:"capabilities"`
Policy *struct {
State string `json:"state"`
@@ -1884,7 +1887,11 @@ func copilotModels(ctx context.Context, app copilotApp) ([]catalog.Model, error)
default:
continue // not the account's to enable: it answers 403
}
out = append(out, catalog.Model{ID: m.ID, Name: m.Name, Efforts: m.Capabilities.Supports.Efforts, APIs: copilotAPIs(m.Endpoints)})
out = append(out, catalog.Model{ID: m.ID, Name: m.Name, Efforts: m.Capabilities.Supports.Efforts, APIs: copilotAPIs(m.Endpoints),
// the prompt this account's Copilot takes for the model (936K
// for gemini-4-carbon), not models.dev's window for the id
// (1048576): over it Copilot answers 400 (codealc on X)
Context: catalog.Window(m.Capabilities.Limits.Prompt)})
}
// Auto, which Copilot's clients offer every account beside the models
// it lists, and the only choice a Student plan has: an account whose
+45
View File
@@ -0,0 +1,45 @@
package provider
import (
"context"
"io"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/yetone/magpie/internal/catalog"
)
// Copilot's /models says the prompt the account takes for a model
// (capabilities.limits.max_prompt_tokens: 936K for gemini-4-carbon), and
// that is the window, not models.dev's 1048576 for the id: past it Copilot
// answers 400 and Codex, told 1M, never compacted (codealc on X). A model
// whose limits say none keeps the window models.dev gives.
func TestCopilotWindowIsThePromptItTakes(t *testing.T) {
signIn(t)
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, `{"data":[
{"id":"gemini-4-carbon","name":"Gemini 4 Carbon","model_picker_enabled":true,"policy":{"state":"enabled"},"supported_endpoints":["/chat/completions"],"capabilities":{"type":"chat","limits":{"max_context_window_tokens":1048576,"max_prompt_tokens":936000,"max_output_tokens":65536}}},
{"id":"gpt-4.1","name":"GPT-4.1","model_picker_enabled":true,"policy":{"state":"enabled"},"supported_endpoints":["/chat/completions"],"capabilities":{"type":"chat"}}]}`)
}))
defer api.Close()
copilotSessions = map[string]copilotSession{"gho_lim": {Token: "sess", ExpiresAt: time.Now().Add(time.Hour).Unix(), Endpoints: struct {
API string `json:"api"`
}{API: api.URL}}}
ms, err := copilotModels(context.Background(), copilotApp{User: "octocat", Token: "gho_lim"})
if err != nil {
t.Fatal(err)
}
p := Provider{ID: "copilot"}
got := map[string]int{}
for _, m := range ms {
got[m.ID] = p.WindowOf(m)
}
if got["gemini-4-carbon"] != 936000 {
t.Errorf("gemini-4-carbon window %d; want 936000", got["gemini-4-carbon"])
}
if got["gpt-4.1"] != catalog.ContextOf("gpt-4.1") {
t.Errorf("gpt-4.1 window %d; want models.dev's %d", got["gpt-4.1"], catalog.ContextOf("gpt-4.1"))
}
}