fix(suggest-compact): don't quote a percentage against an assumed window

The context signal always rendered "N% of <window> window", including when
the window size was the assumed 200k default rather than a detected value.
On a 1M session whose transcript carries no [1m] marker, that produced
lines like:

  [StrategicCompact] Context ~194k tokens (97% of 200k window)

while actual usage was ~19%. The user compacts on a false alarm, loses
context, and the resulting quality drop reads as a model regression.

The gap is structural: the context threshold defaults to 80% of the
window (160k on 200k), so the signal fires precisely in the 160k-200k
band where the size cannot be determined — above 200k the observed-tokens
fallback correctly infers 1M, and below 160k nothing fires.

Model id alone cannot close this. A tier may ship both a 200k and a 1M
variant under one id, so neither the known-family table nor a new entry
can distinguish them, and the transcript records no window field.

So stop asserting what isn't known: resolveContextWindow() now reports
whether the size was detected (env override, [1m] marker, known family,
or observed tokens > 200k) or assumed, and the hook omits the percentage
and window label when it was assumed. The token count, threshold, and
firing behaviour are unchanged.

resolveContextWindowTokens() keeps its existing signature and semantics.

Note: 3 pre-existing failures in tests/hooks/suggest-compact.test.js
reproduce identically on unmodified main and are untouched here.
This commit is contained in:
Tanel
2026-08-29 14:55:13 -04:00
committed by haelyra
parent e82e477034
commit ecdd517765
3 changed files with 82 additions and 15 deletions
+33 -1
View File
@@ -23,7 +23,8 @@ const {
resolveContextThreshold,
resolveContextInterval,
computeContextBucket,
formatWindowLabel
formatWindowLabel,
isContextWindowInferred
} = require('../../scripts/lib/transcript-context');
console.log('=== Testing transcript-context.js ===\n');
@@ -218,6 +219,37 @@ test('treats an empty model id as standard window', () => {
assert.strictEqual(resolveContextWindowTokens(100000, ''), STANDARD_CONTEXT_WINDOW_TOKENS);
});
// ── isContextWindowInferred ──
console.log('\nisContextWindowInferred:');
delete process.env.ECC_CONTEXT_WINDOW_TOKENS;
delete process.env.CLAUDE_CODE_AUTO_COMPACT_WINDOW;
test('flags the assumed 200k default as inferred', () => {
assert.strictEqual(isContextWindowInferred(187000, 'claude-opus-9'), true);
});
test('an env override is a detected window, not inferred', () => {
process.env.ECC_CONTEXT_WINDOW_TOKENS = '1000000';
try {
assert.strictEqual(isContextWindowInferred(187000, 'claude-opus-9'), false);
} finally {
delete process.env.ECC_CONTEXT_WINDOW_TOKENS;
}
});
test('a [1m] marker is a detected window, not inferred', () => {
assert.strictEqual(isContextWindowInferred(187000, 'claude-opus-4-5[1m]'), false);
});
test('a known large-window family is a detected window, not inferred', () => {
assert.strictEqual(isContextWindowInferred(187000, 'claude-fable-5'), false);
});
test('tokens above the standard window make the size detected, not inferred', () => {
assert.strictEqual(isContextWindowInferred(220000, 'claude-opus-9'), false);
});
// ── resolveContextThreshold ──
console.log('\nresolveContextThreshold:');