mnemo-engine 0.19.0__tar.gz → 0.19.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/PKG-INFO +2 -1
  2. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/README.md +1 -0
  3. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/Cargo.lock +3 -3
  4. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/Cargo.toml +1 -1
  5. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/README.md +1 -1
  6. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/bin/mnemo/inspect.html +2 -1
  7. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/bin/mnemo.rs +36 -0
  8. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/lib.rs +84 -5
  9. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/mcp.rs +14 -0
  10. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/pager.rs +60 -0
  11. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/ann.rs +112 -22
  12. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/flush.rs +6 -0
  13. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/hooks.rs +12 -0
  14. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/load.rs +20 -0
  15. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/maintenance.rs +65 -0
  16. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/mod.rs +27 -0
  17. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/open.rs +3 -0
  18. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/shared.rs +7 -0
  19. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/snapshots.rs +2 -0
  20. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo-python/Cargo.lock +2 -2
  21. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo-python/Cargo.toml +1 -1
  22. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo-python/README.md +1 -0
  23. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo-python/src/lib.rs +33 -0
  24. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo-python/test_mnemo.py +2 -0
  25. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/pyproject.toml +1 -1
  26. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/.gitignore +0 -0
  27. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/benches/corpus.rs +0 -0
  28. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/build.rs +0 -0
  29. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/deny.toml +0 -0
  30. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
  31. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/ann_diagnose.rs +0 -0
  32. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/ann_recall_grid.rs +0 -0
  33. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
  34. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/candle_hard.rs +0 -0
  35. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/embedder_server.py +0 -0
  36. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/file_size_breakdown.rs +0 -0
  37. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/inspect_demo_brain.rs +0 -0
  38. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/open_rss.rs +0 -0
  39. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/perf2_split.rs +0 -0
  40. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/quickstart.rs +0 -0
  41. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/ranking_v2.rs +0 -0
  42. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/session.rs +0 -0
  43. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/shared_bench.rs +0 -0
  44. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/examples/thread_profile.rs +0 -0
  45. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/guide/guide.md +0 -0
  46. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/bin/mnemo/export.rs +0 -0
  47. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/bin/mnemo/hook.rs +0 -0
  48. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/bin/mnemo/inspect.rs +0 -0
  49. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/bin/mnemo/mcp_install.rs +0 -0
  50. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/bin/mnemo/onboard.rs +0 -0
  51. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/bin/mnemo/project.rs +0 -0
  52. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/builtin.rs +0 -0
  53. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/cache.rs +0 -0
  54. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/crypto.rs +0 -0
  55. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/embed.rs +0 -0
  56. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/embed_cmd.rs +0 -0
  57. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/error.rs +0 -0
  58. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/format.rs +0 -0
  59. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/freelist.rs +0 -0
  60. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/guide.rs +0 -0
  61. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/ident.rs +0 -0
  62. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/index.rs +0 -0
  63. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/keys/display.rs +0 -0
  64. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/keys/mod.rs +0 -0
  65. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/keys/os_store.rs +0 -0
  66. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/keys/recovery.rs +0 -0
  67. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/keyslot.rs +0 -0
  68. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/mcp/context.rs +0 -0
  69. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/memory.rs +0 -0
  70. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/redact.rs +0 -0
  71. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/result_cache.rs +0 -0
  72. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/session.rs +0 -0
  73. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/shared/call.rs +0 -0
  74. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/shared/fscheck.rs +0 -0
  75. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/shared/lock.rs +0 -0
  76. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/shared/mod.rs +0 -0
  77. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/shared/presence.rs +0 -0
  78. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/shared/sidecar.rs +0 -0
  79. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/cache_api.rs +0 -0
  80. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/continuation.rs +0 -0
  81. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/coordination.rs +0 -0
  82. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/crud.rs +0 -0
  83. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/essence.rs +0 -0
  84. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/findings.rs +0 -0
  85. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/header_graft_tests.rs +0 -0
  86. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/keyed.rs +0 -0
  87. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/recall.rs +0 -0
  88. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/records.rs +0 -0
  89. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/store/threads.rs +0 -0
  90. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/text.rs +0 -0
  91. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/transcript.rs +0 -0
  92. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/veccol.rs +0 -0
  93. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo/src/wal.rs +0 -0
  94. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/mnemo-python/.gitignore +0 -0
  95. {mnemo_engine-0.19.0 → mnemo_engine-0.19.1}/python/mnemo_engine/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mnemo-engine
3
- Version: 0.19.0
3
+ Version: 0.19.1
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -225,6 +225,7 @@ db.notices() # what the handle warns about (also raised as UserWarning at open)
225
225
  | `session(agent_id)` | Begin a conversation `Session` |
226
226
  | `flush()` / `close()` | Persist pending changes |
227
227
  | `verify()` | Decrypt and re-validate every record |
228
+ | `verify_index()` | v0.19.1: read the persisted ANN index apart from the records: `{"status": "none" \| "ok" \| "unknown-layout" \| "damaged", ...}` with `vectors` and `delta_runs`, `layout`, or `error`. A damaged index loses no memories: recall scans exactly, says so once in `notices()`, and the handle's next write rebuilds it |
228
229
  | `build_index()` / `drop_index()` / `has_index()` | Approximate index control |
229
230
  | `snapshots()` / `restore_to(txn_id)` / `restore_to_time(unix_secs)` | Point-in-time recovery |
230
231
  | `set_cache_capacity(pages)` / `page_cache_stats()` | Page-cache tuning (renamed from `cache_stats` in v0.4.0 — that name now belongs to the result cache below) |
@@ -211,6 +211,7 @@ db.notices() # what the handle warns about (also raised as UserWarning at open)
211
211
  | `session(agent_id)` | Begin a conversation `Session` |
212
212
  | `flush()` / `close()` | Persist pending changes |
213
213
  | `verify()` | Decrypt and re-validate every record |
214
+ | `verify_index()` | v0.19.1: read the persisted ANN index apart from the records: `{"status": "none" \| "ok" \| "unknown-layout" \| "damaged", ...}` with `vectors` and `delta_runs`, `layout`, or `error`. A damaged index loses no memories: recall scans exactly, says so once in `notices()`, and the handle's next write rebuilds it |
214
215
  | `build_index()` / `drop_index()` / `has_index()` | Approximate index control |
215
216
  | `snapshots()` / `restore_to(txn_id)` / `restore_to_time(unix_secs)` | Point-in-time recovery |
