Hmbown/CodeWhale · error · anyhow::Error

unknown sub-agent transcript artifact record

Error message

unknown sub-agent transcript artifact record

What it means

Every non-empty line after the header in a transcript artifact must be a record with kind "message". Any other record kind makes the artifact unreadable by this loader, so it fails with this error rather than skipping unknown data.

Solutions

  1. Remove or relocate the non-message lines from the artifact file
  2. Use a reader matching the writer's schema version so new record kinds are understood
  3. Restore the artifact from backup and re-run any post-processing into a separate file
  4. Validate each line's `kind` before appending custom records

Example fix

// before
{"kind":"meta","note":"compacted"}
// after
{"kind":"message","index":3,"role":"user","content":"..."} // only kind=="message" records belong in the artifact
Defensive patterns

Strategy: validation

Validate before calling

fn all_lines_are_message_records(raw: &str) -> bool {
    raw.lines().skip(1).filter(|l| !l.trim().is_empty()).all(|l| {
        serde_json::from_str::<serde_json::Value>(l).ok()
            .and_then(|v| v.get("kind").and_then(|k| k.as_str()).map(|k| k == "message").ok_or(())) == Ok(true)
    })
}

Type guard

fn is_message_record(v: &serde_json::Value) -> bool {
    v.get("kind").and_then(|k| k.as_str()) == Some("message")
}

Try / catch

match load_transcript(state_root, agent_id) {
    Err(e) if e.to_string().contains("unknown sub-agent transcript artifact record") => {
        // find the offending line, move it to a sidecar file, retry
        strip_foreign_lines_and_retry(state_root, agent_id)
    }
    r => r,
}

Prevention

When it happens

Trigger: A transcript file containing a line whose JSON has kind != "message" — e.g. lines from a future schema version, foreign records injected by another tool, or hand-appended junk lines.

Common situations: Post-processing scripts appending metadata lines into the artifact; mixing artifacts across Codewhale versions where newer writers emit extra record kinds; corrupted/partial JSON lines parsed with an unexpected shape.

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

Appendix: source

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

    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 {}",
                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"))?,
        )?;

View on GitHub (pinned to 73e0f67d83)