Files
DeepSeek-Reasonix/internal/runtime/agent/compact_retention.go
T
esengine e1c38d3036 fix(agent): cap verbatim retention by the compaction trigger, not only the window
User turns, retained failures and [[keep]] turns were budgeted as shares of
the window. On a 1M window under the 100K cost trigger those shares plus the
tail passed the trigger, so every fold was refused as still at or above it.
Each budget is now also held to a share of the trigger.
2026-10-25 01:55:42 -07:00

21 lines
791 B
Go

package agent
const keptUserTurnsTriggerFrac = 0.10 // user turns: share of the compaction trigger
// retentionBudget is what one kind of verbatim retention may spend: a share of
// the window, held to a share of the trigger. The tail already stops at half
// the trigger; window shares alone let retention and tail together pass it on a
// window much larger than the trigger, and every fold is then refused as still
// at or above it.
func (a *contextWindow) retentionBudget(windowFrac, triggerFrac float64) int {
window := a.effectiveContextWindow()
if window <= 0 {
return keptUserTurnsFloorTokens
}
budget := int(float64(window) * windowFrac)
if trigger := a.compactTrigger(); trigger > 0 {
budget = min(budget, int(float64(trigger)*triggerFrac))
}
return max(1, budget)
}