{"record":{"id":"4ee4d527829d77a8","repo":"Hmbown/CodeWhale","slug":"sub-agent-state-path-must-include-a-file-name","errorCode":null,"errorMessage":"sub-agent state path must include a file name","messagePattern":"sub-agent state path must include a file name","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/subagent/mod.rs","lineNumber":8651,"sourceCode":"    // is migrated on load (see load_state).\n    checked_subagent_state_path(\n        &state_root,\n        &Path::new(\".codewhale\")\n            .join(\"state\")\n            .join(SUBAGENT_STATE_FILE),\n    )\n}\n\nfn checked_subagent_state_path(state_root: &Path, path: &Path) -> Result<PathBuf> {\n    let state_root = normalize_subagent_workspace(state_root);\n    let absolute = if path.is_absolute() {\n        path.to_path_buf()\n    } else {\n        state_root.join(path)\n    };\n    let file_name = absolute\n        .file_name()\n        .ok_or_else(|| anyhow!(\"sub-agent state path must include a file name\"))?;\n    let parent = absolute\n        .parent()\n        .ok_or_else(|| anyhow!(\"sub-agent state path must include a parent directory\"))?;\n    // Resolve through the deepest existing ancestor so Windows short/long names\n    // and verbatim (`\\\\?\\`) spellings match the already-canonical state root.\n    // A missing parent used to fall back to lexical normalization and could keep\n    // an 8.3 component (for example `RUNNER~1`) that no longer prefixes the root.\n    let parent = resolve_path_for_containment(parent)?;\n    let state_path = parent.join(file_name);\n    if !path_is_within_state_root(&state_path, &state_root) {\n        return Err(anyhow!(\n            \"sub-agent state path must stay within state root: {}\",\n            state_path.display()\n        ));\n    }\n    reject_root_relative_symlinks(&state_root, &state_path)?;\n    Ok(state_path)\n}","sourceCodeStart":8633,"sourceCodeEnd":8669,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/tools/subagent/mod.rs#L8633-L8669","documentation":"Sub-agent state paths are canonicalized against a state root and must name an actual file: `Path::file_name()` must return `Some`. A path that ends in `..`, is a bare drive/root prefix, or otherwise has no final component cannot be joined onto a resolved parent, so the library rejects it.","triggerScenarios":"Calling a sub-agent state API with a path like `/state/dir/..`, `C:\\`, or any path whose final component is empty, so `absolute.file_name()` is `None`.","commonSituations":"Building the state path by string concatenation that ends with a separator or `..`; passing a directory instead of a file path; constructing paths programmatically from config values with trailing slashes.","solutions":["Pass a path ending in an actual file name, e.g. `state/session.json` instead of `state/session.json/` or `state/..`.","Normalize the path before calling (strip trailing separators and `.`/`..` components).","If you have a directory, append the intended file name before invoking the API.","Check config-driven path construction for trailing separators or `.` components."],"exampleFix":"// before\nlet path = Path::new(\"/state/subagent/..\");\n// after\nlet path = Path::new(\"/state/subagent/session.json\");","handlingStrategy":"validation","validationCode":"fn state_path_has_file_name(p: &std::path::Path) -> bool {\n    p.file_name().is_some()\n}\n// guard before calling: state_path_has_file_name(&path)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Strip trailing separators and `.`/`..` from configured state paths.","Always express state paths as `<dir>/<file>`, never a bare directory or root.","Add a config sanity check that rejects root/`..`-terminated paths."],"tags":["subagent","path","validation"],"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"}