{"record":{"id":"d24db2db089c246a","repo":"Hmbown/CodeWhale","slug":"sub-agent-transcript-artifact-header-does-not-matc","errorCode":null,"errorMessage":"sub-agent transcript artifact header does not match agent {agent_id}","messagePattern":"sub-agent transcript artifact header does not match agent (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":8566,"sourceCode":"/// manager state root.\npub fn load_subagent_transcript_artifact(\n    state_root: &Path,\n    agent_id: &str,\n) -> Result<Vec<Message>> {\n    let state_root = normalize_subagent_workspace(state_root);\n    let path = checked_subagent_transcript_artifact_path(&state_root, agent_id)?;\n    let raw = read_subagent_state_file(&state_root, &path)?;\n    let mut lines = raw.lines();\n    let header_line = lines\n        .next()\n        .ok_or_else(|| anyhow!(\"sub-agent transcript artifact is empty\"))?;\n    let header: Value = serde_json::from_str(header_line)?;\n    if header.get(\"kind\").and_then(Value::as_str) != Some(\"subagent_transcript_header\")\n        || header.get(\"schema_version\").and_then(Value::as_u64)\n            != Some(u64::from(SUBAGENT_TRANSCRIPT_ARTIFACT_SCHEMA_VERSION))\n        || header.get(\"agent_id\").and_then(Value::as_str) != Some(agent_id)\n    {\n        return Err(anyhow!(\n            \"sub-agent transcript artifact header does not match agent {agent_id}\"\n        ));\n    }\n\n    let mut messages = Vec::new();\n    for line in lines.filter(|line| !line.trim().is_empty()) {\n        let record: Value = serde_json::from_str(line)?;\n        if record.get(\"kind\").and_then(Value::as_str) != Some(\"message\") {\n            return Err(anyhow!(\"unknown sub-agent transcript artifact record\"));\n        }\n        let index = record\n            .get(\"index\")\n            .and_then(Value::as_u64)\n            .and_then(|value| usize::try_from(value).ok())\n            .ok_or_else(|| anyhow!(\"sub-agent transcript message is missing its index\"))?;\n        if index != messages.len() {\n            return Err(anyhow!(\n                \"sub-agent transcript message index {index} does not follow {}\",","sourceCodeStart":8548,"sourceCodeEnd":8584,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L8548-L8584","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Load the artifact under the agent_id recorded in its own header, or move the file to the correct agent's directory","Regenerate the transcript by re-running the subagent (old-schema artifacts are not upgraded in place)","Restore the matching artifact version from backup if you need the old history","Fix the header's kind/schema_version/agent_id fields to the expected values if you know the file is correct"],"exampleFix":"// before\n{\"kind\":\"subagent_transcript_header\",\"schema_version\":1,\"agent_id\":\"old-id\"}\n// after\n{\"kind\":\"subagent_transcript_header\",\"schema_version\":2,\"agent_id\":\"a1f3...\"} // match expected schema version and agent id","handlingStrategy":"validation","validationCode":"fn header_matches(raw: &str, agent_id: &str, expected_version: u64) -> Result<(), String> {\n    let h: serde_json::Value = serde_json::from_str(raw.lines().next().ok_or(\"empty\")?)?;\n    let ok = h.get(\"kind\").and_then(|v| v.as_str()) == Some(\"subagent_transcript_header\")\n        && h.get(\"schema_version\").and_then(|v| v.as_u64()) == Some(expected_version)\n        && h.get(\"agent_id\").and_then(|v| v.as_str()) == Some(agent_id);\n    if ok { Ok(()) } else { Err(\"header mismatch\".into()) }\n}","typeGuard":"fn is_valid_header(h: &serde_json::Value, agent_id: &str, version: u64) -> bool {\n    h.get(\"kind\").and_then(|v| v.as_str()) == Some(\"subagent_transcript_header\")\n        && h.get(\"schema_version\").and_then(|v| v.as_u64()) == Some(version)\n        && h.get(\"agent_id\").and_then(|v| v.as_str()) == Some(agent_id)\n}","tryCatchPattern":"match load_transcript(state_root, agent_id) {\n    Err(e) if e.to_string().contains(\"header does not match\") => {\n        // inspect the header's agent_id/schema_version and route the file or migrate it\n        inspect_and_relocate_artifact(state_root, agent_id)\n    }\n    r => r,\n}","preventionTips":["After upgrades, check SUBAGENT_TRANSCRIPT_ARTIFACT_SCHEMA_VERSION before replaying old artifacts","Keep each agent's artifacts in its own directory keyed by agent_id","Never hand-edit header fields; regenerate the transcript instead"],"tags":["subagent","rust","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}