Skip to content

Commit f16a4ce

Browse files
committed
fix: remove stale Codex context overrides
1 parent 08709db commit f16a4ce

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎src/codex-inject.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ function stripExistingModelProvider(content: string): string {
5050
return out.join("\n");
5151
}
5252

53+
function stripRootContextWindowOverrides(content: string): string {
54+
const lines = content.split("\n");
55+
const firstTable = lines.findIndex(l => /^\s*\[/.test(l));
56+
return lines
57+
.filter((line, i) => {
58+
const isRoot = firstTable === -1 || i < firstTable;
59+
return !isRoot || !/^\s*model_(?:context_window|auto_compact_token_limit)\s*=/.test(line);
60+
})
61+
.join("\n");
62+
}
63+
5364
/**
5465
* Insert `model_provider = "opencodex"` at the document ROOT — immediately before the first table
5566
* header (TOML root keys must precede all tables). If there are no tables, append it to the root body.
@@ -170,6 +181,7 @@ export async function injectCodexConfig(port: number, config?: OcxConfig): Promi
170181
}
171182
content = removeProfileSection(content);
172183
content = stripExistingModelProvider(content);
184+
content = stripRootContextWindowOverrides(content);
173185
content = normalizeServiceTier(content);
174186
content = ensureFastModeFeature(content);
175187

@@ -227,6 +239,7 @@ export function stripOpencodexConfig(content: string): string {
227239
// Regex (not exact-string) removal so compact `model_provider="opencodex"` is stripped too —
228240
// must match the detection regex above, or a detected line could survive un-removed.
229241
out = out.split("\n").filter(l => !/^\s*model_provider\s*=\s*"opencodex"\s*$/.test(l)).join("\n");
242+
out = stripRootContextWindowOverrides(out);
230243
out = stripDefaultCatalogPath(out);
231244
return out.replace(/\n{3,}/g, "\n\n").trimEnd() + "\n";
232245
}
@@ -243,6 +256,8 @@ export function removeCodexConfig(): { success: boolean; message: string } {
243256
const had = hasOpencodexRouting(content);
244257
if (had) {
245258
atomicWriteFile(CODEX_CONFIG_PATH, stripOpencodexConfig(content));
259+
} else if (stripRootContextWindowOverrides(content) !== content) {
260+
atomicWriteFile(CODEX_CONFIG_PATH, stripOpencodexConfig(content));
246261
}
247262
if (existsSync(CODEX_PROFILE_PATH)) unlinkSync(CODEX_PROFILE_PATH);
248263
return {

‎tests/codex-inject.test.ts‎

Lines changed: 21 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 { buildProviderTableBlock } from "../src/codex-inject";
2+
import { buildProviderTableBlock, stripOpencodexConfig } from "../src/codex-inject";
33

44
describe("Codex config injection", () => {
55
test("advertises provider-level Responses WebSocket support by default", () => {
@@ -16,4 +16,24 @@ describe("Codex config injection", () => {
1616

1717
expect(block).not.toContain("supports_websockets");
1818
});
19+
20+
test("removes stale root context-window overrides so catalog limits drive Codex", () => {
21+
const stripped = stripOpencodexConfig([
22+
'model = "gpt-5.5"',
23+
'model_context_window = 1000000',
24+
'model_auto_compact_token_limit = 900000',
25+
'model_catalog_json = "/Users/jun/.codex/opencodex-catalog.json"',
26+
'model_provider = "opencodex"',
27+
"",
28+
"[features]",
29+
"fast_mode = true",
30+
"",
31+
].join("\n"));
32+
33+
expect(stripped).toContain('model = "gpt-5.5"');
34+
expect(stripped).not.toContain("model_context_window");
35+
expect(stripped).not.toContain("model_auto_compact_token_limit");
36+
expect(stripped).not.toContain("model_provider");
37+
expect(stripped).not.toContain("model_catalog_json");
38+
});
1939
});

0 commit comments

Comments
 (0)