Skip to content

Commit 391bc5a

Browse files
committed
fix(codex-inject): restore stripRootContextWindowOverrides (gpt-5.5 1M regression)
c29ee78 ('harden opencodex release and runtime paths') removed stripRootContextWindowOverrides and its injectCodexConfig call site, so a stale root 'model_context_window = 1000000' in ~/.codex/config.toml was never stripped. Codex treats that root key as a global override that wins over the per-model catalog, forcing every model (incl. gpt-5.5) to report a 1M window. Restore the function + the injection-path strip so the catalog drives per-model context size again. Export it and add a regression unit test. The restore/teardown path keeps c29ee78's preserve-user-overrides behavior (left unchanged).
1 parent bb3826e commit 391bc5a

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎src/codex-inject.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ function stripExistingModelProvider(content: string): string {
8181
return out.join("\n");
8282
}
8383

84+
/**
85+
* Drop ROOT-level `model_context_window` / `model_auto_compact_token_limit` overrides (keys before
86+
* the first table header). Codex treats these root keys as a global override that wins over the
87+
* per-model catalog values, so a stale `model_context_window = 1000000` makes every model (e.g.
88+
* gpt-5.5) report a 1M window. Stripping them on (re)injection lets the catalog drive context size.
89+
*/
90+
export function stripRootContextWindowOverrides(content: string): string {
91+
const lines = content.split("\n");
92+
const firstTable = lines.findIndex(l => /^\s*\[/.test(l));
93+
return lines
94+
.filter((line, i) => {
95+
const isRoot = firstTable === -1 || i < firstTable;
96+
return !isRoot || !/^\s*model_(?:context_window|auto_compact_token_limit)\s*=/.test(line);
97+
})
98+
.join("\n");
99+
}
100+
84101
function stripRootRoutedModel(content: string): string {
85102
const lines = content.split("\n");
86103
const firstTable = lines.findIndex(l => /^\s*\[/.test(l));
@@ -243,6 +260,7 @@ export async function injectCodexConfig(port: number, config?: OcxConfig, option
243260
}
244261
content = removeProfileSection(content);
245262
content = stripExistingModelProvider(content);
263+
content = stripRootContextWindowOverrides(content);
246264
content = normalizeServiceTier(content);
247265
content = ensureFastModeFeature(content);
248266

‎tests/codex-inject.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, test } from "bun:test";
2-
import { buildProfileFile, buildProviderTableBlock, chooseCatalogPathForInjection, stripOpencodexConfig } from "../src/codex-inject";
2+
import { buildProfileFile, buildProviderTableBlock, chooseCatalogPathForInjection, stripOpencodexConfig, stripRootContextWindowOverrides } from "../src/codex-inject";
33

44
describe("Codex config injection", () => {
55
test("omits provider-level Responses WebSocket support by default", () => {
@@ -36,6 +36,29 @@ describe("Codex config injection", () => {
3636
expect(buildProviderTableBlock(10100, false, false, "2001:db8::5")).toContain('base_url = "http://[2001:db8::5]:10100/v1"');
3737
});
3838

39+
test("strips stale root context-window overrides on injection so the catalog drives model context (gpt-5.5 regression)", () => {
40+
const cleaned = stripRootContextWindowOverrides([
41+
'model_provider = "opencodex"',
42+
"model_context_window = 1000000",
43+
"model_auto_compact_token_limit = 900000",
44+
'model = "gpt-5.5"',
45+
"",
46+
"[model_providers.opencodex]",
47+
"# a nested table key must survive",
48+
"model_context_window = 272000",
49+
"",
50+
].join("\n"));
51+
52+
// Root-level overrides (before the first table header) are removed.
53+
expect(cleaned).not.toMatch(/^model_context_window = 1000000$/m);
54+
expect(cleaned).not.toMatch(/^model_auto_compact_token_limit = 900000$/m);
55+
// Non-context-window root keys are untouched.
56+
expect(cleaned).toContain('model_provider = "opencodex"');
57+
expect(cleaned).toContain('model = "gpt-5.5"');
58+
// Table-nested keys (after the first [table]) are preserved.
59+
expect(cleaned).toContain("model_context_window = 272000");
60+
});
61+
3962
test("preserves user root context-window overrides when restoring native Codex", () => {
4063
const stripped = stripOpencodexConfig([
4164
'model = "gpt-5.5"',

0 commit comments

Comments
 (0)