BigPizzaV3/CodexPlusPlus · error

Grok 模型 的上下文窗口过大

Error message

Grok 模型 {alias} 的上下文窗口过大

What it means

context_window is stored as u64 but persisted/compared as i64. validate_request rejects values above i64::MAX to prevent overflow or truncation when the value is written to config or used downstream. Such huge values are never legitimate model windows.

Solutions

  1. Provide the model's real advertised context window (well below i64::MAX)
  2. Use None instead of a sentinel to mean 'unspecified'
  3. Validate/clamp the input in the UI before submitting

Example fix

// before
context_window: Some(u64::MAX) // sentinel for unlimited
// after
context_window: None
Defensive patterns

Strategy: validation

Validate before calling

if let Some(w) = req.context_window { assert!(w <= i64::MAX as u64); }

Prevention

When it happens

Trigger: save_grok_config_at called with input.context_window greater than i64::MAX (9,223,372,036,854,775,807) — practically only from sentinel values like u64::MAX, unvalidated user input, or a 'max' placeholder.

Common situations: Using u64::MAX as an 'unbounded' sentinel; scripts computing window sizes with overflow; copy-pasted hex/binary values misinterpreted as decimal.

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/28cb24ddf8d71643. Report an issue: GitHub.

Appendix: source

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

        }
        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))
        .and_then(Item::as_str)
        .unwrap_or_default()
        .to_string()
}

fn item_string<T: TableLike + ?Sized>(table: &T, key: &str) -> String {

View on GitHub (pinned to b1ed92e5e4)