astrid-runtime/astrid · error
failed to persist {}: {e}
Error message
failed to persist {}: {e} What it means
write_pin writes the trusted distro public key into the Astrid home trust store atomically: it stages the pin in a NamedTempFile, removes any existing pin, then calls tempfile's persist() to rename it into place. This error means the final rename/replace failed (PersistError), so the trust pin was not applied even though the key itself may have been verified.
Source
Thrown at crates/astrid-cli/src/commands/distro/trust.rs:117
}
let mut tmp = tempfile::NamedTempFile::new_in(path.parent().unwrap_or(home.root()))
.context("failed to create temp file for trust pin")?;
std::io::Write::write_all(&mut tmp, format!("{key_str}\n").as_bytes())
.context("failed to write trust pin staging")?;
// Windows `rename` (which `persist` uses) won't overwrite an existing
// destination, so re-pinning (`--accept-new-key`) would fail there.
// Remove any existing pin first; a missing file is expected and fine.
match std::fs::remove_file(&path) {
Ok(()) => {},
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {},
Err(e) => {
return Err(e).with_context(|| {
format!("failed to replace existing trust pin {}", path.display())
});
},
}
tmp.persist(&path)
.map_err(|e| anyhow::anyhow!("failed to persist {}: {e}", path.display()))?;
Ok(())
}
/// Verify a sealed distro's signature and apply the trust policy.
///
/// `manifest_pubkey` is the `[distro.signing].pubkey` declared in the
/// manifest. `sig_hex` is the `Distro.sig` contents. `lock` is the
/// resolved lock the signature covers.
///
/// # Errors
///
/// - signature does not verify (no override),
/// - key differs from the pin and `accept_new_key` is false,
/// - no trust pin exists,
/// - malformed key/signature.
pub(crate) fn verify_and_pin(
home: &AstridHome,
distro_id: &str,View on GitHub (pinned to affd8760f4)
Solutions
- Check free disk space and retry the distro apply / pin command.
- Fix permissions on the trust directory under the Astrid home (chown/chmod to the running user).
- Close processes locking the target file (AV, sync clients) or add the Astrid home to exclusions.
- Remove the existing pin file manually and re-run with --accept-new-key.
Example fix
# before $ astrid distro apply my-distro --accept-new-key Error: failed to persist /home/u/.astrid/trust/my-distro.key: ... # after $ chmod u+w ~/.astrid/trust && rm -f ~/.astrid/trust/my-distro.key $ astrid distro apply my-distro --accept-new-key
Defensive patterns
Strategy: try-catch
Validate before calling
let trust_dir = path.parent().unwrap();
if !trust_dir.exists() { std::fs::create_dir_all(trust_dir)?; }
let meta = std::fs::metadata(trust_dir)?;
assert!(meta.permissions().readonly() == false, "trust dir is read-only"); Try / catch
match verify_and_pin(...) {
Ok(outcome) => info!("pinned: {:?}", outcome),
Err(e) if e.to_string().contains("failed to persist") => {
eprintln!("could not write trust pin (disk/permissions/lock?): {e}");
},
Err(e) => return Err(e),
} Prevention
- Run astrid under a user that owns ~/.astrid.
- Exclude the astrid home directory from AV and file-sync tools.
- Keep free disk headroom on the home volume.
- Prefer native filesystems over network mounts for the astrid home.
When it happens
Trigger: verify_and_pin -> write_pin when persist(&path) fails: destination locked by another process (antivirus/indexer holding the file, especially on Windows rename semantics), permissions on the trust directory changed mid-write, target path re-created between remove_file and persist, disk full, or the Astrid home directory was made read-only.
Common situations: Running the CLI under a different user than the one owning ~/.astrid; syncing tools (Dropbox/OneDrive) locking trust files; corporate EDR/antivirus intercepting renames in the home directory; full disk while applying a distro.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- layout record has no parent
- layout record has no file name
- layout staging path is redirected: {}
- durable layout records are unsupported on this operating sys
- private atomic-file backend is selected by Windows callers o
AI-assisted analysis of astrid-runtime/astrid@affd8760f4 (2026-09-09).
Data as JSON: /api/errors/0649d3f340d0cee3.
Report an issue: GitHub.