{"record":{"id":"076dcb26f3a85117","repo":"tinyhumansai/openhuman","slug":"failed-to-atomically-write-file-e","errorCode":null,"errorMessage":"Failed to atomically write {file}: {e}","messagePattern":"Failed to atomically write (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/openhuman/tools/impl/filesystem/update_memory_md.rs","lineNumber":128,"sourceCode":"\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\n    if let Err(e) = tokio::fs::rename(&tmp_path, path).await {\n        // Best-effort cleanup so a failed rename doesn't litter the workspace.\n        let _ = tokio::fs::remove_file(&tmp_path).await;\n        return Err(anyhow::anyhow!(\"Failed to atomically write {file}: {e}\"));\n    }\n\n    tracing::debug!(\n        target = %path.display(),\n        \"[update_memory_md] atomic write: rename committed\"\n    );\n    Ok(())\n}\n\n/// Appends or replaces a named section in MEMORY.md or SKILL.md.\n///\n/// Supports two actions:\n/// - `append`: adds `content` to the end of the file.\n/// - `replace_section`: locates the first `## {section_title}` heading and\n///   replaces the body (lines until the next `##` heading or EOF) with `content`.\npub struct UpdateMemoryMdTool {\n    workspace_dir: PathBuf,\n}","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/tools/impl/filesystem/update_memory_md.rs#L110-L146","documentation":"The final rename of the staged temp file over the target failed with the OS error {e}, breaking the atomic replace. The temp file was written successfully but the swap did not happen; the target still holds its previous (complete) contents.","triggerScenarios":"Thrown at src/openhuman/tools/impl/filesystem/update_memory_md.rs:128 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read {e}: cross-device errors mean the temp file left the target's filesystem","Check permissions on the target file/directory","Retry after resolving; leftover .tmp siblings are safe to remove"],"exampleFix":null,"handlingStrategy":"retry","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"}