Compaction: 85% Threshold and Optional Two-Pass
The default policy allows auto-compaction when context usage reaches 85%. Both memory flush and two-pass are disabled by default; they must be explicitly enabled to activate their respective flows.
Memorize the five real fields and default values of
CompactionPolicy, and trace the threshold check in Agent::should_auto_compact and xai-token-estimation.used × 100 >= context_window × threshold_percent. Comparison uses saturating multiplication; returns false when context window is 0.
auto_compact_threshold_percent: u3285Auto-compaction threshold percentage.
compact_model: Option<String>NoneUses the current session model when unspecified.
memory_flush_enabled: boolfalseWhen enabled, a memory flush turn runs before compaction.
wall_clock_budget_secs: u64300Wall-clock time budget per compaction, in seconds.
two_pass_enabled: boolfalseWritten in from config; defaults to the single-pass path.
Pre-summarize the History Prefix
Only when two_pass_enabled is true: speculatively summarize the history prefix in the background near the threshold, producing NOTE₁.
Summarize NOTE₁ + Recent Tail
During the actual compaction, combine NOTE₁ with the recent tail for a second summarization. When set to false, the original single-pass path is preserved.
fn default() -> Self {
Self {
auto_compact_threshold_percent: 85,
compact_model: None,
memory_flush_enabled: false,
wall_clock_budget_secs: 300,
two_pass_enabled: false,
}
}
}
used: u64,
context_window: u64,
threshold_percent: u8,
) -> bool {
if context_window == 0 { return false; }
used.saturating_mul(100) >=
context_window.saturating_mul(
threshold_percent as u64
)
}
Agent::should_auto_compact receives total_tokens and NonZeroU64 context_window, then calls xai_token_estimation::exceeds_threshold. The policy struct itself has no fictitious should_compact(&self, usage: f64) method..git metadata, so no claim is made about which commit it corresponds to.Calculate the Boundary by Hand
With a context window of 100,000 and a threshold of 85, determine whether 84,999, 85,000, and 90,000 tokens trigger compaction. Then explain how enabling two_pass_enabled changes the compaction path without changing the default value to true.