{"record":{"id":"3918c7f50edf687d","repo":"zed-industries/zed","slug":"auto-compact-threshold-of-0-is-not-valid","errorCode":null,"errorMessage":"auto_compact threshold of 0 is not valid","messagePattern":"auto_compact threshold of 0 is not valid","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/agent_settings/src/agent_settings.rs","lineNumber":204,"sourceCode":"            .parse()\n            .with_context(|| format!(\"invalid auto_compact threshold percentage {raw:?}\"))?;\n        anyhow::ensure!(\n            value > 0.0 && value <= 100.0,\n            \"auto_compact threshold percentage must be between 0% and 100%, got {raw:?}\"\n        );\n        Ok(AutoCompactThreshold::Percentage(value / 100.0))\n    } else {\n        let tokens: i64 = trimmed.parse().with_context(|| {\n            format!(\n                \"invalid auto_compact threshold {raw:?}; \\\n                 expected a percentage like \\\"90%\\\" or an integer number of tokens\"\n            )\n        })?;\n        match tokens.cmp(&0) {\n            Greater => Ok(AutoCompactThreshold::TokensUsed(tokens as u64)),\n            Less => Ok(AutoCompactThreshold::TokensRemaining(tokens.unsigned_abs())),\n            Equal => {\n                anyhow::bail!(\"auto_compact threshold of 0 is not valid\")\n            }\n        }\n    }\n}\n\n#[derive(Clone, Debug, RegisterSetting)]\npub struct AgentSettings {\n    pub enabled: bool,\n    pub button: bool,\n    pub dock: DockPosition,\n    pub flexible: bool,\n    pub sidebar_side: SidebarDockPosition,\n    pub threads_sidebar_default_width: Pixels,\n    pub threads_sidebar_auto_open: bool,\n    pub default_width: Pixels,\n    pub default_height: Pixels,\n    pub max_content_width: Option<Pixels>,\n    pub default_model: Option<LanguageModelSelection>,","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/agent_settings/src/agent_settings.rs#L186-L222","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// settings.json\n// before\n{ \"agent\": { \"auto_compact\": \"0\" } }\n// after — compact at 90% of the context window\n{ \"agent\": { \"auto_compact\": \"90%\" } }","handlingStrategy":"validation","validationCode":"fn valid_auto_compact(raw: &str) -> bool {\n    let t = raw.trim();\n    if let Some(pct) = t.strip_suffix('%') { return pct.parse::<f64>().is_ok(); }\n    match t.parse::<i64>() { Ok(n) => n != 0, Err(_) => false }\n}","typeGuard":null,"tryCatchPattern":"match AutoCompactThreshold::from_str_value(raw) {\n    Err(e) if e.to_string().contains(\"threshold of 0\") => {\n        // suggest \"90%\" or a nonzero token count to the user\n    }\n    rest => rest,\n}","preventionTips":["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."],"tags":["rust","zed","agent","settings","auto-compact","invalid-value","configuration"],"backgroundTag":"invalid-setting-value","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}