{"record":{"id":"5b14ab62470f3e8d","repo":"tinyhumansai/openhuman","slug":"target-path-has-no-parent-directory","errorCode":null,"errorMessage":"target path has no parent directory","messagePattern":"target path has no parent directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/openhuman/tools/impl/filesystem/update_memory_md.rs","lineNumber":106,"sourceCode":"        file.lock_exclusive()\n            .map_err(|e| anyhow::anyhow!(\"acquire workspace write flock: {e}\"))?;\n        Ok::<std::fs::File, anyhow::Error>(file)\n    })\n    .await\n    .map_err(|e| anyhow::anyhow!(\"workspace lock task join failed: {e}\"))?\n}\n\n/// Atomically replace `path`'s contents with `content`.\n///\n/// Writes to a sibling temp file in the same directory (so the rename stays on\n/// one filesystem and is atomic) and `rename`s it over the target. A crash\n/// mid-write leaves either the old file or the complete new file — never a\n/// half-written truncation. Callers MUST hold the per-workspace write lock so\n/// the read-modify-write is serialized end-to-end.\nasync fn atomic_write(path: &Path, file: &str, content: &str) -> anyhow::Result<()> {\n    let dir = path\n        .parent()\n        .ok_or_else(|| anyhow::anyhow!(\"target path has no parent directory\"))?;\n    let seq = TEMP_FILE_SEQ.fetch_add(1, Ordering::Relaxed);\n    let tmp_name = format!(\".{file}.{}.{seq}.tmp\", std::process::id());\n    let tmp_path = dir.join(tmp_name);\n\n    tracing::debug!(\n        tmp = %tmp_path.display(),\n        target = %path.display(),\n        bytes = content.len(),\n        \"[update_memory_md] atomic write: staging temp file\"\n    );\n\n    if let Err(e) = tokio::fs::write(&tmp_path, content).await {\n        // Clean up a partially-written temp file so a failed stage doesn't\n        // litter the workspace (CodeRabbit: temp not cleaned on initial write).\n        let _ = tokio::fs::remove_file(&tmp_path).await;\n        return Err(anyhow::anyhow!(\"Failed to stage temp file for {file}: {e}\"));\n    }\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/tools/impl/filesystem/update_memory_md.rs#L88-L124","documentation":"Atomic-write helper guard: the target file path has no parent directory component (it resolves to a filesystem root), so no sibling temp file can be staged for the rename-based atomic replace. A path-shape problem, not a permission one.","triggerScenarios":"Thrown at src/openhuman/tools/impl/filesystem/update_memory_md.rs:106 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a real file path with a directory component rather than a bare root","Use a path under the workspace memory directory"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}