BigPizzaV3/CodexPlusPlus · error · anyhow::Error

不支持的会话文件格式

Error message

不支持的会话文件格式

What it means

import_rollout validates the payload structure of the decrypted share and found it does not match the expected codex-rollout JSONL layout (missing kind/session fields). The content decrypted fine but is structurally not a session file this importer accepts.

Solutions

  1. Ensure the payload contains "kind": "codex-rollout" at the top level
  2. Generate the payload via export_rollout instead of hand-crafting it
  3. Check version compatibility between the producing and importing CodexPlusPlus versions

Example fix

// before
let payload = serde_json::json!({ "session_id": "...", "content": "..." });
import_rollout(&home, &payload)?;
// after
let payload = serde_json::json!({
    "kind": "codex-rollout",
    "session_id": "...",
    "content": "..."
});
import_rollout(&home, &payload)?;
Defensive patterns

Strategy: validation

Validate before calling

let v: serde_json::Value = serde_json::from_str(&raw)?;
if v.get("kind").and_then(|k| k.as_str()) != Some("codex-rollout") {
    anyhow::bail!("payload 缺少 kind=codex-rollout");
}

Type guard

fn is_rollout_payload(v: &serde_json::Value) -> bool {
    v.get("kind").and_then(serde_json::Value::as_str) == Some("codex-rollout")
}

Try / catch

match import_rollout(&home, &payload) {
    Err(e) if e.to_string().contains("不支持的会话文件格式") => eprintln!("请使用 export_rollout 生成的分享文件"),
    other => other?,
}

Prevention

When it happens

Trigger: Calling import_rollout(payload) directly with a payload lacking kind:"codex-rollout"; also reachable from import_shared_session_url / import_rollout_file when the decoded document is a different JSON shape.

Common situations: Sharing a hand-edited JSON file without the kind field; importing a payload from an older or newer share format version; passing an unrelated JSON document (e.g. settings or plain JSONL text) to the importer.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at crates/codex-plus-core/src/session_share.rs:203

    let path =
        find_rollout(home, session_id).ok_or_else(|| anyhow::anyhow!("找不到原生会话文件"))?;
    let bytes = fs::read(&path).with_context(|| format!("读取会话文件失败:{}", path.display()))?;
    if bytes.len() > MAX_ROLLOUT_BYTES {
        bail!("会话文件超过分享大小限制");
    }
    let content = String::from_utf8(bytes).context("会话文件不是有效的 UTF-8")?;
    Ok(json!({
        "status": "ok",
        "kind": "codex-rollout",
        "session_id": session_id,
        "content": content,
        "filename": path.file_name().and_then(|value| value.to_str()).unwrap_or("rollout.jsonl"),
    }))
}

pub fn import_rollout(home: &Path, payload: &Value) -> anyhow::Result<Value> {
    if payload.get("kind").and_then(Value::as_str) != Some("codex-rollout") {
        bail!("不支持的会话文件格式");
    }
    let source_id = payload
        .get("session_id")
        .and_then(Value::as_str)
        .unwrap_or_default();
    let content = payload
        .get("content")
        .and_then(Value::as_str)
        .unwrap_or_default();
    let title = payload
        .get("title")
        .and_then(Value::as_str)
        .unwrap_or("导入的会话")
        .trim();
    if source_id.is_empty() || content.is_empty() {
        bail!("会话文件内容不完整");
    }
    if content.len() > MAX_ROLLOUT_BYTES {

View on GitHub (pinned to b1ed92e5e4)