{"record":{"id":"18cf283d8518026e","repo":"Hmbown/CodeWhale","slug":"sub-agent-transcript-artifact-must-have-a-parent-d","errorCode":null,"errorMessage":"sub-agent transcript artifact must have a parent directory","messagePattern":"sub-agent transcript artifact must have a parent directory","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":8957,"sourceCode":"    use std::os::unix::fs::OpenOptionsExt;\n\n    fs::OpenOptions::new()\n        .read(true)\n        .custom_flags(libc::O_NOFOLLOW)\n        .open(path)\n        .map_err(Into::into)\n}\n\n#[cfg(not(unix))]\nfn open_subagent_state_file(path: &Path) -> Result<fs::File> {\n    fs::File::open(path).map_err(Into::into)\n}\n\nfn prepare_subagent_transcript_parent(state_root: &Path, path: &Path) -> Result<()> {\n    reject_root_relative_symlinks(state_root, path)?;\n    let parent = path\n        .parent()\n        .ok_or_else(|| anyhow!(\"sub-agent transcript artifact must have a parent directory\"))?;\n    fs::create_dir_all(parent)?;\n    // Re-check after creation so a pre-existing component cannot redirect the\n    // private transcript outside the state root.\n    reject_root_relative_symlinks(state_root, path)?;\n    #[cfg(unix)]\n    {\n        use std::os::unix::fs::PermissionsExt;\n        fs::set_permissions(parent, fs::Permissions::from_mode(0o700))?;\n    }\n    Ok(())\n}\n\nfn create_private_subagent_transcript(state_root: &Path, path: &Path, bytes: &[u8]) -> Result<()> {\n    prepare_subagent_transcript_parent(state_root, path)?;\n    let mut file = open_private_subagent_transcript(path, false)?;\n    file.write_all(bytes)?;\n    file.sync_all()?;\n    Ok(())","sourceCodeStart":8939,"sourceCodeEnd":8975,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L8939-L8975","documentation":"prepare_subagent_transcript_parent ensures the parent directory of a transcript artifact exists before writing it, after first rejecting root-relative symlink escapes from the state root. Path::parent() returns None only for a path with no parent component (e.g. a bare relative name or a root path), which the code treats as invalid and refuses with this anyhow error. This guards against writing transcripts to an ambiguous location.","triggerScenarios":"Passing a transcript artifact path with no parent directory component — a bare filename relative to no directory (like \"transcript.jsonl\" at a root) or a filesystem root itself — into the sub-agent transcript preparation path.","commonSituations":"A caller building the transcript path from an empty config value or from string joining that dropped the directory component, yielding a bare filename or \"/\".","solutions":["Pass a full artifact path that includes its directory, e.g. <state_root>/transcripts/<session>.jsonl","Check the configuration value that supplies the transcript path — it is likely empty or root-only","Normalize the path before the call so it always resolves under a concrete directory"],"exampleFix":"// before\nlet artifact = Path::new(\"transcript.jsonl\");\n// after\nlet artifact = state_root.join(\"transcripts\").join(\"session-42.jsonl\");","handlingStrategy":"validation","validationCode":"if path.parent().is_none() {\n    return Err(\"transcript artifact path must include a parent directory\".into());\n}","typeGuard":"fn has_parent(path: &Path) -> bool {\n    path.parent().map(|p| !p.as_os_str().is_empty()).unwrap_or(false)\n}","tryCatchPattern":"match prepare_transcript(&state_root, &path) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"parent directory\") =>\n        return Err(anyhow!(\"invalid transcript path {:?}: use <dir>/<file>\", path)),\n    Err(e) => return Err(e),\n}","preventionTips":["Always build artifact paths by joining a directory component under the state root","Never pass bare filenames or root paths as artifact targets","Validate configured transcript paths at load time"],"tags":["subagent","path","transcript"],"backgroundTag":"invalid-argument-value","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"}