{"record":{"id":"49cc9f6cd957cb5c","repo":"astrid-runtime/astrid","slug":"alreadyexists-49cc9f","errorCode":"AlreadyExists","errorMessage":"could not allocate a unique private staging path","messagePattern":"could not allocate a unique private staging path","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/astrid-core/src/platform_fs/windows/io.rs","lineNumber":350,"sourceCode":"            validate_private_acl_handle(\n                output.as_raw_handle().cast(),\n                false,\n                &temporary.display().to_string(),\n            )\n        })();\n        if let Err(error) = write_result {\n            drop(output);\n            let _ = remove_guarded_file(guard, &temporary);\n            return Err(error);\n        }\n        if let Err(error) = guard.verify() {\n            drop(output);\n            let _ = remove_guarded_file(guard, &temporary);\n            return Err(error);\n        }\n        return Ok((temporary, output));\n    }\n    Err(io::Error::new(\n        io::ErrorKind::AlreadyExists,\n        \"could not allocate a unique private staging path\",\n    ))\n}\n\npub(super) fn replace_file_checked(\n    guard: &TrustedPathGuard,\n    live: &Path,\n    replacement: &Path,\n) -> io::Result<()> {\n    #[cfg(test)]\n    if let Some(result) = test_rename_fault() {\n        return result;\n    }\n    rename_guarded_file(guard, replacement, live, true).map_err(|error| {\n        with_context(\n            error,\n            format!(","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-core/src/platform_fs/windows/io.rs#L332-L368","documentation":"stage_unique_bytes_with_share tries up to 16 times to create a fresh private temp file named `.{label}.{uuid}.tmp` in the parent directory. If every attempt collides with an existing file (create_guarded_private_file_with_share returns AlreadyExists), it gives up with this AlreadyExists error. With UUID names this almost never happens naturally, so it usually signals something pathologically wrong with the parent directory or name generation.","triggerScenarios":"Called via stage_unique_bytes / stage_unique_bytes_retained; raised only after all 16 create attempts fail with AlreadyExists. Possible with an extremely large number of leftover `.label.*.tmp` files, a filesystem/plugin that reports AlreadyExists for unrelated failures (e.g. antivirus blocking creation), or a guarded-path verification problem surfacing as a collision.","commonSituations":"Accumulated orphaned temp files from thousands of interrupted runs filling the collision space; a broken security product returning spurious ERROR_ALREADY_EXISTS on every create; a read-only or misconfigured parent directory whose error is misreported by a filter driver.","solutions":["Delete orphaned `.{label}.*.tmp` files in the staging/parent directory and retry.","Investigate antivirus/security filter drivers that may be interfering with file creation; add exclusions for the staging directory.","Check filesystem health and permissions on the parent directory (it must be writable and support exclusive creation).","Upgrade/report to the library maintainers if it persists — 16 UUID collisions in a row indicates an environment bug, not a name-space issue."],"exampleFix":"// before: leaving failed temp files behind forever\nlet tmp = stage_unique_bytes(&guard, &parent, &bytes, \"payload\")?; // 16 collisions -> AlreadyExists\n// after: clean stale temp files first\nfor entry in fs::read_dir(&parent)? {\n    let p = entry?.path();\n    if p.file_name().map_or(false, |n| n.to_string_lossy().starts_with(\".payload.\"))\n        && p.extension().map_or(false, |e| e == \"tmp\")\n    {\n        let _ = fs::remove_file(&p);\n    }\n}\nlet tmp = stage_unique_bytes(&guard, &parent, &bytes, \"payload\")?;","handlingStrategy":"validation","validationCode":"// Rust: ensure the parent dir is writable and free of stale temp files before staging\nlet probe = parent.join(\".write_probe\");\nfs::File::create(&probe)?;\nfs::remove_file(&probe)?;\nfor entry in fs::read_dir(&parent)? {\n    let p = entry?.path();\n    if let Some(n) = p.file_name().and_then(|n| n.to_str()) {\n        if n.starts_with(&format!(\".{label}.\")) && n.ends_with(\".tmp\") {\n            let _ = fs::remove_file(&p); // clear collision space\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"// Rust\nmatch stage_unique_bytes(&guard, &parent, &bytes, \"payload\") {\n    Ok(path) => use(path),\n    Err(e) if e.kind() == io::ErrorKind::AlreadyExists\n        && e.to_string().contains(\"unique private staging path\") => {\n        clean_stale_temp_files(&parent, \"payload\");\n        stage_unique_bytes(&guard, &parent, &bytes, \"payload\") // one retry\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Periodically purge orphaned .label.*.tmp files from staging directories.","Verify the staging directory is writable before starting batches of operations.","Investigate AV/filter drivers if AlreadyExists errors cluster on the same machine.","Alert on high counts of temp files — they indicate interrupted transactions."],"tags":["windows","filesystem","temp-file","already-exists","staging"],"backgroundTag":"file-already-exists","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}