fix(models): use the 1M context window Qoder actually supports (#13)

auto, efficient and lite carried a 180K contextWindow, so pi showed >100%
context usage and auto-compacted early. Live testing in #13 drove global
lite to 1,000K tokens successfully, so the 180K value was a stale
max_input_tokens floor rather than a real limit.

Introduce DEFAULT_CONTEXT_WINDOW (1M) and use it for the global static
models, including gm51model. Apply it as the catalog fallback too, but only
when /model/list advertises no context_config: models that do advertise a
smaller window (kmodel at 256K, CN GLM-5.2 and MiniMax at 200K) keep it
rather than being inflated to 1M. CN Auto stays at 200K since only global
lite was verified at 1M.

Co-authored-by: Simon Shi <simonsmh@users.noreply.github.com>
This commit is contained in:
Cursor Agent
2026-08-31 15:57:49 +00:00
co-authored by Simon Shi
parent 1dd1b0988b
commit 1e44cde685
4 changed files with 159 additions and 36 deletions
+43
View File
@@ -71,4 +71,47 @@ describe("Qoder model cache", () => {
expect(getCachedModels("global").map((model) => model.id)).toEqual(["ultimate"]);
});
it("records a 1M context window when the catalog omits context_config", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({
ok: true,
json: () =>
Promise.resolve({
chat: [{ key: "lite", enable: true, display_name: "Lite", max_input_tokens: 180000 }],
}),
}),
);
await updateQoderModelsCache("access-token", "user-id", "Test User", "test@example.com", "global");
const cache = JSON.parse(readFileSync(CACHE_PATH, "utf8"));
expect(cache.models[0].contextWindow).toBe(1_000_000);
});
it("records the advertised context_config max, even when it is below 1M", async () => {
vi.stubGlobal(
"fetch",
vi.fn().mockResolvedValue({
ok: true,
json: () =>
Promise.resolve({
chat: [
{
key: "gm51model",
enable: true,
display_name: "GLM 5.2",
context_config: { default: { token_count: 200000, is_default: true } },
},
],
}),
}),
);
await updateQoderModelsCache("access-token", "user-id", "Test User", "test@example.com", "global");
const cache = JSON.parse(readFileSync(CACHE_PATH, "utf8"));
expect(cache.models[0].contextWindow).toBe(200000);
});
});
+54 -1
View File
@@ -1,5 +1,11 @@
import { describe, expect, it } from "vitest";
import { staticCnModels, staticModels, ZERO_COST } from "../models.js";
import {
contextWindowFromCatalog,
DEFAULT_CONTEXT_WINDOW,
staticCnModels,
staticModels,
ZERO_COST,
} from "../models.js";
// ── staticModels ──────────────────────────────────────────────────────────
@@ -33,6 +39,21 @@ describe("staticModels", () => {
const ids = staticModels.map((m) => m.id);
expect(new Set(ids).size).toBe(ids.length);
});
it("uses a 1M context window for models confirmed to support it", () => {
// Global lite was live-tested through 1,000K tokens (issue #13). auto,
// efficient, and gm51model share the same Qoder 1M catalog family.
for (const id of ["auto", "efficient", "lite", "gm51model"]) {
const model = staticModels.find((m) => m.id === id);
expect(model, id).toBeDefined();
expect(model?.contextWindow).toBe(DEFAULT_CONTEXT_WINDOW);
expect(model?.contextWindow).toBe(1_000_000);
}
});
it("keeps kmodel at the catalog-advertised 256K window", () => {
expect(staticModels.find((m) => m.id === "kmodel")?.contextWindow).toBe(256000);
});
});
// ── staticCnModels ────────────────────────────────────────────────────────
@@ -73,6 +94,38 @@ describe("staticCnModels", () => {
expect(m.description).toBeTruthy();
}
});
it("does not copy global 1M onto CN models whose live catalog is smaller", () => {
expect(staticCnModels.find((m) => m.id === "Auto")?.contextWindow).toBe(200000);
expect(staticCnModels.find((m) => m.id === "GLM-5.2")?.contextWindow).toBe(200000);
expect(staticCnModels.find((m) => m.id === "MiniMax-M2.7")?.contextWindow).toBe(200000);
expect(staticCnModels.find((m) => m.id === "Kimi-K2.7-Code")?.contextWindow).toBe(256000);
});
});
describe("contextWindowFromCatalog", () => {
it("uses the largest advertised context_config token_count", () => {
expect(
contextWindowFromCatalog({
context_config: {
small: { token_count: 200000 },
large: { token_count: 1000000, is_default: true },
},
}),
).toBe(1000000);
});
it("keeps an advertised 200K window instead of the 1M fallback", () => {
expect(
contextWindowFromCatalog({
context_config: { default: { token_count: 200000, is_default: true } },
}),
).toBe(200000);
});
it("falls back to 1M when the catalog omits context_config", () => {
expect(contextWindowFromCatalog({ key: "lite", max_input_tokens: 180000 })).toBe(DEFAULT_CONTEXT_WINDOW);
});
});
// ── ZERO_COST ─────────────────────────────────────────────────────────────