Skip to content

Commit 395cfdb

Browse files
committed
fix: honour the input ceiling on routed rows and the Desktop writer
Two paths kept advertising the window where they should have advertised the input ceiling, both found by review rather than by the suite. Claude's routed rows ignored maxInputTokens entirely, so the same GPT-5.6 contract arriving through a provider reported 1,050,000 as max_input_tokens and gave its [1m] variant the flat 1e6 -- both past the 922,000 the upstream accepts. The native rows already did this correctly; the routed branch simply never learned. The Desktop writer never received the provider cap, so a config written under a 272k cap still marked Sol supports1m. The dashboard and the written config disagreed about the same model. The cap now threads through generateDesktop3pConfig and writeDesktop3pConfig to every caller, including the CLI apply path. Also make the native cap value visible in the GUI when the cap is off: those rows always advertise some window, and the stored value there is only what a toggle would apply, so the display falls back to the widest window the rows report.
1 parent dbc83f2 commit 395cfdb

9 files changed

Lines changed: 86 additions & 13 deletions

File tree

‎gui/src/pages/Models.tsx‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,15 @@ export default function Models({ apiBase, restartEpoch = 0 }: { apiBase: string;
10171017
const activeCount = rows.filter(isVisible).length;
10181018
const capOn = contextCaps[provider] !== undefined;
10191019
const providerCap = contextCaps[provider] ?? contextCapValue;
1020+
// With the cap off, `providerCap` is only the value a future toggle would apply — for the
1021+
// native group that is the 350k default, which says nothing true about what Codex sees.
1022+
// The honest number there is the largest window the rows actually advertise.
1023+
const widestRowWindow = rows.reduce<number | undefined>((widest, row) => {
1024+
const window = typeof row.contextWindow === "number" && row.contextWindow > 0 ? row.contextWindow : undefined;
1025+
if (window === undefined) return widest;
1026+
return widest === undefined || window > widest ? window : widest;
1027+
}, undefined);
1028+
const capDisplayValue = capOn ? providerCap : (widestRowWindow ?? providerCap);
10201029
// The native group offers only the three windows GPT-5.6 actually has contracts for
10211030
// (272k live, 372k legacy, 1.05M measured); routed providers keep the generic ladder.
10221031
// The set has to follow the list, or a saved value outside it loses its option.
@@ -1109,24 +1118,28 @@ export default function Models({ apiBase, restartEpoch = 0 }: { apiBase: string;
11091118
<button type="button" className="btn btn-ghost btn-sm text-caption" disabled={busy || allOn} onClick={() => bulkToggle(true)}>{t("models.allOn")}</button>
11101119
<button type="button" className="btn btn-ghost btn-sm text-caption" disabled={busy || allOff} onClick={() => bulkToggle(false)}>{t("models.allOff")}</button>
11111120
<>
1112-
<Switch on={capOn} onClick={() => toggleProviderCap(provider)} disabled={busy} label={t("models.capValue", { value: fmtK(providerCap) })} />
1113-
{capOn && (
1121+
<Switch on={capOn} onClick={() => toggleProviderCap(provider)} disabled={busy} label={t("models.capValue", { value: fmtK(capDisplayValue) })} />
1122+
{/* The native group keeps the value visible with the cap off: its rows always
1123+
advertise SOME window, so hiding the number leaves the card saying nothing
1124+
about the context Codex will actually see. Routed providers keep the old
1125+
behaviour, where an off cap genuinely means "no opinion". */}
1126+
{(capOn || nativeProviderGroup) && (
11141127
<>
11151128
<Select
11161129
// A saved cap outside CAP_OPTIONS is still a real selectable option
11171130
// (inserted below), so select it instead of falling back to "Custom";
11181131
// otherwise the trigger hides the persisted 128k value behind the
11191132
// custom-editor label.
1120-
value={providerCapCustomOpen[provider] ? CUSTOM_OPTION : String(providerCap)}
1133+
value={providerCapCustomOpen[provider] ? CUSTOM_OPTION : String(capDisplayValue)}
11211134
options={[
1122-
...(!capOptionSet.has(providerCap) && !providerCapCustomOpen[provider]
1123-
? [{ value: String(providerCap), label: fmtK(providerCap) }] : []),
1135+
...(!capOptionSet.has(capDisplayValue) && !providerCapCustomOpen[provider]
1136+
? [{ value: String(capDisplayValue), label: fmtK(capDisplayValue) }] : []),
11241137
...capOptions.map(v => ({ value: String(v), label: fmtK(v) })),
11251138
{ value: CUSTOM_OPTION, label: t("models.custom") },
11261139
]}
11271140
onChange={v => onSelectProviderCap(provider, v)}
1128-
disabled={busy}
1129-
label={t("models.capValue", { value: fmtK(providerCap) })}
1141+
disabled={busy || !capOn}
1142+
label={t("models.capValue", { value: fmtK(capDisplayValue) })}
11301143
/>
11311144
{providerCapCustomOpen[provider] && (
11321145
<>

‎gui/tests/models-native-group-controls.test.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ test("fmtK renders past a million as M, not as four-digit k", () => {
5050
expect(fmtK(350_000)).toBe("350k");
5151
});
5252

53+
test("the native group keeps its window readable with the cap switched off", async () => {
54+
const src = await Bun.file(new URL("../src/pages/Models.tsx", import.meta.url)).text();
55+
// Routed providers hide the value when the cap is off (off = "no opinion"), but a native
56+
// row always advertises some window, so the number stays on screen for that group.
57+
expect(src).toContain("{(capOn || nativeProviderGroup) && (");
58+
// With the cap off the stored value is only what a future toggle would apply — the 350k
59+
// default — so the display falls back to the widest window the rows actually advertise.
60+
expect(src).toContain("const capDisplayValue = capOn ? providerCap : (widestRowWindow ?? providerCap);");
61+
// The select is inert until the cap is actually on: showing a number is not the same as
62+
// offering to change one.
63+
expect(src).toContain("disabled={busy || !capOn}");
64+
});
65+
5366
test("the native group exposes the custom-model and cap controls, but not the context modal", async () => {
5467
const src = await Bun.file(new URL("../src/pages/Models.tsx", import.meta.url)).text();
5568
// The context-window modal saves through PATCH /api/providers, which the canonical openai
@@ -61,4 +74,3 @@ test("the native group exposes the custom-model and cap controls, but not the co
6174
// The custom-add and cap controls no longer sit behind an isNative guard.
6275
expect(src).not.toMatch(/\{!isNative && </);
6376
});
64-

‎src/claude/desktop-3p.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ export function generateDesktop3pConfig(
337337
apiKey = "ocx",
338338
mode: Desktop3pConfigMode = "static",
339339
profile?: OcxClaudeDesktopProfile,
340+
nativeContextCap?: number,
340341
): object {
341342
const base = {
342343
inferenceProvider: "gateway",
@@ -346,14 +347,14 @@ export function generateDesktop3pConfig(
346347
};
347348
if (mode === "discovery") {
348349
// Build/refresh the decode registry even though no static list is emitted.
349-
buildDesktop3pRegistry(nativeSlugs, routedModels, profile);
350+
buildDesktop3pRegistry(nativeSlugs, routedModels, profile, nativeContextCap);
350351
return { ...base, modelDiscoveryEnabled: true };
351352
}
352353
return {
353354
...base,
354355
modelDiscoveryEnabled: mode === "hybrid",
355356
inferenceModels: (() => {
356-
const models = generateDesktop3pModels(nativeSlugs, routedModels, profile);
357+
const models = generateDesktop3pModels(nativeSlugs, routedModels, profile, nativeContextCap);
357358
// Fail loud at the write boundary rather than ship a config Desktop rejects:
358359
// the output counterpart of the request-path guards.
359360
assertDesktop3pModelsValid(models);
@@ -557,6 +558,7 @@ export function writeDesktop3pConfig(
557558
apiKey?: string,
558559
mode: Desktop3pConfigMode = "static",
559560
profile?: OcxClaudeDesktopProfile,
561+
nativeContextCap?: number,
560562
): { written: boolean; path: string; reason?: string; fingerprint?: string } {
561563
const libraryPath = resolveDesktop3pConfigLibraryPath();
562564
const metadataPath = join(libraryPath, "_meta.json");
@@ -574,7 +576,7 @@ export function writeDesktop3pConfig(
574576
? metadata.entries.map(current => current === existing ? entry : current)
575577
: [...metadata.entries, entry];
576578

577-
const configJson = JSON.stringify(generateDesktop3pConfig(port, nativeSlugs, routedModels, apiKey, mode, profile), null, 2) + "\n";
579+
const configJson = JSON.stringify(generateDesktop3pConfig(port, nativeSlugs, routedModels, apiKey, mode, profile, nativeContextCap), null, 2) + "\n";
578580
const fingerprint = createHash("sha256").update(configJson).digest("hex").slice(0, 16);
579581
const { backupPath } = atomicReplaceDesktopConfig(configPath, configJson);
580582
try {

‎src/claude/model-info.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,19 @@ export function buildAnthropicModelInfos(
156156
seen.add(id);
157157
const ladder = Array.isArray(m.reasoningEfforts) ? m.reasoningEfforts : [];
158158
const imageInput = Array.isArray(m.inputModalities) ? m.inputModalities.includes("image") : false;
159-
const info = modelInfo(id, `${m.id} (${m.provider})`, ladder, imageInput, m.contextWindow);
159+
// max_input_tokens is an input limit, so a row that publishes a lower input ceiling than
160+
// its window (native GPT-5.6 forwarded through a provider: 922k under 1.05M) reports the
161+
// ceiling. Rows without one keep reporting the window, as before.
162+
const routedMaxInput = typeof m.maxInputTokens === "number" && m.maxInputTokens > 0
163+
? (typeof m.contextWindow === "number" && m.contextWindow > 0
164+
? Math.min(m.maxInputTokens, m.contextWindow)
165+
: m.maxInputTokens)
166+
: undefined;
167+
const info = modelInfo(id, `${m.id} (${m.provider})`, ladder, imageInput, routedMaxInput ?? m.contextWindow);
160168
out.push(info);
161169
// Anthropic passthrough guard (audit 021 #3): never auto-widen canonical claude
162170
// routes — only a genuine >=1M window earns the variant row there.
163-
push1mVariant(info, m.contextWindow);
171+
push1mVariant(info, m.contextWindow, routedMaxInput);
164172
}
165173
return out;
166174
}

‎src/cli/claude-desktop.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { filterCatalogVisibleModels, desktopVisibleNativeSlugs } from "../codex/
1515
import { buildClaudeDesktopState, fetchAllModels } from "../server/management-api";
1616
import { findLiveProxy } from "../server/proxy-liveness";
1717
import { runtimeRequest } from "./runtime-api";
18+
import { providerContextCap } from "../providers/context-cap";
19+
import { OPENAI_CODEX_PROVIDER_ID } from "../providers/openai-tiers";
1820

1921
function isFamily(value: string | undefined): value is DesktopFamily {
2022
return !!value && (DESKTOP_FAMILIES as readonly string[]).includes(value);
@@ -98,6 +100,7 @@ export async function applyProfile(
98100
config.apiKeys?.[0]?.key,
99101
mode,
100102
state.profile,
103+
providerContextCap(config, OPENAI_CODEX_PROVIDER_ID),
101104
);
102105
return { ok: result.written, path: result.path, reason: result.reason };
103106
}

‎src/server/management/agent-settings-routes.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
207207
current.apiKeys?.[0]?.key,
208208
"static",
209209
current.claudeCode.desktopProfile,
210+
providerContextCap(current, OPENAI_CODEX_PROVIDER_ID),
210211
);
211212
if (result.written && result.fingerprint) {
212213
current.claudeCode = { ...current.claudeCode, desktopProfile: { ...current.claudeCode.desktopProfile, appliedFingerprint: result.fingerprint, appliedAt: new Date().toISOString() } };
@@ -885,6 +886,7 @@ export async function handleAgentSettingsRoutes(ctx: ManagementContext): Promise
885886
latest.apiKeys?.[0]?.key,
886887
mode,
887888
state.profile,
889+
providerContextCap(latest, OPENAI_CODEX_PROVIDER_ID),
888890
);
889891
if (!result.written) return jsonResponse({ error: result.reason ?? "Claude Desktop apply failed", saved: true, path: result.path }, 500);
890892
// Persist applied fingerprint + timestamp so GUI can show saved-vs-applied state.

‎src/server/management/native-integration-routes.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ async function handleClaudeDesktopToggle(ctx: ManagementContext): Promise<Respon
663663
latest.apiKeys?.[0]?.key,
664664
"static",
665665
latest.claudeCode?.desktopProfile,
666+
providerContextCap(latest, OPENAI_CODEX_PROVIDER_ID),
666667
);
667668
if (!result.written) return postCommitRefusal(500, "claude-desktop", "write_failed", "Claude Desktop apply failed.", { desiredEnabled: latestDesiredEnabled });
668669
return jsonResponse({

‎tests/claude-model-info.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ describe("anthropic-flavor ModelInfo discovery entries (devlog 130 B4b)", () =>
9999
expect(gpt55!.max_input_tokens).toBe(272_000);
100100
});
101101

102+
test("a routed row with its own input ceiling reports it on both the base and [1m] rows", () => {
103+
// The same GPT-5.6 contract reaching Claude through a provider rather than the native
104+
// path: a 1.05M window with a 922k input ceiling. Reporting the window here would push
105+
// Claude Code past what the upstream accepts, and the [1m] variant's flat 1e6 would too.
106+
const infos = buildAnthropicModelInfos([], [
107+
{ provider: "cursor", id: "gpt-5.6-sol", contextWindow: 1_050_000, maxInputTokens: 922_000 },
108+
]);
109+
const base = infos.find(i => !i.id.endsWith("[1m]"));
110+
const variant = infos.find(i => i.id.endsWith("[1m]"));
111+
expect(base!.max_input_tokens).toBe(922_000);
112+
expect(variant!.max_input_tokens).toBe(922_000);
113+
});
114+
115+
test("a routed row without an input ceiling still reports its window", () => {
116+
const infos = buildAnthropicModelInfos([], [
117+
{ provider: "cursor", id: "plain", contextWindow: 400_000 },
118+
]);
119+
expect(infos[0]!.max_input_tokens).toBe(400_000);
120+
});
121+
102122
test("[1m] variant never double-suffixes or duplicates (audit R1#11)", () => {
103123
const infos = buildAnthropicModelInfos([], [
104124
// Anthropic passthrough keeps its id verbatim, so an id already carrying the

‎tests/desktop-3p.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ describe("Claude Desktop 3P models", () => {
9494
]);
9595
});
9696

97+
test("an openai context cap reaches the Desktop writer, not just the dashboard", () => {
98+
// Without the cap the native row is a 1.05M model and earns supports1m. Capping the
99+
// provider at 272k has to take that away here too, or the written Desktop config
100+
// promises a window the proxy will not serve (#854's effective-window contract).
101+
const uncapped = generateDesktop3pModels(["gpt-5.6-sol"], []);
102+
expect(uncapped[0]).toMatchObject({ supports1m: true, prefer1m: true });
103+
104+
const capped = generateDesktop3pModels(["gpt-5.6-sol"], [], undefined, 272_000);
105+
expect(capped[0]!.supports1m).toBeUndefined();
106+
expect(capped[0]!.prefer1m).toBeUndefined();
107+
});
108+
97109
test("passes Anthropic Claude model ids through without encoding", () => {
98110
const models = generateDesktop3pModels([], [
99111
{ provider: "anthropic", id: "claude-opus-4-6" },

0 commit comments

Comments
 (0)