zed-industries/zed · error
auto_compact threshold percentage must be between 0% and…
Error message
auto_compact threshold percentage must be between 0% and 100%, got {raw:?} What it means
Raised by parse_auto_compact_threshold while parsing the user's auto_compact settings string: the value was given with a '%' suffix (percentage form) and parsed as a number successfully, but the resulting percentage falls outside the valid 0–100 range. The offending input is the raw threshold string from agent settings (e.g. "150%" or "-5%").
Solutions
- Set the threshold to a percentage between 0% and 100%
- Use the token-count form (a plain integer) to specify remaining tokens instead
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/agent_settings/src/agent_settings.rs:182 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-08-20).
Data as JSON: /api/errors/6d85b7148b6564de.
Report an issue: GitHub.
Appendix: source
Thrown at crates/agent_settings/src/agent_settings.rs:188
Self::TokensRemaining(tokens) => write!(formatter, "-{tokens}"),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AutoCompactSettings {
pub enabled: bool,
pub threshold: AutoCompactThreshold,
}
fn parse_auto_compact_threshold(raw: &str) -> anyhow::Result<AutoCompactThreshold> {
let trimmed = raw.trim();
if let Some(percent) = trimmed.strip_suffix('%') {
let value: f64 = percent
.trim_end()
.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")
}
}View on GitHub (pinned to 916fc2b8cb)