Skip to content

Commit 5754597

Browse files
krissdingclaude
andcommitted
fix(preemptive-compaction): use MIN_PROMPT_BUDGET_TOKENS as floor, not ceiling
The minPromptBudget calculation used Math.min, making 8000 the upper bound for the ratio-based prompt budget. For small-context models (e.g. phi3:mini at 4096 tokens), the ratio-based value was only 2048, leaving barely any room for the actual prompt after reserve tokens were subtracted. Change Math.min to Math.max so MIN_PROMPT_BUDGET_TOKENS acts as a true floor, ensuring models under 16k context receive at least half the window for prompt content. Large models are unaffected since the ratio-based value already exceeds 8000. Closes #96658 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 4ecb45b commit 5754597

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎src/agents/embedded-agent-runner/run/preemptive-compaction.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,10 @@ export function shouldPreemptivelyCompactBeforePrompt(params: {
281281
}
282282
const contextTokenBudget = Math.max(1, Math.floor(params.contextTokenBudget));
283283
const requestedReserveTokens = Math.max(0, Math.floor(params.reserveTokens));
284-
const minPromptBudget = Math.min(
284+
// Use max so MIN_PROMPT_BUDGET_TOKENS acts as a floor: small-context models
285+
// (e.g. 4k) always keep at least half the window for the prompt instead of
286+
// letting the ratio-based value drop so low that every prompt overflows.
287+
const minPromptBudget = Math.max(
285288
MIN_PROMPT_BUDGET_TOKENS,
286289
Math.max(1, Math.floor(contextTokenBudget * MIN_PROMPT_BUDGET_RATIO)),
287290
);

0 commit comments

Comments
 (0)