Compaction: 85% Threshold & Optional Two-Pass
Verifying auto-compression thresholds, memory flush, two-pass, and timeout budget from real config
THE QUESTION THIS PAGE ANSWERS
ANSWER FIRSTWhat is the key idea behind “Compaction: 85% Threshold & Optional Two-Pass”?
Verifying auto-compression thresholds, memory flush, two-pass, and timeout budget from real config
Make the claim earn its place. Use this page as a decision aid, not a definition to memorize. Connect the idea to one real task, one observable result, and one failure that would change your mind.
Write one question you could answer with evidence after trying this idea.
A conclusion that sounds complete but leaves the key assumption untested.
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.
How “Core Visual · Auto-Compaction Threshold” changes an answer
“used × 100 >= context_window × threshold_percent .” shows that a model does not process the “word count” we see. It processes Token pieces. Tokenization affects input length, how much context fits, and how much computation a request consumes.
Length, information, and context are different
As “Auto-compaction threshold percentage” grows, separate three questions: how many Tokens the text becomes, which pieces can change the current decision, and whether older material has fallen outside the context window. Removing repetition is often more useful than simply making the window larger.
Keep what can change the decision
Use “With a context window of 100,000 and a threshold of 85, determine whether 84,999, 85,000, and 90,000 tokens trigger compaction.” as an A/B test: keep the same question while removing repeated background, compressing format, and trimming irrelevant history. Compare answer quality, latency, and Token count.
From “Core Visual · Auto-Compaction Threshold” to “CompactionPolicy Default Values”
“Core Visual · Auto-Compaction Threshold” grounds the problem in “used × 100 >= context_window × threshold_percent . Comparison uses saturating multiplication; returns false when context window is 0”. “CompactionPolicy Default Values” then moves it toward “Auto-compaction threshold percentage”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.
Carry the judgment into the next situation
For long text, keep what can change the conclusion before compressing format and history. A larger context is worth its cost only when the added information is useful.
- “Core Visual · Auto-Compaction Threshold”: used × 100 >= context_window × threshold_percent . Comparison uses saturating multiplication; returns false when context window is 0
- “CompactionPolicy Default Values”: Auto-compaction threshold percentage
- “The closing point”: 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
The final “The closing point” brings the discussion to “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”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.
I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.
After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.
When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.
No discussion on this article yet.