Skip to content

Commit 486b2f9

Browse files
committed
fix(catalog): read Copilot context window limits
1 parent 7ac4c9f commit 486b2f9

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

‎src/codex/catalog/provider-fetch.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,9 +1195,15 @@ export function catalogHintsFromModelsApiItem(providerName: string, item: Provid
11951195
const metadata = plainRecord(item.metadata);
11961196
const capabilityRecord = plainRecord(metadata?.capabilities) ?? plainRecord(item.capabilities);
11971197
const limits = plainRecord(metadata?.limits);
1198+
const capabilityLimits = plainRecord(plainRecord(item.capabilities)?.limits);
11981199
const contextWindow =
11991200
positiveSafeInteger(
12001201
limits?.max_context_length,
1202+
// GitHub Copilot reports the live context window here instead of in the metadata or
1203+
// top-level fields used by other OpenAI-compatible catalogs (#3156). Keep the existing
1204+
// metadata field authoritative when both are present: adding this provider-specific
1205+
// fallback must not change previously recognized providers.
1206+
capabilityLimits?.max_context_window_tokens,
12011207
metadata?.context_length,
12021208
item.context_length,
12031209
item.context_size,

‎tests/codex-catalog.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5366,6 +5366,49 @@ describe("Codex catalog routed normalization", () => {
53665366
expect(routed?.context_window).toBe(64_000);
53675367
});
53685368

5369+
test("GitHub Copilot capabilities preserve the live context window (#3156)", async () => {
5370+
globalThis.fetch = (async () => new Response(JSON.stringify({
5371+
data: [{
5372+
id: "copilot-wide-model",
5373+
capabilities: {
5374+
limits: { max_context_window_tokens: 1_000_000 },
5375+
},
5376+
}, {
5377+
id: "copilot-existing-metadata",
5378+
metadata: { limits: { max_context_length: 256_000 } },
5379+
capabilities: {
5380+
limits: { max_context_window_tokens: 1_000_000 },
5381+
},
5382+
}, {
5383+
id: "copilot-invalid-window",
5384+
capabilities: {
5385+
limits: { max_context_window_tokens: -1 },
5386+
},
5387+
}],
5388+
}))) as typeof fetch;
5389+
5390+
const models = await gatherRoutedModels({
5391+
port: 10100,
5392+
defaultProvider: "github-copilot",
5393+
providers: {
5394+
"github-copilot": {
5395+
adapter: "openai-chat",
5396+
baseUrl: "https://api.githubcopilot.com",
5397+
apiKey: "sk-test",
5398+
},
5399+
},
5400+
});
5401+
const routed = buildCatalogEntries(nativeTemplate(), [], models)
5402+
.find(entry => entry.slug === "github-copilot/copilot-wide-model");
5403+
5404+
expect(models.find(model => model.id === "copilot-wide-model")?.contextWindow).toBe(1_000_000);
5405+
expect(routed?.context_window).toBe(1_000_000);
5406+
expect(routed?.max_context_window).toBe(1_000_000);
5407+
expect(routed?.auto_compact_token_limit).toBe(900_000);
5408+
expect(models.find(model => model.id === "copilot-existing-metadata")?.contextWindow).toBe(256_000);
5409+
expect(models.find(model => model.id === "copilot-invalid-window")?.contextWindow).toBeUndefined();
5410+
});
5411+
53695412
test("liveModels false preserves configured catalog metadata without live fetch", async () => {
53705413
let fetchCalls = 0;
53715414
globalThis.fetch = (() => {

0 commit comments

Comments
 (0)