← Back to PRs

#17041: fix(memory-flush): add softThresholdPercent for context-relative threshold

by Limitless2023 open 2026-02-15 10:31 View on GitHub →
stale size: XS
Fixes #17034 ## Problem Memory flush softThresholdTokens is an absolute value (default 4000). On large context models (1M tokens), this threshold is never reached, so memory flush never triggers. ## Solution Add softThresholdPercent config option that calculates threshold as a percentage of context window: - Example: softThresholdPercent: 2 = 2%% of context window - For 1M context: 2%% = 20K tokens (reaches threshold) - For 200K context: 2%% = 4K tokens (equivalent to default) ## Usage ```yaml agents: defaults: compaction: memoryFlush: softThresholdPercent: 2 # Use 2%% of context window ``` ## Impact - Memory flush now works correctly on all context window sizes - Backward compatible: existing softThresholdTokens still works <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds `softThresholdPercent` config option to calculate memory flush threshold as a percentage of context window, solving the issue where absolute threshold values don't scale with large context models (e.g., 1M tokens). The implementation correctly passes the new parameter through the call chain and applies it in the threshold calculation with proper fallback to `softThresholdTokens`. The change is backward compatible. <h3>Confidence Score: 4/5</h3> - Safe to merge with minor style improvement suggested - The implementation correctly solves the stated problem with proper logic flow and backward compatibility. The threshold calculation has appropriate safeguards (`Math.max`, type checks). One style suggestion for input validation consistency. - No files require special attention <sub>Last reviewed commit: fd0b6da</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs