Skip to content

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

Rust

fix(hooks): treat a Windows drive root as a broad session anchor

Rudy Celekliac193715c3bc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fee7fa0b..d2f988ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,10 @@ version in [`docs/changelog/`](docs/changelog/):
## [Unreleased]
### Fixed
+- Stopped a session started at a Windows drive root (`C:\`) from capturing
+ every later event on that drive through session stickiness. The broad-anchor
+ guard refused only `/` and `$HOME`; a drive root normalizes to `c:`, so any
+ `C:\...` cwd counted as inside the session and was folded into its project.
- Fixed `memory_lint` reporting findings for TTL-expired pages. The lint pass
now omits expired pages before evaluating episodic staleness, rule suggestions,
duplicate titles, and vector or LLM contradiction candidates, preventing
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 37ac77b6..bec3d375 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -3339,7 +3339,12 @@ fn sticky_within_session_tree(
fn meaningful_session_anchor(session_cwd: Option<&str>, home_dir: Option<&str>) -> Option<String> {
let session_cwd = session_cwd.filter(|s| !s.trim().is_empty())?;
let session_norm = normalize_project_path_key(session_cwd);
- if session_norm == "/" {
+ // The filesystem root, in each spelling it normalizes to: `/`, a bare
+ // Windows drive (`C:\` becomes `c:`), or nothing at all (`//`). Every
+ // path on that root would start with it.
+ let bytes = session_norm.as_bytes();
+ let drive_root = bytes.len() == 2 && bytes[0].is_ascii_alphabetic() && bytes[1] == b':';
+ if session_norm == "/" || session_norm.is_empty() || drive_root {
return None;
}
if let Some(home) = home_dir
@@ -6934,6 +6939,33 @@ pub(crate) mod tests {
Some(r"c:\users\alice\repo"),
Some(r"C:\Users\alice"),
));
+ // A session rooted at a Windows drive root (or a cwd that
+ // normalizes to nothing) is the filesystem root too: every path on
+ // the drive would fold into it.
+ for root in [r"C:\", "C:/", "c:", "//", r"\\"] {
+ assert!(
+ !sticky_within_session_tree(
+ Some(root),
+ Some(r"C:\work\other-project"),
+ Some(r"C:\Users\alice"),
+ ),
+ "{root:?} must not anchor a session"
+ );
+ assert!(
+ !sticky_out_of_tree_under_repo_root(
+ Some(root),
+ Some(r"C:\Users\alice"),
+ ProjectStrategy::RepoRoot,
+ ),
+ "{root:?} must not anchor a session"
+ );
+ }
+ // A real directory on the drive still anchors.
+ assert!(sticky_within_session_tree(
+ Some(r"C:\work"),
+ Some(r"c:\work\repo"),
+ Some(r"C:\Users\alice"),
+ ));
}
// Out-of-tree stickiness is scoped to `repo-root` and keeps the