Hmbown/CodeWhale · error · anyhow::Error

sub-agent transcript message is missing its index

Error message

sub-agent transcript message is missing its index

What it means

Sub-agent transcript artifact parsing: a 'message' record in the JSONL artifact lacks its index field, so message ordering cannot be reconstructed; loading fails rather than presenting a misordered transcript.

Solutions

  1. Add a correct integer `index` field to the offending record (0-based, sequential)
  2. Renumber all records sequentially from 0 if indexes are missing across the file
  3. Restore the artifact from backup and let the runtime rewrite it

Example fix

// before
{"kind":"message","role":"user","content":"hi"}
// after
{"kind":"message","index":0,"role":"user","content":"hi"}
Defensive patterns

Strategy: validation

Validate before calling

fn record_has_sequential_index(v: &serde_json::Value, expected: usize) -> Result<(), String> {
    let idx = v.get("index").and_then(|i| i.as_u64()).and_then(|i| usize::try_from(i).ok()).ok_or("missing index")?;
    if idx == expected { Ok(()) } else { Err(format!("index {idx} != expected {expected}")) }
}

Type guard

fn has_valid_index(v: &serde_json::Value, expected: usize) -> bool {
    v.get("index").and_then(|i| i.as_u64()).and_then(|i| usize::try_from(i).ok()) == Some(expected)
}

Try / catch

match load_transcript(state_root, agent_id) {
    Err(e) if e.to_string().contains("missing its index") => renumber_and_reload(state_root, agent_id),
    r => r,
}

Prevention

When it happens

Trigger: A message record line in the artifact missing the `index` field, or with an index that is not a u64 (e.g. a string, null, or negative) — typically from a hand-edited or externally generated record.

Common situations: Custom tooling writing transcript lines without the index field; manual edits dropping a field; serialization from a different record type that lacks the field.

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 Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/04f42aba1883c7b1. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/tools/subagent/mod.rs:8581

            != Some(u64::from(SUBAGENT_TRANSCRIPT_ARTIFACT_SCHEMA_VERSION))
        || header.get("agent_id").and_then(Value::as_str) != Some(agent_id)
    {
        return Err(anyhow!(
            "sub-agent transcript artifact header does not match agent {agent_id}"
        ));
    }

    let mut messages = Vec::new();
    for line in lines.filter(|line| !line.trim().is_empty()) {
        let record: Value = serde_json::from_str(line)?;
        if record.get("kind").and_then(Value::as_str) != Some("message") {
            return Err(anyhow!("unknown sub-agent transcript artifact record"));
        }
        let index = record
            .get("index")
            .and_then(Value::as_u64)
            .and_then(|value| usize::try_from(value).ok())
            .ok_or_else(|| anyhow!("sub-agent transcript message is missing its index"))?;
        if index != messages.len() {
            return Err(anyhow!(
                "sub-agent transcript message index {index} does not follow {}",
                messages.len()
            ));
        }
        let message = serde_json::from_value::<Message>(
            record
                .get("message")
                .cloned()
                .ok_or_else(|| anyhow!("sub-agent transcript record is missing its message"))?,
        )?;
        messages.push(message);
    }
    Ok(messages)
}

fn remove_subagent_transcript_artifact(state_root: &Path, agent_id: &str) -> Result<bool> {

View on GitHub (pinned to 73e0f67d83)