mnemo-engine 0.12.0__tar.gz → 0.12.2__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 (157) hide show
  1. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/PKG-INFO +2 -2
  2. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/README.md +1 -1
  3. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/Cargo.lock +3 -3
  4. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/Cargo.toml +1 -1
  5. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/README.md +46 -8
  6. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/README.md +132 -17
  7. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/gradle.properties +1 -1
  8. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/release-check/settings.gradle.kts +1 -1
  9. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/scripts/central-dry-run.sh +14 -1
  10. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/scripts/emulator-tests.sh +31 -0
  11. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/androidTest/kotlin/io/github/toarchkumar/mnemo/AndroidTests.kt +30 -2
  12. mnemo_engine-0.12.2/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/FlushPolicy.kt +100 -0
  13. mnemo_engine-0.12.2/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoKeystore.kt +344 -0
  14. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStore.kt +244 -55
  15. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStoreConfiguration.kt +7 -1
  16. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStoreException.kt +12 -5
  17. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/ProcessStopObserver.kt +15 -3
  18. mnemo_engine-0.12.2/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/EmbedderLockTests.kt +112 -0
  19. mnemo_engine-0.12.2/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/FlushPolicyTests.kt +185 -0
  20. mnemo_engine-0.12.2/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/KeystoreErrorTests.kt +126 -0
  21. mnemo_engine-0.12.2/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/StoreHardeningTests.kt +108 -0
  22. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/StoreTests.kt +24 -0
  23. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/uniffi.toml +5 -0
  24. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/README.md +146 -16
  25. mnemo_engine-0.12.2/mnemo/bindings/swift/Sources/Mnemo/FlushPolicy.swift +102 -0
  26. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Sources/Mnemo/Lifecycle.swift +28 -6
  27. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Sources/Mnemo/MnemoKeychain.swift +16 -0
  28. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Sources/Mnemo/MnemoStore.swift +356 -69
  29. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Sources/Mnemo/MnemoStoreError.swift +28 -2
  30. mnemo_engine-0.12.2/mnemo/bindings/swift/TestHost/App/MnemoTestHostApp.swift +74 -0
  31. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/TestHost/project.yml +2 -0
  32. mnemo_engine-0.12.2/mnemo/bindings/swift/Tests/MnemoTests/EmbedderLockTests.swift +125 -0
  33. mnemo_engine-0.12.2/mnemo/bindings/swift/Tests/MnemoTests/FlushPolicyTests.swift +165 -0
  34. mnemo_engine-0.12.2/mnemo/bindings/swift/Tests/MnemoTests/StoreHardeningTests.swift +155 -0
  35. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Tests/MnemoTests/StoreTests.swift +37 -0
  36. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Tests/MnemoTests/iOSTests.swift +56 -0
  37. mnemo_engine-0.12.2/mnemo/bindings/swift/scripts/check-published-package.sh +140 -0
  38. mnemo_engine-0.12.2/mnemo/bindings/swift/scripts/kill-test.sh +78 -0
  39. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/device_budget.rs +128 -2
  40. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/bin/mnemo.rs +27 -1
  41. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/lib.rs +4 -3
  42. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/mcp.rs +1 -0
  43. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/crud.rs +52 -0
  44. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/essence.rs +1 -1
  45. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/flush.rs +41 -1
  46. mnemo_engine-0.12.2/mnemo/src/store/header_graft_tests.rs +180 -0
  47. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/keyed.rs +30 -3
  48. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/maintenance.rs +244 -52
  49. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/mod.rs +102 -0
  50. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/open.rs +42 -0
  51. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/records.rs +59 -4
  52. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/wal.rs +16 -0
  53. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/cli_smoke.rs +43 -0
  54. mnemo_engine-0.12.2/mnemo/tests/engine_safety.rs +277 -0
  55. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/fmt9b_column.rs +125 -5
  56. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/fmt9d_bm25.rs +13 -6
  57. mnemo_engine-0.12.2/mnemo/tests/rekey_export.rs +208 -0
  58. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo-python/Cargo.lock +2 -2
  59. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo-python/Cargo.toml +1 -1
  60. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo-python/README.md +1 -1
  61. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo-python/src/lib.rs +1 -0
  62. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo-python/test_mnemo.py +9 -0
  63. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/pyproject.toml +1 -1
  64. mnemo_engine-0.12.0/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoKeystore.kt +0 -213
  65. mnemo_engine-0.12.0/mnemo/bindings/swift/TestHost/App/MnemoTestHostApp.swift +0 -11
  66. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/.gitignore +0 -0
  67. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/benches/cache.rs +0 -0
  68. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/benches/corpus.rs +0 -0
  69. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/benches/embed_overhead.rs +0 -0
  70. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/benches/open.rs +0 -0
  71. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/benches/recall.rs +0 -0
  72. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/benches/thread.rs +0 -0
  73. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/benches/write.rs +0 -0
  74. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/.gitignore +0 -0
  75. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/NOTICE +0 -0
  76. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/build.gradle.kts +0 -0
  77. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/consumer-rules.pro +0 -0
  78. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/gradle/wrapper/gradle-wrapper.jar +0 -0
  79. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/gradle/wrapper/gradle-wrapper.properties +0 -0
  80. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/gradlew +0 -0
  81. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/gradlew.bat +0 -0
  82. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/release-check/build.gradle.kts +0 -0
  83. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/release-check/src/main/AndroidManifest.xml +0 -0
  84. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/release-check/src/test/kotlin/io/github/toarchkumar/mnemo/check/ConsumerTest.kt +0 -0
  85. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/scripts/build-native.sh +0 -0
  86. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/scripts/check-elf.py +0 -0
  87. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/scripts/check-package.py +0 -0
  88. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/settings.gradle.kts +0 -0
  89. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/androidTest/AndroidManifest.xml +0 -0
  90. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/androidTest/kotlin/io/github/toarchkumar/mnemo/TestActivity.kt +0 -0
  91. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/main/AndroidManifest.xml +0 -0
  92. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/KeyId.kt +0 -0
  93. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoKeyStorage.kt +0 -0
  94. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/sharedTest/kotlin/io/github/toarchkumar/mnemo/Support.kt +0 -0
  95. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/KeystoreFileTests.kt +0 -0
  96. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/.gitignore +0 -0
  97. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Package.swift +0 -0
  98. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Sources/Mnemo/FilePolicy.swift +0 -0
  99. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/Tests/MnemoTests/Support.swift +0 -0
  100. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/scripts/build-xcframework.sh +0 -0
  101. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/scripts/check-release-package.sh +0 -0
  102. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/bindings/swift/scripts/make-release-package.sh +0 -0
  103. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/deny.toml +0 -0
  104. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
  105. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/ann_diagnose.rs +0 -0
  106. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/ann_recall_grid.rs +0 -0
  107. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
  108. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/embedder_server.py +0 -0
  109. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/file_size_breakdown.rs +0 -0
  110. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/fmt9_proto.rs +0 -0
  111. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/open_rss.rs +0 -0
  112. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/quickstart.rs +0 -0
  113. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/ranking_v2.rs +0 -0
  114. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/session.rs +0 -0
  115. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/examples/thread_profile.rs +0 -0
  116. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/cache.rs +0 -0
  117. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/crypto.rs +0 -0
  118. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/embed.rs +0 -0
  119. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/embed_cmd.rs +0 -0
  120. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/error.rs +0 -0
  121. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/format.rs +0 -0
  122. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/freelist.rs +0 -0
  123. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/index.rs +0 -0
  124. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/keyslot.rs +0 -0
  125. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/memory.rs +0 -0
  126. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/pager.rs +0 -0
  127. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/result_cache.rs +0 -0
  128. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/session.rs +0 -0
  129. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/ann.rs +0 -0
  130. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/cache_api.rs +0 -0
  131. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/continuation.rs +0 -0
  132. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/hooks.rs +0 -0
  133. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/load.rs +0 -0
  134. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/recall.rs +0 -0
  135. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/snapshots.rs +0 -0
  136. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/store/threads.rs +0 -0
  137. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/text.rs +0 -0
  138. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/transcript.rs +0 -0
  139. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/src/veccol.rs +0 -0
  140. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/dur1_torn_header.rs +0 -0
  141. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/fix1_correctness_sweep.rs +0 -0
  142. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/fixtures/v0_10_0_memories.jsonl +0 -0
  143. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/fmt9_skeleton.rs +0 -0
  144. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/fmt9c_commit.rs +0 -0
  145. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/fmt9e_zstd.rs +0 -0
  146. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/integration.rs +0 -0
  147. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/proptest_store.proptest-regressions +0 -0
  148. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/proptest_store.rs +0 -0
  149. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/sec1_nonce_uniqueness.rs +0 -0
  150. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/suites/dur1_torn_header.rs +0 -0
  151. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/suites/fix1_correctness_sweep.rs +0 -0
  152. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/suites/integration.rs +0 -0
  153. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/suites/sec1_nonce_uniqueness.rs +0 -0
  154. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/v0_10_fixture.rs +0 -0
  155. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo/tests/wal_recover_alloc.rs +0 -0
  156. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/mnemo-python/.gitignore +0 -0
  157. {mnemo_engine-0.12.0 → mnemo_engine-0.12.2}/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.12.0
