Skip to content

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

Rust

test(store): cover observation FTS drift (#392)

AkitaOnRailsfd2e7c30b0d5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 489fec5a..c2818794 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
indexed documents instead of content-table rows. Both FTS tables use external
content, so `SELECT COUNT(*)` against them was answered from `pages` /
`observations` and the `fts: N/M` health pair could never diverge, no matter
- how far the index had drifted.
+ how far the index had drifted (#392).
## [1.26.0] - 2026-08-12
diff --git a/crates/ai-memory-store/tests/fts_drift_status.rs b/crates/ai-memory-store/tests/fts_drift_status.rs
index f326277c..2242000c 100644
--- a/crates/ai-memory-store/tests/fts_drift_status.rs
+++ b/crates/ai-memory-store/tests/fts_drift_status.rs
@@ -6,7 +6,10 @@
//! it. Counting the `_docsize` shadow table is what turns the `fts: N/M`
//! status pair into a drift check instead of a tautology.
-use ai_memory_core::{NewPage, PagePath, Tier};
+use ai_memory_core::{
+ AgentKind, NewObservation, NewPage, NewSession, ObservationKind, PagePath, Sanitized,
+ Sanitizer, SessionId, Tier,
+};
use ai_memory_store::Store;
#[tokio::test]
@@ -76,3 +79,82 @@ async fn page_fts_rows_report_index_drift() {
"the status pair must surface the drift, not mirror the content table",
);
}
+
+#[tokio::test]
+async fn observation_fts_rows_report_index_drift() {
+ 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 proj = store
+ .writer
+ .get_or_create_project(ws, "app".to_string(), None)
+ .await
+ .unwrap();
+ let session_id = SessionId::new();
+ store
+ .writer
+ .begin_session(NewSession {
+ id: session_id,
+ workspace_id: ws,
+ project_id: proj,
+ agent_kind: AgentKind::Codex,
+ cwd: None,
+ actor_user: None,
+ })
+ .await
+ .unwrap();
+ store
+ .writer
+ .insert_observation(Sanitized::new(
+ NewObservation {
+ session_id,
+ workspace_id: ws,
+ project_id: proj,
+ kind: ObservationKind::UserPrompt,
+ extension: None,
+ source_event: None,
+ title: "prompt".into(),
+ body: "bravo zebra".into(),
+ importance: 5,
+ },
+ &Sanitizer::builtin(),
+ ))
+ .await
+ .unwrap();
+
+ let before = store.reader.derived_index_status().await.unwrap();
+ assert_eq!(before.observations_rows, 1);
+ assert_eq!(
+ before.observations_fts_rows, 1,
+ "a freshly written observation is indexed",
+ );
+
+ {
+ let conn = rusqlite::Connection::open(store.db_path()).unwrap();
+ conn.execute(
+ "INSERT INTO observations_fts(observations_fts, rowid, title, body) \
+ SELECT 'delete', rowid, title, body FROM observations",
+ [],
+ )
+ .unwrap();
+ let hits: i64 = conn
+ .query_row(
+ "SELECT COUNT(*) FROM observations_fts WHERE observations_fts MATCH 'bravo'",
+ [],
+ |row| row.get(0),
+ )
+ .unwrap();
+ assert_eq!(hits, 0, "the entry really left the index");
+ }
+
+ let after = store.reader.derived_index_status().await.unwrap();
+ assert_eq!(after.observations_rows, 1, "the source row is untouched");
+ assert_eq!(
+ after.observations_fts_rows, 0,
+ "the status pair must surface the drift, not mirror the content table",
+ );
+}