Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge pull request #1368 from viniciusdsandrade/fix/dangling-target-resolution
AkitaOnRails74fcac3dd7e5
diff --cc CHANGELOG.mdindex e6808092,055ffaa0..8973f8f5--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -12,70 -12,10 +12,74 @@@ version in [`docs/changelog/`](docs/cha## [Unreleased]### Fixed+- `ai-memory auth login openai-oauth` and `auth login copilot` no longer print+ a failed endpoint's whole response body. Error bodies are bounded, scrubbed+ of secrets and terminal control sequences, then capped for display; provider+ errors, including OIDC login and refresh, use the same ordering so a secret+ at the display boundary is still redacted. (#1359)+- Fixed OIDC device login and refresh sending credential-bearing requests to+ non-TLS endpoints. Issuers and advertised or persisted device/token endpoints+ must now use `https` outside loopback, and authentication requests do not+ follow redirects. Plain `http` remains available for local test issuers on+ `localhost`, `127.0.0.1` and `::1`. (#1354)+- Fixed `install-instructions` printing a false "Claude Code reads <file> instead+ of AGENTS.md" note when `$HOME` is reached through a symlink. The home+ `.claude/CLAUDE.md` skip now compares with the same canonicalising+ `paths_match` helper the import check uses, so a symlinked home matches its+ resolved path. (#1345)+- Corrected stale claims in `docs/comparison.md` and `docs/competitive-parity.md`+ that said Windows has no service step and the Windows install is experimental.+ The 3.1 `install.ps1` + `setup` Windows service step is shipped production,+ not experimental; the "3.0 (unreleased)" observation-stream note is corrected+ to reflect the released 3.0 line. (#1271)+- Made the executable auto-improvement eval policy server-owned. Manual CLI and+ HTTP reviews now use `[auto_improve.eval]` from the server process, and legacy+ requests that try to supply an `eval` object fail closed with an upgrade+ message.+- Made managed cross-harness continuation survive quota exhaustion without a+ voluntary handoff. The startup packet now places its server-authored resume+ directive outside the untrusted transcript fence, and refreshed+ `CLAUDE.md` / `AGENTS.md` routing tells an incoming agent that "continue",+ "resume", and "pick up where we left off" must consult the private+ `AI_MEMORY_PREVIOUS_SESSION_HISTORY` dossier when the managed-run variables+ are present. The dossier remains untrusted evidence and stays local to the+ launcher machine.+- Fixed unbounded memory use in consolidation and auto-improve for long+ sessions: both paths now read a bounded projection of the session's+ observations instead of loading every row, keeping the LLM input+ byte-identical. Sessions with no observations in the consolidator's target+ scope (purged or foreign) are refused before any work, exactly as empty+ sessions were before. (#1363)+- Fixed the session page's uncapped `## Prompts` list. Above 500 prompts the+ page now lists the first 250 titles and the last 250, numbered by their real+ position, with one line between them saying how many were left out. The+ store reads at most 500 titles for it, and the page's prompt count and the+ digest stats still report the true total. (#1349)+- Fixed auto-improve approvals that failed because a `reject`-policy admission+ webhook was unreachable, timed out, rate-limited or answered 5xx being+ stored as rejections. The proposal is still marked `failed`, but the outage+ no longer enters the rejection buffer, so later reviews are not told to+ avoid a proposal nobody refused and rejection telemetry counts only real+ refusals. (#1358)+- Fixed consolidation persisting non-page `relations:` targets in YAML+ frontmatter on disk. Raw titles containing dots, directory paths, or stemless+ `.md` strings in `relations:` were previously written into frontmatter and+ retained by `prune_relations` when `extract_relation_links` returned an empty+ list, causing the wiki watcher to emit repeated warnings on every+ reconciliation pass. Targets are now validated through `extract_relation_links`+ before frontmatter assembly and during relation pruning. (#1353, #1366)+- Consolidation now also drops well-shaped same-project `relations:` targets+ that name no existing page. Relations among pages in the same atomic batch+ remain valid, and ordinary same-project body wikilinks may still point to a+ page that will be written later. (#1353)+- Verified target latest status and expiration in+ `ReaderPool::contradiction_edges`, so a contradiction pointing at a+ tombstoned or expired page is reported as unresolved instead of active, and+ expired source pages do not emit contradiction findings. (#1367)+ - Verified target latest status and expiration in+ `ReaderPool::dangling_cross_project_links`, so cross-project links to+ tombstoned or expired pages are reported as dangling instead of resolved,- and expired source pages do not emit dangling link findings.++ and expired source pages do not emit dangling link findings. (#1368)## [3.1.0] - 2026-10-16diff --cc crates/ai-memory-store/tests/suite/related_walk.rsindex 47875d92,473ed413..582a27ab--- a/crates/ai-memory-store/tests/suite/related_walk.rs+++ b/crates/ai-memory-store/tests/suite/related_walk.rs@@@ -858,146 -849,155 +858,299 @@@ async fn page_links_preview_caps_in_sqlassert_eq!(cut_root, head);}+/// `contradiction_edges` returns declared contradicts edges from latest+/// unexpired pages. A target edge resolves only when pointing at an existing,+/// latest, and unexpired page. If the target was tombstoned, expired, or never+/// existed, `resolved` evaluates to false. An expired source page is omitted+/// entirely from contradiction edges.+#[tokio::test]+async fn contradiction_edges_require_latest_unexpired_target() {+ 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();++ store+ .writer+ .upsert_page(page_with_links(ws, app, "notes/live_target.md", vec![]))+ .await+ .unwrap();++ let tombstoned_target_id = store+ .writer+ .upsert_page(page_with_links(+ ws,+ app,+ "notes/tombstoned_target.md",+ vec![],+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(ws, app, "notes/expired_target.md", vec![]),+ expired_at(),+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(ws, app, "notes/future_target.md", vec![]),+ future_at(),+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(page_with_links(+ ws,+ app,+ "notes/source.md",+ vec![+ contradiction_link("notes/live_target.md"),+ contradiction_link("notes/tombstoned_target.md"),+ contradiction_link("notes/expired_target.md"),+ contradiction_link("notes/future_target.md"),+ contradiction_link("notes/missing_target.md"),+ ],+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(+ ws,+ app,+ "notes/expired_source.md",+ vec![contradiction_link("notes/live_target.md")],+ ),+ expired_at(),+ ))+ .await+ .unwrap();++ let soft_deleted = store+ .writer+ .soft_delete_for_decay_if_latest(+ ws,+ app,+ PagePath::new("notes/tombstoned_target.md").unwrap(),+ tombstoned_target_id,+ )+ .await+ .unwrap();+ assert!(soft_deleted, "tombstone soft delete succeeded");++ let edges = store.reader.contradiction_edges(ws, app).await.unwrap();++ assert!(+ !edges+ .iter()+ .any(|e| e.from_path == "notes/expired_source.md"),+ "expired source page must not emit contradiction edges"+ );++ let pairs: Vec<(String, String, bool)> = edges+ .into_iter()+ .map(|e| (e.from_path, e.to_path, e.resolved))+ .collect();++ assert_eq!(+ pairs,+ vec![+ (+ "notes/source.md".to_string(),+ "notes/expired_target.md".to_string(),+ false,+ ),+ (+ "notes/source.md".to_string(),+ "notes/future_target.md".to_string(),+ true,+ ),+ (+ "notes/source.md".to_string(),+ "notes/live_target.md".to_string(),+ true,+ ),+ (+ "notes/source.md".to_string(),+ "notes/missing_target.md".to_string(),+ false,+ ),+ (+ "notes/source.md".to_string(),+ "notes/tombstoned_target.md".to_string(),+ false,+ ),+ ]+ );+}+++ /// `dangling_cross_project_links` returns declared dependencies on pages in+ /// another project that do not resolve to an existing, latest, unexpired page.+ /// If the target was tombstoned (soft-deleted), expired, or never existed, it+ /// is reported as dangling. Targets that are live or have future TTL do not+ /// dangle. An expired source page is omitted entirely.+ #[tokio::test]+ async fn dangling_cross_project_links_require_latest_unexpired_target() {+ 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 lib = store+ .writer+ .get_or_create_project(ws, "lib".to_string(), None)+ .await+ .unwrap();++ store+ .writer+ .upsert_page(page_with_links(ws, lib, "notes/live_target.md", vec![]))+ .await+ .unwrap();++ let tombstoned_target_id = store+ .writer+ .upsert_page(page_with_links(+ ws,+ lib,+ "notes/tombstoned_target.md",+ vec![],+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(ws, lib, "notes/expired_target.md", vec![]),+ expired_at(),+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(ws, lib, "notes/future_target.md", vec![]),+ future_at(),+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(page_with_links(+ ws,+ app,+ "notes/source.md",+ vec![+ cross_project_link("ghost", "notes/missing.md"),+ cross_project_link("lib", "notes/live_target.md"),+ cross_project_link("lib", "notes/tombstoned_target.md"),+ cross_project_link("lib", "notes/expired_target.md"),+ cross_project_link("lib", "notes/future_target.md"),+ cross_project_link("lib", "notes/missing_target.md"),+ ],+ ))+ .await+ .unwrap();++ store+ .writer+ .upsert_page(with_expiry(+ page_with_links(+ ws,+ app,+ "notes/expired_source.md",+ vec![cross_project_link("lib", "notes/live_target.md")],+ ),+ expired_at(),+ ))+ .await+ .unwrap();++ let soft_deleted = store+ .writer+ .soft_delete_for_decay_if_latest(+ ws,+ lib,+ PagePath::new("notes/tombstoned_target.md").unwrap(),+ tombstoned_target_id,+ )+ .await+ .unwrap();+ assert!(soft_deleted, "tombstone soft delete succeeded");++ let dangling = store+ .reader+ .dangling_cross_project_links(ws, app)+ .await+ .unwrap();++ assert!(+ !dangling+ .iter()+ .any(|d| d.from_path == "notes/expired_source.md"),+ "expired source page must not emit dangling links"+ );++ let summary: Vec<(String, String, String, bool)> = dangling+ .into_iter()+ .map(|d| (d.from_path, d.project, d.path, d.project_exists))+ .collect();++ assert_eq!(+ summary,+ vec![+ (+ "notes/source.md".to_string(),+ "ghost".to_string(),+ "notes/missing.md".to_string(),+ false,+ ),+ (+ "notes/source.md".to_string(),+ "lib".to_string(),+ "notes/expired_target.md".to_string(),+ true,+ ),+ (+ "notes/source.md".to_string(),+ "lib".to_string(),+ "notes/missing_target.md".to_string(),+ true,+ ),+ (+ "notes/source.md".to_string(),+ "lib".to_string(),+ "notes/tombstoned_target.md".to_string(),+ true,+ ),+ ]+ );+ }