Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(store): hide edges touching an expired page from the cross-project graph
AkitaOnRails1478c2840ead
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 777c59c3..2e34707f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,11 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Fixed-- Hidden expired pages from `page_links` and `related_walk`, the graph- neighbour surfaces used by the web link panel and- `memory_read_page include_related`. Search, recent, briefing, and+- Fixed expired pages still showing in `page_links`, `related_walk` and+ `cross_project_edges`: the web link panel, `memory_read_page+ include_related`, and the web / `/api/v1` graph view now hide a page (and+ any edge touching it) once its TTL has passed. Search, recent, briefing, and`graph_neighbors_for_project` already applied the retrieval TTL- (`expires_at` is null or still in the future); these two queries only+ (`expires_at` is null or still in the future); these three queries onlyfiltered `is_latest`. An expired neighbour is neither returned norwalked through. Exact-path reads of an expired page are unchanged. (#1141)- Fixed the scheduled auto-improve tests' intermittent empty log capturesdiff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rsindex 41340008..750a5681 100644--- a/crates/ai-memory-store/src/reader.rs+++ b/crates/ai-memory-store/src/reader.rs@@ -7887,17 +7887,25 @@ impl ReaderPool {readable_repository_predicate("fp.project_id", viewer),readable_repository_predicate("tp.project_id", viewer),);- let base = format!(- "SELECT fw.name, fpr.name, fp.path, tw.name, tpr.name, tp.path \- FROM links l \- JOIN pages fp ON fp.id = l.from_page_id AND fp.is_latest = 1 \- JOIN pages tp ON tp.id = l.to_page_id AND tp.is_latest = 1 \- JOIN projects fpr ON fpr.id = fp.project_id \- JOIN workspaces fw ON fw.id = fp.workspace_id \- JOIN projects tpr ON tpr.id = tp.project_id \- JOIN workspaces tw ON tw.id = tp.workspace_id \- WHERE fp.project_id != tp.project_id{visible}"- );+ // An edge to or from an expired page is hidden like the page+ // itself (#1141); `now` is bound at the placeholder each query+ // passes in.+ let base = |now_param: &str| {+ format!(+ "SELECT fw.name, fpr.name, fp.path, tw.name, tpr.name, tp.path \+ FROM links l \+ JOIN pages fp ON fp.id = l.from_page_id AND fp.is_latest = 1{from_ttl} \+ JOIN pages tp ON tp.id = l.to_page_id AND tp.is_latest = 1{to_ttl} \+ JOIN projects fpr ON fpr.id = fp.project_id \+ JOIN workspaces fw ON fw.id = fp.workspace_id \+ JOIN projects tpr ON tpr.id = tp.project_id \+ JOIN workspaces tw ON tw.id = tp.workspace_id \+ WHERE fp.project_id != tp.project_id{visible}",+ from_ttl = not_expired("fp", now_param),+ to_ttl = not_expired("tp", now_param),+ )+ };+ let now = now_us();let map_row = |row: &rusqlite::Row<'_>| {Ok(CrossProjectEdge {from_workspace: row.get(0)?,@@ -7910,17 +7918,19 @@ impl ReaderPool {};let mut out = Vec::new();if let Some((_ws, proj)) = scope {- let sql =- format!("{base} AND (fp.project_id = ?1 OR tp.project_id = ?1) ORDER BY fw.name, fpr.name, fp.path");+ let sql = format!(+ "{} AND (fp.project_id = ?1 OR tp.project_id = ?1) ORDER BY fw.name, fpr.name, fp.path",+ base("?2")+ );let mut stmt = conn.prepare(&sql)?;- let rows = stmt.query_map(params![proj.as_bytes()], map_row)?;+ let rows = stmt.query_map(params![proj.as_bytes(), now], map_row)?;for r in rows {out.push(r?);}} else {- let sql = format!("{base} ORDER BY fw.name, fpr.name, fp.path");+ let sql = format!("{} ORDER BY fw.name, fpr.name, fp.path", base("?1"));let mut stmt = conn.prepare(&sql)?;- let rows = stmt.query_map([], map_row)?;+ let rows = stmt.query_map(params![now], map_row)?;for r in rows {out.push(r?);}diff --git a/crates/ai-memory-store/tests/suite/related_walk.rs b/crates/ai-memory-store/tests/suite/related_walk.rsindex 6c29f742..953990c6 100644--- a/crates/ai-memory-store/tests/suite/related_walk.rs+++ b/crates/ai-memory-store/tests/suite/related_walk.rs@@ -657,3 +657,84 @@ async fn page_links_hides_expired_neighbours() {"expired incoming neighbour is hidden; live backlink stays");}++/// The cross-project graph (`/api/v1/graph`, the web graph view) hides an+/// edge whose either end is expired, like every other retrieval surface:+/// an edge names both pages' paths. A live edge and one into a page whose+/// TTL is still in the future stay visible, scoped or not.+#[tokio::test]+async fn cross_project_edges_hide_edges_touching_an_expired_page() {+ let tmp = tempfile::tempdir().unwrap();+ let store = Store::open(tmp.path()).unwrap();+ let ws = store+ .writer+ .get_or_create_workspace("default".to_string())+ .await+ .unwrap();+ let app = store+ .writer+ .get_or_create_project(ws, "app".to_string(), None)+ .await+ .unwrap();+ let infra = store+ .writer+ .get_or_create_project(ws, "infra".to_string(), None)+ .await+ .unwrap();++ for page in [+ page_with_links(ws, infra, "runbooks/live.md", vec![]),+ with_expiry(+ page_with_links(ws, infra, "runbooks/expired.md", vec![]),+ expired_at(),+ ),+ with_expiry(+ page_with_links(ws, infra, "runbooks/future.md", vec![]),+ future_at(),+ ),+ page_with_links(+ ws,+ app,+ "notes/to_all.md",+ vec![+ cross_project_link("infra", "runbooks/live.md"),+ cross_project_link("infra", "runbooks/expired.md"),+ cross_project_link("infra", "runbooks/future.md"),+ ],+ ),+ with_expiry(+ page_with_links(+ ws,+ app,+ "notes/expired_from.md",+ vec![cross_project_link("infra", "runbooks/live.md")],+ ),+ expired_at(),+ ),+ ] {+ store.writer.upsert_page(page).await.unwrap();+ }++ for scope in [None, Some((ws, app))] {+ let edges = store.reader.cross_project_edges(scope, None).await.unwrap();+ let mut pairs: Vec<(String, String)> = edges+ .into_iter()+ .map(|e| (e.from_path, e.to_path))+ .collect();+ pairs.sort();+ assert_eq!(+ pairs,+ vec![+ (+ "notes/to_all.md".to_string(),+ "runbooks/future.md".to_string()+ ),+ (+ "notes/to_all.md".to_string(),+ "runbooks/live.md".to_string()+ ),+ ],+ "scope {scope:?}: edges touching an expired page must be hidden"+ );+ }+}