Watch
1
0
Fork
You've already forked souveraine
0

memory: append creates the directory it writes into

write has always called create_dir_all; append never did, so an append under
a directory that did not exist yet failed ENOENT. Every subconscious surfacing
to system/metacognition/subconscious.md was lost this way — three WARNs at
00:01:40 on 2026-08-17, and the directory had never existed in the repo's
history.
This commit is contained in:
Fimeg 2026-08-17 08:40:35 -04:00
commit 06a1a035a6

View file

@ -492,6 +492,17 @@ impl MemoryRepo {
pub async fn append(&self, label: &str, content: &str) -> Result<()> {
let path = self.resolve_path(label);
// `write` has always created parent directories; `append` never did,
// so appending to a file under a directory that does not exist yet
// failed ENOENT. Measured 2026-08-17: every inner-voice surfacing to
// `system/metacognition/subconscious.md` was lost this way, because
// nothing ever created `system/metacognition/`.
if let Some(parent) = path.parent() {
tokio::fs::create_dir_all(parent)
.await
.context("creating parent directories")?;
}
// Frontmatter never belongs mid-file; merge it instead of nesting.
let (supplied, content) = split_supplied_frontmatter(content);
@ -1869,11 +1880,29 @@ mod tests {
}
#[tokio::test]
async fn test_memory_repo_list() {
async fn append_creates_missing_parent_directories() {
// The inner-voice path: nothing ever created `system/metacognition/`,
// so every append to it failed ENOENT and the surfacing was lost.
let dir = TempDir::new().unwrap();
let repo = MemoryRepo::new("test-agent", dir.path());
repo.init().await.unwrap();
repo.append("system/metacognition/subconscious.md", "a thought")
.await
.expect("append must create the parent directory");
let written = repo
.read("system/metacognition/subconscious.md")
.await
.unwrap();
assert!(written.body.contains("a thought"));
}
#[tokio::test]
async fn test_memory_repo_list() { let dir = TempDir::new().unwrap();
let repo = MemoryRepo::new("test-agent", dir.path());
repo.init().await.unwrap();
let entries = repo.list(None).await.unwrap();
assert!(entries.iter().any(|e| e == "system/"));
}