Skip to content

Commit a944d3c

Browse files
committed
fix(codex): preserve auto-compaction limit on inject
1 parent f182f08 commit a944d3c

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/codex/inject.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,18 @@ function stripExistingModelProvider(content: string): string {
296296
}
297297

298298
/**
299-
* Drop ROOT-level `model_context_window` / `model_auto_compact_token_limit` overrides (keys before
300-
* the first table header). Codex treats these root keys as a global override that wins over the
301-
* per-model catalog values, so a stale `model_context_window = 1000000` makes every model (e.g.
302-
* gpt-5.5) report a 1M window. Stripping them on (re)injection lets the catalog drive context size.
299+
* Drop ROOT-level `model_context_window` overrides (keys before the first table header). Codex
300+
* treats this root key as a global override that wins over the per-model catalog values, so a stale
301+
* `model_context_window = 1000000` makes every model (e.g. gpt-5.5) report a 1M window. User-owned
302+
* compaction limits do not alter the advertised context window and must survive reinjection.
303303
*/
304304
export function stripRootContextWindowOverrides(content: string): string {
305305
const lines = content.split("\n");
306306
const firstTable = lines.findIndex(l => /^\s*\[/.test(l));
307307
return lines
308308
.filter((line, i) => {
309309
const isRoot = firstTable === -1 || i < firstTable;
310-
return !isRoot || !/^\s*model_(?:context_window|auto_compact_token_limit)\s*=/.test(line);
310+
return !isRoot || !/^\s*model_context_window\s*=/.test(line);
311311
})
312312
.join("\n");
313313
}

tests/codex-inject.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe("Codex config injection", () => {
6060
'model_provider = "opencodex"',
6161
"model_context_window = 1000000",
6262
"model_auto_compact_token_limit = 900000",
63+
'model_auto_compact_token_limit_scope = "total"',
6364
'model = "gpt-5.5"',
6465
"",
6566
"[model_providers.opencodex]",
@@ -68,9 +69,10 @@ describe("Codex config injection", () => {
6869
"",
6970
].join("\n"));
7071

71-
// Root-level overrides (before the first table header) are removed.
72+
// Only the stale root context-window override is removed. Compaction is a user-owned limit.
7273
expect(cleaned).not.toMatch(/^model_context_window = 1000000$/m);
73-
expect(cleaned).not.toMatch(/^model_auto_compact_token_limit = 900000$/m);
74+
expect(cleaned).toContain("model_auto_compact_token_limit = 900000");
75+
expect(cleaned).toContain('model_auto_compact_token_limit_scope = "total"');
7476
// Non-context-window root keys are untouched.
7577
expect(cleaned).toContain('model_provider = "opencodex"');
7678
expect(cleaned).toContain('model = "gpt-5.5"');

0 commit comments

Comments
 (0)