3
+ Version: 0.12.2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: OSI Approved :: Apache Software License
@@ -193,7 +193,7 @@ its own agent.
193
193
  | `remember_text(content, memory_type, **kwargs)` | Embed `content` via the registered embedder and `remember` the result. Accepts the same per-memory kwargs as `remember` (`agent_id`, `importance`, `session_id`, `ttl_secs`, `shared`, `metadata`) |
194
194
  | `recall_text(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None, filter=None, max_bytes=None, keywords=None, keyword_weight=None)` | Embed `query` via the registered embedder and run `recall`. Same return shape and kwargs as `recall`. `keywords` (v9 files): identifiers or exact terms to match (a version, a PR number, a function name), not the question; their BM25 score is added with weight `keyword_weight` (default 0.5) |
195
195
  | `cache_get_semantic_text(namespace, text, threshold=0.97)` | Text-side semantic cache lookup; uses the embedder's `name` as the semantic cache's `model` component |
196
- | `stats()` | Summary statistics — includes `fsyncs_last_flush` (count of `sync_all` the most recent `flush()` on this handle issued; `0` on a fresh handle before any flush — Phase 6 instrumentation) |
196
+ | `stats()` | Summary statistics — includes `fsyncs_last_flush` (count of `sync_all` the most recent `flush()` on this handle issued; `0` on a fresh handle before any flush — Phase 6 instrumentation) and `recall_mode` (`"exact_resident"`: the live facts' vectors fit the vector cache budget and recall scans them in memory; `"exact_paged"`: over the budget, or a v8 file, so recall reads them from the file; `"indexed"`: an IVF+PQ index shortlists) |
197
197
  | `export_encrypted(dest)` | Copy the (already-encrypted) file elsewhere |
198
198
  | `len(db)` | Live memory count |
199
199
 
@@ -179,7 +179,7 @@ its own agent.
179
179
  | `remember_text(content, memory_type, **kwargs)` | Embed `content` via the registered embedder and `remember` the result. Accepts the same per-memory kwargs as `remember` (`agent_id`, `importance`, `session_id`, `ttl_secs`, `shared`, `metadata`) |
180
180
  | `recall_text(query, top_k=10, memory_types=None, agent_id=None, track_access=True, n_probe=None, n_rerank=None, filter=None, max_bytes=None, keywords=None, keyword_weight=None)` | Embed `query` via the registered embedder and run `recall`. Same return shape and kwargs as `recall`. `keywords` (v9 files): identifiers or exact terms to match (a version, a PR number, a function name), not the question; their BM25 score is added with weight `keyword_weight` (default 0.5) |
181
181
  | `cache_get_semantic_text(namespace, text, threshold=0.97)` | Text-side semantic cache lookup; uses the embedder's `name` as the semantic cache's `model` component |
182
- | `stats()` | Summary statistics — includes `fsyncs_last_flush` (count of `sync_all` the most recent `flush()` on this handle issued; `0` on a fresh handle before any flush — Phase 6 instrumentation) |
182
+ | `stats()` | Summary statistics — includes `fsyncs_last_flush` (count of `sync_all` the most recent `flush()` on this handle issued; `0` on a fresh handle before any flush — Phase 6 instrumentation) and `recall_mode` (`"exact_resident"`: the live facts' vectors fit the vector cache budget and recall scans them in memory; `"exact_paged"`: over the budget, or a v8 file, so recall reads them from the file; `"indexed"`: an IVF+PQ index shortlists) |
183
183
  | `export_encrypted(dest)` | Copy the (already-encrypted) file elsewhere |
184
184
  | `len(db)` | Live memory count |
185
185
 
@@ -821,7 +821,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
821
821
 
822
822
  [[package]]
823
823
  name = "mnemo-engine"
824
- version = "0.12.0"
824
+ version = "0.12.2"
825
825
  dependencies = [
826
826
  "aes-gcm",
827
827
  "argon2",
@@ -849,7 +849,7 @@ dependencies = [
849
849
 
850
850
  [[package]]
851
851
  name = "mnemo-node"
852
- version = "0.12.0"
852
+ version = "0.12.2"
853
853
  dependencies = [
854
854
  "mnemo-engine",
855
855
  "napi",
@@ -859,7 +859,7 @@ dependencies = [
859
859
 
860
860
  [[package]]
861
861
  name = "mnemo-uniffi"
862
- version = "0.12.0"
862
+ version = "0.12.2"
863
863
  dependencies = [
864
864
  "mnemo-engine",
865
865
  "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.12.0"
13
+ version = "0.12.2"
14
14
  edition = "2021"
15
15
  rust-version = "1.75"
16
16
  # `benches/corpus.rs` is a shared helper module pulled into real benches
@@ -309,6 +309,16 @@ Argon2id; the KEK wraps a random data-encryption key (DEK); the DEK encrypts
309
309
  every data page with AES-256-GCM. Changing the passphrase (`rekey`) only
310
310
  re-wraps the DEK — the bulk pages are never rewritten.
311
311
 
312
+ That makes `rekey` cheap, and it means **a plain `rekey` changes the
313
+ secret that opens this file from now on; anyone who had the file and the
314
+ old secret can still read it and later writes.** The DEK is the same, so an
315
+ earlier copy of the file, or of just its header, still unlocks it with the
316
+ old passphrase. **Use `--rotate` to revoke** (after a suspected leak, say):
317
+ `mnemo rekey --rotate`, or `rekey` followed by `Mnemo::compact_file`,
318
+ rewrites the file under a fresh DEK. `Mnemo::export_rekeyed` writes a copy
319
+ under a fresh DEK and a new secret, sharing no key material with the
320
+ source. Rotation can't erase old ciphertext the storage hardware still holds: flash keeps rewritten blocks until it reuses them, and that's out of the engine's hands.
321
+
312
322
  The file is a sequence of fixed **8 KiB pages**:
313
323
 
314
324
  - **Page 0** — the header (plaintext): magic, version, KDF parameters, salt,
@@ -428,10 +438,36 @@ navigable history.
428
438
 
429
439
  A restore is itself an ordinary committed transaction (and a new snapshot), so
430
440
  it is crash-safe *and* reversible — having rewound, you can roll forward again.
431
- History reaches back to the last `compact_file`, which reclaims space by
432
- rewriting the file and so collapses the manifest to a single snapshot. That
433
- compaction boundary is the one limit: there is no external log archiving, so
434
- you cannot restore to an instant older than the last compaction.
441
+
442
+ **How far back you can restore is capped.** Only retained snapshots can be
443
+ restored, and the cap differs by format:
444
+
445
+ | Format | Retained by default | Override |
446
+ |---|---|---|
447
+ | v9 (new files) | the newest **16** snapshots, plus any from the **last 24 hours**; retained snapshots never pin more than a quarter of the file (past that, the oldest go first, whatever their age) | `max_snapshots` / `set_max_snapshots` changes the count |
448
+ | v8 | the newest **256** snapshots | `max_snapshots` (`0`: no cap) |
449
+
450
+ So on a v9 file that flushes often (a phone app under the default
451
+ coalesced flush policy commits about once a second while it's writing),
452
+ "restore to an hour ago" works only within the last 24 hours, and "restore
453
+ to last week" doesn't work unless you raise the count. `restore_to` a
454
+ snapshot that's gone returns `MnemoError::NotFound`. `compact_file`
455
+ collapses the manifest to a single snapshot, and there's no external log
456
+ archiving, so nothing older than the last compaction is ever restorable.
457
+ `snapshots()` lists exactly what's restorable now.
458
+
459
+ ### The vector column (v9)
460
+
461
+ On a v9 file, recall scans an fp16 copy of the vectors (`dims × 2 + 4`
462
+ bytes a fact). It stays in memory while the file's **live facts** fit
463
+ `set_vector_cache_budget` (96 MiB by default, 16 MiB in the mobile
464
+ packages). Thread turns, essence items, tombstones and superseded
465
+ versions don't count. Past the budget, recall reads the vectors through
466
+ the page cache instead: at 10,000 facts × 384 dimensions, warm recall goes
467
+ from about 2 ms to about 11 ms (M1 Pro). `stats().recall_mode` says which
468
+ path recall takes now: `ExactResident`, `ExactPaged` (over the budget, or
469
+ a v8 file) or `Indexed` (an IVF+PQ index, which v9 builds from 20,000
470
+ facts).
435
471
 
436
472
  ### Page cache
437
473
 
@@ -678,7 +714,7 @@ cargo run --bin mnemo -- <command>
678
714
  | `search` | Exact nearest-neighbour search (similarity only) |
679
715
  | `recall` | Multi-signal ranked retrieval (sim + recency + …) |
680
716
  | `verify` | Decrypt and re-validate every live record |
681
- | `rekey` | Re-encrypt the data key under a new passphrase |
717
+ | `rekey` | Re-encrypt the data key under a new passphrase; `--rotate` also rewrites the file under a fresh data key (revokes the old passphrase) |
682
718
  | `compact` | Rebuild the file, dropping tombstones and expired; writes v9, which upgrades a v8 file (`--format v8` keeps v8 for one release) |
683
719
  | `snapshots` | List the restorable snapshots (one per flush) |
684
720
  | `restore` | Roll the database back to a past snapshot |
@@ -880,9 +916,11 @@ let cfg = MnemoConfig {
880
916
  **2. Cap the snapshot manifest.** Every `flush` appends one snapshot
881
917
  entry; without a cap, long-running services accumulate them forever —
882
918
  manifest serialize-cost and the manifest run on disk grow O(total
883
- flushes). The default cap is 256 retained snapshots (the most recent N
884
- are kept; older ones are pruned at flush time, with their data pages
885
- left on disk until the next `compact_file`). Override per-database:
919
+ flushes). The default cap on v8 is 256 retained snapshots (the most
920
+ recent N are kept; older ones are pruned at flush time, with their data
921
+ pages left on disk until the next `compact_file`). On v9 it's 16, plus
922
+ any from the last 24 hours (see "Snapshots & point-in-time recovery"),
923
+ and pruned snapshots' pages are reused. Override per-database:
886
924
 
887
925
  ```rust
888
926
  let cfg = MnemoConfig {
@@ -19,7 +19,7 @@ From Maven Central (`mavenCentral()` in your repositories):
19
19
 
20
20
  ```kotlin
21
21
  dependencies {
22
- implementation("io.github.toarchkumar:mnemo-android:0.12.0")
22
+ implementation("io.github.toarchkumar:mnemo-android:0.12.2")
23
23
  }
24
24
  ```
25
25
 
@@ -101,9 +101,89 @@ val byWord = store.recall(emptyList(), RecallOptions(keywords = "UA 931"))
101
101
  - **Keyed facts:** `RememberOptions(key = ...)` writes a new version and
102
102
  supersedes the old one. `history(key)` lists the versions, newest first.
103
103
  - **The result cache:** `cachePut` and `cacheGet`, by exact key.
104
+ - **Access counts:** `RecallOptions.trackAccess` is off by default here
105
+ (v0.12.2). With it on, every recall marks its hits as read, which dirties
106
+ the file, so a recall made in the background ends in a full commit, and
107
+ ranking doesn't need it. Pass `RecallOptions(topK = 5u, trackAccess = true)` on the calls whose
108
+ access counts the app reads.
109
+ - **Batches:** `withSession { session -> ... }` runs many calls on one
110
+ open handle and commits once at the end (see Durability).
104
111
  - **Also:** `get`, `update`, `delete`, `about`, `stats`, `count`, `flush`,
105
112
  `close` and `compact`.
106
113
 
114
+ ### Memory and recall speed
115
+
116
+ Recall scans an fp16 copy of the vectors (`dims × 2 + 4` bytes a fact).
117
+ It stays in memory while the file's **live facts** fit the configuration's
118
+ `vectorCacheBudgetBytes` (16 MiB by default). Thread turns, essence items and
119
+ superseded versions don't count. Past the budget, recall reads the vectors
120
+ from the file instead, which is slower, and slower still as the file grows.
121
+
122
+ | Dimensions | Bytes per fact | Facts that fit 16 MiB | Budget to stay resident at 50,000 facts |
123
+ |---|---|---|---|
124
+ | 384 | 772 | 21,732 | 38.6 MB |
125
+ | 512 | 1,028 | 16,320 | 51.4 MB |
126
+ | 768 | 1,540 | 10,894 | 77.0 MB |
127
+
128
+ `store.stats()` says which path recall takes now, in `recallMode`:
129
+ `RecallMode.EXACT_RESIDENT` (in memory, the fast path),
130
+ `RecallMode.EXACT_PAGED` (from the file) or `RecallMode.INDEXED`, and how many bytes the column needs to stay in memory, in
131
+ `vectorColumnBytes` (`facts × (2 × dimensions + 4)`).
132
+
133
+ **At the cliff, raise the budget first.** Setting `vectorCacheBudgetBytes` to at least
134
+ `vectorColumnBytes` costs that much memory and gives the fast path back at
135
+ once (at 22,000 facts × 384, warm recall went from 23.6 ms paged to 4.9 ms
136
+ with the budget raised). Build an index (`buildIndex()`) only when the
137
+ column no longer fits the memory the app can spare, past 20,000 facts, and
138
+ only in a maintenance window: the build holds the store and takes long (49.8
139
+ s at 22,000 facts on an M1 Pro; 19 s at 10,000 and 179 s at 100,000 in the
140
+ perf file's `build_secs`), and a raised `cachePages` doesn't help a large
141
+ file.
142
+
143
+ ### History
144
+
145
+ Every commit leaves a restorable snapshot, but only some are kept. A
146
+ new (v9) file keeps the newest 16 plus any from the last 24 hours, and
147
+ never lets them pin more than a quarter of the file. Under the default
148
+ flush policy a busy app commits about once a second, so the history
149
+ reaches back about a day, not further. A v8 file keeps the newest 256.
150
+ `compact()` drops all of them.
151
+ `setMaxSnapshots(_:)` (Kotlin: `setMaxSnapshots(count)`) keeps a different
152
+ number instead, as a hard cap; the store applies it every time it opens the
153
+ file.
154
+
155
+ ### Durability
156
+
157
+ A write is in memory until the store commits it to disk. A crash, a kill
158
+ (`am force-stop`, the low-memory killer, a swipe from Recents) or a power
159
+ loss keeps every committed write and loses the rest. When the store
160
+ commits is the configuration's `flushPolicy`:
161
+
162
+ | Policy | A write is durable | Use it for |
163
+ |---|---|---|
164
+ | `FlushPolicy.Coalesced(maxDelayMillis = 1000, maxWrites = 64)` (the default) | in the foreground, at most about 1 second after it returns, or at once when it's the 64th write waiting; while the app is stopped, before it returns | most apps: one commit per burst of writes |
165
+ | `FlushPolicy.EveryWrite` | before it returns | data the app can't lose, at the cost of a commit (a page write and a sync) per write |
166
+ | `FlushPolicy.Manual` | only on the events below (the behaviour before v0.12.1) | benchmarks, and apps that call `flush()` themselves |
167
+
168
+ "Stopped" is `ProcessLifecycleOwner` below `STARTED`: the app is in the
169
+ background, or the process started without an activity (a service, a
170
+ broadcast, WorkManager). A write made then commits before it returns,
171
+ because the process can be killed at any moment. Whatever the policy, the
172
+ store also commits on every `ON_STOP`, and on `flush()` and `close()`.
173
+
174
+ `withSession` batches many writes into one commit:
175
+
176
+ ```kotlin
177
+ store.withSession { session ->
178
+ for ((text, vector) in notes) session.remember(text, vector)
179
+ }
180
+ ```
181
+
182
+ The calls run on one open handle with nothing else in between, and the
183
+ store commits once at the end (not under `Manual`). A session doesn't
184
+ embed, so compute the vectors first. If the block throws, the writes it
185
+ made stay and are committed the same way.
186
+
107
187
  The names follow the Swift package where Kotlin allows. Two differ in the
108
188
  generated layer:
109
189
 
@@ -126,8 +206,11 @@ class MyEmbedder : MnemoEmbedder {
126
206
  }
127
207
  ```
128
208
 
129
- - `embed` is called synchronously on the store's dispatcher thread, never
130
- on the main thread, and never with the database locked.
209
+ - `embed` runs on the store's dispatcher before the call takes the store's
210
+ lock, never on the main thread. The store isn't held while it runs, so
211
+ other calls go ahead, and `embed` may call back into the same store.
212
+ (Before v0.12.1 it ran under the store's lock, so a slow model held every
213
+ other call.)
131
214
  - If it throws anything, the call fails with `MnemoException.Embedder`,
132
215
  and nothing is written. Throw `EmbedderException.Failed(reason)` to
133
216
  choose the message.
@@ -152,11 +235,13 @@ class MyEmbedder : MnemoEmbedder {
152
235
  - **Flushing.** When the app's last activity stops, `ProcessLifecycleOwner`
153
236
  sends `ON_STOP`, about 700 ms later, and the store flushes. Every write
154
237
  made so far is then durable, even if the process is killed in the
155
- background.
238
+ background. From then until the next `ON_START`, each write under the
239
+ default policy commits before it returns (see Durability).
156
240
  - **The file stays open.** Android doesn't kill a cached process for
157
241
  holding a file lock, unlike iOS, so the next call needs no reopen.
158
- - **Errors.** A failed background flush is kept in `lastBackgroundError`.
159
- The data written before the last successful flush is safe.
242
+ - **Errors.** A failed background flush, or a failed coalesced commit, is
243
+ kept in `lastBackgroundError`. The data written before the last
244
+ successful commit is safe.
160
245
  - **Reopening.** After `close()`, or if the engine reports its handle
161
246
  closed, the next call reopens the file transparently. No call fails with
162
247
  `MnemoException.Closed`.
@@ -197,22 +282,32 @@ transfer. So neither the file nor its key reaches a new phone, and the app
197
282
  starts empty there unless it imports an export.
198
283
 
199
284
  **Recovering from `MnemoStoreException.KeyMissing`.** The file exists, but
200
- its key isn't available. This happens in three ways:
285
+ its key is gone. This happens in four ways:
201
286
 
202
287
  - the key file was deleted;
203
288
  - the file was copied from another device;
204
- - the Keystore key that wraps it is gone or invalidated, which is rare.
289
+ - the key file is damaged, or doesn't authenticate;
290
+ - the Keystore key that wraps it is missing or permanently invalidated,
291
+ which is rare.
205
292
 
206
293
  The data can't be read without the key. The app can import a passphrase
207
294
  export (below), or delete the file and start over.
208
295
 
296
+ **`MnemoStoreException.Keystore` is different: never delete anything for
297
+ it.** It means the Keystore, or the key file behind it, failed for a reason
298
+ that can pass: the Keystore service busy or restarting, a binder error, an
299
+ I/O error, or a wrapping-key entry that exists but couldn't be read. The key
300
+ is probably still there. Retry later (on the next launch, say), and treat
301
+ only `KeyMissing` as a lost key. The store never replaces a wrapping key
302
+ whose alias exists, since that would orphan every key it wraps.
303
+
209
304
  ### Moving to another device: passphrase export and import
210
305
 
211
306
  ```kotlin
212
307
  // On the old device: a copy that opens with the passphrase alone.
213
308
  store.exportWithPassphrase(exportFile, passphrase)
214
309
 
215
- // On the new device: re-protected by a fresh key in this device's Keystore.
310
+ // On the new device: a fresh copy under a new key in this device's Keystore.
216
311
  val store = MnemoStore.importWithPassphrase(
217
312
  context, exportFile, passphrase,
218
313
  MnemoStoreConfiguration(name = "assistant", dimensions = 384u),
@@ -222,7 +317,13 @@ val store = MnemoStore.importWithPassphrase(
222
317
  - Both calls take a few seconds, because the passphrase goes through the
223
318
  KDF.
224
319
  - The destination must not exist yet, and the source is never modified.
225
- - Have the user choose the passphrase. Never store it next to the export.
320
+ - Both write a compacted copy (live data, no history) under a **fresh data
321
+ key**. The export shares no key material with the device's file, and the
322
+ import is re-protected under a new data key: the transfer passphrase never
323
+ opens the imported file, even with a leftover copy of the export.
324
+ - Rotation can't erase old ciphertext the storage hardware still holds: flash keeps rewritten blocks until it reuses them, and that's out of the engine's hands.
325
+ - Have the user choose the passphrase. Never store it next to the export,
326
+ and delete the export once it's imported.
226
327
 
227
328
  ## ABIs
228
329
 
@@ -250,10 +351,22 @@ name. Nothing else is needed.
250
351
 
251
352
  - **`MnemoException`** comes from the engine: `Locked`, `WrongPassphrase`,
252
353
  `HeaderTampered`, `UnsupportedVersion`, `NotFound`, `ReadOnly`,
253
- `DimensionMismatch`, `Invalid`, `Io`, `Corrupt`, `Closed` and `Embedder`.
254
- `MnemoStore` never surfaces `Closed`.
354
+ `DimensionMismatch`, `Invalid`, `Io`, `Corrupt`, `Closed` and `Embedder`,
355
+ and since v0.12.2 `NotAMnemoFile`, `NeedsWriteOpen`, `Kdf` and `Crypto`.
356
+ `MnemoStore` never surfaces `Closed`: it reopens the file and retries once,
357
+ and a handle a panic poisoned is treated the same way.
255
358
  - **`MnemoStoreException`** comes from this layer: `KeyMissing(keyId,
256
- path)`, `Keystore(operation)` and `File`.
359
+ path)` (the key is gone), `Keystore(operation)` (retryable; see above)
360
+ and `File`.
361
+
362
+ **What to do about an error, in three classes** (`e.isRetryable()` tells the first
363
+ apart for `MnemoException`):
364
+
365
+ | Class | Errors | What to do |
366
+ |---|---|---|
367
+ | Retry later | `Locked`, `Io`, `Kdf` (the KDF couldn't get its memory), `Closed`; `MnemoStoreException.Keystore` | Try again later, on the next launch, say. The data is fine. |
368
+ | Fix the call | `Invalid`, `DimensionMismatch`, `ReadOnly`, `NeedsWriteOpen`, `NotFound`, `WrongPassphrase`, `Embedder` | Change what's passed (or open read-write once, for `NeedsWriteOpen`). |
369
+ | The data is unreadable | `Corrupt` (integrity failures only), `HeaderTampered`, `Crypto`, `NotAMnemoFile`, `UnsupportedVersion`; `MnemoStoreException.KeyMissing` | Restore from a backup or an export. Only here is deleting the file ever the answer. |
257
370
 
258
371
  ## Tests
259
372
 
@@ -262,10 +375,12 @@ name. Nothing else is needed.
262
375
  a software AES key in place of the Keystore. They need the host library
263
376
  that `scripts/build-native.sh` puts in `generated/host/`.
264
377
  - **Instrumented tests** (`src/androidTest`): the Android Keystore, the
265
- `ON_STOP` flush through the real process lifecycle, the default
266
- directory, and loading the native libraries on the device's page size.
267
- The `android-emulator` workflow runs them nightly and on release tags,
268
- on API 35 `x86_64` images with 4 KB and 16 KB pages.
378
+ `ON_STOP` flush and the flush policy through the real process lifecycle,
379
+ the default directory, and loading the native libraries on the device's
380
+ page size. The `android-emulator` workflow runs them nightly and on
381
+ release tags, on API 35 `x86_64` images with 4 KB and 16 KB pages, then
382
+ the sample's kill test: it writes, is force-stopped with no flush, and a
383
+ relaunch must find every write older than the coalescing window.
269
384
  - **In your app's own JVM tests**, the plain JNA jar has to be on the test
270
385
  classpath (`testImplementation("net.java.dev.jna:jna:5.19.1")`), along
271
386
  with a host build of `libmnemo_uniffi` on `jna.library.path`.
@@ -3,4 +3,4 @@ org.gradle.caching=true
3
3
  android.useAndroidX=true
4
4
  # The published coordinates (io.github.toarchkumar:mnemo-android).
5
5
  GROUP=io.github.toarchkumar
6
- VERSION_NAME=0.12.0
6
+ VERSION_NAME=0.12.2
@@ -2,7 +2,7 @@
2
2
  // mnemo-android artifact from mavenLocal() (run the library's signed
3
3
  // publishToMavenLocal first) and runs a JVM smoke test against it.
4
4
  //
5
- // ../gradlew -p release-check test -PmnemoVersion=0.12.0 \
5
+ // ../gradlew -p release-check test -PmnemoVersion=0.12.2 \
6
6
  // -Pjna.library.path=$PWD/generated/host
7
7
  pluginManagement {
8
8
  repositories {
@@ -14,7 +14,10 @@ set -euo pipefail
14
14
 
15
15
  : "${MAVEN_CENTRAL_USERNAME:?}" "${MAVEN_CENTRAL_PASSWORD:?}"
16
16
  API=https://central.sonatype.com/api/v1/publisher
17
- AUTH="Authorization: Bearer $(printf '%s:%s' "$MAVEN_CENTRAL_USERNAME" "$MAVEN_CENTRAL_PASSWORD" | base64 | tr -d '\n')"
17
+ B64=$(printf '%s:%s' "$MAVEN_CENTRAL_USERNAME" "$MAVEN_CENTRAL_PASSWORD" | base64 | tr -d '\n')
18
+ # A derived credential GitHub's log masking doesn't know: mask it too.
19
+ if [ -n "${GITHUB_ACTIONS:-}" ]; then echo "::add-mask::$B64"; fi
20
+ AUTH="Authorization: Bearer $B64"
18
21
  LOG="$(mktemp)"
19
22
  trap 'rm -f "$LOG" "$LOG.body"' EXIT
20
23
 
@@ -25,6 +28,16 @@ state_of() { # deployment id -> its deploymentState (or the HTTP code)
25
28
  python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["deploymentState"])' "$LOG.body"
26
29
  }
27
30
 
31
+ # Central refuses a version it already has ("Component ... already
32
+ # exists"), so a dry run between releases (to test a workflow change, say)
33
+ # has nothing to validate. A release dry run runs with the next version.
34
+ VERSION=$(sed -n 's/^VERSION_NAME=//p' gradle.properties)
35
+ POM="https://repo1.maven.org/maven2/io/github/toarchkumar/mnemo-android/$VERSION/mnemo-android-$VERSION.pom"
36
+ if [ "$(curl -s -o /dev/null -w '%{http_code}' --max-time 30 "$POM")" = 200 ]; then
37
+ echo "::notice::mnemo-android $VERSION is already on Maven Central, which refuses a second upload: nothing to validate (a release dry run runs with the next version)"
38
+ exit 0
39
+ fi
40
+
28
41
  echo "==> publishToMavenCentral (USER_MANAGED: upload and validate, never release)"
29
42
  status=0
30
43
  ./gradlew --no-daemon --stacktrace publishToMavenCentral \
@@ -8,6 +8,8 @@
8
8
  # the image should report.
9
9
  # 2. The Android sample's R8-minified release APK: install it, launch its
10
10
  # self-test, and check logcat for "MNEMO_SELFTEST ok" (MOBILE-1d).
11
+ # 3. The kill test: the same APK writes, is force-stopped with no flush,
12
+ # and a relaunch counts what survived (MOBILE-2b).
11
13
  #
12
14
  # Emulators, the 16 KB image especially, can restart the system server
13
15
  # shortly after boot. An install then fails ("Can't find service:
@@ -79,3 +81,32 @@ for _ in $(seq 1 60); do
79
81
  done
80
82
  adb logcat -d -s MnemoSelfTest:I AndroidRuntime:E | tee selftest.log
81
83
  grep -q "MNEMO_SELFTEST ok" selftest.log
84
+
85
+ # 3. The kill test for the default flush policy (MOBILE-2b): the sample
86
+ # writes, waits past the coalescing window, writes a few more, and is
87
+ # force-stopped with no lifecycle event. A relaunch must find every write
88
+ # older than the window (see DurabilityTest in the sample).
89
+ SETTLED=20
90
+ wait_for_line() { # tag, pattern, seconds
91
+ for _ in $(seq 1 "$3"); do
92
+ adb logcat -d -s "$1:I" | grep -q "$2" && return 0
93
+ sleep 1
94
+ done
95
+ return 1
96
+ }
97
+ # A fresh process: the self-test's activity is still on top, and an intent
98
+ # to it would only reach onNewIntent.
99
+ adb shell am force-stop io.github.toarchkumar.mnemo.sample
100
+ adb logcat -c
101
+ adb shell am start -W -n io.github.toarchkumar.mnemo.sample/.MainActivity --es durability write
102
+ wait_for_line MnemoDurability "MNEMO_DURABILITY \(late\|failed\)" 60 || { echo "the durability writer never finished" >&2; exit 1; }
103
+ adb shell am force-stop io.github.toarchkumar.mnemo.sample
104
+ adb logcat -d -s MnemoDurability:I | tee durability.log
105
+ grep -q "MNEMO_DURABILITY late" durability.log
106
+ adb logcat -c
107
+ adb shell am start -W -n io.github.toarchkumar.mnemo.sample/.MainActivity --es durability count
108
+ wait_for_line MnemoDurability "MNEMO_DURABILITY \(count\|failed\)" 60 || { echo "the durability reader never finished" >&2; exit 1; }
109
+ adb logcat -d -s MnemoDurability:I AndroidRuntime:E | tee -a durability.log
110
+ count=$(sed -n 's/.*MNEMO_DURABILITY count=\([0-9]*\).*/\1/p' durability.log | tail -1)
111
+ echo "after am force-stop: $count memories (at least $SETTLED expected)"
112
+ [ -n "$count" ] && [ "$count" -ge "$SETTLED" ]
@@ -49,7 +49,7 @@ class AndroidTests {
49
49
  val alias = "mnemo-test-${UUID.randomUUID()}"
50
50
  aliases += alias
51
51
  val dir = File(context.cacheDir, "keys-${UUID.randomUUID()}").also { cleanup += it }
52
- return MnemoKeystore(dir, AndroidKeystoreWrapper(alias)) to alias
52
+ return MnemoKeystore(dir, AndroidKeystoreWrapper(alias, AndroidKeystoreKeys, File(dir, MnemoKeystore.LOCK_FILE))) to alias
53
53
  }
54
54
 
55
55
  @Test fun theKeystoreWrapsKeysWithANonExportableKey() {
@@ -109,7 +109,9 @@ class AndroidTests {
109
109
  @Test fun onStopFlushesAndKeepsTheFileOpen(): Unit = runBlocking {
110
110
  val (keystore, _) = testKeystore()
111
111
  val dir = File(context.cacheDir, "stop-${UUID.randomUUID()}").also { cleanup += it }
112
- val store = MnemoStore(context, MnemoStoreConfiguration("stop", 4u, dir), keystore)
112
+ // Manual, so only ON_STOP commits: the default would already have
113
+ // committed each write (the process is stopped: no activity yet).
114
+ val store = MnemoStore(context, MnemoStoreConfiguration("stop", 4u, dir, flushPolicy = FlushPolicy.Manual), keystore)
113
115
  // The observer is added on the main thread; wait for it.
114
116
  InstrumentationRegistry.getInstrumentation().runOnMainSync {}
115
117
  for (i in 0 until 3) store.remember("pending $i", vec(i))
@@ -134,6 +136,32 @@ class AndroidTests {
134
136
  store.close()
135
137
  }
136
138
 
139
+ @Test fun theDefaultPolicyFollowsTheProcessLifecycle(): Unit = runBlocking {
140
+ val keys = InMemoryKeyStorage()
141
+ val dir = File(context.cacheDir, "policy-${UUID.randomUUID()}").also { cleanup += it }
142
+ val store = MnemoStore(context, MnemoStoreConfiguration("policy", 4u, dir), keys)
143
+ InstrumentationRegistry.getInstrumentation().runOnMainSync {}
144
+ // No activity: the process is stopped, and a write commits before it
145
+ // returns. (An earlier test's activity may still be stopping: ON_STOP
146
+ // comes about 700 ms after it.)
147
+ assertTrue(eventually(10_000) { processState() == Lifecycle.State.CREATED && store.processStopped })
148
+ store.remember("stopped", vec(0))
149
+ assertEquals(1, store.commits)
150
+ assertCopyHolds(store.file, keys, 1uL)
151
+
152
+ // An activity started: ON_START, and writes coalesce again.
153
+ val scenario = ActivityScenario.launch(TestActivity::class.java)
154
+ scenario.moveToState(Lifecycle.State.RESUMED)
155
+ assertTrue("ON_START reached the store", eventually { !store.processStopped })
156
+ store.remember("started", vec(1))
157
+ assertEquals("not committed yet", 1, store.commits)
158
+ assertTrue("committed within the window", eventually(5_000) { store.commits == 2 })
159
+ assertCopyHolds(store.file, keys, 2uL)
160
+ scenario.close()
161
+ assertTrue("ON_STOP reached the store", eventually(10_000) { store.processStopped })
162
+ store.close()
163
+ }
164
+
137
165
  @Test fun theNativeLibraryLoadsOnThisPageSize(): Unit = runBlocking {
138
166
  val pageSize = Os.sysconf(OsConstants._SC_PAGESIZE)
139
167
  Log.i(TAG, "page size $pageSize, API ${Build.VERSION.SDK_INT}, ABIs ${Build.SUPPORTED_ABIS.joinToString()}")
@@ -0,0 +1,100 @@
1
+ package io.github.toarchkumar.mnemo
2
+
3
+ /**
4
+ * When a [MnemoStore] commits its writes to disk on its own.
5
+ *
6
+ * A write is durable once it's committed: a crash, a kill (`am force-stop`,
7
+ * the low-memory killer) or a power loss after that keeps it. Before that,
8
+ * it's in memory only. Whatever the policy, the store also commits on every
9
+ * `ON_STOP`, and on [MnemoStore.flush] and [MnemoStore.close].
10
+ */
11
+ sealed class FlushPolicy {
12
+ /**
13
+ * The default. The first write after a commit starts a timer, and the
14
+ * store commits once when it fires ([maxDelayMillis] later) or as soon as
15
+ * [maxWrites] writes are waiting, whichever comes first. A write made
16
+ * while the app is in the foreground is durable at most about
17
+ * [maxDelayMillis] after it returns. While the app is stopped (in the
18
+ * background, or started without an activity), each write commits
19
+ * before it returns.
20
+ */
21
+ data class Coalesced(val maxDelayMillis: Long = 1_000, val maxWrites: Int = 64) : FlushPolicy()
22
+
23
+ /**
24
+ * Every write commits before it returns. The safest, and the slowest for
25
+ * bursts: each commit writes and syncs pages.
26
+ */
27
+ data object EveryWrite : FlushPolicy()
28
+
29
+ /**
30
+ * The store commits only on the events above (the behaviour before
31
+ * v0.12.1). For benchmarks, and for apps that call [MnemoStore.flush]
32
+ * themselves.
33
+ */
34
+ data object Manual : FlushPolicy()
35
+
36
+ companion object {
37
+ /** `Coalesced(maxDelayMillis = 1000, maxWrites = 64)`. */
38
+ @JvmField
39
+ val DEFAULT: FlushPolicy = Coalesced()
40
+ }
41
+ }
42
+
43
+ /**
44
+ * A batch of calls on one open handle, from [MnemoStore.withSession].
45
+ *
46
+ * The calls run in order on the store's handle, with no other call in
47
+ * between, and the store commits once at the end. A session doesn't embed:
48
+ * pass vectors (embed first, then open the session). It's valid only inside
49
+ * the block it was passed to; afterwards every call throws
50
+ * [MnemoException.Closed].
51
+ */
52
+ class MnemoSession internal constructor(private val db: MnemoDb) {
53
+ @Volatile private var ended = false
54
+
55
+ /** The writes made in this session. */
56
+ @Volatile internal var writes = 0
57
+ private set
58
+
59
+ internal fun end() {
60
+ ended = true
61
+ }
62
+
63
+ private fun handle(write: Boolean): MnemoDb {
64
+ if (ended) throw MnemoException.Closed()
65
+ if (write) writes += 1
66
+ return db
67
+ }
68
+
69
+ /** Stores a memory with its vector. */
70
+ fun remember(content: String, vector: List<Float>, options: RememberOptions = RememberOptions()): WriteResult =
71
+ handle(true).remember(content, vector, options)
72
+
73
+ /** Changes fields of a memory. A content change needs its vector in the patch: a session doesn't embed. */
74
+ fun update(id: String, patch: MemoryPatch): WriteOutcome {
75
+ if (patch.content != null && patch.vector == null) {
76
+ throw MnemoException.Invalid("a session doesn't embed: a content change needs its vector in the patch")
77
+ }
78
+ return handle(true).update(id, patch)
79
+ }
80
+
81
+ /** Deletes a memory. */
82
+ fun delete(id: String) = handle(true).delete(id)
83
+
84
+ /** One memory by id. */
85
+ fun get(id: String): MemoryRecord = handle(false).get(id)
86
+
87
+ /** Recall by vector. */
88
+ fun recall(vector: List<Float>, options: RecallOptions = RecallOptions()): RecallPage =
89
+ handle(false).recall(vector, options)
90
+
91
+ /** The number of live memories. */
92
+ fun count(): ULong = handle(false).len()
93
+
94
+ /** Stores a value in the result cache. */
95
+ fun cachePut(namespace: String, key: String, value: ByteArray, ttlSecs: ULong? = null) =
96
+ handle(true).cachePut(namespace, key, value, ttlSecs)
97
+
98
+ /** A cached value, or `null`. */
99
+ fun cacheGet(namespace: String, key: String): ByteArray? = handle(false).cacheGet(namespace, key)
100
+ }