BigPizzaV3/CodexPlusPlus · error

model_windows 的模型 窗口值无效:

Error message

model_windows 的模型 {slug} 窗口值无效:{value}

What it means

validate_model_windows checks each (slug, window) pair in the model_windows map by parsing the value with parse_window_token. If a value is not a recognized window token (e.g. "1M", "256k" format), the function bails naming the offending model slug and value, preventing an invalid suffix from being written into model_list.

Solutions

  1. Use a supported window token format (e.g. "1M", "256k") matching model_suffix::parse_window_token's grammar
  2. Normalize imported values before inserting them into model_windows
  3. Add UI-side validation mirroring parse_window_token so bad values are caught at entry

Example fix

// before
model_windows.insert("deepseek-v4-pro".into(), "1,000,000".into());
// after
model_windows.insert("deepseek-v4-pro".into(), "1M".into());
Defensive patterns

Strategy: validation

Validate before calling

fn valid_window(v: &str) -> bool {
    crate::model_suffix::parse_window_token(v).is_some()
}

Type guard

fn is_window_token(v: &str) -> bool {
    crate::model_suffix::parse_window_token(v).is_some()
}

Try / catch

match apply_relay_profile(...) {
    Err(e) if e.to_string().contains("窗口值无效") => show_window_format_hint(e),
    other => other?,
}

Prevention

When it happens

Trigger: Calling the apply/validate path with model_windows containing a value like "1,000,000", "100mb", "abc", or a lowercase/wrong-unit token that parse_window_token rejects.

Common situations: User typed a raw token count or a unit the parser doesn't accept into the per-model window field; values imported from another tool use a different suffix format; locale-formatted numbers with commas.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at crates/codex-plus-core/src/relay_config.rs:2121

        .map_err(|error| anyhow::anyhow!("{field_name} JSON 解析失败:{error}"))?;
    let object = parsed
        .as_object()
        .ok_or_else(|| anyhow::anyhow!("{field_name} 必须是 JSON 对象"))?;
    object
        .iter()
        .map(|(key, value)| {
            let value = value
                .as_str()
                .ok_or_else(|| anyhow::anyhow!("{field_name} 的模型 {key} 值必须是字符串"))?;
            Ok((key.clone(), value.to_string()))
        })
        .collect()
}

fn validate_model_windows(model_windows: &HashMap<String, String>) -> anyhow::Result<()> {
    for (slug, value) in model_windows {
        if crate::model_suffix::parse_window_token(value).is_none() {
            anyhow::bail!("model_windows 的模型 {slug} 窗口值无效:{value}");
        }
    }
    Ok(())
}

fn validate_model_auto_compact(model_auto_compact: &HashMap<String, String>) -> anyhow::Result<()> {
    for (slug, value) in model_auto_compact {
        if crate::model_suffix::parse_compact_percent(value).is_none() {
            anyhow::bail!("model_auto_compact 的模型 {slug} 百分比无效:{value}");
        }
    }
    Ok(())
}

fn parse_model_metadata_map(metadata_json: &str) -> anyhow::Result<serde_json::Map<String, Value>> {
    if metadata_json.trim().is_empty() {
        return Ok(serde_json::Map::new());
    }

View on GitHub (pinned to b1ed92e5e4)