Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(profile): ignore TTL-expired pages when deciding a project is new
Rudy Celekli171925e51d64
diff --git a/crates/ai-memory-store/src/profile.rs b/crates/ai-memory-store/src/profile.rsindex 25de9556..a6d51eac 100644--- a/crates/ai-memory-store/src/profile.rs+++ b/crates/ai-memory-store/src/profile.rs@@ -190,18 +190,24 @@ pub(crate) fn project_stack_tags(Ok(tags)}-/// Whether a project has any current page: a project without one is new, and-/// gets the larger baseline digest.+/// Whether a project has any current, unexpired page: a project without one is+/// new, and gets the larger baseline digest. A project whose every page has+/// passed its TTL reads as new, the same way the digest's own reads skip+/// expired pages.pub(crate) fn project_has_pages(conn: &Connection,workspace_id: WorkspaceId,project_id: ProjectId,) -> StoreResult<bool> {+ let sql = format!(+ "SELECT 1 FROM pages WHERE workspace_id = ?1 AND project_id = ?2 \+ AND is_latest = 1{not_expired} LIMIT 1",+ not_expired = not_expired("pages", "?3"),+ );Ok(conn.query_row(- "SELECT 1 FROM pages WHERE workspace_id = ?1 AND project_id = ?2 \- AND is_latest = 1 LIMIT 1",- params![workspace_id.as_bytes(), project_id.as_bytes()],+ &sql,+ params![workspace_id.as_bytes(), project_id.as_bytes(), now_us()],|_| Ok(()),).optional()?diff --git a/crates/ai-memory-store/tests/suite/profile.rs b/crates/ai-memory-store/tests/suite/profile.rsindex ac2ecb21..17a12b1f 100644--- a/crates/ai-memory-store/tests/suite/profile.rs+++ b/crates/ai-memory-store/tests/suite/profile.rs@@ -413,3 +413,57 @@ async fn digest_inputs_read_entries_stack_and_newness() {);assert!(inputs.project_has_pages);}++/// Newness honours the TTL, both directions. A project whose every page has+/// passed its `expires_at` is as new as one that never had a page: its pages+/// are already hidden from every other digest read, so counting them would+/// halve the digest budget and suppress the `profile apply` offer for a+/// project with nothing left to show. A single live page still counts.+#[tokio::test]+async fn expired_pages_do_not_make_a_project_look_established() {+ let tmp = tempfile::tempdir().unwrap();+ let store = Store::open(tmp.path()).unwrap();+ let ws = default_workspace(&store).await;+ let global = ai_memory_store::create_global_scope(&store.writer)+ .await+ .unwrap();+ let app = store+ .writer+ .get_or_create_project(ws, "app".to_owned(), None)+ .await+ .unwrap();++ let mut expired = profile_page(ws, app, "notes/stale.md", "# Stale\n\nlong gone");+ expired.expires_at = Some(jiff::Timestamp::from_second(1).unwrap());+ store.writer.upsert_page(expired).await.unwrap();++ let inputs = store+ .reader+ .profile_digest_inputs(global.as_tuple(), (ws, app))+ .await+ .unwrap();+ assert!(+ !inputs.project_has_pages,+ "a project whose every page has expired is still new"+ );++ store+ .writer+ .upsert_page(profile_page(+ ws,+ app,+ "notes/live.md",+ "# Live\n\nstill here",+ ))+ .await+ .unwrap();+ let inputs = store+ .reader+ .profile_digest_inputs(global.as_tuple(), (ws, app))+ .await+ .unwrap();+ assert!(+ inputs.project_has_pages,+ "one unexpired page means the project has memory"+ );+}