Skip to content

Commit ea9debf

Browse files
committed
fix(catalog): do not carry a retained compact limit onto a corrected window
#1905 taught catalog sync never to raise a compaction threshold retained from Codex. The rule is right, but the retained number was trusted even when sync corrected the row's context window in the same pass. An upstream entry arriving as 128k/115_200 whose window is then widened to 272k kept the stale 115_200 — 42% of the real window — so every long turn compacted early. CI caught it on macos and test 1/4 at 121c1fb. A retained threshold only describes the window it arrived with. Capture the incoming window before any override or cap rewrites the row, and trust the retained value only when the window is unchanged; lower-is-policy still holds there, which is what #1905 was protecting.
1 parent 121c1fb commit ea9debf

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/codex/catalog/parsing.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ export function applyNativeOpenAiContextOverride(entry: RawEntry, limits?: Nativ
320320
?? (isNativeOpenAiEntry(entry) ? entry.slug as string : undefined);
321321
if (!nativeSlug) return;
322322
const override = NATIVE_OPENAI_CONTEXT_OVERRIDES[nativeSlug];
323+
// Captured before any override/cap rewrites the row: a retained compaction threshold only
324+
// describes the window it arrived with.
325+
const incomingContextWindow = typeof entry.context_window === "number" ? entry.context_window : undefined;
323326
if (override) {
324327
// Read the effective values through the accessors rather than re-deriving them from the
325328
// static table: this function used to apply only the provider cap, so a per-model window
@@ -352,7 +355,14 @@ export function applyNativeOpenAiContextOverride(entry: RawEntry, limits?: Nativ
352355
: undefined;
353356
if (effectiveContext !== undefined) {
354357
const derivedAutoCompactTokenLimit = nativeOpenAiAutoCompactTokenLimit(nativeSlug, limits);
355-
const retainedAutoCompactTokenLimit = isNativeOpenAiEntry(entry)
358+
// Only trust a retained threshold that still describes THIS window. When sync corrects the
359+
// window, the old number is an artifact of the old one: a 115_200 limit retained from a
360+
// 128k row would pin a corrected 272k model to 42% of its real window and compact every
361+
// long turn early. Lower-is-policy still holds whenever the window is unchanged.
362+
const retainedDescribesCurrentContext = incomingContextWindow === undefined
363+
|| incomingContextWindow === effectiveContext;
364+
const retainedAutoCompactTokenLimit = retainedDescribesCurrentContext
365+
&& isNativeOpenAiEntry(entry)
356366
&& typeof entry.auto_compact_token_limit === "number"
357367
&& Number.isSafeInteger(entry.auto_compact_token_limit)
358368
&& entry.auto_compact_token_limit > 0

0 commit comments

Comments
 (0)