Skip to content

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

Rust

fix(consolidate): require relation targets to resolve

AkitaOnRails2113968cae02
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e90d018..bea76e42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,6 +68,10 @@ version in [`docs/changelog/`](docs/changelog/):
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)
## [3.1.0] - 2026-10-16
diff --git a/crates/ai-memory-consolidate/src/bootstrap.rs b/crates/ai-memory-consolidate/src/bootstrap.rs
index e523a01f..ee4b592f 100644
--- a/crates/ai-memory-consolidate/src/bootstrap.rs
+++ b/crates/ai-memory-consolidate/src/bootstrap.rs
@@ -653,13 +653,19 @@ impl Bootstrap {
.iter()
.map(|req| (&req.path, req.body.as_str(), &req.frontmatter))
.collect();
- crate::link_guard::unresolved_cross_scope_links(&self.reader, cfg.workspace_id, &pages)
- .await?
+ crate::link_guard::unresolved_generated_links(
+ &self.reader,
+ cfg.workspace_id,
+ cfg.project_id,
+ &pages,
+ )
+ .await?
};
if !unresolved.is_empty() {
for req in &mut requests {
- req.body =
- crate::link_guard::delink_body(&req.body, &req.path, &unresolved).into_owned();
+ req.body = crate::link_guard::delink_body(&req.body, &req.path, &unresolved.body)
+ .into_owned();
+ crate::link_guard::prune_relations(&mut req.frontmatter, &unresolved.relations);
}
}
diff --git a/crates/ai-memory-consolidate/src/consolidator.rs b/crates/ai-memory-consolidate/src/consolidator.rs
index cf388c67..6b6d7a0a 100644
--- a/crates/ai-memory-consolidate/src/consolidator.rs
+++ b/crates/ai-memory-consolidate/src/consolidator.rs
@@ -383,15 +383,17 @@ impl Consolidator {
// so the write cannot mint a dangling cross-project edge the lint
// pass would flag.
let mut frontmatter = build_frontmatter(&page, session_id, agent_kind);
- let unresolved = crate::link_guard::unresolved_cross_scope_links(
+ let unresolved = crate::link_guard::unresolved_generated_links(
&self.reader,
ws,
+ proj,
&[(&path, page.body_markdown.as_str(), &frontmatter)],
)
.await?;
page.body_markdown =
- crate::link_guard::delink_body(&page.body_markdown, &path, &unresolved).into_owned();
- crate::link_guard::prune_relations(&mut frontmatter, &unresolved);
+ crate::link_guard::delink_body(&page.body_markdown, &path, &unresolved.body)
+ .into_owned();
+ crate::link_guard::prune_relations(&mut frontmatter, &unresolved.relations);
let id = self
.wiki
.write_page(WritePageRequest {
@@ -941,15 +943,16 @@ impl Consolidator {
.iter()
.map(|req| (&req.path, req.body.as_str(), &req.frontmatter))
.collect();
- crate::link_guard::unresolved_cross_scope_links(&self.reader, ws, &pages).await?
+ crate::link_guard::unresolved_generated_links(&self.reader, ws, proj, &pages).await?
};
if !unresolved.is_empty() {
for (req, outcome) in requests.iter_mut().zip(outcomes_preview.iter_mut()) {
let rewritten =
- crate::link_guard::delink_body(&req.body, &req.path, &unresolved).into_owned();
+ crate::link_guard::delink_body(&req.body, &req.path, &unresolved.body)
+ .into_owned();
req.body = rewritten.clone();
outcome.new_body_markdown = rewritten;
- crate::link_guard::prune_relations(&mut req.frontmatter, &unresolved);
+ crate::link_guard::prune_relations(&mut req.frontmatter, &unresolved.relations);
}
}
@@ -6342,23 +6345,36 @@ mod tests {
assert!(stored.body.contains("[[notes/pending.md]]"));
}
- /// #1218 covers typed `relations:` edges too: an unresolved cross-scope
- /// relation target is dropped before the write (an emptied relation goes
- /// with it), while a live cross-scope target and a same-project target
- /// stay, so frontmatter cannot mint the dangling edge the body guard
- /// prevents.
+ /// Typed `relations:` targets must resolve, whether local or cross-scope;
+ /// unlike ordinary body links, a local relation may not dangle.
#[tokio::test]
async fn single_page_drops_unresolved_cross_scope_relations() {
let tmp = tempfile::tempdir().unwrap();
let (store, wiki, session, ws, proj) = batch_fixture(tmp.path()).await;
seed_other_project_page(&store, &wiki, ws, "otherproj", "notes/exists.md").await;
+ wiki.write_page(WritePageRequest {
+ workspace_id: ws,
+ project_id: proj,
+ path: PagePath::new("notes/local.md").unwrap(),
+ frontmatter: serde_json::json!({}),
+ body: "Existing local target.".into(),
+ tier: Tier::Semantic,
+ pinned: false,
+ title: None,
+ admission_ctx: None,
+ author_id: None,
+ actor: ai_memory_core::ActorContext::anonymous(),
+ evidence: Vec::new(),
+ })
+ .await
+ .unwrap();
let response = serde_json::json!({
"title": "Relation cleanup",
- "body_markdown": "No links in the body.",
+ "body_markdown": "A pending [[notes/missing.md]] body link remains.",
"tags": [],
"relations": {
- "causes": ["otherproj:notes/missing.md", "otherproj:notes/exists.md", "notes/local.md"],
+ "causes": ["otherproj:notes/missing.md", "otherproj:notes/exists.md", "notes/local.md", "notes/missing.md"],
"fixes": ["ghostproj:x.md"],
},
});
@@ -6389,6 +6405,7 @@ mod tests {
stored.frontmatter
);
assert!(stored.frontmatter["relations"].get("fixes").is_none());
+ assert!(stored.body.contains("[[notes/missing.md]]"));
}
}
diff --git a/crates/ai-memory-consolidate/src/link_guard.rs b/crates/ai-memory-consolidate/src/link_guard.rs
index 1144f724..58587001 100644
--- a/crates/ai-memory-consolidate/src/link_guard.rs
+++ b/crates/ai-memory-consolidate/src/link_guard.rs
@@ -15,19 +15,19 @@
use std::borrow::Cow;
use std::collections::{BTreeMap, BTreeSet};
-use ai_memory_core::{PagePath, WorkspaceId};
+use ai_memory_core::{PagePath, ProjectId, WorkspaceId};
use ai_memory_store::{ReaderPool, ScopeResolutionError, lookup_existing_scope};
use tracing::warn;
/// A normalised link key as `ai_memory_wiki::extract_links` yields it:
/// `(workspace, project, path)`, with `workspace`/`project` `None` for a
-/// same-project link. Only project-qualified keys ever enter the sets this
-/// module handles.
+/// same-project link.
pub(crate) type LinkKey = (Option<String>, Option<String>, String);
-/// Collect the cross-scope link targets across `pages` — body wikilinks and
-/// typed `relations:` frontmatter entries — that do NOT resolve to an
-/// existing latest page in the store.
+/// Collect generated links that do not resolve to an existing latest page.
+/// Cross-scope body links and every typed relation are checked. Same-project
+/// body links remain deliberately unchecked, while same-project relations may
+/// also target another page proposed in this atomic batch.
///
/// Lookups are no-create and batched: each named scope is resolved once via
/// [`lookup_existing_scope`], then every path under it is checked in a
@@ -40,24 +40,77 @@ pub(crate) type LinkKey = (Option<String>, Option<String>, String);
/// `source_workspace_id` supplies the workspace name for project-only
/// `[[project:path]]` links, exactly as the write-path link resolver treats
/// a missing workspace qualifier as "the source page's workspace".
-pub(crate) async fn unresolved_cross_scope_links(
+#[derive(Debug, Default)]
+pub(crate) struct UnresolvedGeneratedLinks {
+ pub body: BTreeSet<LinkKey>,
+ pub relations: BTreeSet<LinkKey>,
+}
+
+impl UnresolvedGeneratedLinks {
+ pub(crate) fn is_empty(&self) -> bool {
+ self.body.is_empty() && self.relations.is_empty()
+ }
+}
+
+pub(crate) async fn unresolved_generated_links(
reader: &ReaderPool,
source_workspace_id: WorkspaceId,
+ source_project_id: ProjectId,
pages: &[(&PagePath, &str, &serde_json::Value)],
-) -> Result<BTreeSet<LinkKey>, ScopeResolutionError> {
- let mut targets: BTreeSet<LinkKey> = BTreeSet::new();
+) -> Result<UnresolvedGeneratedLinks, ScopeResolutionError> {
+ let proposed_paths: BTreeSet<String> = pages
+ .iter()
+ .map(|(path, _, _)| path.as_str().to_string())
+ .collect();
+ let mut body_targets: BTreeSet<LinkKey> = BTreeSet::new();
+ let mut relation_targets: BTreeSet<LinkKey> = BTreeSet::new();
for (page_path, body, frontmatter) in pages {
- let links = ai_memory_wiki::extract_links(body, page_path)
- .into_iter()
- .chain(ai_memory_wiki::extract_relation_links(frontmatter));
- for link in links {
+ for link in ai_memory_wiki::extract_links(body, page_path) {
if link.project.is_some() {
- targets.insert((link.workspace, link.project, link.path.as_str().to_string()));
+ body_targets.insert((link.workspace, link.project, link.path.as_str().to_string()));
}
}
+ relation_targets.extend(
+ ai_memory_wiki::extract_relation_links(frontmatter)
+ .into_iter()
+ .map(|link| (link.workspace, link.project, link.path.as_str().to_string())),
+ );
}
- if targets.is_empty() {
- return Ok(BTreeSet::new());
+ if body_targets.is_empty() && relation_targets.is_empty() {
+ return Ok(UnresolvedGeneratedLinks::default());
+ }
+
+ let mut result = UnresolvedGeneratedLinks::default();
+ let local_relations: Vec<LinkKey> = relation_targets
+ .iter()
+ .filter(|(workspace, project, _)| workspace.is_none() && project.is_none())
+ .cloned()
+ .collect();
+ let local_paths: Vec<String> = local_relations
+ .iter()
+ .map(|(_, _, path)| path.clone())
+ .filter(|path| !proposed_paths.contains(path))
+ .collect();
+ let existing_local: BTreeSet<String> = reader
+ .existing_latest_paths(source_workspace_id, source_project_id, local_paths)
+ .await?
+ .into_iter()
+ .collect();
+ for key in local_relations {
+ if !proposed_paths.contains(&key.2) && !existing_local.contains(&key.2) {
+ warn!(target = %key.2, "dropping same-project relation: no such page");
+ result.relations.insert(key);
+ }
+ }
+
+ let cross_targets: BTreeSet<LinkKey> = body_targets
+ .iter()
+ .chain(relation_targets.iter())
+ .filter(|(_, project, _)| project.is_some())
+ .cloned()
+ .collect();
+ if cross_targets.is_empty() {
+ return Ok(result);
}
// The source workspace exists by construction — the session's
@@ -71,13 +124,12 @@ pub(crate) async fn unresolved_cross_scope_links(
})?;
let mut by_scope: BTreeMap<(String, String), Vec<LinkKey>> = BTreeMap::new();
- for key in targets {
+ for key in cross_targets {
let workspace = key.0.clone().unwrap_or_else(|| source_workspace.clone());
let project = key.1.clone().unwrap_or_default();
by_scope.entry((workspace, project)).or_default().push(key);
}
- let mut unresolved = BTreeSet::new();
for ((workspace, project), keys) in by_scope {
let scope = match lookup_existing_scope(reader, &workspace, &project).await {
Ok(scope) => scope,
@@ -91,7 +143,14 @@ pub(crate) async fn unresolved_cross_scope_links(
error = %error,
"de-linking cross-scope wikilinks: the named scope does not resolve",
);
- unresolved.extend(keys);
+ for key in keys {
+ if body_targets.contains(&key) {
+ result.body.insert(key.clone());
+ }
+ if relation_targets.contains(&key) {
+ result.relations.insert(key);
+ }
+ }
continue;
}
Err(error) => return Err(error),
@@ -108,11 +167,16 @@ pub(crate) async fn unresolved_cross_scope_links(
target = %format!("{}:{}", key.1.as_deref().unwrap_or_default(), key.2),
"de-linking cross-scope wikilink: no such page in the target project",
);
- unresolved.insert(key);
+ if body_targets.contains(&key) {
+ result.body.insert(key.clone());
+ }
+ if relation_targets.contains(&key) {
+ result.relations.insert(key);
+ }
}
}
}
- Ok(unresolved)
+ Ok(result)
}
/// Rewrite `body`, replacing every wikilink whose key is in `unresolved`
@@ -230,4 +294,47 @@ mod tests {
serde_json::json!(["local/valid.md"])
);
}
+
+ #[tokio::test]
+ async fn same_project_relations_require_existing_or_same_batch_targets() {
+ let tmp = tempfile::tempdir().unwrap();
+ let store = ai_memory_store::Store::open(tmp.path()).unwrap();
+ let ws = store
+ .writer
+ .get_or_create_workspace("default")
+ .await
+ .unwrap();
+ let proj = store
+ .writer
+ .get_or_create_project(ws, "app", None)
+ .await
+ .unwrap();
+ let source = PagePath::new("notes/source.md").unwrap();
+ let peer = PagePath::new("notes/peer.md").unwrap();
+ let source_frontmatter = serde_json::json!({
+ "relations": {"causes": ["notes/peer.md", "notes/missing.md"]}
+ });
+ let peer_frontmatter = serde_json::json!({});
+ let unresolved = unresolved_generated_links(
+ &store.reader,
+ ws,
+ proj,
+ &[
+ (
+ &source,
+ "A pending [[notes/missing.md]] body link stays valid.",
+ &source_frontmatter,
+ ),
+ (&peer, "Peer", &peer_frontmatter),
+ ],
+ )
+ .await
+ .unwrap();
+
+ assert!(unresolved.body.is_empty(), "local body links may dangle");
+ assert_eq!(
+ unresolved.relations,
+ BTreeSet::from([(None, None, "notes/missing.md".to_string())])
+ );
+ }
}
diff --git a/docs/security-boundaries.md b/docs/security-boundaries.md
index 2e835c5a..e8b7008d 100644
--- a/docs/security-boundaries.md
+++ b/docs/security-boundaries.md
@@ -114,7 +114,7 @@ means the boundary is not built yet.
| 14c | Client-supplied event time is bounded and self-scoped (#919) | `ai-memory-hooks/src/payload.rs` `HookEnvelope::occurred_at_micros` — a `/hook` caller's optional `occurred_at` must be `> 0` and `<= now + 5min`; it only sets the caller's *own* admitted session's `started_at`/`ended_at`/`created_at`, never another session/project/user, and the ingest dedup `seen_at`/TTL stays on `now` | `payload.rs` `occurred_at_micros_rejects_a_far_future_timestamp`, `…_rejects_non_positive_values`, `…_rejects_garbage_strings` | MEDIUM — self-scoped numeric bound; no cross-tenant surface (a client already controls its own content) |
| 14d | `include_related` and the web page's backlinks show and walk only readable projects (#708) | `ai-memory-store/src/reader.rs` `related_walk(.., viewer)` — both the outgoing and incoming hop queries carry `readable_repository_predicate("pg.project_id", viewer)`, the same far-end filter `page_links` and `page_links_preview` apply (the preview's visible totals are counted under it too), so a page in a project the viewer cannot read is neither returned nor expanded; `ai-memory-mcp/src/server.rs` `memory_read_page` passes `viewer_from_parts`, `ai-memory-web/src/routes/page.rs` passes the request's viewer to `page_links_preview`, and the access bump only touches the filtered nodes | `related_walk.rs` `the_walk_hides_and_does_not_cross_projects_the_viewer_cannot_read` (an outgoing and an incoming neighbour in an ungranted restricted project are absent, and so is a granted page reachable only through one; control: a granted restricted project is shown, and no viewer walks the whole graph) — fails with the predicate removed; `ai-memory-web` `tests/suite/routes.rs` `page_backlink_from_an_unreadable_project_is_hidden` (the `/web` page's "Cited by" omits a page in an ungranted restricted project, with no title, path or project name; controls: a reader of both projects and an unrestricted viewer see it) — fails with the page handler passing no viewer to `page_links_preview`; `related_walk.rs` `page_links_preview_caps_in_sql_and_counts_only_readable_neighbours` (back-links from an ungranted restricted project are neither listed nor counted in the total behind "and N more"; control: no viewer counts them all) — fails with the predicate removed; `ai-memory-mcp` `server.rs` `bob_does_not_see_restricted_pages_through_the_related_walk` (an ungranted user's `memory_read_page{include_related}` omits the restricted page; control: no viewer still reaches it) — fails with `memory_read_page` passing `None` instead of `viewer_from_parts` | STRONG |
| 14e | `memory_write_page` session evidence cites only a session of the target project (#708) | `ai-memory-mcp/src/server.rs` `memory_write_page` — a `session_id` is accepted only when `require_session_in_scope` resolves the session (where its observations landed, else its session row, as `Consolidator::session_target` does) to the same `(workspace_id, project_id)` the write grant was checked against; unknown and foreign ids get one refusal, so the error is no existence oracle; `scope: "global"` with a `session_id` is refused; `refuse_pinned_page_overwrite` keeps a write that cites a session off a pinned page; only a write to `sessions/<id>.md` reconciles the session's queued SessionEnd job | `server.rs` `write_page_refuses_a_session_from_another_project` (a foreign and an unknown session refused, no evidence row written, the foreign job still queued; control: the project's own session accepted), `session_evidence_write_leaves_a_pinned_page_alone` (control: the same write without `session_id` edits the page), `session_evidence_on_another_path_leaves_the_job_queued`, `write_page_rejects_a_malformed_or_global_session_id` — each of the scope check, the pinned check and the session-page-only reconcile proven to fail its test when removed | STRONG |
-| 14f | Consolidation apply path validates cross-scope wikilinks against the store (#1218) | `ai-memory-consolidate/src/link_guard.rs` `unresolved_cross_scope_links` — every `[[project:path]]` / `[[workspace/project:path]]` / `[[_global:path]]` target in a proposed body is resolved with the no-create `lookup_existing_scope` (never creates a scope) and batch-checked via `reader.rs` `existing_latest_paths`; a missing workspace/project, an ambiguous project name, or a missing target page de-links the wikilink, while a genuine store failure aborts the consolidation before any write. Typed `relations:` frontmatter targets go through the same check, and `prune_relations` drops an unresolved entry (an emptied relation and an emptied map with it). `delink_body` → `ai-memory-wiki/src/markdown.rs` `delink_wikilinks` drops the brackets and keeps the label, skipping code fences and inline code exactly as `extract_links` does. Wired into all three apply paths (`consolidator.rs` single-page and batch, `bootstrap.rs`) after the pinned/foreign-slot/portable guards and before the atomic `Wiki::apply_batch` / `write_page`, so an invented cross-project dependency can no longer be written and flagged by the lint pass later. Same-project `[[target]]` links stay untouched by design (the target may be written later). The probe runs with no viewer, so it reports nothing for a `restricted` project (the global preferences project excepted): a link into one is always de-linked, and whether a link survived says nothing about which paths exist there | `consolidator.rs` `batch_delinks_invented_cross_scope_wikilinks` (invented `[[_global:nope]]`, `[[otherproj:notes/missing.md]]`, `[[ghostproj:x.md]]` de-linked to plain text; controls: a cross-scope link to an existing page and a same-project pending link survive byte-identical; `dangling_cross_project_links` left empty), `single_page_delinks_invented_cross_scope_wikilinks`, `single_page_drops_unresolved_cross_scope_relations` (unresolved `relations:` entries dropped; controls: a live cross-scope and a same-project target stay), `link_guard.rs` `prune_relations_drops_only_unresolved_cross_scope_entries`, `bootstrap.rs` `bootstrap_delinks_invented_cross_scope_wikilinks` — each proven to fail with the guard neutralized; `markdown.rs` `delink_wikilinks_strips_only_listed_cross_scope_links`, `delink_wikilinks_without_label_keeps_the_target_text`, `delink_wikilinks_skips_code_and_leaves_empty_set_untouched`; store `multi_session.rs` `existing_latest_paths_reports_exactly_the_live_paths` (exact live-path set, superseded path still resolves, foreign scope sees nothing), `existing_latest_paths_reports_nothing_for_a_restricted_project` (real and absent paths answer alike while restricted; control: reopened, the page is seen) | STRONG |
+| 14f | Consolidation apply path validates generated cross-scope body links and every typed relation against the store (#1218, #1353) | `ai-memory-consolidate/src/link_guard.rs` `unresolved_generated_links` keeps body and relation refusals separate. Every `[[project:path]]` / `[[workspace/project:path]]` / `[[_global:path]]` target in a proposed body is resolved with the no-create `lookup_existing_scope` and batch-checked via `reader.rs` `existing_latest_paths`; a missing workspace/project, ambiguous project name, or missing target de-links the body link. Every typed `relations:` target is checked too, including same-project targets; a local target is admitted only when it already exists or is another page in the same atomic batch. `prune_relations` drops malformed and unresolved entries. Same-project body links stay untouched by design. Wired into consolidation single/batch and bootstrap before writes; restricted cross-project probes reveal no paths | `consolidator.rs` `batch_delinks_invented_cross_scope_wikilinks`, `single_page_delinks_invented_cross_scope_wikilinks`, `single_page_drops_unresolved_cross_scope_relations`; `link_guard.rs` `same_project_relations_require_existing_or_same_batch_targets` (missing local relation refused, same-batch relation and dangling local body link controls), malformed and cross-scope prune tests; bootstrap cross-scope test; store `multi_session.rs` `existing_latest_paths_reports_exactly_the_live_paths`, `existing_latest_paths_reports_nothing_for_a_restricted_project` | STRONG |
| 14g | Web project search and its recall trace honour `memory_query`'s scope rules (#708) and never describe another project | `ai-memory-web/src/routes/search.rs` resolves `workspace`+`project` through `resolve_read_scope` (`lookup_existing_scope_guarded`, no-create, `ProjectAccess::Read`) before any ranking, and refuses partial scope; scoped `/api/v1/search` keeps `lookup_project` / `resolve_many_existing_scopes_guarded`; `ai-memory-web/src/recall.rs` ranks only the resolved scopes through `ReaderPool::hybrid_search_scopes`, whose streams and graph expansion are bound to each `(workspace_id, project_id)`; a search with no scope stays `search_pages_with_meta(.., viewer)` (readable repositories only) | `ai-memory-web` `tests/suite/recall_trace.rs` — `project_search_refuses_a_restricted_project_without_a_grant` (bob, with no grant, gets 403 from `/web/search` with and without `explain=1` and from scoped `/api/v1/search`, with no path, body text or trace in the response, and a `scopes` POST naming the restricted project next to an open one is refused; alice's grant and an unrestricted viewer are the controls), `project_search_fails_closed_on_unknown_and_partial_scope` (unknown project or workspace 404 with nothing created, partial scope 400), `explain_renders_stream_ranks_rrf_authority_and_timings` (a better-matching page in a sibling project never reaches the hits or the trace), `search_scope_selector_lists_only_readable_projects` (the search page's "Search in" selector lists only projects the viewer may read, and a hand-typed `scope=` for an ungranted project is a 403 that leaks nothing; controls: the granted reader and an unrestricted viewer; passing no viewer to `list_projects_with_stats` in the handler fails it), `routes.rs` `search_page_scope_selector_round_trips_and_rejects_malformed_values` (a malformed `scope` is a 400); `recall_trace.rs` `kind_filter_does_not_widen_what_a_viewer_can_read` (a `kind`/`tier` filter only narrows: bob gets no hits and a 403 on a scoped search; alice and an unrestricted viewer are the controls), `search_filters_a_project_by_kind_and_tier_keeping_rank_order` (survivors of a filter keep the unfiltered order), `reranker_is_shown_only_the_pages_the_filter_keeps` (a dropped page never reaches the reranker), `kind_and_tier_filters_hold_in_every_stream` (FTS, entity, vector, observation and both graph directions each filter in SQL; dropping any one stream's predicate fails it), `kind_filter_finds_a_rare_kind_the_unfiltered_page_ranks_out` and `cross_project_kind_filter_sees_past_the_candidate_window` (the filter sees past the candidate window in both modes); `ai-memory-mcp` `tests/suite/web_search_parity.rs` (same top-k order as `memory_query` from `/web` and `/api/v1`, with a deterministic embedder and with none, explain on and off, and merged `scopes`; controls show a web search without the embedder, or the old FTS-only scoped search, would fail it) | STRONG. Bite checks: passing no viewer to `resolve_read_scope` in the search handler, to `lookup_project` or to `resolve_scopes` in the API each fails the restricted-project test; dropping the query vector in `recall.rs` fails the embedder parity tests |
| 15 | Agent-archive restore path confinement, resource bounds, and consistency | `ai-memory-cli/src/commands/restore_agents.rs` stages only bounded regular UTF-8 entries; requires a one-to-one manifest/body/checksum/target mapping; allowlists destinations by scope; rejects symlinked descendants; writes each file atomically and rolls back earlier writes after a later failure. `backup_agents.rs` skips direct and directory-root source symlinks, bounds individual assets, and atomically replaces a private archive only after gzip completion | `backup_agents.rs` `restore_agents_rejects_path_traversal`, `restore_agents_rejects_unauthorized_destination_path`, `restore_agents_verifies_sha256_integrity`, `restore_agents_requires_a_complete_one_to_one_manifest`, `restore_agents_rejects_oversized_entries_from_the_header`, `restore_agents_rejects_a_symlinked_destination_parent`, `backup_agents_does_not_follow_config_or_asset_root_symlinks`, and `failed_backup_leaves_the_previous_archive_intact`; `backup_and_restore_agents_round_trip` is the valid-path control; `restore_agents::tests::rollback_removes_new_files_and_restores_overwrites` covers recovery | STRONG |
| 16 | Relay queue identity, migration, and private filesystem state | `companions/ai-memory-relay/src/queue.rs` `Queue::open_inner` performs read-only identity preflight, rechecks under `IMMEDIATE`, commits schema and metadata together; `configure` checks the presence of user objects and rechecks `identity`/`schema_version` metadata on the same connection before every bounded BUSY/LOCKED retry; `fsguard.rs` checks existing paths and creates owner-only files before SQLite opens them | `tests/relay.rs` `a_foreign_database_is_refused_byte_for_byte`, `unknown_schemas_refuse_without_mutation`, `a_foreign_database_with_a_writer_is_refused_before_write_coordination`, `a_foreign_identity_after_preflight_is_refused_without_mutation`, `a_foreign_identity_during_journal_retry_is_refused_without_mutation`, `journal_retry_refuses_a_changed_version_or_empty_database_without_mutation`; controls: `journal_transition_retries_sqlite_lock_without_losing_v1_values`, `fresh_queue_init_and_v1_reopens_work_across_processes`; recovery: `interrupted_and_failed_migrations_roll_back_and_recover`, `journal_reclassification_busy_preserves_committed_migration_and_retries_same_queue`; diagnostics: `classification_read_failures_display_the_sqlite_cause_once_and_preserve_foreign_bytes`; Unix privacy: `the_queue_database_and_its_sidecars_are_owner_only` and the contended migration control | Guard-removal proof covers preflight, locked recheck, and journal retry identity/version checks; full table structure is outside this classification. Windows path rejection is preserved; Windows ACL hardening remains operator-owned |