{"record":{"id":"1b0fa5b9c075925e","repo":"Hmbown/CodeWhale","slug":"name-context-window-must-be-greater-than-0","errorCode":null,"errorMessage":"{name}.context_window must be greater than 0","messagePattern":"(.+?)\\.context_window must be greater than 0","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/config.rs","lineNumber":3605,"sourceCode":"            (\"providers.sakana\", &self.sakana),\n            (\"providers.opencode_go\", &self.opencode_go),\n            (\"providers.opencode_zen\", &self.opencode_zen),\n            (\"providers.meta\", &self.meta),\n            (\"providers.xai\", &self.xai),\n        ];\n        for (name, config) in builtins {\n            validate_provider_context_window(name, config.context_window)?;\n        }\n        for (name, config) in &self.custom {\n            validate_provider_context_window(&format!(\"providers.{name}\"), config.context_window)?;\n        }\n        Ok(())\n    }\n}\n\nfn validate_provider_context_window(name: &str, value: Option<u32>) -> Result<()> {\n    if value == Some(0) {\n        anyhow::bail!(\"{name}.context_window must be greater than 0\");\n    }\n    Ok(())\n}\n\n#[derive(Debug, Clone, Deserialize, Default)]\nstruct ConfigFile {\n    #[serde(flatten)]\n    base: Config,\n    profiles: Option<HashMap<String, Config>>,\n}\n\n#[derive(Debug, Clone, Deserialize, Default)]\nstruct RequirementsFile {\n    #[serde(default)]\n    allowed_approval_policies: Vec<String>,\n    #[serde(default)]\n    allowed_sandbox_modes: Vec<String>,\n}","sourceCodeStart":3587,"sourceCodeEnd":3623,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/config.rs#L3587-L3623","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasted custom provider templates with placeholder zeros; scripts generating provider sections.","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"],"exampleFix":"# config.toml - before\n[providers.myhost]\napi_base = \"http://localhost:8000/v1\"\ncontext_window = 0\n\n# config.toml - after\n[providers.myhost]\napi_base = \"http://localhost:8000/v1\"\ncontext_window = 128000\n","handlingStrategy":"validation","validationCode":"for (name, p) in &custom_providers {\n    if p.context_window == Some(0) {\n        return Err(anyhow!(\"{name}.context_window must be > 0\"));\n    }\n}","typeGuard":"fn valid_context_window(v: Option<u32>) -> bool { v != Some(0) }","tryCatchPattern":"// When generating provider config, omit the key rather than zeroing it\nlet toml = if cw > 0 { format!(\"context_window = {cw}\\n\") } else { String::new() };","preventionTips":["Never use 0 as 'unset' in TOML - delete the key instead","Check the model card for the real context size when adding providers"],"tags":["config","provider","context-window","validation"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}