Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(reindex): identify missing scope manifests

lihuiyang10240cdf6fd1021a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6f92c69..d17954eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+- `ai-memory reindex` now names the exact missing or unreadable scope
+ `_meta.md` path instead of collapsing the filesystem error to a bare `No such
+ file or directory (os error 2)`. This makes the existing startup-backfill
+ workaround discoverable when a scope was first created during the server's
+ last run. (#643)
+
## [2.0.3] - 2026-09-04
### Changed
diff --git a/crates/ai-memory-wiki/src/wiki.rs b/crates/ai-memory-wiki/src/wiki.rs
index 07c3da74..9c642b80 100644
--- a/crates/ai-memory-wiki/src/wiki.rs
+++ b/crates/ai-memory-wiki/src/wiki.rs
@@ -1351,14 +1351,29 @@ impl Wiki {
/// Read a `_meta.md` scope-manifest's frontmatter from `dir`.
fn read_scope_meta(dir: &Path) -> WikiResult<serde_json::Value> {
let path = dir.join("_meta.md");
- let meta = std::fs::symlink_metadata(&path)?;
+ let meta = std::fs::symlink_metadata(&path).map_err(|error| {
+ let message = if error.kind() == std::io::ErrorKind::NotFound {
+ format!("scope manifest {} is missing", path.display())
+ } else {
+ format!(
+ "could not inspect scope manifest {}: {error}",
+ path.display()
+ )
+ };
+ WikiError::Io(std::io::Error::new(error.kind(), message))
+ })?;
if meta.file_type().is_symlink() {
return Err(WikiError::Io(std::io::Error::other(format!(
"refusing to read symlinked scope manifest {}",
path.display()
))));
}
- let raw = std::fs::read_to_string(path)?;
+ let raw = std::fs::read_to_string(&path).map_err(|error| {
+ WikiError::Io(std::io::Error::new(
+ error.kind(),
+ format!("could not read scope manifest {}: {error}", path.display()),
+ ))
+ })?;
Ok(parse(&raw)?.frontmatter)
}
@@ -4404,6 +4419,50 @@ mod tests {
assert!(healed.contains("type: Scope Manifest"), "{healed}");
}
+ #[tokio::test]
+ async fn reindex_names_a_missing_workspace_manifest() {
+ let tmp = TempDir::new().unwrap();
+ let store = Store::open(tmp.path()).unwrap();
+ let wiki = Wiki::new(tmp.path(), store.writer.clone()).unwrap();
+ let ws = WorkspaceId::new();
+ let proj = ProjectId::new();
+ let ws_dir = tmp.path().join("wiki").join(ws.to_string());
+ let missing = ws_dir.join("_meta.md");
+ std::fs::create_dir_all(ws_dir.join(proj.to_string())).unwrap();
+
+ let err = wiki.reindex_all().await.unwrap_err();
+
+ assert_eq!(
+ err.to_string(),
+ format!("scope manifest {} is missing", missing.display())
+ );
+ }
+
+ #[tokio::test]
+ async fn reindex_names_a_missing_project_manifest() {
+ let tmp = TempDir::new().unwrap();
+ let store = Store::open(tmp.path()).unwrap();
+ let wiki = Wiki::new(tmp.path(), store.writer.clone()).unwrap();
+ let ws = WorkspaceId::new();
+ let proj = ProjectId::new();
+ let ws_dir = tmp.path().join("wiki").join(ws.to_string());
+ let proj_dir = ws_dir.join(proj.to_string());
+ let missing = proj_dir.join("_meta.md");
+ std::fs::create_dir_all(&proj_dir).unwrap();
+ std::fs::write(
+ ws_dir.join("_meta.md"),
+ "---\nworkspace: acme\ntype: Scope Manifest\n---\n",
+ )
+ .unwrap();
+
+ let err = wiki.reindex_all().await.unwrap_err();
+
+ assert_eq!(
+ err.to_string(),
+ format!("scope manifest {} is missing", missing.display())
+ );
+ }
+
#[cfg(any(unix, windows))]
#[tokio::test]
async fn reindex_rejects_symlinked_scope_manifest() {
diff --git a/docs/lifecycle-ops.md b/docs/lifecycle-ops.md
index 65161ed3..74a5605a 100644
--- a/docs/lifecycle-ops.md
+++ b/docs/lifecycle-ops.md
@@ -731,6 +731,10 @@ volume.
ai-memory reindex --data-dir <path>
```
+If reindex reports a missing scope `_meta.md`, the error includes its exact
+path. Restore the original DB, start and stop the current server once so its
+startup backfill writes missing manifests, then retry against a clean DB.
+
Direct-disk lifecycle operation. Refuses if any sibling `ai-memory` process is
alive, and also refuses if SQLite already contains rows. `reindex` is a
rebuild-from-files path, not an in-place dirty-index repair.