{"record":{"id":"c0498d7ff9b2f202","repo":"Hmbown/CodeWhale","slug":"unknown-sub-agent-transcript-artifact-record","errorCode":null,"errorMessage":"unknown sub-agent transcript artifact record","messagePattern":"unknown sub-agent transcript artifact record","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":8575,"sourceCode":"    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 {}\",\n                messages.len()\n            ));\n        }\n        let message = serde_json::from_value::<Message>(\n            record\n                .get(\"message\")\n                .cloned()\n                .ok_or_else(|| anyhow!(\"sub-agent transcript record is missing its message\"))?,\n        )?;","sourceCodeStart":8557,"sourceCodeEnd":8593,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L8557-L8593","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove or relocate the non-message lines from the artifact file","Use a reader matching the writer's schema version so new record kinds are understood","Restore the artifact from backup and re-run any post-processing into a separate file","Validate each line's `kind` before appending custom records"],"exampleFix":"// before\n{\"kind\":\"meta\",\"note\":\"compacted\"}\n// after\n{\"kind\":\"message\",\"index\":3,\"role\":\"user\",\"content\":\"...\"} // only kind==\"message\" records belong in the artifact","handlingStrategy":"validation","validationCode":"fn all_lines_are_message_records(raw: &str) -> bool {\n    raw.lines().skip(1).filter(|l| !l.trim().is_empty()).all(|l| {\n        serde_json::from_str::<serde_json::Value>(l).ok()\n            .and_then(|v| v.get(\"kind\").and_then(|k| k.as_str()).map(|k| k == \"message\").ok_or(())) == Ok(true)\n    })\n}","typeGuard":"fn is_message_record(v: &serde_json::Value) -> bool {\n    v.get(\"kind\").and_then(|k| k.as_str()) == Some(\"message\")\n}","tryCatchPattern":"match load_transcript(state_root, agent_id) {\n    Err(e) if e.to_string().contains(\"unknown sub-agent transcript artifact record\") => {\n        // find the offending line, move it to a sidecar file, retry\n        strip_foreign_lines_and_retry(state_root, agent_id)\n    }\n    r => r,\n}","preventionTips":["Never append custom/metadata lines to transcript artifacts; use a separate sidecar file","Validate `kind == \"message\"` in any script that post-processes artifacts","Use a matching reader version when artifacts were written by a newer writer"],"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"}