xai-org/grok-build · error
memory directory {:?} does not exist: {e}
Error message
memory directory {:?} does not exist: {e} What it means
In MemoryStorage::read_file, the global memory directory is canonicalized defensively before any path containment check. If dunce::canonicalize fails on global_dir, this NotFound io::Error is returned, naming the missing directory and the underlying error. It prevents reading from a storage root that does not exist.
Source
Thrown at crates/codegen/xai-grok-memory/src/storage.rs:270
}
/// Read a memory file, optionally returning only a range of lines.
///
/// - `from`: 0-based start line (default 0)
/// - `lines`: max number of lines to return (default: all)
///
/// The path must resolve (via `canonicalize`) to a location inside the memory directory tree.
/// Both the path and the memory root must be canonicalizable; if either fails, the read is rejected.
pub fn read_file(
&self,
path: &Path,
from: Option<usize>,
lines: Option<usize>,
) -> std::io::Result<String> {
// Security: canonicalize both sides; fail hard if either doesn't exist
let canonical = dunce::canonicalize(path)?;
let canonical_global = dunce::canonicalize(&self.global_dir).map_err(|e| {
std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("memory directory {:?} does not exist: {e}", self.global_dir),
)
})?;
// Fail-closed caveat for paths longer than MAX_PATH: see workspace clippy.toml
if !canonical.starts_with(&canonical_global) {
return Err(std::io::Error::new(
std::io::ErrorKind::PermissionDenied,
format!(
"path {:?} is outside the memory directory {:?}",
path, self.global_dir
),
));
}
// Read the canonicalized path, not the original, to prevent TOCTOU races.
let content = std::fs::read_to_string(&canonical)?;View on GitHub (pinned to bc7f02eddd)
Solutions
- Create the memory directory before reading (run the storage init/ensure routine)
- Point the storage configuration at an existing directory
- Verify HOME / grok-home env vars resolve to a real location
- Check the wrapped io error for permission vs missing-directory cause
Example fix
// before let content = storage.read_file(&path, None, None)?; // NotFound if global_dir missing // after std::fs::create_dir_all(&memory_dir)?; let content = storage.read_file(&path, None, None)?;
Defensive patterns
Strategy: validation
Validate before calling
let global_dir = storage.global_dir();
if !global_dir.is_dir() {
std::fs::create_dir_all(&global_dir)?;
} Try / catch
match storage.read_file(&path, None, None) {
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
std::fs::create_dir_all(storage.global_dir())?;
storage.read_file(&path, None, None)?
}
other => other?,
} Prevention
- Initialize/ensure the memory directory at storage construction
- Verify HOME / grok-home env vars resolve in service contexts
- Do not delete the memory root while storage instances are live
- Canonicalize the root once and reuse it
When it happens
Trigger: Calling read_file when the global memory directory has been deleted, was never created, or GROK home points at a non-existent location.
Common situations: Fresh machines/CI where ~/.grok/memory was never initialized; users deleting the memory dir manually; misconfigured HOME or GROK_* env pointing elsewhere.
Related errors
- NotFound
- Compaction checkpoint file missing: {checkpoint_path}. Canno
- Failed to set working directory to {:?}: {}
- clear failed
- failed to read {}: {e}
AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31).
Data as JSON: /api/errors/0fdf7f4d874eb69a.
Report an issue: GitHub.