can1357/oh-my-pi · error
failed to create a unique fc temporary file
Error message
failed to create a unique fc temporary file
What it means
The fc builtin's temp-file creator loops attempting to create a uniquely named temporary file (e.g. /tmp/fc.XXXX); if every attempt collides with an existing file it gives up and returns io::ErrorKind::AlreadyExists with this message. It signals exhaustion of the naming space, not a single collision.
Source
Thrown at crates/pi-builtins/src/fc.rs:406
struct FcTempFile {
path: PathBuf,
}
impl FcTempFile {
fn create() -> Result<Self, brush_core::Error> {
let temp_dir = std::env::temp_dir();
let process_id = std::process::id();
for attempt in 0_u32..100 {
let path = temp_dir.join(format!("brush-fc-{process_id}-{attempt}.sh"));
match OpenOptions::new().write(true).create_new(true).open(&path) {
Ok(_) => return Ok(Self { path }),
Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => {},
Err(err) => return Err(err.into()),
}
}
Err(std::io::Error::new(
std::io::ErrorKind::AlreadyExists,
"failed to create a unique fc temporary file",
)
.into())
}
fn path(&self) -> &Path {
&self.path
}
}
impl Drop for FcTempFile {
fn drop(&mut self) {
let _ = fs::remove_file(&self.path);
}
}
fn shell_quote_path(path: &Path) -> String {View on GitHub (pinned to 9690622007)
Solutions
- Clean stale fc temp files from the temp directory, then retry
- Retry the command — transient collisions with concurrent sessions usually clear
- Use a per-user TMPDIR (TMPDIR=$HOME/.tmp fc ...) to isolate the naming space
- If persistent, inspect the temp path for permissions or a full filesystem (`df -h`, `ls -ld $TMPDIR`)
Example fix
// before TMPDIR=/shared-tmp fc -l // collisions with other users' files // after mkdir -p ~/.tmp && TMPDIR=$HOME/.tmp fc -l
Defensive patterns
Strategy: retry
Validate before calling
// pre-flight: ensure TMPDIR is writable and not saturatedlet md = std::fs::metadata(tmpdir)?;assert!(md.is_dir());let count = std::fs::read_dir(tmpdir)?.filter(|e| e.as_ref().unwrap().file_name().to_string_lossy().starts_with("fc.")).count();if count > 10_000 { clean_stale_fc_temps(tmpdir); } Try / catch
match FcTemp::create() { Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => { clean_stale_temps(); retry_with_backoff(3); }, Err(e) => return Err(e), Ok(t) => t } Prevention
- Give long-lived shells their own TMPDIR to shrink collision space
- Periodically clean stale fc.* temp files from shared temp dirs
- Keep the temp-creator's random name space large (don't shrink the suffix)
When it happens
Trigger: Many concurrent fc invocations racing for the same temp-name pattern, a stale directory full of fc.* leftovers, or a broken/predictable RNG making the same name every attempt.
Common situations: Heavily parallel shell sessions on shared /tmp, containers with tiny tmpfs and leftover files, or hardened /tmp with sticky-bit + quota issues preventing creation.
Related errors
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/79bade75a247524e.
Report an issue: GitHub.