216
217
  | `set_cache_capacity(pages)` / `page_cache_stats()` | Page-cache tuning (renamed from `cache_stats` in v0.4.0 — that name now belongs to the result cache below) |
@@ -1520,7 +1520,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
1520
1520
 
1521
1521
  [[package]]
1522
1522
  name = "mnemo-engine"
1523
- version = "0.19.0"
1523
+ version = "0.19.1"
1524
1524
  dependencies = [
1525
1525
  "aes-gcm",
1526
1526
  "apple-native-keyring-store",
@@ -1561,7 +1561,7 @@ dependencies = [
1561
1561
 
1562
1562
  [[package]]
1563
1563
  name = "mnemo-node"
1564
- version = "0.19.0"
1564
+ version = "0.19.1"
1565
1565
  dependencies = [
1566
1566
  "mnemo-engine",
1567
1567
  "napi",
@@ -1571,7 +1571,7 @@ dependencies = [
1571
1571
 
1572
1572
  [[package]]
1573
1573
  name = "mnemo-uniffi"
1574
- version = "0.19.0"
1574
+ version = "0.19.1"
1575
1575
  dependencies = [
1576
1576
  "mnemo-engine",
1577
1577
  "serde_json",
@@ -10,7 +10,7 @@
10
10
  # The CLI binary name stays `mnemo`, so users still invoke `mnemo` on
11
11
  # the command line after `cargo install mnemo-engine`.
12
12
  name = "mnemo-engine"
13
- version = "0.19.0"
13
+ version = "0.19.1"
14
14
  edition = "2021"
15
15
  rust-version = "1.94"
16
16
  # `benches/corpus.rs` is a shared helper module pulled into real benches
@@ -1000,7 +1000,7 @@ cargo run --bin mnemo -- <command>
1000
1000
  | `search` | Exact nearest-neighbour search (similarity only); no path needed in a git repository (v0.16.1). Since v0.17 it leaves out coordination records, and private ones unless `--visibility` asks |
1001
1001
  | `recall` | Multi-signal ranked retrieval (sim + recency + …). Since v0.17 private records only with `--visibility private` (or `all`) |
1002
1002
  | `stale [PATH] [--mine] [--visibility L]` | The stale records, oldest first (private ones only when asked): past their `review_by`, or older than their kind's default (essence `state` and `next` 14 days, `open` 30; an `active` task with no update 3 days, a `blocked` one 7; an unread message 3). `--mine` keeps yours (`--as`, else `MNEMO_AGENT`) (v0.17) |
1003
- | `verify` | Decrypt and re-validate every live record |
1003
+ | `verify` | Decrypt and re-validate every live record; since v0.19.1 it also reads the ANN index and reports it on its own line (a damaged index is a warning: the memories are intact, and `mnemo index --rebuild` repairs it) |
1004
1004
  | `rekey` | Re-encrypt the data key under a new passphrase, or a new generated key (`--new-key`, v0.15, kept in the key store); `--rotate` also rewrites the file under a fresh data key (revokes the old secret) |
1005
1005
  | `compact` | Rebuild the file, dropping tombstones and expired; writes v9, which converts a v8 (or older) file. Since v0.13 that's the only way to make a v8 file writable again. Since v0.15 it also rebuilds the keyword index with tokenizer 2 |
1006
1006
  | `reembed` | Embed every live memory again with a new embedder (`--embed-cmd`, `--embed-name`, `--embed-query`, `--embed-dims`; without `--embed-cmd`, the built-in) and record its identity: a compaction with new vectors, so an interrupted run leaves the file as it was (v0.15) |
@@ -442,7 +442,8 @@ async function header() {
442
442
  } catch (e) { fail(e); }
443
443
  }
444
444
  function selectTab(name) {
445
- if (!views[name]) return false;
445
+ // RB-015.2: own keys only, so `#__proto__` or `#toString` opens no tab.
446
+ if (!Object.hasOwn(views, name)) return false;
446
447
  view = name;
447
448
  for (const x of document.querySelectorAll("#tabs button")) x.classList.toggle("on", x.dataset.view === name);
448
449
  return true;
@@ -2285,9 +2285,24 @@ fn warn_notices(db: Mnemo) -> Mnemo {
2285
2285
  for n in db.notices() {
2286
2286
  eprintln!("warning: {n}");
2287
2287
  }
2288
+ NOTICES_SHOWN.store(db.notices().len(), std::sync::atomic::Ordering::Relaxed);
2288
2289
  db
2289
2290
  }
2290
2291
 
2292
+ /// How many of the open handle's notices [`warn_notices`] has shown.
2293
+ static NOTICES_SHOWN: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
2294
+
2295
+ /// RB-015.1: say what the handle found to tell its owner after it opened
2296
+ /// (a damaged index, met on the first recall), once, on stderr.
2297
+ fn warn_late_notices(db: &Mnemo) {
2298
+ use std::sync::atomic::Ordering::Relaxed;
2299
+ let shown = NOTICES_SHOWN.load(Relaxed);
2300
+ for n in db.notices().iter().skip(shown) {
2301
+ eprintln!("warning: {n}");
2302
+ }
2303
+ NOTICES_SHOWN.store(shown.max(db.notices().len()), Relaxed);
2304
+ }
2305
+
2291
2306
  /// 12.3: where this command's secret came from, and the next source of the
2292
2307
  /// same kind that's present, for `info` and for a wrong secret's error.
2293
2308
  static SOURCE: std::sync::OnceLock<(String, Option<String>)> = std::sync::OnceLock::new();
@@ -3597,6 +3612,26 @@ fn run() -> std::result::Result<(), String> {
3597
3612
  if let Some(line) = mistagged_line(&mut db) {
3598
3613
  eprintln!("warning: {line}");
3599
3614
  }
3615
+ // RB-015.1: the ANN index, apart from the records.
3616
+ match db.verify_index().map_err(fmt)? {
3617
+ mnemo_engine::IndexCheck::None => {}
3618
+ mnemo_engine::IndexCheck::Ok {
3619
+ vectors,
3620
+ delta_runs,
3621
+ } => {
3622
+ println!("verified the ANN index — {vectors} vectors, {delta_runs} delta runs")
3623
+ }
3624
+ mnemo_engine::IndexCheck::UnknownLayout(l) => eprintln!(
3625
+ "note: the ANN index has layout {l}, which a newer mnemo wrote; this \
3626
+ build recalls exactly. `mnemo index --rebuild` writes one it reads"
3627
+ ),
3628
+ mnemo_engine::IndexCheck::Damaged(why) => eprintln!(
3629
+ "warning: the ANN index is damaged ({why}), so recall scans every memory. \
3630
+ Your memories are intact (checked above); `mnemo index --rebuild` \
3631
+ repairs the index"
3632
+ ),
3633
+ _ => {}
3634
+ }
3600
3635
  }
3601
3636
  Command::Import {
3602
3637
  path,
@@ -4505,6 +4540,7 @@ fn run() -> std::result::Result<(), String> {
4505
4540
  req = req.track_access(false);
4506
4541
  }
4507
4542
  let resp = db.recall_budgeted(&req).map_err(fmt)?;
4543
+ warn_late_notices(&db);
4508
4544
  // R-001.4: a tracking recall mutates the catalog's
4509
4545
  // `accessed_at` / `access_count` in memory. Flush before
4510
4546
  // exit so the bumps reach disk — otherwise the usage
@@ -161,11 +161,11 @@ pub use store::{
161
161
  /// v0.18.0 (13a step 8b): review findings.
162
162
  pub use store::{valid_finding_id, Finding, FindingFilter, FindingSpec};
163
163
  pub use store::{
164
- CloseError, CompactReport, Mnemo, MnemoConfig, RecallMode, RecallRequest, RecallResponse,
165
- RecallResult, ReembedReport, SharedMnemo, SnapshotInfo, Stats, StatsSummary, VerifyReport,
166
- DEFAULT_KEYWORD_WEIGHT, DEFAULT_TEXT_KEYWORD_WEIGHT, DEFAULT_TURN_COMPRESS_AFTER_SECS,
167
- DEFAULT_VECTOR_CACHE_BUDGET, INDEX_PERSIST_EVERY_CHANGES, INDEX_PERSIST_EVERY_COMMITS,
168
- V9_ANN_MIN_FACTS, V9_RERANK_PER_HIT,
164
+ CloseError, CompactReport, IndexCheck, Mnemo, MnemoConfig, RecallMode, RecallRequest,
165
+ RecallResponse, RecallResult, ReembedReport, SharedMnemo, SnapshotInfo, Stats, StatsSummary,
166
+ VerifyReport, DEFAULT_KEYWORD_WEIGHT, DEFAULT_TEXT_KEYWORD_WEIGHT,
167
+ DEFAULT_TURN_COMPRESS_AFTER_SECS, DEFAULT_VECTOR_CACHE_BUDGET, INDEX_PERSIST_EVERY_CHANGES,
168
+ INDEX_PERSIST_EVERY_COMMITS, V9_ANN_MIN_FACTS, V9_RERANK_PER_HIT,
169
169
  };
170
170
  pub use text::{KeywordIndex, KeywordTokenizer};
171
171
  pub use transcript::{
@@ -354,6 +354,13 @@ pub mod __failpoints {
354
354
  crate::pager::failpoints::writes_seen()
355
355
  }
356
356
 
357
+ /// v0.19.1: make the next `count` reads that cover page `page` fail
358
+ /// with an I/O error, in any thread; `count = 0` disarms it. It's
359
+ /// process-wide, so a test that arms it runs in a binary of its own.
360
+ pub fn set_page_read_fails(page: u64, count: u32) {
361
+ crate::pager::failpoints::set_page_read_fails(page, count)
362
+ }
363
+
357
364
  thread_local! {
358
365
  static AFTER_SHARED_COMMIT: std::cell::RefCell<Option<Box<dyn FnOnce()>>> =
359
366
  const { std::cell::RefCell::new(None) };
@@ -663,6 +670,78 @@ pub mod __fuzz {
663
670
  .map_err(|e| crate::MnemoError::Serialize(e.to_string()))
664
671
  }
665
672
 
673
+ /// RB-015.2 (v0.19.1): decode a v9 index run body in layout 2 (the
674
+ /// bytes after its layout byte) from arbitrary bytes. When it decodes,
675
+ /// the index is queried, changed and written again, and what it writes
676
+ /// must decode: none of it may panic.
677
+ pub fn decode_index_layout2(bytes: &[u8]) -> crate::Result<()> {
678
+ let idx = crate::index::IvfPqIndex::read_layout2(&mut &bytes[..], bytes.len() as u64)?;
679
+ exercise_index(idx)
680
+ }
681
+
682
+ /// RB-015.2: [`decode_index_layout2`] on a valid layout-2 body (a small
683
+ /// index built once) with `edits` applied, so the fuzzer starts from a
684
+ /// well-formed run. Each 3 bytes are a little-endian `u16` offset (taken
685
+ /// modulo the body's length) and a byte XORed in there; a last byte or
686
+ /// two cut the body to that fraction of its length (out of 256 or 65536).
687
+ pub fn mutate_index_layout2(edits: &[u8]) -> crate::Result<()> {
688
+ static BASE: std::sync::OnceLock<Vec<u8>> = std::sync::OnceLock::new();
689
+ let base = BASE.get_or_init(|| {
690
+ let vecs: Vec<(u128, Vec<f32>)> = (0..300u32)
691
+ .map(|i| {
692
+ let x = i as f32;
693
+ (
694
+ i as u128 + 1,
695
+ vec![
696
+ 1.0 + (x * 0.37).sin(),
697
+ (x * 0.11).cos(),
698
+ (x * 0.07).sin(),
699
+ 0.5,
700
+ ],
701
+ )
702
+ })
703
+ .collect();
704
+ let items: Vec<(u128, &[f32])> = vecs.iter().map(|(i, v)| (*i, v.as_slice())).collect();
705
+ let idx = crate::index::IvfPqIndex::build(4, &items, crate::IndexConfig::default())
706
+ .expect("the seed index builds");
707
+ let mut out = Vec::new();
708
+ idx.write_layout2(&mut out);
709
+ out
710
+ });
711
+ let mut body = base.clone();
712
+ let mut chunks = edits.chunks_exact(3);
713
+ for e in chunks.by_ref() {
714
+ let at = u16::from_le_bytes([e[0], e[1]]) as usize % body.len();
715
+ body[at] ^= e[2];
716
+ }
717
+ match chunks.remainder() {
718
+ [c] => body.truncate(body.len() * *c as usize / 256),
719
+ [a, b] => body.truncate(body.len() * u16::from_le_bytes([*a, *b]) as usize / 65536),
720
+ _ => {}
721
+ }
722
+ decode_index_layout2(&body)
723
+ }
724
+
725
+ fn exercise_index(mut idx: crate::index::IvfPqIndex) -> crate::Result<()> {
726
+ let dims = idx.dims();
727
+ if dims == 0 || dims > 4096 {
728
+ return Ok(());
729
+ }
730
+ let q = vec![0.5f32; dims];
731
+ let _ = idx.query(&q, None, None);
732
+ let first = idx.ids().next();
733
+ idx.add(u128::MAX - 1, &q);
734
+ if let Some(id) = first {
735
+ idx.remove(id);
736
+ }
737
+ let _ = idx.query(&q, Some(2), Some(8));
738
+ let mut out = Vec::new();
739
+ idx.write_layout2(&mut out);
740
+ crate::index::IvfPqIndex::read_layout2(&mut &out[..], out.len() as u64)
741
+ .expect("an index this build wrote decodes again");
742
+ Ok(())
743
+ }
744
+
666
745
  /// Parse a single MCP stdio JSON-RPC request line. Malformed
667
746
  /// input returns `Err(String)`; the fuzz target only asserts
668
747
  /// no panic and that the server would not die on this line.
@@ -224,6 +224,13 @@ enum ServerDb {
224
224
  }
225
225
 
226
226
  impl ServerDb {
227
+ fn notices(&self) -> &[String] {
228
+ match self {
229
+ ServerDb::Plain(db) => db.notices(),
230
+ ServerDb::Shared(s) => s.notices(),
231
+ }
232
+ }
233
+
227
234
  fn len(&mut self) -> Result<usize> {
228
235
  match self {
229
236
  ServerDb::Plain(db) => Ok(db.len()),
@@ -1083,6 +1090,9 @@ fn serve_inner<R: Read, W: Write>(
1083
1090
  // using it: later requests get an error, and nothing is flushed at
1084
1091
  // shutdown (the file keeps its last committed state).
1085
1092
  let mut broken = false;
1093
+ // RB-015.1: notices the handle meets during a call (a damaged index on
1094
+ // the first recall) are logged once, like the ones at start.
1095
+ let mut notices_shown = db.notices().len();
1086
1096
  for line in reader.lines() {
1087
1097
  let line = line.map_err(MnemoError::Io)?;
1088
1098
  let trimmed = line.trim();
@@ -1123,6 +1133,10 @@ fn serve_inner<R: Read, W: Write>(
1123
1133
  }
1124
1134
  }
1125
1135
  };
1136
+ for n in db.notices().iter().skip(notices_shown) {
1137
+ eprintln!("mnemo mcp: note: {n}");
1138
+ }
1139
+ notices_shown = notices_shown.max(db.notices().len());
1126
1140
  if is_notification {
1127
1141
  // Per JSON-RPC 2.0: notifications get no response.
1128
1142
  continue;
@@ -39,6 +39,46 @@ pub(crate) mod failpoints {
39
39
  static FAILING: std::cell::RefCell<Vec<u64>> = const { std::cell::RefCell::new(Vec::new()) };
40
40
  }
41
41
 
42
+ // v0.19.1 (task v0191-1b): reads of one page fail, `count` times, in
43
+ // any thread (the batch reads decrypt and stream on helper threads).
44
+ // Process-wide, so a test that arms it keeps a binary of its own.
45
+ static READ_FAIL_PAGE: std::sync::atomic::AtomicU64 =
46
+ std::sync::atomic::AtomicU64::new(u64::MAX);
47
+ static READ_FAILS_LEFT: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
48
+
49
+ /// Make the next `count` reads that cover page `page` fail with a
50
+ /// synthetic `io::Error`, in any thread. `count = 0` disarms it.
51
+ pub fn set_page_read_fails(page: u64, count: u32) {
52
+ use std::sync::atomic::Ordering::SeqCst;
53
+ READ_FAILS_LEFT.store(count, SeqCst);
54
+ READ_FAIL_PAGE.store(if count == 0 { u64::MAX } else { page }, SeqCst);
55
+ }
56
+
57
+ /// Called before every read of pages `first..first + n`.
58
+ pub(crate) fn check_read(first: u64, n: u64) -> std::io::Result<()> {
59
+ use std::sync::atomic::Ordering::SeqCst;
60
+ let page = READ_FAIL_PAGE.load(SeqCst);
61
+ if page == u64::MAX || page < first || page >= first + n {
62
+ return Ok(());
63
+ }
64
+ // A compare-exchange loop: `fetch_update` is deprecated on newer
65
+ // toolchains and its rename `try_update` is newer than the MSRV.
66
+ let mut left = READ_FAILS_LEFT.load(SeqCst);
67
+ loop {
68
+ if left == 0 {
69
+ return Ok(());
70
+ }
71
+ match READ_FAILS_LEFT.compare_exchange(left, left - 1, SeqCst, SeqCst) {
72
+ Ok(_) => break,
73
+ Err(now) => left = now,
74
+ }
75
+ }
76
+ if left == 1 {
77
+ READ_FAIL_PAGE.store(u64::MAX, SeqCst);
78
+ }
79
+ Err(std::io::Error::other("injected read failure"))
80
+ }
81
+
42
82
  /// Fail exactly the writes numbered in `ns`, counting from 0 at this
43
83
  /// call (each write the pager or the WAL makes is one number). Unlike
44
84
  /// [`set_writes_until_fail_n`], the failing writes needn't be
@@ -126,6 +166,20 @@ pub(crate) fn __failpoint_check() -> std::io::Result<()> {
126
166
  failpoints::check()
127
167
  }
128
168
 
169
+ /// v0.19.1: the read-side failpoint ([`failpoints::set_page_read_fails`]),
170
+ /// checked before every read of pages `first..first + n`.
171
+ #[cfg(not(any(test, feature = "failpoints")))]
172
+ #[inline(always)]
173
+ fn read_failpoint(_first: u64, _n: u64) -> std::io::Result<()> {
174
+ Ok(())
175
+ }
176
+
177
+ #[cfg(any(test, feature = "failpoints"))]
178
+ #[inline(always)]
179
+ fn read_failpoint(first: u64, n: u64) -> std::io::Result<()> {
180
+ failpoints::check_read(first, n)
181
+ }
182
+
129
183
  use zeroize::Zeroizing;
130
184
 
131
185
  use crate::cache::PageCache;
@@ -203,6 +257,10 @@ impl PageBatch {
203
257
  /// use the file's cursor, which every other read and write here sets
204
258
  /// itself first.
205
259
  fn read_exact_at(file: &File, buf: &mut [u8], offset: u64) -> std::io::Result<()> {
260
+ read_failpoint(
261
+ offset / PAGE_SIZE as u64,
262
+ (buf.len() as u64).div_ceil(PAGE_SIZE as u64),
263
+ )?;
206
264
  #[cfg(unix)]
207
265
  {
208
266
  use std::os::unix::fs::FileExt;
@@ -547,6 +605,7 @@ impl Pager {
547
605
  let mut disk = [0u8; PAGE_SIZE];
548
606
  self.f()?
549
607
  .seek(SeekFrom::Start(page_no * PAGE_SIZE as u64))?;
608
+ read_failpoint(page_no, 1)?;
550
609
  self.f()?.read_exact(&mut disk)?;
551
610
 
552
611
  let mut nonce = [0u8; NONCE_LEN];
@@ -571,6 +630,7 @@ impl Pager {
571
630
  let mut disk = [0u8; PAGE_SIZE];
572
631
  self.f()?
573
632
  .seek(SeekFrom::Start(page_no * PAGE_SIZE as u64))?;
633
+ read_failpoint(page_no, 1)?;
574
634
  self.f()?.read_exact(&mut disk)?;
575
635
  let mut nonce = [0u8; NONCE_LEN];
576
636
  nonce.copy_from_slice(&disk[0..NONCE_LEN]);
@@ -39,8 +39,14 @@ impl Mnemo {
39
39
  .unwrap_or(V9_ANN_MIN_FACTS);
40
40
  #[cfg(not(feature = "dev-hooks"))]
41
41
  let min_facts = V9_ANN_MIN_FACTS;
42
+ // A build replaces an index that was never loaded: track its delta
43
+ // runs first, so this commit frees them with the base.
44
+ if self.ann_unloaded && self.is_v9() {
45
+ self.track_index_chain();
46
+ }
42
47
  if self.is_v9() && mems.len() < min_facts {
43
- if self.ann.is_some() || self.ann_unloaded {
48
+ if self.ann.is_some() || self.ann_unloaded || self.index_repair {
49
+ self.index_repair = false;
44
50
  self.ann = None;
45
51
  self.ann_unloaded = false;
46
52
  self.dirty_index = true;
@@ -64,6 +70,7 @@ impl Mnemo {
64
70
  }
65
71
  self.ann = Some(idx);
66
72
  self.ann_unloaded = false;
73
+ self.index_repair = false;
67
74
  self.dirty_index = true;
68
75
  self.index_persist.forced = true;
69
76
  Ok(info)
@@ -91,12 +98,21 @@ impl Mnemo {
91
98
  if self.read_only {
92
99
  return;
93
100
  }
101
+ if self.ann_unloaded && self.is_v9() {
102
+ self.track_index_chain();
103
+ }
94
104
  if self.ann.is_some() || self.ann_unloaded {
95
105
  self.ann = None;
96
106
  self.ann_unloaded = false;
97
107
  self.dirty_index = true;
98
108
  self.index_persist.forced = true;
99
109
  }
110
+ // RB-015.1: dropping a damaged index persists "no index" too.
111
+ if self.index_repair {
112
+ self.index_repair = false;
113
+ self.dirty_index = true;
114
+ self.index_persist.forced = true;
115
+ }
100
116
  }
101
117
 
102
118
  /// PERF-1 (R-004.1): bring a just-loaded ANN index up to date with the
@@ -186,27 +202,18 @@ impl Mnemo {
186
202
  return Ok(());
187
203
  }
188
204
  self.ann_unloaded = false;
189
- self.ann = load_index(
190
- &mut self.pager,
191
- self.header.index_start,
192
- self.header.index_pages,
193
- self.header.index_len,
194
- self.header.index_gen,
195
- self.dimensions,
196
- )?;
197
- // FMT-9c.3: replay the v9 index delta chain, then record changes.
198
- if self.is_v9() {
199
- if let Some(ann) = self.ann.as_mut() {
200
- let (chain, n) = apply_index_chain(&mut self.pager, ann, self.header.index_delta)?;
201
- self.index_chain = chain;
202
- self.index_chain_ops = n;
203
- ann.enable_log();
204
- } else if self.header.index_pages > 0 {
205
- // FMT-9f (the 9d leak): an unknown-layout base loads as no
206
- // index; still track its delta runs, so rebuilding or
207
- // dropping the index frees them along with the base.
208
- self.index_chain = index_chain_runs(&mut self.pager, self.header.index_delta);
209
- self.index_chain_ops = 0;
205
+ match self.load_persisted_index() {
206
+ Ok(()) => {}
207
+ // RB-015.1 (v0.19.1): the index is derived data. A run that
208
+ // doesn't decrypt or decode loads as no index, like a layout
209
+ // this build doesn't know: recall scans exactly, the handle
210
+ // says so once, and a read-write handle rebuilds it.
211
+ Err(e) if index_damage(&e) => self.index_damaged(&e),
212
+ // Anything else (an I/O error) says nothing about the run: the
213
+ // next call tries the load again (task v0191-1b).
214
+ Err(e) => {
215
+ self.ann_unloaded = true;
216
+ return Err(e);
210
217
  }
211
218
  }
212
219
  let (index_start, index_gen) = (self.header.index_start, self.index_gen_now());
@@ -237,5 +244,88 @@ impl Mnemo {
237
244
  Ok(())
238
245
  }
239
246
 
247
+ /// Load the header's index run and replay its delta chain into
248
+ /// `self.ann`, or leave `self.ann` as `None` (no index, or a layout this
249
+ /// build doesn't know). Nothing is set when it fails.
250
+ fn load_persisted_index(&mut self) -> Result<()> {
251
+ let mut ann = load_index(
252
+ &mut self.pager,
253
+ self.header.index_start,
254
+ self.header.index_pages,
255
+ self.header.index_len,
256
+ self.header.index_gen,
257
+ self.dimensions,
258
+ )?;
259
+ // FMT-9c.3: replay the v9 index delta chain, then record changes.
260
+ if self.is_v9() {
261
+ if let Some(a) = ann.as_mut() {
262
+ let (chain, n) = apply_index_chain(&mut self.pager, a, self.header.index_delta)?;
263
+ a.enable_log();
264
+ self.index_chain = chain;
265
+ self.index_chain_ops = n;
266
+ } else if self.header.index_pages > 0 {
267
+ // FMT-9f (the 9d leak): an unknown-layout base loads as no
268
+ // index; still track its delta runs, so rebuilding or
269
+ // dropping the index frees them along with the base.
270
+ self.track_index_chain();
271
+ }
272
+ }
273
+ self.ann = ann;
274
+ Ok(())
275
+ }
276
+
277
+ /// FMT-9f: the delta runs of an index that isn't loaded, so the next
278
+ /// build or drop frees them with the base.
279
+ fn track_index_chain(&mut self) {
280
+ self.index_chain = index_chain_runs(&mut self.pager, self.header.index_delta);
281
+ self.index_chain_ops = 0;
282
+ }
283
+
284
+ /// RB-015.1: the persisted index didn't load. Recall scans exactly; the
285
+ /// runs stay tracked so a rebuild frees them; the handle's next commit
286
+ /// that writes rebuilds the index.
287
+ fn index_damaged(&mut self, e: &MnemoError) {
288
+ self.ann = None;
289
+ if self.is_v9() {
290
+ self.track_index_chain();
291
+ }
292
+ // Set on a read-only handle too: a shared handle is read-only only
293
+ // inside a read window, and its next write window repairs it.
294
+ self.index_repair = true;
295
+ let next = if self.read_only {
296
+ "`mnemo index --rebuild` repairs it"
297
+ } else {
298
+ "this handle rebuilds it with its next write, or `mnemo index --rebuild` does now"
299
+ };
300
+ let text = format!(
301
+ "the approximate index is damaged ({e}), so recall scans every memory; \
302
+ your memories are intact, and {next}"
303
+ );
304
+ if !self.notices.contains(&text) {
305
+ self.notices.push(text);
306
+ }
307
+ }
308
+
309
+ /// RB-015.1: in a commit that writes, rebuild the index a damaged run
310
+ /// left this handle without. A file too small for an index (or with no
311
+ /// facts left) drops the damaged run instead.
312
+ pub(super) fn repair_index(&mut self) -> Result<()> {
313
+ if !self.index_repair || self.read_only {
314
+ return Ok(());
315
+ }
316
+ self.index_repair = false;
317
+ match self.build_index() {
318
+ Ok(_) => {}
319
+ Err(MnemoError::Invalid(_)) => {}
320
+ Err(e) => return Err(e),
321
+ }
322
+ if self.ann.is_none() {
323
+ // Persisted as "no index": frees the damaged base and its chain.
324
+ self.dirty_index = true;
325
+ self.index_persist.forced = true;
326
+ }
327
+ Ok(())
328
+ }
329
+
240
330
  // --- durability & maintenance ----------------------------------------
241
331
  }
@@ -187,6 +187,12 @@ impl Mnemo {
187
187
  self.ensure_ann()?;
188
188
  }
189
189
  }
190
+ // RB-015.1: a damaged index run left this handle without an index;
191
+ // a commit that writes rebuilds it (or drops the run on a file too
192
+ // small for one).
193
+ if self.index_repair && (self.dirty_catalog || self.dirty_cache) {
194
+ self.repair_index()?;
195
+ }
190
196
  // PERF-1: persist the (derived) ANN index only when forced or due.
191
197
  // Otherwise the header keeps pointing at the previous index run, and
192
198
  // records written since then are re-assigned when it's next loaded
@@ -240,6 +240,18 @@ impl Mnemo {
240
240
  (self.index_chain.len(), self.header.index_start)
241
241
  }
242
242
 
243
+ /// **Not a stable API.** RB-015.1: `[(first page, pages)]` of the base
244
+ /// index run and the newest index delta run (`(0, 0)` when absent), so
245
+ /// a test can damage one on disk.
246
+ #[doc(hidden)]
247
+ pub fn __index_runs(&self) -> [(u64, u64); 2] {
248
+ let h = &self.header;
249
+ [
250
+ (h.index_start, h.index_pages),
251
+ (h.index_delta.start, h.index_delta.pages),
252
+ ]
253
+ }
254
+
243
255
  /// **Not a stable API.** FMT-9d: BM25 keyword scores for `query`, best
244
256
  /// first: `(id, score)`, with k1 1.2 and b 0.75.
245
257
  #[doc(hidden)]
@@ -727,10 +727,15 @@ pub(super) fn index_chain_runs(pager: &mut Pager, head: RunPtr) -> Vec<RunPtr> {
727
727
  let mut runs = Vec::new();
728
728
  let mut at = head;
729
729
  while !at.is_empty() && runs.len() <= 4096 {
730
+ // RB-015.1: a run that doesn't read is still the chain's (its
731
+ // pointer was authenticated), so it's freed too; the runs before
732
+ // it can't be found, and wait for a compaction.
730
733
  let Ok(buf) = read_run_bytes(pager, at.start, at.pages, at.len, at.gen) else {
734
+ runs.push(at);
731
735
  break;
732
736
  };
733
737
  let Ok(d) = rmp_serde::from_slice::<IndexDeltaOwned>(&buf) else {
738
+ runs.push(at);
734
739
  break;
735
740
  };
736
741
  runs.push(at);
@@ -826,6 +831,21 @@ pub(super) fn load_cache_directory(
826
831
  }
827
832
 
828
833
  /// Load an ANN index run, validating its dimensionality.
834
+ /// RB-015.1 (v0.19.1): an error loading the persisted ANN index that means
835
+ /// the run itself is bad (a page that fails authentication, bytes that
836
+ /// don't decode, a shape that doesn't fit), as opposed to an I/O error or a
837
+ /// lock, which say nothing about the run and still fail the call.
838
+ pub(super) fn index_damage(e: &MnemoError) -> bool {
839
+ matches!(
840
+ e,
841
+ MnemoError::PageAuthFailed(_)
842
+ | MnemoError::Crypto(_)
843
+ | MnemoError::Serialize(_)
844
+ | MnemoError::Invalid(_)
845
+ | MnemoError::DimensionMismatch { .. }
846
+ )
847
+ }
848
+
829
849
  pub(super) fn load_index(
830
850
  pager: &mut Pager,
831
851
  start: u64,
@@ -620,6 +620,71 @@ impl Mnemo {
620
620
  })
621
621
  }
622
622
 
623
+ /// RB-015.1 (v0.19.1): read the persisted ANN index run and its delta
624
+ /// runs from disk, apart from [`Mnemo::verify_report`]'s records. The
625
+ /// index is derived data, so a damaged one is reported, not an error:
626
+ /// the memories are intact and `mnemo index --rebuild` replaces it. An
627
+ /// I/O error still fails the call. Reads only; this handle's own
628
+ /// loaded index (if any) isn't touched.
629
+ pub fn verify_index(&mut self) -> Result<IndexCheck> {
630
+ let h = &self.header;
631
+ let (start, pages, len, gen, delta) = (
632
+ h.index_start,
633
+ h.index_pages,
634
+ h.index_len,
635
+ h.index_gen,
636
+ h.index_delta,
637
+ );
638
+ if pages == 0 {
639
+ return Ok(IndexCheck::None);
640
+ }
641
+ let damaged = |e: MnemoError| -> Result<IndexCheck> {
642
+ if index_damage(&e) {
643
+ Ok(IndexCheck::Damaged(e.to_string()))
644
+ } else {
645
+ Err(e)
646
+ }
647
+ };
648
+ let buf = match read_run_bytes(&mut self.pager, start, pages, len, gen) {
649
+ Ok(b) => b,
650
+ Err(e) => return damaged(e),
651
+ };
652
+ let decoded: Result<crate::index::IvfPqIndex> = if !self.is_v9() {
653
+ rmp_serde::from_slice(&buf).map_err(|e| MnemoError::Serialize(e.to_string()))
654
+ } else {
655
+ match buf.first() {
656
+ Some(&V9_INDEX_LAYOUT) => {
657
+ crate::index::IvfPqIndex::read_layout2(&mut &buf[1..], buf.len() as u64 - 1)
658
+ }
659
+ Some(&V9_INDEX_LAYOUT_MSGPACK) => rmp_serde::from_slice(&buf[1..])
660
+ .map_err(|e| MnemoError::Serialize(e.to_string())),
661
+ Some(&other) => return Ok(IndexCheck::UnknownLayout(other)),
662
+ None => Err(MnemoError::Invalid("the index run is empty".into())),
663
+ }
664
+ };
665
+ let mut idx = match decoded {
666
+ Ok(i) => i,
667
+ Err(e) => return damaged(e),
668
+ };
669
+ if idx.dims() != self.dimensions {
670
+ return damaged(MnemoError::Invalid(
671
+ "ANN index dimensionality does not match the database".into(),
672
+ ));
673
+ }
674
+ let delta_runs = if self.is_v9() {
675
+ match apply_index_chain(&mut self.pager, &mut idx, delta) {
676
+ Ok((chain, _)) => chain.len(),
677
+ Err(e) => return damaged(e),
678
+ }
679
+ } else {
680
+ 0
681
+ };
682
+ Ok(IndexCheck::Ok {
683
+ vectors: idx.len(),
684
+ delta_runs,
685
+ })
686
+ }
687
+
623
688
  /// FMT-9 (a): fail if the free list (or a pending free) overlaps any
624
689
  /// page the current state references.
625
690
  pub(super) fn check_free_list_disjoint(&self) -> Result<()> {
@@ -1023,6 +1023,29 @@ pub struct VerifyReport {
1023
1023
  pub keyword_tokenizer: Option<crate::KeywordTokenizer>,
1024
1024
  }
1025
1025
 
1026
+ /// RB-015.1 (v0.19.1): what [`Mnemo::verify_index`] found in the persisted
1027
+ /// ANN index. The index is derived data: whatever this says, the memories
1028
+ /// are intact, and `mnemo index --rebuild` writes a new index.
1029
+ #[derive(Clone, Debug, PartialEq, Eq)]
1030
+ #[non_exhaustive]
1031
+ pub enum IndexCheck {
1032
+ /// The file has no persisted index; recall scans exactly.
1033
+ None,
1034
+ /// The index run and its delta runs decrypt and decode.
1035
+ Ok {
1036
+ /// Vectors in the index, with the delta runs applied.
1037
+ vectors: usize,
1038
+ /// Delta runs on the chain after the base run.
1039
+ delta_runs: usize,
1040
+ },
1041
+ /// The base run has a layout this build doesn't know (a newer build
1042
+ /// wrote it). Recall scans exactly; the newer build still reads it.
1043
+ UnknownLayout(u8),
1044
+ /// A run didn't decrypt or decode. Recall scans exactly until the index
1045
+ /// is rebuilt. The text is the error.
1046
+ Damaged(String),
1047
+ }
1048
+
1026
1049
  /// An encrypted, single-file agent memory database.
1027
1050
  pub struct Mnemo {
1028
1051
  /// 12.4: the lock layer's note for a handle opened through it for a
@@ -1055,6 +1078,10 @@ pub struct Mnemo {
1055
1078
  /// PERF-1 step 3: the header points at a persisted ANN index that
1056
1079
  /// hasn't been loaded yet. It loads on first use (`ensure_ann`).
1057
1080
  ann_unloaded: bool,
1081
+ /// RB-015.1 (v0.19.1): the persisted index run didn't load (a damaged
1082
+ /// page or a run that doesn't decode), so this handle recalls exactly.
1083
+ /// On a read-write handle, the next commit that writes rebuilds it.
1084
+ index_repair: bool,
1058
1085
  /// Append-only manifest of committed snapshots, oldest first. Capped
1059
1086
  /// at [`Mnemo::max_snapshots`] entries on every flush — the oldest
1060
1087
  /// entries are pruned first.
@@ -445,6 +445,7 @@ impl Mnemo {
445
445
  bm25: Bm25State::default(),
446
446
  kw: None,
447
447
  index_layout_override: None,
448
+ index_repair: false,
448
449
  dirty_rows: std::collections::BTreeSet::new(),
449
450
  delta_chain: Vec::new(),
450
451
  delta_rows: 0,
@@ -936,6 +937,7 @@ impl Mnemo {
936
937
  },
937
938
  kw: None,
938
939
  index_layout_override: None,
940
+ index_repair: false,
939
941
  dirty_rows: std::collections::BTreeSet::new(),
940
942
  delta_chain,
941
943
  delta_rows,
@@ -1266,6 +1268,7 @@ impl Mnemo {
1266
1268
  },
1267
1269
  kw: None,
1268
1270
  index_layout_override: None,
1271
+ index_repair: false,
1269
1272
  dirty_rows: std::collections::BTreeSet::new(),
1270
1273
  delta_chain,
1271
1274
  delta_rows,
@@ -540,6 +540,13 @@ impl SharedMnemo {
540
540
  // resumed. A write window has cleared its stamp before running the
541
541
  // closure, so the handle's next call reloads.
542
542
  let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| run(self)));
543
+ // RB-015.1: what the handle met inside the call (a damaged index)
544
+ // joins the notices, once.
545
+ if let Some(db) = &self.db {
546
+ for n in db.notices() {
547
+ self.locks.notice(n.clone());
548
+ }
549
+ }
543
550
  // The lock-info note (if any) goes before the unlock.
544
551
  drop(held);
545
552
  if let Some(db) = self.db.as_mut() {
@@ -119,6 +119,8 @@ impl Mnemo {
119
119
  self.recs = RecPages::from_catalog(&self.catalog);
120
120
  self.ann = ann;
121
121
  self.ann_unloaded = false;
122
+ // RB-015.1: the restored index replaces a damaged one.
123
+ self.index_repair = false;
122
124
  // The handle caches describe the catalog being replaced.
123
125
  self.key_index = None;
124
126
  self.superseded = None;
@@ -1251,7 +1251,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
1251
1251
 
1252
1252
  [[package]]
1253
1253
  name = "mnemo-engine"
1254
- version = "0.19.0"
1254
+ version = "0.19.1"
1255
1255
  dependencies = [
1256
1256
  "aes-gcm",
1257
1257
  "apple-native-keyring-store",
@@ -1285,7 +1285,7 @@ dependencies = [
1285
1285
 
1286
1286
  [[package]]
1287
1287
  name = "mnemo-python"
1288
- version = "0.19.0"
1288
+ version = "0.19.1"
1289
1289
  dependencies = [
1290
1290
  "mnemo-engine",
1291
1291
  "pyo3",
@@ -4,7 +4,7 @@
4
4
  # fields below are still useful for `cargo publish --dry-run` to lint
5
5
  # cleanly and for `cargo doc` to render coherently.
6
6
  name = "mnemo-python"
7
- version = "0.19.0"
7
+ version = "0.19.1"
8
8
  edition = "2021"
9
9
  rust-version = "1.94"
10
10
  description = "Python (PyO3) bindings for the Mnemo encrypted agent-memory engine; built by maturin into the mnemo-engine wheel on PyPI"
@@ -211,6 +211,7 @@ db.notices() # what the handle warns about (also raised as UserWarning at open)
211
211
  | `session(agent_id)` | Begin a conversation `Session` |
212
212
  | `flush()` / `close()` | Persist pending changes |
213
213
  | `verify()` | Decrypt and re-validate every record |
214
+ | `verify_index()` | v0.19.1: read the persisted ANN index apart from the records: `{"status": "none" \| "ok" \| "unknown-layout" \| "damaged", ...}` with `vectors` and `delta_runs`, `layout`, or `error`. A damaged index loses no memories: recall scans exactly, says so once in `notices()`, and the handle's next write rebuilds it |
214
215
  | `build_index()` / `drop_index()` / `has_index()` | Approximate index control |
215
216
  | `snapshots()` / `restore_to(txn_id)` / `restore_to_time(unix_secs)` | Point-in-time recovery |
216
217
  | `set_cache_capacity(pages)` / `page_cache_stats()` | Page-cache tuning (renamed from `cache_stats` in v0.4.0 — that name now belongs to the result cache below) |
@@ -2083,6 +2083,39 @@ impl Mnemo {
2083
2083
  self.rd_nogil(py, |db| db.verify())
2084
2084
  }
2085
2085
 
2086
+ /// RB-015.1 (v0.19.1): read the persisted ANN index from disk, apart
2087
+ /// from the records `verify` checks. A dict: `status` is `"none"`,
2088
+ /// `"ok"` (with `vectors` and `delta_runs`), `"unknown-layout"` (with
2089
+ /// `layout`: a newer build wrote it) or `"damaged"` (with `error`).
2090
+ /// The index is derived data: when it's damaged the memories are
2091
+ /// intact, recall scans exactly, and `rebuild_index` replaces it.
2092
+ /// Releases the GIL.
2093
+ fn verify_index<'py>(&mut self, py: Python<'py>) -> PyResult<Bound<'py, PyDict>> {
2094
+ let check = self.rd_nogil(py, |db| db.verify_index())?;
2095
+ let d = PyDict::new_bound(py);
2096
+ match check {
2097
+ mnemo_core::IndexCheck::None => d.set_item("status", "none")?,
2098
+ mnemo_core::IndexCheck::Ok {
2099
+ vectors,
2100
+ delta_runs,
2101
+ } => {
2102
+ d.set_item("status", "ok")?;
2103
+ d.set_item("vectors", vectors)?;
2104
+ d.set_item("delta_runs", delta_runs)?;
2105
+ }
2106
+ mnemo_core::IndexCheck::UnknownLayout(layout) => {
2107
+ d.set_item("status", "unknown-layout")?;
2108
+ d.set_item("layout", layout)?;
2109
+ }
2110
+ mnemo_core::IndexCheck::Damaged(error) => {
2111
+ d.set_item("status", "damaged")?;
2112
+ d.set_item("error", error)?;
2113
+ }
2114
+ _ => d.set_item("status", "unknown")?,
2115
+ }
2116
+ Ok(d)
2117
+ }
2118
+
2086
2119
  /// What the handle warns about once: for a shared handle (12.4), a
2087
2120
  /// sidecar directory it can't use, a synced folder, an allowed network
2088
2121
  /// filesystem; for any handle (12.3), a passphrase on raw-key KDF
@@ -132,6 +132,8 @@ def test_index_and_snapshots():
132
132
  v = [float(i % 4 == j) for j in range(4)]
133
133
  db.remember(f"m{i}", "semantic", v)
134
134
  db.flush()
135
+ # v0.19.1 (RB-015.1): the index, read apart from the records.
136
+ assert db.verify_index() == {"status": "none"}
135
137
 
136
138
  db.build_index()
137
139
  assert db.has_index()
@@ -15,7 +15,7 @@ build-backend = "maturin"
15
15
  # sites unchanged). See the "Breaking: import name" section in
16
16
  # CHANGELOG.md for the full migration.
17
17
  name = "mnemo-engine"
18
- version = "0.19.0"
18
+ version = "0.19.1"
19
19
  description = "Encrypted, portable agent-memory engine — Python bindings"
20
20
  readme = "README.md"
21
21
  requires-python = ">=3.8"