{"record":{"id":"b9aae4b2312c3330","repo":"Hmbown/CodeWhale","slug":"context-window-must-be-greater-than-0","errorCode":null,"errorMessage":"context_window must be greater than 0","messagePattern":"context_window must be greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/config/src/lib.rs","lineNumber":1160,"sourceCode":"fn get_provider_config_display_value(\n    config: &ProviderConfigToml,\n    field: ProviderConfigField,\n) -> Option<String> {\n    match field {\n        ProviderConfigField::ApiKey => config.api_key.as_deref().map(redact_secret),\n        ProviderConfigField::HttpHeaders => {\n            serialize_http_headers_for_display(&config.http_headers)\n        }\n        _ => get_provider_config_value(config, field),\n    }\n}\n\nfn parse_context_window(value: &str) -> Result<u32> {\n    let parsed = value.trim().parse::<u32>().with_context(|| {\n        format!(\"invalid context_window '{value}': expected a positive token count\")\n    })?;\n    if parsed == 0 {\n        bail!(\"context_window must be greater than 0\");\n    }\n    Ok(parsed)\n}\n\nfn set_provider_config_value(\n    config: &mut ConfigToml,\n    provider: ProviderKind,\n    field: ProviderConfigField,\n    value: &str,\n) -> Result<()> {\n    if provider == ProviderKind::Antigravity {\n        bail!(LEGACY_ANTIGRAVITY_TOMBSTONE_MESSAGE);\n    }\n    match field {\n        ProviderConfigField::Vendor => {\n            if provider != ProviderKind::Openrouter {\n                bail!(\"vendor is only supported by providers.openrouter\");\n            }","sourceCodeStart":1142,"sourceCodeEnd":1178,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/config/src/lib.rs#L1142-L1178","documentation":"Thrown by `parse_context_window` when the parsed `context_window` value is 0. The context window is a token budget and must be a positive count; a zero value would make the budget meaningless. Parsing itself must already have succeeded as a u32.","triggerScenarios":"Setting a provider's `context_window` field (via `set_provider_config_value` or the ConfigToml setter) to \"0\" — the string parses fine as u32 but fails the >0 check.","commonSituations":"User typed `context_window = \"0\"` intending 'unlimited' or left a placeholder value; a template or script emitted 0 as a default.","solutions":["Set `context_window` to the provider model's actual token limit (e.g. \"128000\").","Remove the `context_window` override entirely to fall back to the model's default.","Never use 0 to mean 'unlimited' — the field requires a positive integer."],"exampleFix":"// before\ncontext_window = \"0\"\n// after\ncontext_window = \"200000\"","handlingStrategy":"validation","validationCode":"fn valid_context_window(v: &str) -> bool {\n    v.trim().parse::<u32>().map(|n| n > 0).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match parse_context_window(value) {\n    Err(e) if e.to_string().contains(\"greater than 0\") => {\n        // fall back to the model default instead of forcing 0\n        config.providers.for_provider_mut(provider).context_window = None;\n        Ok(())\n    }\n    other => other,\n}","preventionTips":["Never write 0 for context_window; omit the field to use the model default.","Validate positive integer inputs in any CLI/config UI before persisting.","Document that context_window is a token count, not a boolean/unlimited flag."],"tags":["config","validation","parsing"],"backgroundTag":"invalid-config-value","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}