Record memory storage size after successful consolidation (#45956)

## What changed

Emit a `codex.memory.storage_bytes` histogram after successful phase-two consolidation, including runs with no workspace changes. Sum regular-file sizes recursively from filesystem metadata, excluding `.git` entries and symbolic links. Stop the phase-two duration timer before measuring storage.

## Testing

Add coverage for both memory versions, nested files, UTF-8 byte counts, Git metadata exclusion, and Unix symbolic links, including broken links and directory loops. Extend the workspace baseline reset test to verify the remaining storage size.

GitOrigin-RevId: 9170c34d656728897790decd2e2cabb38a81836f
This commit is contained in:
jif authored and copyberry committed 2026-09-16 14:49:24 +00:00
1 parent 4701aa4b42
commit 6500c1f844
5 files changed
+102 -3

No files matched your search

@@ -48,12 +48,51 @@ async fn reset_memory_workspace_baseline_removes_generated_diff() {
.expect("reset baseline");
assert!(!root.join(crate::workspace_diff::FILENAME).exists());
assert_eq!(memory_storage_bytes(&root).await.expect("storage size"), 6);
let diff = memory_workspace_diff(&root)
.await
.expect("load workspace diff");
assert_eq!(diff.changes, Vec::new());
}
#[tokio::test]
async fn memory_storage_size_counts_nested_files_but_not_git_or_symlinks() -> anyhow::Result<()> {
let home = TempDir::new()?;
for version in [MemoryVersion::V1, MemoryVersion::V2] {
let root = home.path().join(version.directory_name());
fs::create_dir_all(root.join("rollout_summaries"))?;
fs::create_dir_all(root.join("extensions/notes"))?;
fs::create_dir_all(root.join(".git/objects"))?;
fs::write(
root.join(".git/objects/baseline"),
"git metadata is not memory",
)?;
let files = [
("memory_summary.md", "summary"),
("rollout_summaries/thread.md", "rollout"),
("extensions/notes/note.md", "café"),
];
for (path, content) in files {
fs::write(root.join(path), content)?;
}
#[cfg(unix)]
{
use std::os::unix::fs::symlink;
symlink(root.join("memory_summary.md"), root.join("file-link"))?;
symlink(&root, root.join("directory-loop"))?;
symlink(root.join("missing"), root.join("broken-link"))?;
}
assert_eq!(
memory_storage_bytes(&root).await?,
files
.iter()
.map(|(_, content)| content.len() as u64)
.sum::<u64>(),
);
}
Ok(())
}
#[tokio::test]
async fn prepare_memory_workspace_recovers_unusable_git_dir() {
let home = TempDir::new().expect("tempdir");