Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(store): date Created from the supersedes chain, without a migration
AkitaOnRails8f17deab5b1a
diff --git a/crates/ai-memory-store/migrations/V77__pages_path_created_index.sql b/crates/ai-memory-store/migrations/V77__pages_path_created_index.sqldeleted file mode 100644index 20f80edb..00000000--- a/crates/ai-memory-store/migrations/V77__pages_path_created_index.sql+++ /dev/null@@ -1,6 +0,0 @@--- V77: serve the page header's "Created" (the oldest retained version of a--- path). idx_pages_latest_path is partial on is_latest = 1, so it cannot answer--- MIN(created_at) over a page's superseded versions; without this index every--- page view scanned all versions in the project.-CREATE INDEX idx_pages_path_created- ON pages(workspace_id, project_id, path, created_at);diff --git a/crates/ai-memory-store/src/api_credentials.rs b/crates/ai-memory-store/src/api_credentials.rsindex 9fa0ba20..471cdc6c 100644--- a/crates/ai-memory-store/src/api_credentials.rs+++ b/crates/ai-memory-store/src/api_credentials.rs@@ -411,7 +411,7 @@ mod tests {|row| row.get(0),).unwrap();- assert_eq!(version, 77, "update the pin when adding a migration");+ assert_eq!(version, 76, "update the pin when adding a migration");let cols: i64 = conn.query_row("SELECT COUNT(*) FROM pragma_table_info('users') WHERE name = 'token_hash'",diff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rsindex 54f83052..e5d68659 100644--- a/crates/ai-memory-store/src/reader.rs+++ b/crates/ai-memory-store/src/reader.rs@@ -10460,16 +10460,20 @@ fn health_page_from_row(row: &rusqlite::Row<'_>) -> rusqlite::Result<HealthPage>/// SQL for [`PageMeta::created_at`]: when the page itself first appeared.////// `pages.created_at` is per version, so the latest row alone would report the-/// last rewrite. Every version shares `(workspace_id, project_id, path)`;-/// the earliest retained one is the page's creation instant, which also-/// follows a tombstone-resurrected page onto its old chain (#929). Versions-/// removed by retention or ledger reclaim no longer count. Served by-/// `idx_pages_path_created`.+/// last rewrite. The page's versions form its `supersedes` chain (a+/// tombstone-resurrected page is re-linked onto its old chain, #929), so the+/// oldest retained version is the minimum along that chain. Each step is a+/// primary-key lookup, so no index on `(path, created_at)` is needed and the+/// walk cannot reach a same-path page in another project. Versions removed by+/// retention or ledger reclaim end the chain early and no longer count.const PAGE_FIRST_CREATED_EXPR: &str = "COALESCE(\- (SELECT MIN(v.created_at) FROM pages v \- WHERE v.workspace_id = pg.workspace_id \- AND v.project_id = pg.project_id \- AND v.path = pg.path), \+ (WITH RECURSIVE chain(supersedes, created_at, depth) AS (\+ SELECT pg.supersedes, pg.created_at, 0 \+ UNION ALL \+ SELECT v.supersedes, v.created_at, chain.depth + 1 \+ FROM pages v JOIN chain ON v.id = chain.supersedes \+ WHERE chain.depth < 100000) \+ SELECT MIN(created_at) FROM chain), \pg.created_at)";fn page_meta_from_row(row: &rusqlite::Row<'_>) -> rusqlite::Result<StoreResult<PageMeta>> {diff --git a/docs/frontend-api.md b/docs/frontend-api.mdindex 9dc47334..0a5e189d 100644--- a/docs/frontend-api.md+++ b/docs/frontend-api.md@@ -200,6 +200,9 @@ links + back-links.}```+`created_at` is when the page's oldest retained version was written, so it+stays put across rewrites; `updated_at` is when the latest version was written.+`404` for missing workspace/project, missing page row, or missing fileon disk (the body is read from the markdown file at request time).