{"record":{"id":"2a1a2a4b6c42b334","repo":"Hmbown/CodeWhale","slug":"sub-agent-transcript-record-is-missing-its-message","errorCode":null,"errorMessage":"sub-agent transcript record is missing its message","messagePattern":"sub-agent transcript record is missing its message","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":8592,"sourceCode":"        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        )?;\n        messages.push(message);\n    }\n    Ok(messages)\n}\n\nfn remove_subagent_transcript_artifact(state_root: &Path, agent_id: &str) -> Result<bool> {\n    let state_root = normalize_subagent_workspace(state_root);\n    let path = checked_subagent_transcript_artifact_path(&state_root, agent_id)?;\n    reject_root_relative_symlinks(&state_root, &path)?;\n    let metadata = match fs::symlink_metadata(&path) {\n        Ok(metadata) => metadata,\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(false),\n        Err(err) => return Err(err.into()),\n    };\n    if metadata.file_type().is_symlink() || !metadata.file_type().is_file() {\n        return Err(anyhow!(\n            \"sub-agent transcript artifact is not a regular file: {}\",","sourceCodeStart":8574,"sourceCodeEnd":8610,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L8574-L8610","documentation":"Each record of a sub-agent transcript JSONL artifact must contain both an `index` and a `message` field. When a record lacks the `message` key, the parser cannot deserialize a `Message` for it and throws this error instead of letting serde produce a vaguer failure.","triggerScenarios":"Calling transcript-parsing code on a JSONL line that has an `index` but no `message` field — e.g. `serde_json::from_value` path where `record.get(\"message\")` returns `None`.","commonSituations":"A partially written or truncated last line in the JSONL file; manual editing dropped the message; a writer bug or schema change emitted metadata-only records; log rotation truncated lines.","solutions":["Open the transcript file and repair or delete the record that lacks a `message` field.","If the last line is truncated/partial, truncate the file at the last complete JSON line.","Regenerate the sub-agent session so a fresh, complete transcript is written.","If a custom tooling wrote the transcript, fix it to always emit both `index` and `message` per record."],"exampleFix":"// before (incomplete record)\n{\"index\":3}\n// after\n{\"index\":3,\"message\":{\"role\":\"assistant\",\"content\":\"...\"}}","handlingStrategy":"validation","validationCode":"// pre-check every record has a message\nlet complete = records.iter().all(|r| r.get(\"message\").map_or(false, |m| m.is_object()));\nif !complete { /* drop or repair incomplete records first */ }","typeGuard":"fn has_message(record: &Value) -> bool {\n    record.get(\"message\").map_or(false, |m| m.is_object())\n}","tryCatchPattern":null,"preventionTips":["Stop writers cleanly so the last JSONL line is never truncated mid-record.","Tolerate a torn final line by truncating to the last complete newline before parsing.","Keep writer and reader versions in sync on the record schema."],"tags":["subagent","transcript","missing-field","json"],"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"}