openai/codex · error · std::io::Error
refusing to clear symlinked memory root
Error message
refusing to clear symlinked memory root {} What it means
clear_memory_root_contents refuses to wipe a memory root (CODEX_HOME/memories or memories_extensions) that is a symbolic link. Deleting through a symlink would destroy the link target's contents, so the destructive clear operation aborts when symlink_metadata reports a link.
Solutions
- Inspect the symlink and replace it with a real directory if the layout is intended
- Point CODEX_HOME at a non-symlinked directory
- Remove the symlink manually and let codex recreate the directory structure
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at codex-rs/memories/write/src/control.rs:17 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of openai/codex@339751715c (2026-08-25).
Data as JSON: /api/errors/1a4522f35c7cd74e.
Report an issue: GitHub.
Appendix: source
Thrown at codex-rs/memories/write/src/control.rs:17
use std::path::Path;
pub async fn clear_memory_roots_contents(codex_home: &Path) -> std::io::Result<()> {
for memory_root in [
codex_home.join("memories"),
codex_home.join("memories_extensions"),
] {
clear_memory_root_contents(memory_root.as_path()).await?;
}
Ok(())
}
pub(crate) async fn clear_memory_root_contents(memory_root: &Path) -> std::io::Result<()> {
match tokio::fs::symlink_metadata(memory_root).await {
Ok(metadata) if metadata.file_type().is_symlink() => {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!(
"refusing to clear symlinked memory root {}",
memory_root.display()
),
));
}
Ok(_) => {}
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {}
Err(err) => return Err(err),
}
tokio::fs::create_dir_all(memory_root).await?;
let mut entries = tokio::fs::read_dir(memory_root).await?;
while let Some(entry) = entries.next_entry().await? {
let path = entry.path();
let file_type = entry.file_type().await?;View on GitHub (pinned to 339751715c)