#17041: fix(memory-flush): add softThresholdPercent for context-relative threshold
stale
size: XS
Cluster:
Memory Management Enhancements
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
#4999: fix(memory-flush): use contextTokens instead of totalTokens for thr...
by Farfadium · 2026-01-30
82.0%
#12254: fix: add minimum token guard to prevent double compaction after flush
by Yida-Dev · 2026-02-09
79.9%
#20713: fix(compaction): trigger memory flush after missed compaction cycles
by zerone0x · 2026-02-19
77.6%
#15945: fix(memory-flush): only write memoryFlushCompactionCount when compa...
by aldoeliacim · 2026-02-14
76.5%
#12760: fix(memory-flush): fire on every compaction cycle instead of skippi...
by lailoo · 2026-02-09
74.4%
#15196: fix: clear stale token totals after compaction
by bufordtjustice2918 · 2026-02-13
74.3%
#8919: Pr/memory flush improvements
by shortbus · 2026-02-04
73.9%
#9012: fix(memory): resilient flush for large sessions [AI-assisted]
by cheenu1092-oss · 2026-02-04
73.8%
#21242: fix(memory): add token budget limits for memory tools (#21187)
by Asm3r96 · 2026-02-19
73.3%
#9620: fix: increase auto-compaction reserve buffer to 40k tokens
by Arlo83963 · 2026-02-05
73.0%