{"record":{"id":"d56276e5b18301a8","repo":"Hmbown/CodeWhale","slug":"sub-agent-transcript-artifact-is-empty","errorCode":null,"errorMessage":"sub-agent transcript artifact is empty","messagePattern":"sub-agent transcript artifact is empty","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":8559,"sourceCode":"        &subagent_transcript_artifact_relative_path(agent_id),\n    )\n}\n\n/// Read the complete structured worker chat for the TUI Open action. The path\n/// is derived from `agent_id` rather than accepted from handle JSON, so a\n/// corrupted or model-supplied payload cannot redirect the reader outside the\n/// 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","sourceCodeStart":8541,"sourceCodeEnd":8577,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L8541-L8577","documentation":"When loading a sub-agent transcript artifact (a JSON-lines file), the first line must be the transcript header. If the file contains no lines at all, the loader cannot even validate the header and throws this error.","triggerScenarios":"Reading a zero-byte transcript artifact file under the subagent state root — e.g. the file was created (touch/truncate) but the header was never written, a crashed writer, or an interrupted first write.","commonSituations":"Manual cleanup or log rotation that truncated the file; a crash between file creation and header flush; copying an empty placeholder file during state migration.","solutions":["Delete the empty artifact and let the sub-agent recreate its transcript (or restore from a backup)","Check the writer/parent process logs for a crash before the header was flushed and re-run the agent","Re-spawn the subagent session; the transcript is rebuilt","If editing by hand, write a valid header line first: {\"kind\":\"subagent_transcript_header\",\"schema_version\":<N>,\"agent_id\":\"...\"}"],"exampleFix":"// before\n$ : > subagent-a1f3.transcript  # truncates -> loader error\n// after\n$ rm subagent-a1f3.transcript   # let the runtime recreate it with a valid header","handlingStrategy":"validation","validationCode":"fn transcript_artifact_readable(path: &Path) -> Result<(), String> {\n    let meta = std::fs::metadata(path).map_err(|e| e.to_string())?;\n    if meta.len() == 0 { Err(\"transcript artifact is empty\".into()) } else { Ok(()) }\n}","typeGuard":"fn is_nonempty_file(path: &Path) -> bool {\n    std::fs::metadata(path).map(|m| m.len() > 0).unwrap_or(false)\n}","tryCatchPattern":"match load_transcript(state_root, agent_id) {\n    Err(e) if e.to_string().contains(\"artifact is empty\") => recreate_transcript(state_root, agent_id), // delete + respawn\n    r => r,\n}","preventionTips":["Never truncate or `touch` transcript artifact files manually","Back up artifacts before migrations or state-root changes","Check writer logs for crashes between file creation and header flush"],"tags":["subagent","rust","file"],"backgroundTag":"empty-required-field","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"}