zed-industries/zed · error · anyhow::Error
auto_compact threshold of 0 is not valid
Error message
auto_compact threshold of 0 is not valid
What it means
`auto_compact` threshold is parsed from a string in agent settings: a percent suffix (`"90%"`) becomes a `Percentage`, a positive integer becomes `TokensUsed`, a negative integer becomes `TokensRemaining` (unsigned absolute value), and exactly `0` — which fits neither direction — is rejected. The parse first strips whitespace (`trimmed`), so `" 0 "` and `"0"` both fail.
Solutions
- Set a valid threshold: `"90%"` (compact at 90% of context), `"100000"` (compact after 100k tokens used), or `"-20000"` (compact when 20k tokens remain).
- To effectively disable auto-compact, set a very high token count (e.g. `"1000000"`) rather than 0.
- Check for stray whitespace or a literal `0` mixed into a percent string when editing settings by hand.
- After editing, reload settings and confirm the agent panel no longer reports the parse error.
Example fix
// settings.json
// before
{ "agent": { "auto_compact": "0" } }
// after — compact at 90% of the context window
{ "agent": { "auto_compact": "90%" } } Defensive patterns
Strategy: validation
Validate before calling
fn valid_auto_compact(raw: &str) -> bool {
let t = raw.trim();
if let Some(pct) = t.strip_suffix('%') { return pct.parse::<f64>().is_ok(); }
match t.parse::<i64>() { Ok(n) => n != 0, Err(_) => false }
} Try / catch
match AutoCompactThreshold::from_str_value(raw) {
Err(e) if e.to_string().contains("threshold of 0") => {
// suggest "90%" or a nonzero token count to the user
}
rest => rest,
} Prevention
- Use a percentage (`"90%"`) or nonzero token counts; never 0.
- To disable compaction, use a very large token threshold rather than zero.
- Validate user input with a parse check before persisting settings.
When it happens
Trigger: Setting `"agent.auto_compact": "0"` (or `"0%"`-adjacent forms that parse as the integer 0, e.g. `"00"`) in `settings.json`; passing `"0"` programmatically to the threshold parser.
Common situations: Users try to disable auto-compaction by setting the threshold to 0, or try to trigger compaction immediately; the setting expects either a percentage or a nonzero token count, and disabling is expressed differently (e.g. omitting the setting or a dedicated toggle).
Related errors
- Cannot list directory because its path matches the user's…
- Cannot list directory because its path matches the user's…
- Cannot read file because its path matches the global…
- Cannot read file because its path matches the global…
- Cannot read file because its path matches the worktree…
AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-08-20).
Data as JSON: /api/errors/3918c7f50edf687d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/agent_settings/src/agent_settings.rs:204
.parse()
.with_context(|| format!("invalid auto_compact threshold percentage {raw:?}"))?;
anyhow::ensure!(
value > 0.0 && value <= 100.0,
"auto_compact threshold percentage must be between 0% and 100%, got {raw:?}"
);
Ok(AutoCompactThreshold::Percentage(value / 100.0))
} else {
let tokens: i64 = trimmed.parse().with_context(|| {
format!(
"invalid auto_compact threshold {raw:?}; \
expected a percentage like \"90%\" or an integer number of tokens"
)
})?;
match tokens.cmp(&0) {
Greater => Ok(AutoCompactThreshold::TokensUsed(tokens as u64)),
Less => Ok(AutoCompactThreshold::TokensRemaining(tokens.unsigned_abs())),
Equal => {
anyhow::bail!("auto_compact threshold of 0 is not valid")
}
}
}
}
#[derive(Clone, Debug, RegisterSetting)]
pub struct AgentSettings {
pub enabled: bool,
pub button: bool,
pub dock: DockPosition,
pub flexible: bool,
pub sidebar_side: SidebarDockPosition,
pub threads_sidebar_default_width: Pixels,
pub threads_sidebar_auto_open: bool,
pub default_width: Pixels,
pub default_height: Pixels,
pub max_content_width: Option<Pixels>,
pub default_model: Option<LanguageModelSelection>,View on GitHub (pinned to 916fc2b8cb)