fix: update compaction safeguard to respect context window tokens

This commit is contained in:
Evan
2026-02-01 11:09:43 +00:00
committed by Ayaan Zaidi
parent 0e0e395b9e
commit 5d3c898a94
3 changed files with 15 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
export type CompactionSafeguardRuntimeValue = {
maxHistoryShare?: number;
contextWindowTokens?: number;
};
// Session-scoped runtime registry keyed by object identity.

View File

@@ -195,11 +195,15 @@ export default function compactionSafeguardExtension(api: ExtensionAPI): void {
}
try {
const contextWindowTokens = resolveContextWindowTokens(model);
const runtime = getCompactionSafeguardRuntime(ctx.sessionManager);
const modelContextWindow = resolveContextWindowTokens(model);
const contextWindowTokens = Math.min(
runtime?.contextWindowTokens ?? modelContextWindow,
modelContextWindow,
);
const turnPrefixMessages = preparation.turnPrefixMessages ?? [];
let messagesToSummarize = preparation.messagesToSummarize;
const runtime = getCompactionSafeguardRuntime(ctx.sessionManager);
const maxHistoryShare = runtime?.maxHistoryShare ?? 0.5;
const tokensBefore =