Hmbown/CodeWhale · error · anyhow::Error
sub-agent state path must include a parent directory
Error message
sub-agent state path must include a parent directory
What it means
After requiring a file-name component, the resolver calls `Path::parent()` to obtain the directory that will be canonicalized for containment checking. A path with no parent (e.g. a bare relative file name or a filesystem root) cannot be processed, so this error is thrown. It is a sibling guard to the file-name check and rarely fires alone.
Solutions
- Provide a fully qualified path including its directory, e.g. `<state_root>/session.json`.
- Join the file name onto the state root yourself before calling the API.
- Verify config values so the state path never resolves to a bare file name or root.
- Ensure the path is absolute (or rooted under the configured state root) before calling.
Example fix
// before
resolve_state_path(state_root, Path::new("session.json"))
// after
resolve_state_path(state_root, &state_root.join("session.json")) Defensive patterns
Strategy: validation
Validate before calling
fn state_path_has_parent(p: &std::path::Path) -> bool {
p.parent().is_some() && p.file_name().is_some()
}
// guard: state_path_has_parent(&path) Prevention
- Join bare file names onto the state root before calling the API.
- Never pass `/` or a drive root as a state path.
- Validate that configured state paths are absolute with a directory component.
When it happens
Trigger: Calling a sub-agent state API with a path that has no parent component — e.g. `Path::new("session.json")` after resolution, or a root path like `/`.
Common situations: Passing just a file name relative to the process CWD expecting the library to resolve it against the state root; passing `/` or a drive root directly; misconfigured state path that collapses to a root.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- sub-agent state path must include a file name
- budget baseline_receipt path changed
- Checkpoint continuation requires a source agent
- Codewhale credentials directory has an unsupported component
- Codewhale credentials directory must be lexically normalized
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/5fa2823a5def88c0.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/tools/subagent/mod.rs:8654
&Path::new(".codewhale")
.join("state")
.join(SUBAGENT_STATE_FILE),
)
}
fn checked_subagent_state_path(state_root: &Path, path: &Path) -> Result<PathBuf> {
let state_root = normalize_subagent_workspace(state_root);
let absolute = if path.is_absolute() {
path.to_path_buf()
} else {
state_root.join(path)
};
let file_name = absolute
.file_name()
.ok_or_else(|| anyhow!("sub-agent state path must include a file name"))?;
let parent = absolute
.parent()
.ok_or_else(|| anyhow!("sub-agent state path must include a parent directory"))?;
// Resolve through the deepest existing ancestor so Windows short/long names
// and verbatim (`\\?\`) spellings match the already-canonical state root.
// A missing parent used to fall back to lexical normalization and could keep
// an 8.3 component (for example `RUNNER~1`) that no longer prefixes the root.
let parent = resolve_path_for_containment(parent)?;
let state_path = parent.join(file_name);
if !path_is_within_state_root(&state_path, &state_root) {
return Err(anyhow!(
"sub-agent state path must stay within state root: {}",
state_path.display()
));
}
reject_root_relative_symlinks(&state_root, &state_path)?;
Ok(state_path)
}
/// Canonicalize `path` when it exists; otherwise canonicalize the deepest
/// existing ancestor and re-append the missing tail. Keeps containment checksView on GitHub (pinned to 73e0f67d83)