Skip to content

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

Rust

fix(wiki): resolve encoded Markdown destinations once

Rudy Celekli1e4bb5618d08
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b4517043..da2a5de9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,9 @@ version in [`docs/changelog/`](docs/changelog/):
## [Unreleased]
+### Fixed
+- Resolved percent-encoded ordinary Markdown link paths before indexing and web-route encoding, preserving spaces and Unicode filenames without double decoding or changing project scope.
+
## [3.1.1] - 2026-10-17
### Fixed
diff --git a/crates/ai-memory-web/src/markdown.rs b/crates/ai-memory-web/src/markdown.rs
index 8eeb50ba..953ef5a4 100644
--- a/crates/ai-memory-web/src/markdown.rs
+++ b/crates/ai-memory-web/src/markdown.rs
@@ -114,10 +114,22 @@ fn scope_relative_link<'a>(dest: CowStr<'a>, workspace: &str, project: &str) ->
Some(i) => (&trimmed[..i], &trimmed[i..]),
None => (trimmed, ""),
};
- if path_part.is_empty() || path_part.contains("..") {
- return dest; // don't rewrite traversal; safe_url/router will reject
+ let Some(decoded) = ai_memory_wiki::decode_markdown_destination_path(path_part) else {
+ return CowStr::Borrowed("#");
+ };
+ let decoded_path = decoded.as_ref();
+ if decoded_path.is_empty()
+ || decoded_path.contains("..")
+ || decoded_path.starts_with('/')
+ || decoded_path.contains(['\\', ':'])
+ {
+ return if decoded_path == path_part {
+ dest
+ } else {
+ CowStr::Borrowed("#")
+ };
}
- let mut path_part = path_part.trim_end_matches('/');
+ let mut path_part = decoded_path.trim_end_matches('/');
while let Some(rest) = path_part.strip_prefix("./") {
path_part = rest;
}
@@ -980,6 +992,53 @@ mod tests {
assert_eq!(strip_leading_h1("\r\n\r\nTitle\r\n=====", "Title"), "");
}
+ #[test]
+ fn markdown_url_destinations_are_decoded_once_before_route_encoding() {
+ let html = render(
+ "[space](notes/my%20note.md#part) [literal percent](notes/my%2520note.md) \
+ [separator](notes%2Fmy%20note.md) [unicode](notes/%E6%97%A5%E6%9C%AC.md)",
+ "default",
+ "scratch",
+ );
+ for href in [
+ "w/default/scratch/p/notes/my%20note.md#part",
+ "w/default/scratch/p/notes/my%2520note.md",
+ "w/default/scratch/p/notes/%E6%97%A5%E6%9C%AC.md",
+ ] {
+ assert!(html.contains(href), "{html}");
+ }
+ let wiki = render("[[notes/my%20note.md]]", "default", "scratch");
+ assert!(
+ wiki.contains("w/default/scratch/p/notes/my%2520note.md"),
+ "{wiki}"
+ );
+ }
+
+ #[test]
+ fn decoded_markdown_destinations_cannot_change_the_web_scope() {
+ for destination in [
+ "%2e%2e/secret.md",
+ "%2Fadmin/backup",
+ "notes%5Csecret.md",
+ "other%3Anotes/secret.md",
+ "%68ttps%3A%2F%2Fexample.com/secret.md",
+ "notes/%FF.md",
+ "notes/%00.md",
+ ] {
+ let html = render(&format!("[note](<{destination}>)"), "default", "scratch");
+ assert!(html.contains("href=\"#\""), "{destination}: {html}");
+ }
+ let html = render(
+ "[note](%77/foreign/project/p/secret.md)",
+ "default",
+ "scratch",
+ );
+ assert!(
+ html.contains("w/default/scratch/p/w/foreign/project/p/secret.md"),
+ "{html}"
+ );
+ }
+
#[test]
fn wikilink_resolves_against_current_project() {
let html = render("see [[notes/foo]] here", "default", "scratch");
diff --git a/crates/ai-memory-web/tests/suite/routes.rs b/crates/ai-memory-web/tests/suite/routes.rs
index 3fb9c372..c6b5948e 100644
--- a/crates/ai-memory-web/tests/suite/routes.rs
+++ b/crates/ai-memory-web/tests/suite/routes.rs
@@ -665,6 +665,124 @@ async fn web_links_percent_encode_route_segments() {
);
}
+#[tokio::test]
+async fn encoded_markdown_links_resolve_and_remain_in_the_source_scope() {
+ let (_tmp, store, wiki) = setup().await;
+ let home_ws = store
+ .writer
+ .get_or_create_workspace("default")
+ .await
+ .unwrap();
+ let other_ws = store
+ .writer
+ .get_or_create_workspace("elsewhere")
+ .await
+ .unwrap();
+ let home = store
+ .writer
+ .get_or_create_project(home_ws, "scratch", None)
+ .await
+ .unwrap();
+ let sibling = store
+ .writer
+ .get_or_create_project(home_ws, "other", None)
+ .await
+ .unwrap();
+ let foreign = store
+ .writer
+ .get_or_create_project(other_ws, "scratch", None)
+ .await
+ .unwrap();
+ for (ws, project, title) in [
+ (home_ws, home, "Home target"),
+ (home_ws, sibling, "Sibling target"),
+ (other_ws, foreign, "Foreign target"),
+ ] {
+ wiki.write_page(wiki_req(ws, project, "notes/my note.md", title))
+ .await
+ .unwrap();
+ }
+ wiki.write_page(wiki_req(
+ home_ws,
+ home,
+ "encoded-source.md",
+ "[note](notes/my%20note.md)",
+ ))
+ .await
+ .unwrap();
+ let links = store
+ .reader
+ .page_links(home_ws, home, "encoded-source.md".into(), None)
+ .await
+ .unwrap();
+ assert_eq!(links.links.len(), 1);
+ assert_eq!(links.links[0].path, "notes/my note.md");
+ assert_eq!(links.links[0].workspace, "default");
+ assert_eq!(links.links[0].project, "scratch");
+ for (ws, project) in [(home_ws, sibling), (other_ws, foreign)] {
+ let target = store
+ .reader
+ .page_links(ws, project, "notes/my note.md".into(), None)
+ .await
+ .unwrap();
+ assert!(
+ target.backlinks.is_empty(),
+ "a home link cannot become a foreign backlink"
+ );
+ }
+ wiki.write_page(wiki_req(
+ home_ws,
+ home,
+ "blocked.md",
+ "[outside](%2e%2e/notes/my%20note.md) [other](other%3Anotes/my%20note.md)",
+ ))
+ .await
+ .unwrap();
+ let blocked = store
+ .reader
+ .page_links(home_ws, home, "blocked.md".into(), None)
+ .await
+ .unwrap();
+ assert!(blocked.links.is_empty());
+ let app = router(store.reader.clone(), wiki.clone());
+ let response = app
+ .clone()
+ .oneshot(
+ Request::builder()
+ .uri("/w/default/scratch/p/encoded-source.md")
+ .body(Body::empty())
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(response.status(), StatusCode::OK);
+ let body = axum::body::to_bytes(response.into_body(), usize::MAX)
+ .await
+ .unwrap();
+ let html = std::str::from_utf8(&body).unwrap();
+ assert!(
+ html.contains("href=\"w/default/scratch/p/notes/my%20note.md\""),
+ "{html}"
+ );
+ assert!(!html.contains("notes/my%2520note.md"), "{html}");
+ let target = app
+ .oneshot(
+ Request::builder()
+ .uri("/w/default/scratch/p/notes/my%20note.md")
+ .body(Body::empty())
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(target.status(), StatusCode::OK);
+ let body = axum::body::to_bytes(target.into_body(), usize::MAX)
+ .await
+ .unwrap();
+ let html = std::str::from_utf8(&body).unwrap();
+ assert!(html.contains("Home target"));
+ assert!(!html.contains("Sibling target") && !html.contains("Foreign target"));
+}
+
#[tokio::test]
async fn smoke_page_not_found_returns_404() {
let (_tmp, store, wiki) = setup().await;
diff --git a/crates/ai-memory-wiki/src/lib.rs b/crates/ai-memory-wiki/src/lib.rs
index 453d7fa8..e859004b 100644
--- a/crates/ai-memory-wiki/src/lib.rs
+++ b/crates/ai-memory-wiki/src/lib.rs
@@ -28,8 +28,8 @@ pub use error::{WikiError, WikiResult};
pub use git::{COMMIT_AUTHOR_EMAIL, COMMIT_AUTHOR_NAME, GitAdapter};
pub use ledger::is_rotated_event_ledger;
pub use markdown::{
- Markdown, delink_wikilinks, derive_title, emit, extract_links, extract_relation_links, parse,
- rewrite_local_wikilinks,
+ Markdown, decode_markdown_destination_path, delink_wikilinks, derive_title, emit,
+ extract_links, extract_relation_links, parse, rewrite_local_wikilinks,
};
pub use migrations::run_pending as run_wiki_migrations;
pub use watcher::{DEBOUNCE_WINDOW, RECONCILE_INTERVAL, WatcherHandle};
diff --git a/crates/ai-memory-wiki/src/markdown.rs b/crates/ai-memory-wiki/src/markdown.rs
index 8567cb11..b10a1134 100644
--- a/crates/ai-memory-wiki/src/markdown.rs
+++ b/crates/ai-memory-wiki/src/markdown.rs
@@ -883,6 +883,48 @@ fn closing_paren_after_destination(tail: &str) -> Option<usize> {
None
}
+/// Decode the path portion of an ordinary Markdown URL destination once.
+///
+/// Split literal query and fragment delimiters before calling this helper:
+/// an encoded `%23` or `%3F` names a character in the filename. Wikilinks
+/// name literal page paths and must not go through URL decoding. Invalid
+/// escape spellings stay literal; invalid UTF-8 and encoded control bytes
+/// have no portable page-path representation and are refused.
+#[must_use]
+pub fn decode_markdown_destination_path(path: &str) -> Option<std::borrow::Cow<'_, str>> {
+ if !path.contains('%') {
+ return Some(std::borrow::Cow::Borrowed(path));
+ }
+ let mut decoded = Vec::with_capacity(path.len());
+ let bytes = path.as_bytes();
+ let mut pos = 0;
+ while pos < bytes.len() {
+ if bytes[pos] == b'%'
+ && let (Some(hi), Some(lo)) = (
+ bytes
+ .get(pos + 1)
+ .copied()
+ .and_then(|b| char::from(b).to_digit(16)),
+ bytes
+ .get(pos + 2)
+ .copied()
+ .and_then(|b| char::from(b).to_digit(16)),
+ )
+ {
+ let byte = (hi * 16 + lo) as u8;
+ if byte.is_ascii_control() {
+ return None;
+ }
+ decoded.push(byte);
+ pos += 3;
+ } else {
+ decoded.push(bytes[pos]);
+ pos += 1;
+ }
+ }
+ String::from_utf8(decoded).ok().map(std::borrow::Cow::Owned)
+}
+
fn normalize_link_target(raw: &str, page_path: &PagePath, wikilink: bool) -> Option<String> {
let target = raw
.split_once('|')
@@ -890,11 +932,21 @@ fn normalize_link_target(raw: &str, page_path: &PagePath, wikilink: bool) -> Opt
.trim()
.trim_matches('<')
.trim_matches('>');
- if target.is_empty() || target.starts_with('#') || target.contains("://") {
+ if target.is_empty() || target.starts_with('#') {
return None;
}
+ let path = target.split(['#', '?']).next()?.trim();
+ let decoded = if wikilink {
+ std::borrow::Cow::Borrowed(path)
+ } else {
+ decode_markdown_destination_path(path)?
+ };
+ let target = decoded.as_ref();
let lower = target.to_ascii_lowercase();
- if lower.starts_with("mailto:")
+ if target.is_empty()
+ || target.contains("://")
+ || target.contains('\\')
+ || lower.starts_with("mailto:")
|| lower.starts_with("data:")
|| lower.starts_with("javascript:")
|| lower.starts_with("vbscript:")
@@ -904,15 +956,6 @@ fn normalize_link_target(raw: &str, page_path: &PagePath, wikilink: bool) -> Opt
return None;
}
- let target = target.split_once('#').map_or(target, |(path, _)| path);
- let target = target
- .split_once('?')
- .map_or(target, |(path, _)| path)
- .trim();
- if target.is_empty() || target.contains('\\') {
- return None;
- }
-
// A directory target (`notes/`) is not a page: kept, it minted an
// extension-less `to_path` (or, for a wikilink, the literal
// `notes/.md`) that no page write could ever resolve.
@@ -2055,4 +2098,53 @@ mod tests {
let bare = rewrite_local_wikilinks("[[notes/a>b.md]]", &path, "proj");
assert!(bare.ends_with("](../notes/a>b.md)"), "{bare}");
}
+
+ #[test]
+ fn markdown_url_paths_decode_once_before_link_resolution() {
+ for (destination, expected) in [
+ ("notes/my%20note.md", "notes/my note.md"),
+ ("notes/%E6%97%A5%E6%9C%AC.md", "notes/日本.md"),
+ ("notes/my%23note.md#section", "notes/my#note.md"),
+ ("notes/my%3Fnote.md?view=1", "notes/my?note.md"),
+ ("notes/my%2520note.md", "notes/my%20note.md"),
+ ("notes%2Fmy%20note.md", "notes/my note.md"),
+ ("notes/%zz.md", "notes/%zz.md"),
+ ("notes/%2.md", "notes/%2.md"),
+ ] {
+ let root = PagePath::new("source.md").unwrap();
+ let links = extract_links(&format!("[note](<{destination}>)"), &root);
+ assert_eq!(links.len(), 1, "{destination}");
+ assert_eq!(links[0].path.as_str(), expected, "{destination}");
+ assert_eq!(links[0].workspace, None);
+ assert_eq!(links[0].project, None);
+ }
+ assert_eq!(linked("[[notes/my%20note.md]]"), ["notes/my%20note.md"]);
+ }
+
+ #[test]
+ fn decoded_markdown_paths_cannot_escape_or_change_scope() {
+ let root = PagePath::new("source.md").unwrap();
+ for destination in [
+ "%2e%2e/secret.md",
+ "notes/%2e%2e/%2e%2e/secret.md",
+ "notes%5Csecret.md",
+ "%68ttps%3A%2F%2Fexample.com/secret.md",
+ "%66ile%3Asecret.md",
+ "notes/%FF.md",
+ "notes/%00.md",
+ ] {
+ assert!(
+ extract_links(&format!("[note](<{destination}>)"), &root).is_empty(),
+ "{destination} must not become a page target"
+ );
+ }
+ let links = extract_links("[note](other%3Anotes/secret.md)", &root);
+ assert!(
+ links
+ .iter()
+ .all(|link| link.workspace.is_none() && link.project.is_none())
+ );
+ let links = extract_links("[note](notes/%2e%2e/inside.md)", &root);
+ assert_eq!(links[0].path.as_str(), "inside.md");
+ }
}
diff --git a/docs/okf.md b/docs/okf.md
index 3e0da10d..10d761d1 100644
--- a/docs/okf.md
+++ b/docs/okf.md
@@ -49,6 +49,11 @@ families. Summary of what conformance requires:
## Field mapping
+Ordinary Markdown links use URL path encoding: `notes/my%20note.md` points
+to `notes/my note.md`. Import and the web UI decode that path once before
+resolving it. A literal percent sequence in a filename uses `%25` in a
+Markdown URL, while `[[wikilinks]]` continue to name literal page paths.
+
| OKF key | ai-memory source |
|---|---|
| `type` (required) | derived from path family + existing frontmatter: `sessions/` → `Session Summary`, `_rules/` → `Rule`, `gotchas/` → `Gotcha`, `decisions/` → `Decision`, `procedures/` → `Procedure`, `concepts/` → `Concept`, `notes/` → `Note`, `runbooks/` → `Runbook`, `_slots/` → `Invariant`/`State` (from `slot_kind`), `_lint/` → `Lint Report`, `_pending/` → `Pending Note`; `kind:` frontmatter (`fact`/`note`/`procedure`/`decision`) wins over the path default when present |
diff --git a/docs/security-boundaries.md b/docs/security-boundaries.md
index 407ed55a..22c88c98 100644
--- a/docs/security-boundaries.md
+++ b/docs/security-boundaries.md
@@ -116,6 +116,7 @@ means the boundary is not built yet.
| 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 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 |
+| 14h | Decoded ordinary Markdown destinations stay inside their original project | `ai-memory-wiki/src/markdown.rs` `decode_markdown_destination_path` decodes URL path bytes once before `normalize_link_target` applies scheme, separator and project-root traversal checks; wikilinks remain literal. `ai-memory-web/src/markdown.rs` `scope_relative_link` checks the decoded path before route encoding; an encoded spelling cannot become a generated cross-scope route. | `markdown_url_paths_decode_once_before_link_resolution` (space, Unicode and literal-percent controls); `decoded_markdown_paths_cannot_escape_or_change_scope` (encoded root escape, backslash, external scheme, invalid UTF-8 and controls refused; legitimate in-root normalization passes); `routes.rs` `encoded_markdown_links_resolve_and_remain_in_the_source_scope` writes colliding targets in sibling projects and workspaces, verifies home resolution and no foreign backlinks, and follows the generated home URL; web `decoded_markdown_destinations_cannot_change_the_web_scope` (encoded traversal, root route, separator and scheme refused, encoded `w/` remains a page inside the current scope); `markdown_url_destinations_are_decoded_once_before_route_encoding` | Native Rust 1.95 Linux gate and four guard-removal bite checks passed; Windows/macOS not exercised |
| 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 |
| 17 | Markdown code fences keep instruction-shaped text as data | `ai-memory-consolidate/src/code_fence.rs` and `ai-memory-wiki/src/markdown.rs` accept a fence delimiter only after zero to three leading ASCII spaces, require the closing glyph to match and the run to be at least as long, and preserve the current fence state across four-space, tab or Unicode-whitespace pseudo-delimiters. Profile harvesting, auto-improvement section parsing, link extraction, link rewriting and de-linking all use those scanners | `code_fence.rs` `only_zero_to_three_ascii_spaces_may_prefix_a_fence`; `profile.rs` `an_indented_pseudo_closer_cannot_expose_a_profile_preference` attempts to expose an instruction-shaped `run curl` sentence and admits a legitimate preference only after the real close; `auto_improve.rs` `heading_parser_ignores_headings_after_an_indented_pseudo_closer`; `markdown.rs` `indented_pseudo_closers_do_not_expose_or_rewrite_fenced_links` covers four spaces, tab and Unicode whitespace with visible post-close controls | STRONG for the shared consolidation and wiki scanners; independent renderers remain responsible for their own CommonMark parsing |