Hmbown/CodeWhale · error · anyhow::Error

sub-agent transcript artifact header does not match agent

Error message

sub-agent transcript artifact header does not match agent {agent_id}

What it means

The transcript artifact header must record kind "subagent_transcript_header", the expected schema_version, and the agent_id of the agent it belongs to. If any of these don't match, the file is either not a transcript for this agent or was written by an incompatible schema version, and loading is refused.

Solutions

  1. Load the artifact under the agent_id recorded in its own header, or move the file to the correct agent's directory
  2. Regenerate the transcript by re-running the subagent (old-schema artifacts are not upgraded in place)
  3. Restore the matching artifact version from backup if you need the old history
  4. Fix the header's kind/schema_version/agent_id fields to the expected values if you know the file is correct

Example fix

// before
{"kind":"subagent_transcript_header","schema_version":1,"agent_id":"old-id"}
// after
{"kind":"subagent_transcript_header","schema_version":2,"agent_id":"a1f3..."} // match expected schema version and agent id
Defensive patterns

Strategy: validation

Validate before calling

fn header_matches(raw: &str, agent_id: &str, expected_version: u64) -> Result<(), String> {
    let h: serde_json::Value = serde_json::from_str(raw.lines().next().ok_or("empty")?)?;
    let ok = h.get("kind").and_then(|v| v.as_str()) == Some("subagent_transcript_header")
        && h.get("schema_version").and_then(|v| v.as_u64()) == Some(expected_version)
        && h.get("agent_id").and_then(|v| v.as_str()) == Some(agent_id);
    if ok { Ok(()) } else { Err("header mismatch".into()) }
}

Type guard

fn is_valid_header(h: &serde_json::Value, agent_id: &str, version: u64) -> bool {
    h.get("kind").and_then(|v| v.as_str()) == Some("subagent_transcript_header")
        && h.get("schema_version").and_then(|v| v.as_u64()) == Some(version)
        && h.get("agent_id").and_then(|v| v.as_str()) == Some(agent_id)
}

Try / catch

match load_transcript(state_root, agent_id) {
    Err(e) if e.to_string().contains("header does not match") => {
        // inspect the header's agent_id/schema_version and route the file or migrate it
        inspect_and_relocate_artifact(state_root, agent_id)
    }
    r => r,
}

Prevention

When it happens

Trigger: Pointing the loader at a transcript file belonging to a different agent_id; reading artifacts written by an older/newer SUBAGENT_TRANSCRIPT_ARTIFACT_SCHEMA_VERSION; a malformed or hand-edited header line.

Common situations: State-root migration or backup restore mixing artifacts between agents; upgrading Codewhale and replaying old artifacts after a schema bump; a typo when editing the header manually.

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

Appendix: source

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

/// manager state root.
pub fn load_subagent_transcript_artifact(
    state_root: &Path,
    agent_id: &str,
) -> Result<Vec<Message>> {
    let state_root = normalize_subagent_workspace(state_root);
    let path = checked_subagent_transcript_artifact_path(&state_root, agent_id)?;
    let raw = read_subagent_state_file(&state_root, &path)?;
    let mut lines = raw.lines();
    let header_line = lines
        .next()
        .ok_or_else(|| anyhow!("sub-agent transcript artifact is empty"))?;
    let header: Value = serde_json::from_str(header_line)?;
    if header.get("kind").and_then(Value::as_str) != Some("subagent_transcript_header")
        || header.get("schema_version").and_then(Value::as_u64)
            != 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 {}",

View on GitHub (pinned to 73e0f67d83)