BigPizzaV3/CodexPlusPlus · error

Grok 模型 的上下文窗口必须大于 0

Error message

Grok 模型 {alias} 的上下文窗口必须大于 0

What it means

When a Grok model entry specifies a context_window, it must be greater than 0. A value of exactly Some(0) is rejected because a zero-size context window is meaningless and would break request sizing logic downstream.

Solutions

  1. Set context_window to a positive value appropriate for the model (e.g. 131072)
  2. Omit the field entirely (None) if the model has no explicit window requirement
  3. Fix UI/serialization defaults so unset maps to None, not Some(0)

Example fix

// before
context_window: Some(0)
// after
context_window: Some(131072)
Defensive patterns

Strategy: validation

Validate before calling

if let Some(w) = req.context_window { assert!(w > 0, "context_window must be > 0"); }

Prevention

When it happens

Trigger: save_grok_config_at called with input.context_window == Some(0) — typically a default-initialized struct, a UI bound to a numeric field starting at 0, or deserialization that turned an empty string into 0.

Common situations: Leaving a spinner/number input at its 0 default; template configs with placeholder 0 values meant to be filled in; forgetting that None (unset) is the correct way to express 'no limit'.

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


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/aaa1fa0d5e30f60b. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/grok_config.rs:296

        }
        if alias.chars().any(char::is_control) {
            bail!("Grok 模型别名不能包含控制字符");
        }
        if !aliases.insert(alias.to_string()) {
            bail!("Grok 模型别名重复:{alias}");
        }
        let source = input.source_alias.trim();
        if !source.is_empty() && !sources.insert(source.to_string()) {
            bail!("Grok 模型来源别名重复:{source}");
        }
        if !matches!(
            input.api_backend.trim(),
            "responses" | "chat_completions" | "messages"
        ) {
            bail!("Grok 模型 {alias} 的 API 协议无效");
        }
        if input.context_window == Some(0) {
            bail!("Grok 模型 {alias} 的上下文窗口必须大于 0");
        }
        if input
            .context_window
            .is_some_and(|value| value > i64::MAX as u64)
        {
            bail!("Grok 模型 {alias} 的上下文窗口过大");
        }
        if input.remove_api_key && !input.api_key_update.is_empty() {
            bail!("Grok 模型 {alias} 不能同时替换并移除 API Key");
        }
    }
    Ok(())
}

fn table_string(doc: &DocumentMut, table: &str, key: &str) -> String {
    doc.get(table)
        .and_then(Item::as_table_like)
        .and_then(|values| values.get(key))

View on GitHub (pinned to b1ed92e5e4)