Skip to content

Commit 7ba7cfd

Browse files
authored
fix(devin): report the context windows Cognition actually serves (#4323)
The shipped window table for the `devin` provider had been assembled from each model's ORIGINAL vendor rather than from what Cognition serves, so nine of its eleven rows were wrong: the three Claude models claimed 200k against an actual 1M, grok-4-5 claimed 256k against 500k, and the GPT rows claimed 1.05M against 1M. `devin-cli` had no table at all, so every model there — including swe-2, its default — reported the 128k fallback against a real 262k. Cognition publishes no context window anywhere: not on the Devin CLI or Desktop model pages, not in the SWE-2 or SWE-1.7 announcements, and not in the Windsurf model reference, which has no such table. The only published numbers are long-context pricing thresholds, a different quantity. The per-account GetCascadeModelConfigs catalog carries the real figure in ClientModelConfig field #18, so the catalog parser now reads it and live discovery reports it, which makes the cloud provider self-correcting. The static tables are corrected to the same measured numbers and kept for degraded mode. Correcting the registry does not reach configs already saved, because enrichProviderFromRegistry is fill-only by design. A startup repair rewrites a window whose saved value is still exactly the wrong number, on a provider that still carries the registry's adapter; a value the user changed does not match and is left alone.
1 parent c7e4d5c commit 7ba7cfd

12 files changed

Lines changed: 365 additions & 24 deletions

File tree

‎scripts/test-layout/layout.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@
856856
"model-pinned-effort.test.ts": "codex-integration",
857857
"model-presets.test.ts": "providers",
858858
"model-rename-migration.test.ts": "providers",
859+
"context-window-seed-repair.test.ts": "providers",
859860
"model-selection-guidance.test.ts": "cli",
860861
"model-visibility-management-api.test.ts": "codex-integration",
861862
"models-feedback-callback.test.ts": "gui",

‎src/adapters/devin-cli/models.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,37 @@ export const DEVIN_CLI_MODELS = [
2121
"glm-5-3-low",
2222
"kimi-k3-high",
2323
] as const;
24+
25+
/**
26+
* Context windows for the CLI roster, in the same effort-suffixed ids the CLI
27+
* accepts.
28+
*
29+
* Without this the picker fell back to the 128k default for every Devin CLI
30+
* model, including `swe-2`, which is the roster's own default — so the one
31+
* model most sessions ran reported less than half its real window.
32+
*
33+
* The numbers come from Cognition's `GetCascadeModelConfigs` catalog
34+
* (`ClientModelConfig` field #18), which is the only first-party source: the
35+
* Devin CLI and Desktop model pages, the SWE-2 announcement, and the Windsurf
36+
* model reference all list these models without a window. The CLI is a separate
37+
* product from the cloud, but Cognition documents the same models on both and
38+
* describes no per-surface difference — the SWE-2 announcement ships it to
39+
* Desktop, CLI, Web, and Fusion in one sentence — so the catalog's figure is
40+
* used for both rather than inventing a second table.
41+
*
42+
* ACP has no discovery call, so unlike the cloud provider this cannot be
43+
* refreshed live; it needs updating when the roster above does.
44+
*/
45+
export const DEVIN_CLI_MODEL_CONTEXT_WINDOWS: Record<string, number> = {
46+
"swe-2": 262_000,
47+
"swe-2-high": 262_000,
48+
"claude-opus-5-medium": 1_000_000,
49+
"claude-fable-5-1-medium": 1_000_000,
50+
"claude-sonnet-5-medium": 1_000_000,
51+
"gpt-6-astra-medium": 1_000_000,
52+
"gpt-5-6-sol-medium": 1_000_000,
53+
"gemini-3-8-flash-medium": 1_048_576,
54+
"glm-5-3-high": 1_048_576,
55+
"glm-5-3-low": 1_048_576,
56+
"kimi-k3-high": 1_048_576,
57+
};

‎src/adapters/devin/cloud-direct/catalog.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ export interface ModelCatalogEntry {
6363
label: string;
6464
/** True when the caller's account tier cannot use this UID for chat. */
6565
disabled: boolean;
66+
/**
67+
* Maximum input tokens the account may send this model, from
68+
* `ClientModelConfig` field #18.
69+
*
70+
* Cognition publishes no context-window numbers anywhere: not in the Devin
71+
* CLI or Desktop model pages, not in the SWE-2 or SWE-1.7 announcements, and
72+
* not in the Windsurf model reference, which has no such table. The only
73+
* numbers on those pages are long-context PRICING thresholds, which are a
74+
* different quantity. That makes this field the single first-party source,
75+
* and it is per account rather than per model id.
76+
*
77+
* Absent when the entry omits the field, which is how a future schema change
78+
* degrades: the caller keeps its static fallback instead of reporting zero.
79+
*/
80+
contextWindow?: number;
6681
}
6782

6883
export interface CacheEntry {
@@ -89,26 +104,38 @@ function flightKey(apiKey: string, host: string): string {
89104
* Parse a GetCascadeModelConfigsResponse buffer into a UID-keyed map.
90105
* A malformed catalog returns an empty map.
91106
*/
92-
function parseCatalogBuffer(buf: Buffer, apiKey: string, host: string): CacheEntry {
107+
export function parseCatalogBuffer(buf: Buffer, apiKey: string, host: string): CacheEntry {
93108
// GetCascadeModelConfigsResponse #1 (repeated ClientModelConfig)
94109
const byUid = new Map<string, ModelCatalogEntry>();
95110
for (const f of iterFields(buf)) {
96111
if (f.num !== 1 || f.wire !== 2 || !Buffer.isBuffer(f.value)) continue;
97112
let label = '';
98113
let modelUid = '';
99114
let disabled = false;
115+
let contextWindow = 0;
100116
for (const sf of iterFields(f.value as Buffer)) {
101117
if (sf.num === 1 && sf.wire === 2 && Buffer.isBuffer(sf.value)) {
102118
label = (sf.value as Buffer).toString('utf8');
103119
} else if (sf.num === 4 && sf.wire === 0) {
104120
// #4 = disabled (bool, varint 0/1)
105121
disabled = sf.value === 1n;
122+
} else if (sf.num === 18 && sf.wire === 0) {
123+
// #18 = max input tokens. Identified by dumping a live catalog and
124+
// reading the varints back against models whose windows are known from
125+
// their upstream vendors: 1000000 on the Claude and GPT rows, 1048576
126+
// on Gemini/Kimi/GLM, 500000 on Grok, 262000 on swe-2.
127+
contextWindow = Number(sf.value);
106128
} else if (sf.num === 22 && sf.wire === 2 && Buffer.isBuffer(sf.value)) {
107129
modelUid = (sf.value as Buffer).toString('utf8');
108130
}
109131
}
110132
if (modelUid.length > 0) {
111-
byUid.set(modelUid, { modelUid, label: label || modelUid, disabled });
133+
byUid.set(modelUid, {
134+
modelUid,
135+
label: label || modelUid,
136+
disabled,
137+
...(contextWindow > 0 ? { contextWindow } : {}),
138+
});
112139
}
113140
}
114141
return { byUid, fetchedAt: Date.now(), apiKey, host };

‎src/adapters/devin/live-models.ts‎

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,43 @@ export const DEVIN_STATIC_MODELS = [
2929
"grok-4-5",
3030
] as const;
3131

32-
/** Per-model context windows for Devin/Cognition models. Source: Cognition model catalog. */
32+
/**
33+
* Degraded-mode context windows, used only when live discovery cannot run.
34+
*
35+
* Every number here was read from a live `GetCascadeModelConfigs` response
36+
* (`ClientModelConfig` field #18) rather than from documentation, because
37+
* Cognition publishes none: the Devin CLI and Desktop model pages, the SWE-2
38+
* and SWE-1.7 announcements, and the Windsurf model reference all state model
39+
* names without a context window. The only published numbers are long-context
40+
* pricing thresholds, which are a different quantity and were not used.
41+
*
42+
* The previous copy of this table was wrong for nine of its eleven rows — the
43+
* three Claude models were listed at 200k against an actual 1M, `grok-4-5` at
44+
* 256k against 500k, and the GPT rows at 1.05M against 1M — because it was
45+
* assembled from each model's upstream vendor window instead of what Cognition
46+
* actually serves. Measure the catalog when updating this; do not carry a
47+
* number over from the model's original vendor.
48+
*/
3349
export const DEVIN_MODEL_CONTEXT_WINDOWS: Record<string, number> = {
34-
"swe-1-7": 256_000,
35-
"swe-1-7-lightning": 256_000,
36-
"gpt-5-6-sol": 1_050_000,
37-
"gpt-5-6-luna": 1_050_000,
38-
"gpt-5-6-terra": 1_050_000,
39-
"claude-opus-4-8": 200_000,
40-
"claude-fable-5-1": 200_000,
41-
"claude-sonnet-5": 200_000,
50+
"swe-2": 262_000,
51+
"swe-1-7": 262_000,
52+
"swe-1-7-lightning": 202_752,
53+
"swe-1-6": 200_000,
54+
"gpt-5-6-sol": 1_000_000,
55+
"gpt-5-6-luna": 1_000_000,
56+
"gpt-5-6-terra": 1_000_000,
57+
"gpt-6-astra": 1_000_000,
58+
"claude-opus-4-8": 1_000_000,
59+
"claude-opus-5": 1_000_000,
60+
"claude-fable-5-1": 1_000_000,
61+
"claude-sonnet-5": 1_000_000,
4262
"glm-5-2": 200_000,
43-
"kimi-k2-7": 256_000,
44-
"grok-4-5": 256_000,
63+
"glm-5-3": 1_048_576,
64+
"kimi-k2-7": 262_144,
65+
"kimi-k3": 1_048_576,
66+
"gemini-3-8-flash": 1_048_576,
67+
"grok-4-5": 500_000,
68+
"grok-4-6": 500_000,
4569
};
4670

4771
/**
@@ -62,7 +86,7 @@ export function collapseDevinModelUid(uid: string): string {
6286
}
6387

6488
export type DevinUsableModelsResult =
65-
| { ok: true; models: string[] }
89+
| { ok: true; models: string[]; contextWindows: Record<string, number> }
6690
| { ok: false; error: "auth" | "http" | "empty" | "unknown"; detail?: string };
6791

6892
/**
@@ -80,15 +104,27 @@ export async function fetchDevinUsableModels(opts: {
80104
const catalog = await getCachedCatalog(opts.apiKey, host, opts.signal);
81105
if (!catalog) return { ok: false, error: "empty" };
82106
const bases = new Set<string>();
107+
const contextWindows: Record<string, number> = {};
83108
for (const entry of catalog.byUid.values()) {
84109
if (entry.disabled) continue;
85110
// Skip internal enum constants (e.g. MODEL_GPT_5_2_LOW, MODEL_PRIVATE_*).
86111
// Real chat model UIDs are lowercase dashed strings (swe-1-7, gpt-5-6-sol).
87112
if (entry.modelUid.startsWith("MODEL_")) continue;
88-
bases.add(collapseDevinModelUid(entry.modelUid));
113+
const base = collapseDevinModelUid(entry.modelUid);
114+
bases.add(base);
115+
if (entry.contextWindow && entry.contextWindow > 0) {
116+
// Variants of one base can disagree: the opt-in `-1m` rows report a
117+
// larger window than the plain row of the same base, and both collapse
118+
// here because `1m` is an effort token. Keep the smallest, because the
119+
// base id routes to the plain variant — advertising the long-context
120+
// number would promise a window the request the picker actually sends
121+
// cannot use.
122+
const seen = contextWindows[base];
123+
contextWindows[base] = seen === undefined ? entry.contextWindow : Math.min(seen, entry.contextWindow);
124+
}
89125
}
90126
if (bases.size === 0) return { ok: false, error: "empty" };
91-
return { ok: true, models: [...bases].sort() };
127+
return { ok: true, models: [...bases].sort(), contextWindows };
92128
} catch (error) {
93129
const message = error instanceof Error ? error.message : String(error);
94130
if (/unauth|401|invalid token|login/i.test(message)) return { ok: false, error: "auth", detail: message };

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,11 +1722,23 @@ async function fetchProviderModelsWithAuth(
17221722
if (liveResult.ok) {
17231723
// Live catalog is the source of truth — use the discovered base models
17241724
// directly, not a filtered subset of the static seed.
1725-
const result = liveResult.models.map((id) => ({
1726-
id,
1727-
provider: name,
1728-
...catalogHintsFromProviderConfig(name, prov, id, contextCap, metadataModelIdCaseFold, captured.effectiveAlias),
1729-
}) as CatalogModel);
1725+
//
1726+
// That extends to the context window. Cognition publishes no window
1727+
// anywhere, so the per-account catalog is the only first-party number,
1728+
// and the shipped static table is a degraded-mode guess that was wrong
1729+
// for nine of its eleven rows. The live value is applied first and the
1730+
// config hints run after it, so an explicit per-model override and an
1731+
// enabled Context cap still win — this only replaces the number nobody
1732+
// chose.
1733+
const result = liveResult.models.map((id) => {
1734+
const liveWindow = liveResult.contextWindows[id];
1735+
return {
1736+
id,
1737+
provider: name,
1738+
...(liveWindow ? { contextWindow: liveWindow } : {}),
1739+
...catalogHintsFromProviderConfig(name, prov, id, contextCap, metadataModelIdCaseFold, captured.effectiveAlias),
1740+
} as CatalogModel;
1741+
});
17301742
const forCache = withConfiguredRetention(result, { retainComboTargets: false });
17311743
if (!setCached(name, forCache, Date.now(), cacheGeneration)) {
17321744
return observed(withConfiguredRetention(configured), "degraded");

‎src/providers/model-rename-startup.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
import { mutatePersistedConfig } from "../config";
22
import { projectModelRenames } from "./model-rename-migration";
3+
import { projectStaleContextWindows } from "./stale-context-window-migration";
34
import type { OcxConfig } from "../types";
45

6+
/**
7+
* The startup projection: registry model renames, then the context-window
8+
* repair. Both fix a saved row the registry can no longer reach on its own —
9+
* `enrichProviderFromRegistry` backfills a missing field and never rewrites a
10+
* present one — so they share this pass rather than adding a second boot step
11+
* with its own persistence, adopt, and failure handling.
12+
*/
13+
export function projectStartupConfigRepairs(config: OcxConfig): ReturnType<typeof projectModelRenames> {
14+
const renames = projectModelRenames(config);
15+
const windows = projectStaleContextWindows(renames.config);
16+
return {
17+
config: windows.config,
18+
changed: renames.changed || windows.changed,
19+
warnings: [...renames.warnings, ...windows.warnings],
20+
};
21+
}
22+
523
export interface ModelRenameStartupDeps {
624
project: typeof projectModelRenames;
725
/** Injected writer for tests and callers that own their own persistence. */
@@ -59,7 +77,7 @@ function adoptConfig(target: OcxConfig, source: OcxConfig): void {
5977
*/
6078
export function runModelRenameStartupMigration(
6179
config: OcxConfig,
62-
deps: ModelRenameStartupDeps = { project: projectModelRenames },
80+
deps: ModelRenameStartupDeps = { project: projectStartupConfigRepairs },
6381
): OcxConfig {
6482
const projection = deps.project(structuredClone(config));
6583
if (!projection.changed) {

‎src/providers/registry.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { CodexAccountMode, FastWire, OcxProviderConfig } from "../types";
22
import { fastWireDeclarationError } from "./fastwire";
33
import { KIRO_MODELS, KIRO_MODEL_CONTEXT_WINDOWS, KIRO_MODEL_REASONING_EFFORTS } from "./kiro-models";
4-
import { DEVIN_CLI_DEFAULT_MODEL, DEVIN_CLI_MODELS } from "../adapters/devin-cli/models";
4+
import { DEVIN_CLI_DEFAULT_MODEL, DEVIN_CLI_MODEL_CONTEXT_WINDOWS, DEVIN_CLI_MODELS } from "../adapters/devin-cli/models";
55
import { DEVIN_MODEL_CONTEXT_WINDOWS } from "../adapters/devin/live-models";
66
import { ANTIGRAVITY_MODELS, ANTIGRAVITY_MODEL_CONTEXT_WINDOWS, ANTIGRAVITY_MODEL_EFFORTS, ANTIGRAVITY_MODEL_INPUT_MODALITIES } from "./antigravity-models";
77
import type { ProviderBaseUrlChoice } from "./base-url-choices";
@@ -1343,6 +1343,7 @@ export const PROVIDER_REGISTRY: readonly ProviderRegistryEntry[] = [
13431343
note: "Drives the locally installed Devin CLI over the Agent Client Protocol (`devin acp`, newline-delimited JSON-RPC on stdio). Requires the CLI on PATH and a completed `devin auth login`; no API key is stored by opencodex. Set OPENCODEX_DEVIN_CLI_BIN to point at a specific build, and OPENCODEX_DEVIN_CLI_ALLOW_TOOLS=1 to let the CLI read and write files — the default is to refuse.",
13441344
models: [...DEVIN_CLI_MODELS],
13451345
defaultModel: DEVIN_CLI_DEFAULT_MODEL,
1346+
modelContextWindows: DEVIN_CLI_MODEL_CONTEXT_WINDOWS,
13461347
},
13471348
{
13481349
id: "devin",
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* Repair context windows that a saved config inherited from a wrong registry seed.
3+
*
4+
* `enrichProviderFromRegistry` is fill-only: it seeds `modelContextWindows` when
5+
* the row has none and never rewrites it afterwards. That posture is right — a
6+
* hand-tuned window must survive an upgrade — but it means a registry table that
7+
* shipped WRONG numbers is frozen into every config that was saved while those
8+
* numbers were current. Correcting the registry alone fixes new installs and
9+
* leaves existing ones reporting the old figure forever.
10+
*
11+
* This rewrites one thing: a window whose saved value is still byte-for-byte the
12+
* wrong number this file names, on a provider that still carries the registry's
13+
* adapter. A value the user changed does not match `from` and is left alone, and
14+
* nothing else in the row is touched. Same shape and the same restraint as
15+
* `model-rename-migration`, for the case where the id was right and the number
16+
* was not.
17+
*/
18+
import { PROVIDER_REGISTRY } from "./registry";
19+
import type { OcxConfig } from "../types";
20+
21+
export interface StaleContextWindow {
22+
/** Registry provider id whose saved rows may carry the wrong window. */
23+
provider: string;
24+
model: string;
25+
/** The wrong value this migration is allowed to replace, and nothing else. */
26+
from: number;
27+
to: number;
28+
}
29+
30+
export interface StaleContextWindowProjection {
31+
config: OcxConfig;
32+
changed: boolean;
33+
warnings: string[];
34+
}
35+
36+
/**
37+
* Cognition windows corrected against a live `GetCascadeModelConfigs` response.
38+
*
39+
* The shipped table had been assembled from each model's ORIGINAL vendor window
40+
* rather than from what Cognition serves, so the Claude rows claimed 200k against
41+
* an actual 1M and Grok claimed 256k against 500k. Cognition documents no window
42+
* anywhere, so the per-account catalog is the only first-party source; these are
43+
* the degraded-mode figures, and live discovery supersedes them when it runs.
44+
*/
45+
export const STALE_CONTEXT_WINDOWS: readonly StaleContextWindow[] = [
46+
{ provider: "devin", model: "swe-1-7", from: 256_000, to: 262_000 },
47+
{ provider: "devin", model: "swe-1-7-lightning", from: 256_000, to: 202_752 },
48+
{ provider: "devin", model: "gpt-5-6-sol", from: 1_050_000, to: 1_000_000 },
49+
{ provider: "devin", model: "gpt-5-6-luna", from: 1_050_000, to: 1_000_000 },
50+
{ provider: "devin", model: "gpt-5-6-terra", from: 1_050_000, to: 1_000_000 },
51+
{ provider: "devin", model: "claude-opus-4-8", from: 200_000, to: 1_000_000 },
52+
{ provider: "devin", model: "claude-fable-5-1", from: 200_000, to: 1_000_000 },
53+
{ provider: "devin", model: "claude-sonnet-5", from: 200_000, to: 1_000_000 },
54+
{ provider: "devin", model: "kimi-k2-7", from: 256_000, to: 262_144 },
55+
{ provider: "devin", model: "grok-4-5", from: 256_000, to: 500_000 },
56+
];
57+
58+
function providerStillMatchesRegistry(id: string, adapter: unknown): boolean {
59+
const entry = PROVIDER_REGISTRY.find(row => row.id === id);
60+
return entry !== undefined && entry.adapter === adapter;
61+
}
62+
63+
/** Pure projection. The caller decides whether to persist. */
64+
export function projectStaleContextWindows(
65+
config: OcxConfig,
66+
entries: readonly StaleContextWindow[] = STALE_CONTEXT_WINDOWS,
67+
): StaleContextWindowProjection {
68+
const warnings: string[] = [];
69+
const repaired = new Map<string, string[]>();
70+
71+
for (const entry of entries) {
72+
const prov = config.providers?.[entry.provider];
73+
if (!prov) continue;
74+
if (!providerStillMatchesRegistry(entry.provider, prov.adapter)) continue;
75+
const windows = prov.modelContextWindows;
76+
if (!windows || windows[entry.model] !== entry.from) continue;
77+
windows[entry.model] = entry.to;
78+
const list = repaired.get(entry.provider) ?? [];
79+
list.push(`${entry.model} ${entry.from} -> ${entry.to}`);
80+
repaired.set(entry.provider, list);
81+
}
82+
83+
for (const [provider, list] of repaired) {
84+
warnings.push(
85+
`corrected ${list.length} context window(s) on "${provider}" that the saved config `
86+
+ `inherited from a wrong registry seed: ${list.join(", ")}.`,
87+
);
88+
}
89+
90+
return { config, changed: repaired.size > 0, warnings };
91+
}
92+

‎tests/fixtures/test-layout-expected.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@
690690
"model-pinned-effort.test.ts": "codex-integration",
691691
"model-presets.test.ts": "providers",
692692
"model-rename-migration.test.ts": "providers",
693+
"context-window-seed-repair.test.ts": "providers",
693694
"model-selection-guidance.test.ts": "cli",
694695
"model-visibility-management-api.test.ts": "codex-integration",
695696
"models-feedback-callback.test.ts": "gui",

0 commit comments

Comments
 (0)