Hmbown/CodeWhale · error · anyhow::Error
{name}.context_window must be greater than 0
Error message
{name}.context_window must be greater than 0 What it means
Provider context-window validation (crates/tui/src/config.rs:3605) rejects an explicit context_window = 0, both for builtin overrides and custom [providers.<name>] entries. Zero would make every context-budget calculation degenerate, so it fails config validation by name, e.g. providers.myhost.context_window.
Source
Thrown at crates/tui/src/config.rs:3605
("providers.sakana", &self.sakana),
("providers.opencode_go", &self.opencode_go),
("providers.opencode_zen", &self.opencode_zen),
("providers.meta", &self.meta),
("providers.xai", &self.xai),
];
for (name, config) in builtins {
validate_provider_context_window(name, config.context_window)?;
}
for (name, config) in &self.custom {
validate_provider_context_window(&format!("providers.{name}"), config.context_window)?;
}
Ok(())
}
}
fn validate_provider_context_window(name: &str, value: Option<u32>) -> Result<()> {
if value == Some(0) {
anyhow::bail!("{name}.context_window must be greater than 0");
}
Ok(())
}
#[derive(Debug, Clone, Deserialize, Default)]
struct ConfigFile {
#[serde(flatten)]
base: Config,
profiles: Option<HashMap<String, Config>>,
}
#[derive(Debug, Clone, Deserialize, Default)]
struct RequirementsFile {
#[serde(default)]
allowed_approval_policies: Vec<String>,
#[serde(default)]
allowed_sandbox_modes: Vec<String>,
}View on GitHub (pinned to 8880682c63)
Solutions
- Set a positive token count matching the model (e.g. 128000)
- Or delete the context_window key entirely to fall back to defaults
- Re-run config load to confirm the validation passes
Example fix
# config.toml - before [providers.myhost] api_base = "http://localhost:8000/v1" context_window = 0 # config.toml - after [providers.myhost] api_base = "http://localhost:8000/v1" context_window = 128000
Defensive patterns
Strategy: validation
Validate before calling
for (name, p) in &custom_providers {
if p.context_window == Some(0) {
return Err(anyhow!("{name}.context_window must be > 0"));
}
} Type guard
fn valid_context_window(v: Option<u32>) -> bool { v != Some(0) } Try / catch
// When generating provider config, omit the key rather than zeroing it
let toml = if cw > 0 { format!("context_window = {cw}\n") } else { String::new() }; Prevention
- Never use 0 as 'unset' in TOML - delete the key instead
- Check the model card for the real context size when adding providers
When it happens
Trigger: A custom provider entry with context_window = 0 left as a placeholder; an override table where 0 was meant as 'use default'; YAML-to-TOML conversions producing zeros for empty values.
Common situations: Copy-pasted custom provider templates with placeholder zeros; scripts generating provider sections.
Related errors
- Invalid provider '{provider}': expected {}.
- Invalid default_text_model '{model}' for provider '{}': expe
- ${name} is required
- ${names.join(" or ")} is required
- ${name} is required
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/1b0fa5b9c075925e.
Report an issue: GitHub.