BigPizzaV3/CodexPlusPlus · error · anyhow::Error

会话文件内容不完整

Error message

会话文件内容不完整

What it means

import_rollout requires both a non-empty source session_id and non-empty rollout content; if either is missing the shared file is deemed incomplete and rejected. This guards against writing a corrupted/empty session into the Codex home.

Solutions

  1. Re-export the session with export_rollout to obtain a complete payload
  2. Verify the share URL/file was not truncated (check content length) before importing
  3. Include a non-empty session_id when constructing the payload manually

Example fix

// before
let payload = json!({ "kind": "codex-rollout", "session_id": "", "content": data });
// after
if source_id.is_empty() || content.is_empty() {
    anyhow::bail!("分享内容缺失 session_id 或 content");
}
let payload = json!({ "kind": "codex-rollout", "session_id": source_id, "content": content });
Defensive patterns

Strategy: validation

Validate before calling

if payload.get("session_id").and_then(|v| v.as_str()).unwrap_or("").trim().is_empty()
    || payload.get("content").and_then(|v| v.as_str()).unwrap_or("").is_empty()
{
    anyhow::bail!("分享内容不完整");
}

Type guard

fn is_complete_payload(v: &serde_json::Value) -> bool {
    !v.get("session_id").and_then(serde_json::Value::as_str).unwrap_or("").trim().is_empty()
        && !v.get("content").and_then(serde_json::Value::as_str).unwrap_or("").is_empty()
}

Prevention

When it happens

Trigger: import_rollout(payload) where payload.session_id is empty/absent or the content string is empty; also reachable via import_shared_session_url / import_rollout_file for such payloads.

Common situations: Truncated share payload (content stripped during copy/paste); exported file whose content field was lost in transit; payload built manually without session_id.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

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 {
        bail!("会话文件超过导入大小限制");
    }
    let new_id = Uuid::new_v4().to_string();
    let rewritten = rewrite_rollout(content, source_id, &new_id)?;
    let now = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .unwrap_or_default()
        .as_secs();
    let directory = home.join("sessions").join("imported");
    fs::create_dir_all(&directory).context("创建会话目录失败")?;
    let path = directory.join(format!("rollout-{now}-{new_id}.jsonl"));
    fs::write(&path, rewritten).context("写入导入会话失败")?;

    register_imported_thread(home, &new_id, &path, title, content, now)?;

    let index_path = home.join("session_index.jsonl");

View on GitHub (pinned to b1ed92e5e4)