Hmbown/CodeWhale · error
.model_context_windows. must be greater than 0
Error message
{name}.model_context_windows.{model} must be greater than 0 What it means
Per-model context window overrides in a provider's `model_context_windows` table must be greater than zero. A zero entry would produce a zero token budget for that model, so validation rejects it. Thrown by validate_model_context_windows at config.rs:4090.
Solutions
- Set the model's window to its real positive limit.
- Delete the zero entry so the model falls back to the provider-level context_window or default.
- Fix the generator/lookup that emitted 0 for unknown models.
Example fix
// before
model_context_windows = { "claude-x" = 0 }
// after
model_context_windows = { "claude-x" = 200000 } Defensive patterns
Strategy: validation
Validate before calling
for (model, w) in provider.model_context_windows.iter().flatten() {
if *w == 0 { return Err(format!("{model} context window must be > 0")); }
} Prevention
- Remove unknown-model entries instead of filling them with 0.
- Validate generated per-model tables before writing config.
When it happens
Trigger: A provider's `model_context_windows` BTreeMap contains a model whose value is exactly 0, e.g. model_context_windows = { "gpt-4o" = 0 }. The error names the offending provider and model.
Common situations: Placeholder zeros left in generated config; overriding a model whose limit was unknown and someone wrote 0; scripted config generation where a fetch returned 0.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Choose both a provider and a model.
- custom provider ' ' must set [providers. ].kind =…
- fleet task worker.model cannot be empty
- Invalid configured model
- Invalid default_text_model
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/806bfb3b0e854b05.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/config.rs:4090
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(())
}
fn validate_model_context_windows(
name: &str,
table: Option<&std::collections::BTreeMap<String, u32>>,
) -> Result<()> {
if let Some(table) = table {
for (model, window) in table {
if *window == 0 {
anyhow::bail!("{name}.model_context_windows.{model} must be greater than 0");
}
}
}
Ok(())
}
#[derive(Debug, Clone, Deserialize, Default)]
struct ConfigFile {
/// Boxed so the parsed document never carries the multi-kilobyte
/// `Config` by value through `toml::de` and `apply_profile` frames. A
/// `#[tokio::test]` runs those frames on libtest's default 2 MiB stack,
/// which the by-value copies overflowed (#6362).
#[serde(flatten)]
base: Box<Config>,
profiles: Option<HashMap<String, Config>>,
}
#[derive(Debug, Clone, Deserialize, Default)]View on GitHub (pinned to 73e0f67d83)