Skip to content

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

Rust

test(consolidate): cover expired page omission in lint findings

Vinícius DS Andradef006720fb55e
diff --git a/crates/ai-memory-consolidate/src/lint.rs b/crates/ai-memory-consolidate/src/lint.rs
index eb59fe44..8e507abb 100644
--- a/crates/ai-memory-consolidate/src/lint.rs
+++ b/crates/ai-memory-consolidate/src/lint.rs
@@ -1093,6 +1093,75 @@ mod tests {
);
}
+ #[test]
+ fn rule_pass_skips_expired_pages() {
+ let past = Timestamp::now().as_microsecond() - 1_000_000;
+ let very_old = Timestamp::now().as_microsecond() - (90 * 86_400_000_000i64);
+ let expired_episodic = DecayCandidate {
+ id: ai_memory_core::PageId::new(),
+ path: ai_memory_core::PagePath::new("sessions/old.md").unwrap(),
+ tier: Tier::Episodic,
+ pinned: false,
+ updated_at_us: very_old,
+ access_count: 0,
+ last_accessed_at_us: None,
+ frontmatter_json: "{}".into(),
+ expires_at_us: Some(past),
+ salience: None,
+ compacted_at_us: None,
+ };
+ let expired_rule = DecayCandidate {
+ id: ai_memory_core::PageId::new(),
+ path: ai_memory_core::PagePath::new("_rules/expired.md").unwrap(),
+ tier: Tier::Semantic,
+ pinned: false,
+ updated_at_us: very_old,
+ access_count: 0,
+ last_accessed_at_us: None,
+ frontmatter_json: r#"{"kind": "rule"}"#.into(),
+ expires_at_us: Some(past),
+ salience: None,
+ compacted_at_us: None,
+ };
+ let live_page = DecayCandidate {
+ id: ai_memory_core::PageId::new(),
+ path: ai_memory_core::PagePath::new("concepts/live.md").unwrap(),
+ tier: Tier::Semantic,
+ pinned: false,
+ updated_at_us: Timestamp::now().as_microsecond(),
+ access_count: 1,
+ last_accessed_at_us: None,
+ frontmatter_json: r#"{"title": "Shared Title"}"#.into(),
+ expires_at_us: None,
+ salience: None,
+ compacted_at_us: None,
+ };
+ let expired_duplicate = DecayCandidate {
+ id: ai_memory_core::PageId::new(),
+ path: ai_memory_core::PagePath::new("concepts/expired-dupe.md").unwrap(),
+ tier: Tier::Semantic,
+ pinned: false,
+ updated_at_us: very_old,
+ access_count: 0,
+ last_accessed_at_us: None,
+ frontmatter_json: r#"{"title": "Shared Title"}"#.into(),
+ expires_at_us: Some(past),
+ salience: None,
+ compacted_at_us: None,
+ };
+ let candidates = vec![
+ expired_episodic,
+ expired_rule,
+ live_page,
+ expired_duplicate,
+ ];
+ let findings = rule_based_findings(&candidates, STALE_DAYS);
+ assert!(
+ findings.is_empty(),
+ "expired pages must not produce stale, rule_suggestion, or duplicate findings: {findings:?}"
+ );
+ }
+
// ── LintFinding tolerant deserialization ─────────────────────────────
/// The old prompt used `summary`/`detail` instead of `message` and
diff --git a/crates/ai-memory-consolidate/tests/suite/contradiction_lint.rs b/crates/ai-memory-consolidate/tests/suite/contradiction_lint.rs
index 7e0f6a19..9860f802 100644
--- a/crates/ai-memory-consolidate/tests/suite/contradiction_lint.rs
+++ b/crates/ai-memory-consolidate/tests/suite/contradiction_lint.rs
@@ -322,3 +322,56 @@ async fn no_embeddings_is_a_clean_no_op() {
without_coord.findings
);
}
+
+/// An expired semantic page in the contradiction band must not produce a
+/// contradiction finding against an active page.
+#[tokio::test]
+async fn contradiction_pass_skips_expired_pages() {
+ let fx = seed_fixture().await;
+ let live = write_semantic(
+ &fx,
+ "concepts/live-claim.md",
+ "The retry budget is 5.",
+ )
+ .await;
+ let expired = write_semantic(
+ &fx,
+ "concepts/expired-claim.md",
+ "The retry budget is 3.",
+ )
+ .await;
+ seed_embedding(&fx, live, &[1.0, 0.0]);
+ seed_embedding(&fx, expired, &[0.6, 0.8]);
+
+ {
+ let conn = rusqlite::Connection::open(fx.tmp.path().join("db/memory.sqlite")).unwrap();
+ conn.pragma_update(None, "busy_timeout", 5_000).unwrap();
+ conn.execute(
+ "UPDATE pages SET expires_at = 1 \
+ WHERE workspace_id = ?1 AND project_id = ?2 AND path = ?3 AND is_latest = 1",
+ params![
+ fx.ws.as_bytes(),
+ fx.proj.as_bytes(),
+ "concepts/expired-claim.md"
+ ],
+ )
+ .unwrap();
+ }
+
+ let report = run_lint(
+ &fx.store.reader,
+ &fx.wiki,
+ None,
+ fx.ws,
+ fx.proj,
+ options(coord()),
+ )
+ .await
+ .unwrap();
+
+ assert!(
+ !report.findings.iter().any(|f| f.kind == "contradiction"),
+ "expired pages must not produce contradiction findings: {:?}",
+ report.findings
+ );
+}