mnemo-engine 0.12.2__tar.gz → 0.12.3__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.
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/PKG-INFO +1 -1
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/Cargo.lock +3 -3
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/Cargo.toml +1 -1
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/README.md +1 -1
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/gradle.properties +1 -1
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/release-check/settings.gradle.kts +1 -1
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/EmbedderLockTests.kt +41 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/README.md +16 -6
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Sources/Mnemo/MnemoStore.swift +76 -16
- mnemo_engine-0.12.3/mnemo/bindings/swift/Tests/MnemoTests/EmbedQueueTests.swift +120 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Tests/MnemoTests/EmbedderLockTests.swift +2 -2
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Tests/MnemoTests/StoreHardeningTests.swift +3 -12
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/pager.rs +44 -3
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/load.rs +6 -2
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/mod.rs +1 -1
- mnemo_engine-0.12.3/mnemo/tests/lock_release.rs +115 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo-python/Cargo.lock +2 -2
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo-python/Cargo.toml +1 -1
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/pyproject.toml +1 -1
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/README.md +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/.gitignore +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/README.md +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/benches/cache.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/benches/corpus.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/benches/embed_overhead.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/benches/open.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/benches/recall.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/benches/thread.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/benches/write.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/.gitignore +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/NOTICE +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/build.gradle.kts +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/consumer-rules.pro +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/gradle/wrapper/gradle-wrapper.jar +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/gradle/wrapper/gradle-wrapper.properties +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/gradlew +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/gradlew.bat +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/release-check/build.gradle.kts +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/release-check/src/main/AndroidManifest.xml +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/release-check/src/test/kotlin/io/github/toarchkumar/mnemo/check/ConsumerTest.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/scripts/build-native.sh +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/scripts/central-dry-run.sh +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/scripts/check-elf.py +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/scripts/check-package.py +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/scripts/emulator-tests.sh +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/settings.gradle.kts +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/androidTest/AndroidManifest.xml +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/androidTest/kotlin/io/github/toarchkumar/mnemo/AndroidTests.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/androidTest/kotlin/io/github/toarchkumar/mnemo/TestActivity.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/AndroidManifest.xml +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/FlushPolicy.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/KeyId.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoKeyStorage.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoKeystore.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStore.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStoreConfiguration.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/MnemoStoreException.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/main/kotlin/io/github/toarchkumar/mnemo/ProcessStopObserver.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/sharedTest/kotlin/io/github/toarchkumar/mnemo/Support.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/FlushPolicyTests.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/KeystoreErrorTests.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/KeystoreFileTests.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/StoreHardeningTests.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/src/test/kotlin/io/github/toarchkumar/mnemo/StoreTests.kt +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/uniffi.toml +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/.gitignore +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Package.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Sources/Mnemo/FilePolicy.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Sources/Mnemo/FlushPolicy.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Sources/Mnemo/Lifecycle.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Sources/Mnemo/MnemoKeychain.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Sources/Mnemo/MnemoStoreError.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/TestHost/App/MnemoTestHostApp.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/TestHost/project.yml +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Tests/MnemoTests/FlushPolicyTests.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Tests/MnemoTests/StoreTests.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Tests/MnemoTests/Support.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Tests/MnemoTests/iOSTests.swift +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/scripts/build-xcframework.sh +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/scripts/check-published-package.sh +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/scripts/check-release-package.sh +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/scripts/kill-test.sh +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/scripts/make-release-package.sh +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/deny.toml +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/ann_defaults_v0_6_0.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/ann_diagnose.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/ann_recall_grid.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/ann_recall_grid_v2.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/device_budget.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/embedder_server.py +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/file_size_breakdown.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/fmt9_proto.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/open_rss.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/quickstart.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/ranking_v2.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/session.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/examples/thread_profile.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/bin/mnemo.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/cache.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/crypto.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/embed.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/embed_cmd.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/error.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/format.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/freelist.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/index.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/keyslot.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/lib.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/mcp.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/memory.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/result_cache.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/session.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/ann.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/cache_api.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/continuation.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/crud.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/essence.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/flush.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/header_graft_tests.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/hooks.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/keyed.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/maintenance.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/open.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/recall.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/records.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/snapshots.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/store/threads.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/text.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/transcript.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/veccol.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/src/wal.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/cli_smoke.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/dur1_torn_header.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/engine_safety.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/fix1_correctness_sweep.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/fixtures/v0_10_0_memories.jsonl +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/fmt9_skeleton.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/fmt9b_column.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/fmt9c_commit.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/fmt9d_bm25.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/fmt9e_zstd.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/integration.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/proptest_store.proptest-regressions +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/proptest_store.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/rekey_export.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/sec1_nonce_uniqueness.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/suites/dur1_torn_header.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/suites/fix1_correctness_sweep.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/suites/integration.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/suites/sec1_nonce_uniqueness.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/v0_10_fixture.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/tests/wal_recover_alloc.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo-python/.gitignore +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo-python/README.md +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo-python/src/lib.rs +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo-python/test_mnemo.py +0 -0
- {mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/python/mnemo_engine/__init__.py +0 -0
|
@@ -821,7 +821,7 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|
|
821
821
|
|
|
822
822
|
[[package]]
|
|
823
823
|
name = "mnemo-engine"
|
|
824
|
-
version = "0.12.
|
|
824
|
+
version = "0.12.3"
|
|
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.
|
|
852
|
+
version = "0.12.3"
|
|
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.
|
|
862
|
+
version = "0.12.3"
|
|
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.
|
|
13
|
+
version = "0.12.3"
|
|
14
14
|
edition = "2021"
|
|
15
15
|
rust-version = "1.75"
|
|
16
16
|
# `benches/corpus.rs` is a shared helper module pulled into real benches
|
{mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/kotlin/release-check/settings.gradle.kts
RENAMED
|
@@ -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.
|
|
5
|
+
// ../gradlew -p release-check test -PmnemoVersion=0.12.3 \
|
|
6
6
|
// -Pjna.library.path=$PWD/generated/host
|
|
7
7
|
pluginManagement {
|
|
8
8
|
repositories {
|
|
@@ -5,6 +5,8 @@ import java.util.concurrent.atomic.AtomicBoolean
|
|
|
5
5
|
import java.util.concurrent.atomic.AtomicInteger
|
|
6
6
|
import kotlinx.coroutines.Dispatchers
|
|
7
7
|
import kotlinx.coroutines.async
|
|
8
|
+
import kotlinx.coroutines.awaitAll
|
|
9
|
+
import kotlinx.coroutines.delay
|
|
8
10
|
import kotlinx.coroutines.runBlocking
|
|
9
11
|
import kotlinx.coroutines.withTimeout
|
|
10
12
|
import org.junit.Assert.assertEquals
|
|
@@ -48,6 +50,45 @@ class EmbedderLockTests {
|
|
|
48
50
|
store.close()
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
/**
|
|
54
|
+
* MOBILE-2f's confirming test (v0.12.3): no Kotlin change. The embed runs
|
|
55
|
+
* in `withContext(dispatcher)`, `Dispatchers.IO` by default, which grows
|
|
56
|
+
* for blocking work. Twice as many stores as cores each have a slow embed
|
|
57
|
+
* in flight, and more short coroutines than cores (one of them a store
|
|
58
|
+
* call) on the same dispatcher all finish within 0.5 s.
|
|
59
|
+
*/
|
|
60
|
+
@Test fun slowEmbedsDontStallOtherCoroutinesOnTheStoresDispatcher(): Unit = runBlocking {
|
|
61
|
+
val cores = Runtime.getRuntime().availableProcessors()
|
|
62
|
+
val embedders = List(2 * cores) { SlowEmbedder(1_500) }
|
|
63
|
+
val stores = embedders.mapIndexed { i, e ->
|
|
64
|
+
MnemoStore(MnemoStoreConfiguration("starve$i", 32u, scratchDirectory()), InMemoryKeyStorage(), e)
|
|
65
|
+
}
|
|
66
|
+
val launched = System.nanoTime()
|
|
67
|
+
val writers = stores.map { s -> async(Dispatchers.IO) { s.rememberText("slow to embed") } }
|
|
68
|
+
assertTrue(eventually(5_000) { embedders.any { it.started.get() } })
|
|
69
|
+
|
|
70
|
+
val start = System.nanoTime()
|
|
71
|
+
val waits = List(cores + 2) {
|
|
72
|
+
async(Dispatchers.IO) {
|
|
73
|
+
delay(50)
|
|
74
|
+
(System.nanoTime() - start) / 1_000_000
|
|
75
|
+
}
|
|
76
|
+
} + async(Dispatchers.IO) {
|
|
77
|
+
assertEquals(0uL, stores[0].count())
|
|
78
|
+
(System.nanoTime() - start) / 1_000_000
|
|
79
|
+
}
|
|
80
|
+
val done = waits.awaitAll()
|
|
81
|
+
val sinceLaunchMs = (System.nanoTime() - launched) / 1_000_000
|
|
82
|
+
assertTrue("slowest coroutine: ${done.max()} ms", done.all { it < 500 })
|
|
83
|
+
assertTrue("the coroutines ended $sinceLaunchMs ms after the embeds began", sinceLaunchMs < 1_200)
|
|
84
|
+
|
|
85
|
+
writers.awaitAll()
|
|
86
|
+
for (s in stores) {
|
|
87
|
+
assertEquals(1uL, s.count())
|
|
88
|
+
s.close()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
51
92
|
@Test fun embedderErrorsAreUnchangedAndWriteNothing(): Unit = runBlocking {
|
|
52
93
|
val store = MnemoStore(MnemoStoreConfiguration("emberr", 32u, scratchDirectory()), InMemoryKeyStorage())
|
|
53
94
|
val none = expectThrows<MnemoException.Invalid> { store.rememberText("x") }
|
|
@@ -20,7 +20,7 @@ product. Or, in `Package.swift`:
|
|
|
20
20
|
|
|
21
21
|
```swift
|
|
22
22
|
dependencies: [
|
|
23
|
-
.package(url: "https://github.com/toarchkumar/mnemo-swift", from: "0.12.
|
|
23
|
+
.package(url: "https://github.com/toarchkumar/mnemo-swift", from: "0.12.3"),
|
|
24
24
|
],
|
|
25
25
|
targets: [
|
|
26
26
|
.target(name: "MyApp", dependencies: [.product(name: "Mnemo", package: "mnemo-swift")]),
|
|
@@ -194,11 +194,21 @@ final class MyEmbedder: MnemoEmbedder, @unchecked Sendable {
|
|
|
194
194
|
}
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
-
- `embed` runs before a call reaches the store's actor,
|
|
198
|
-
off the main thread
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
197
|
+
- `embed` runs before a call reaches the store's actor, on the store's own
|
|
198
|
+
serial queue, off the main thread and off Swift's cooperative thread
|
|
199
|
+
pool. A slow model doesn't block the app's Swift concurrency, the store
|
|
200
|
+
isn't held while it runs (other calls go ahead, and a background close
|
|
201
|
+
isn't held up), and `embed` may call back into the same store. (Before
|
|
202
|
+
v0.12.1 it ran on the actor, so a slow model held every other call;
|
|
203
|
+
before v0.12.3 it ran on the cooperative pool, so slow embeds could
|
|
204
|
+
starve the app's other tasks.)
|
|
205
|
+
- Embeds run one at a time per store, because Core ML models often aren't
|
|
206
|
+
safe to call concurrently. So `embed` must not wait on a text call
|
|
207
|
+
(`rememberText`, `recallText`, ...) of the same store: that call queues
|
|
208
|
+
behind it.
|
|
209
|
+
- A cancelled text call stops waiting at once and writes nothing. An embed
|
|
210
|
+
already running can't be interrupted: it finishes on the queue and its
|
|
211
|
+
result is dropped.
|
|
202
212
|
- If it throws (any error), the call fails with `MnemoError.Embedder`, and
|
|
203
213
|
nothing is written.
|
|
204
214
|
- The identity is recorded in the file. Opening the file with a different
|
{mnemo_engine-0.12.2 → mnemo_engine-0.12.3}/mnemo/bindings/swift/Sources/Mnemo/MnemoStore.swift
RENAMED
|
@@ -125,9 +125,15 @@ public struct MnemoStoreConfiguration: Sendable, Equatable {
|
|
|
125
125
|
/// calls into one commit.
|
|
126
126
|
/// - Calls run on the actor, never on the main thread, and are serialized.
|
|
127
127
|
/// Each is a blocking call into the engine, so keep batches reasonable.
|
|
128
|
-
/// - The embedder runs before a call reaches the actor,
|
|
129
|
-
///
|
|
130
|
-
///
|
|
128
|
+
/// - The embedder runs before a call reaches the actor, on the store's own
|
|
129
|
+
/// serial embed queue, never on Swift's cooperative thread pool: other
|
|
130
|
+
/// calls to the store and the app's other tasks go ahead while it runs, a
|
|
131
|
+
/// background close isn't held up by it, and it may call back into the
|
|
132
|
+
/// same store (but must not wait on that store's text calls, which queue
|
|
133
|
+
/// behind it). Embeds run one at a time, because Core ML models often
|
|
134
|
+
/// aren't safe to call concurrently. A cancelled text call stops waiting
|
|
135
|
+
/// at once and writes nothing; an embed already running can't be
|
|
136
|
+
/// interrupted, so it finishes on the queue and its result is dropped.
|
|
131
137
|
/// - The file lives in `Application Support/mnemo/` by default, with the
|
|
132
138
|
/// protection class `completeUntilFirstUserAuthentication`, and under
|
|
133
139
|
/// ``KeyPolicy/deviceOnly`` it's excluded from backups.
|
|
@@ -140,6 +146,9 @@ public actor MnemoStore {
|
|
|
140
146
|
private let keyStore: any MnemoKeyStore
|
|
141
147
|
/// Read outside the actor: the text calls embed before they reach it.
|
|
142
148
|
private nonisolated let embedderBox: EmbedderBox
|
|
149
|
+
/// Runs the embedder, one call at a time, off the cooperative pool. QoS
|
|
150
|
+
/// `.userInitiated`: a text call is something the app is waiting on.
|
|
151
|
+
private nonisolated let embedQueue: DispatchQueue
|
|
143
152
|
private var db: MnemoDb?
|
|
144
153
|
private var keyID: String?
|
|
145
154
|
private nonisolated let lifecycle = LifecycleObserver()
|
|
@@ -179,6 +188,7 @@ public actor MnemoStore {
|
|
|
179
188
|
self.fileURL = try configuration.fileURL()
|
|
180
189
|
self.keyStore = keyStore
|
|
181
190
|
self.embedderBox = EmbedderBox(embedder)
|
|
191
|
+
self.embedQueue = DispatchQueue(label: "mnemo.embed.\(configuration.name)", qos: .userInitiated)
|
|
182
192
|
activityReason = "MNemo: \(configuration.name) in the background"
|
|
183
193
|
lifecycle.start(reason: "MNemo: flush and close \(configuration.name)") { [weak self] in
|
|
184
194
|
await self?.closeForBackground()
|
|
@@ -198,7 +208,7 @@ public actor MnemoStore {
|
|
|
198
208
|
@discardableResult
|
|
199
209
|
public nonisolated func rememberText(_ content: String,
|
|
200
210
|
options: RememberOptions = RememberOptions()) async throws -> WriteResult {
|
|
201
|
-
let vector = try embed(content)
|
|
211
|
+
let vector = try await embed(content)
|
|
202
212
|
return try await remember(content, vector: vector, options: options)
|
|
203
213
|
}
|
|
204
214
|
|
|
@@ -208,7 +218,7 @@ public actor MnemoStore {
|
|
|
208
218
|
public nonisolated func update(id: String, patch: MemoryPatch) async throws -> WriteOutcome {
|
|
209
219
|
var patch = patch
|
|
210
220
|
if let content = patch.content, patch.vector == nil, embedderBox.value != nil {
|
|
211
|
-
patch.vector = try embed(content)
|
|
221
|
+
patch.vector = try await embed(content)
|
|
212
222
|
}
|
|
213
223
|
return try await updateOnHandle(id: id, patch: patch)
|
|
214
224
|
}
|
|
@@ -242,7 +252,7 @@ public actor MnemoStore {
|
|
|
242
252
|
|
|
243
253
|
/// Recall by text, embedded with the store's embedder first.
|
|
244
254
|
public nonisolated func recallText(_ query: String, options: RecallOptions = RecallOptions()) async throws -> RecallPage {
|
|
245
|
-
let vector = try embed(query)
|
|
255
|
+
let vector = try await embed(query)
|
|
246
256
|
return try await recall(vector: vector, options: options)
|
|
247
257
|
}
|
|
248
258
|
|
|
@@ -264,7 +274,7 @@ public actor MnemoStore {
|
|
|
264
274
|
@discardableResult
|
|
265
275
|
public nonisolated func essenceAdd(_ section: EssenceSection, _ text: String, scope: EssenceScope = .project,
|
|
266
276
|
refs: [String]? = nil) async throws -> String {
|
|
267
|
-
let vector = try embedIfSet(text)
|
|
277
|
+
let vector = try await embedIfSet(text)
|
|
268
278
|
return try await essenceAddOnHandle(section, text, scope: scope, refs: refs, vector: vector)
|
|
269
279
|
}
|
|
270
280
|
|
|
@@ -280,7 +290,7 @@ public actor MnemoStore {
|
|
|
280
290
|
@discardableResult
|
|
281
291
|
public nonisolated func essenceAppendTimeline(_ text: String, scope: EssenceScope = .project,
|
|
282
292
|
refs: [String]? = nil) async throws -> String {
|
|
283
|
-
let vector = try embedIfSet(text)
|
|
293
|
+
let vector = try await embedIfSet(text)
|
|
284
294
|
return try await essenceAppendOnHandle(text, scope: scope, refs: refs, vector: vector)
|
|
285
295
|
}
|
|
286
296
|
|
|
@@ -341,7 +351,7 @@ public actor MnemoStore {
|
|
|
341
351
|
public nonisolated func ingestThread(_ threadID: String, turns: [ThreadTurn]) async throws -> IngestReport {
|
|
342
352
|
for _ in 0..<3 {
|
|
343
353
|
let texts = try await ingestPlan(threadID, turns: turns)
|
|
344
|
-
let vectors = texts.isEmpty ? [] : try embed(texts)
|
|
354
|
+
let vectors = texts.isEmpty ? [] : try await embed(texts)
|
|
345
355
|
if let report = try await ingestApply(threadID, turns: turns, texts: texts, vectors: vectors) {
|
|
346
356
|
return report
|
|
347
357
|
}
|
|
@@ -504,20 +514,36 @@ public actor MnemoStore {
|
|
|
504
514
|
|
|
505
515
|
// MARK: Embedding
|
|
506
516
|
|
|
507
|
-
/// One text's vector, embedded
|
|
508
|
-
private nonisolated func embed(_ text: String) throws -> [Float] {
|
|
509
|
-
try embed([text])[0]
|
|
517
|
+
/// One text's vector, embedded outside the actor, on the embed queue.
|
|
518
|
+
private nonisolated func embed(_ text: String) async throws -> [Float] {
|
|
519
|
+
try await embed([text])[0]
|
|
510
520
|
}
|
|
511
521
|
|
|
512
|
-
|
|
522
|
+
/// Runs the embedder on the store's serial embed queue and waits for it
|
|
523
|
+
/// without holding a cooperative-pool thread. A cancelled caller stops
|
|
524
|
+
/// waiting with `CancellationError`; an embed not yet started is skipped,
|
|
525
|
+
/// and one already running finishes and its result is dropped.
|
|
526
|
+
private nonisolated func embed(_ texts: [String]) async throws -> [[Float]] {
|
|
513
527
|
guard let embedder = embedderBox.value else {
|
|
514
528
|
throw MnemoError.Invalid(message: "no embedder set; call set_embedder first")
|
|
515
529
|
}
|
|
516
|
-
|
|
530
|
+
let dimensions = configuration.dimensions
|
|
531
|
+
let call = EmbedCall()
|
|
532
|
+
return try await withTaskCancellationHandler {
|
|
533
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
534
|
+
guard call.wait(continuation) else { return }
|
|
535
|
+
embedQueue.async {
|
|
536
|
+
guard !call.isCancelled else { return }
|
|
537
|
+
call.finish(Result { try embedTexts(embedder: embedder, texts: texts, dimensions: dimensions) })
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
} onCancel: {
|
|
541
|
+
call.cancel()
|
|
542
|
+
}
|
|
517
543
|
}
|
|
518
544
|
|
|
519
|
-
private nonisolated func embedIfSet(_ text: String) throws -> [Float]? {
|
|
520
|
-
embedderBox.value == nil ? nil : try embed(text)
|
|
545
|
+
private nonisolated func embedIfSet(_ text: String) async throws -> [Float]? {
|
|
546
|
+
embedderBox.value == nil ? nil : try await embed(text)
|
|
521
547
|
}
|
|
522
548
|
|
|
523
549
|
// MARK: Internals
|
|
@@ -804,6 +830,40 @@ final class KeyBytes {
|
|
|
804
830
|
}
|
|
805
831
|
}
|
|
806
832
|
|
|
833
|
+
/// One embed's hand-off between the caller and the embed queue: whichever of
|
|
834
|
+
/// the result and a cancellation comes first resumes the caller, once.
|
|
835
|
+
final class EmbedCall: @unchecked Sendable {
|
|
836
|
+
private let lock = NSLock()
|
|
837
|
+
private var continuation: CheckedContinuation<[[Float]], any Error>?
|
|
838
|
+
private var cancelled = false
|
|
839
|
+
|
|
840
|
+
var isCancelled: Bool { lock.lock(); defer { lock.unlock() }; return cancelled }
|
|
841
|
+
|
|
842
|
+
/// Parks the caller. False (and the caller resumed with
|
|
843
|
+
/// `CancellationError`) when the task was cancelled first.
|
|
844
|
+
func wait(_ c: CheckedContinuation<[[Float]], any Error>) -> Bool {
|
|
845
|
+
lock.lock()
|
|
846
|
+
if cancelled {
|
|
847
|
+
lock.unlock()
|
|
848
|
+
c.resume(throwing: CancellationError())
|
|
849
|
+
return false
|
|
850
|
+
}
|
|
851
|
+
continuation = c
|
|
852
|
+
lock.unlock()
|
|
853
|
+
return true
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
func finish(_ result: Result<[[Float]], any Error>) {
|
|
857
|
+
lock.lock(); let c = continuation; continuation = nil; lock.unlock()
|
|
858
|
+
c?.resume(with: result)
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
func cancel() {
|
|
862
|
+
lock.lock(); cancelled = true; let c = continuation; continuation = nil; lock.unlock()
|
|
863
|
+
c?.resume(throwing: CancellationError())
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
807
867
|
/// The store's embedder, readable from outside the actor.
|
|
808
868
|
final class EmbedderBox: @unchecked Sendable {
|
|
809
869
|
private let lock = NSLock()
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Testing
|
|
3
|
+
@testable import Mnemo
|
|
4
|
+
|
|
5
|
+
/// MOBILE-2f (v0.12.3): the store runs the app's synchronous embedder on its
|
|
6
|
+
/// own serial queue, so a slow embed never blocks Swift's cooperative pool.
|
|
7
|
+
@Suite struct EmbedQueueTests {
|
|
8
|
+
/// Twice as many stores as the machine has cores, each with a slow embed
|
|
9
|
+
/// in flight (before v0.12.3 those blocked every cooperative-pool
|
|
10
|
+
/// thread), and more short tasks than cores: each task's 50 ms sleep
|
|
11
|
+
/// ends within about 0.5 s, while the embeds are still running.
|
|
12
|
+
@Test func slowEmbedsDontStarveTheAppsOtherTasks() async throws {
|
|
13
|
+
let cores = ProcessInfo.processInfo.activeProcessorCount
|
|
14
|
+
let embedders = (0..<(2 * cores)).map { _ in SlowEmbedder(seconds: 1.5) }
|
|
15
|
+
var stores: [MnemoStore] = []
|
|
16
|
+
for (i, embedder) in embedders.enumerated() {
|
|
17
|
+
stores.append(try MnemoStore(
|
|
18
|
+
configuration: MnemoStoreConfiguration(name: "starve\(i)", dimensions: 32,
|
|
19
|
+
directory: try scratchDirectory()),
|
|
20
|
+
keyStore: MemoryKeyStore(), embedder: embedder))
|
|
21
|
+
}
|
|
22
|
+
let launched = Date()
|
|
23
|
+
let writers = stores.map { store in Task { try await store.rememberText("slow to embed") } }
|
|
24
|
+
#expect(try await eventually(5) { embedders.contains(where: \.started) })
|
|
25
|
+
try await Task.sleep(nanoseconds: 100_000_000)
|
|
26
|
+
|
|
27
|
+
// Timed from before the tasks are scheduled, so a task that waits
|
|
28
|
+
// for a free thread counts that wait.
|
|
29
|
+
let taskCount = cores + 2
|
|
30
|
+
let start = Date()
|
|
31
|
+
let waits = await withTaskGroup(of: Double.self) { group in
|
|
32
|
+
for _ in 0..<taskCount {
|
|
33
|
+
group.addTask {
|
|
34
|
+
try? await Task.sleep(nanoseconds: 50_000_000)
|
|
35
|
+
return Date().timeIntervalSince(start)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
var all: [Double] = []
|
|
39
|
+
for await w in group { all.append(w) }
|
|
40
|
+
return all
|
|
41
|
+
}
|
|
42
|
+
let stillEmbedding = embedders.filter { !$0.finished }.count
|
|
43
|
+
// The test's own task resumed while the first embeds were running.
|
|
44
|
+
let sinceLaunch = Date().timeIntervalSince(launched)
|
|
45
|
+
#expect(sinceLaunch < 1.2, "the short tasks ended \(sinceLaunch) s after the embeds began")
|
|
46
|
+
#expect(waits.count == taskCount)
|
|
47
|
+
#expect(waits.allSatisfy { $0 < 0.5 }, "slowest task: \(waits.max() ?? 0) s")
|
|
48
|
+
#expect(stillEmbedding > 0, "the embeds were over before the tasks ran")
|
|
49
|
+
|
|
50
|
+
for writer in writers { _ = try await writer.value }
|
|
51
|
+
for store in stores {
|
|
52
|
+
#expect(try await store.count() == 1)
|
|
53
|
+
try await store.close()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// A cancelled text call stops waiting at once and writes nothing; the
|
|
58
|
+
/// embed already running finishes on the queue and its result is dropped.
|
|
59
|
+
@Test func aCancelledTextCallStopsWaitingAndWritesNothing() async throws {
|
|
60
|
+
let slow = SlowEmbedder(seconds: 1.5)
|
|
61
|
+
let store = try MnemoStore(
|
|
62
|
+
configuration: MnemoStoreConfiguration(name: "cancel", dimensions: 32, directory: try scratchDirectory()),
|
|
63
|
+
keyStore: MemoryKeyStore(), embedder: slow)
|
|
64
|
+
let writer = Task { try await store.rememberText("never stored") }
|
|
65
|
+
#expect(try await eventually(5) { slow.started })
|
|
66
|
+
let start = Date()
|
|
67
|
+
writer.cancel()
|
|
68
|
+
await #expect(throws: CancellationError.self) { try await writer.value }
|
|
69
|
+
#expect(Date().timeIntervalSince(start) < 0.5)
|
|
70
|
+
|
|
71
|
+
#expect(try await eventually(5) { slow.finished })
|
|
72
|
+
try await Task.sleep(nanoseconds: 100_000_000)
|
|
73
|
+
#expect(try await store.count() == 0)
|
|
74
|
+
// The store still works, and the queue is free for the next embed.
|
|
75
|
+
let fast = Task { try await store.rememberText("stored") }
|
|
76
|
+
_ = try await fast.value
|
|
77
|
+
#expect(try await store.count() == 1)
|
|
78
|
+
try await store.close()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// Embeds on one store run one at a time (Core ML models often aren't
|
|
82
|
+
/// safe to call concurrently), whatever the number of callers.
|
|
83
|
+
@Test func embedsOnOneStoreRunOneAtATime() async throws {
|
|
84
|
+
let counting = ConcurrencyCountingEmbedder()
|
|
85
|
+
let store = try MnemoStore(
|
|
86
|
+
configuration: MnemoStoreConfiguration(name: "serial", dimensions: 32, directory: try scratchDirectory()),
|
|
87
|
+
keyStore: MemoryKeyStore(), embedder: counting)
|
|
88
|
+
try await withThrowingTaskGroup(of: Void.self) { group in
|
|
89
|
+
for i in 0..<6 {
|
|
90
|
+
group.addTask { try await store.rememberText("note \(i)") }
|
|
91
|
+
}
|
|
92
|
+
try await group.waitForAll()
|
|
93
|
+
}
|
|
94
|
+
#expect(counting.maxConcurrent == 1)
|
|
95
|
+
#expect(counting.calls == 6)
|
|
96
|
+
#expect(try await store.count() == 6)
|
|
97
|
+
try await store.close()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// Records how many embeds overlap; each takes 50 ms.
|
|
102
|
+
final class ConcurrencyCountingEmbedder: MnemoEmbedder, @unchecked Sendable {
|
|
103
|
+
private let lock = NSLock()
|
|
104
|
+
private var running = 0
|
|
105
|
+
private var _maxConcurrent = 0
|
|
106
|
+
private var _calls = 0
|
|
107
|
+
private let words = WordEmbedder()
|
|
108
|
+
|
|
109
|
+
var maxConcurrent: Int { lock.lock(); defer { lock.unlock() }; return _maxConcurrent }
|
|
110
|
+
var calls: Int { lock.lock(); defer { lock.unlock() }; return _calls }
|
|
111
|
+
|
|
112
|
+
func identity() -> EmbedderIdentity { words.identity() }
|
|
113
|
+
|
|
114
|
+
func embed(texts: [String]) throws -> [[Float]] {
|
|
115
|
+
lock.lock(); running += 1; _calls += 1; _maxConcurrent = max(_maxConcurrent, running); lock.unlock()
|
|
116
|
+
Thread.sleep(forTimeInterval: 0.05)
|
|
117
|
+
lock.lock(); running -= 1; lock.unlock()
|
|
118
|
+
return try words.embed(texts: texts)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -3,7 +3,8 @@ import Testing
|
|
|
3
3
|
@testable import Mnemo
|
|
4
4
|
|
|
5
5
|
/// The embedder runs outside the store (MOBILE-2c): before a call reaches
|
|
6
|
-
/// the actor,
|
|
6
|
+
/// the actor, on the store's embed queue (MOBILE-2f), so the store keeps
|
|
7
|
+
/// serving other calls while it runs.
|
|
7
8
|
@Suite struct EmbedderLockTests {
|
|
8
9
|
@Test func anEmbedderThatCallsBackIntoTheStoreCompletes() async throws {
|
|
9
10
|
let embedder = CallbackEmbedder()
|
|
@@ -99,7 +100,6 @@ final class SlowEmbedder: MnemoEmbedder, @unchecked Sendable {
|
|
|
99
100
|
init(seconds: Double) { self.seconds = seconds }
|
|
100
101
|
|
|
101
102
|
var started: Bool { lock.lock(); defer { lock.unlock() }; return _started }
|
|
102
|
-
/// True once the embed is about to return; its write can land only after.
|
|
103
103
|
var finished: Bool { lock.lock(); defer { lock.unlock() }; return _finished }
|
|
104
104
|
|
|
105
105
|
func identity() -> EmbedderIdentity { words.identity() }
|
|
@@ -42,9 +42,8 @@ import Testing
|
|
|
42
42
|
|
|
43
43
|
/// T9 (b): a 1.5 s embed in flight; `count()` and `closeForBackground()`
|
|
44
44
|
/// 0.2 s in. Before 2c both waited about 1.3 s. After: milliseconds.
|
|
45
|
-
///
|
|
46
|
-
///
|
|
47
|
-
/// is 1 only when the embed hadn't finished when `count()` was called.
|
|
45
|
+
/// Strict since MOBILE-2f: the embed no longer holds a cooperative-pool
|
|
46
|
+
/// thread, so the test resumes while it's still in flight.
|
|
48
47
|
@Test func t9bCountAndTheBackgroundCloseDontWaitForAnEmbed() async throws {
|
|
49
48
|
let slow = SlowEmbedder(seconds: 1.5)
|
|
50
49
|
let store = try MnemoStore(
|
|
@@ -55,19 +54,11 @@ import Testing
|
|
|
55
54
|
#expect(try await eventually(5) { slow.started })
|
|
56
55
|
try await Task.sleep(nanoseconds: 200_000_000)
|
|
57
56
|
var t = Date()
|
|
58
|
-
|
|
57
|
+
#expect(try await store.count() == 1)
|
|
59
58
|
let countSecs = Date().timeIntervalSince(t)
|
|
60
|
-
// Read after count() returns: if the embed still hadn't finished, its
|
|
61
|
-
// write can't have landed before count() read the file.
|
|
62
|
-
let embedDone = slow.finished
|
|
63
59
|
t = Date()
|
|
64
60
|
await store.closeForBackground()
|
|
65
61
|
let closeSecs = Date().timeIntervalSince(t)
|
|
66
|
-
if embedDone {
|
|
67
|
-
#expect(count == 1 || count == 2, "count \(count) after the embed finished")
|
|
68
|
-
} else {
|
|
69
|
-
#expect(count == 1, "count \(count) with the embed in flight")
|
|
70
|
-
}
|
|
71
62
|
#expect(countSecs < 0.3, "count took \(countSecs) s")
|
|
72
63
|
#expect(closeSecs < 0.3, "the background close took \(closeSecs) s")
|
|
73
64
|
_ = try await writer.value
|
|
@@ -86,6 +86,47 @@ use crate::crypto::{self, KEY_LEN, NONCE_LEN};
|
|
|
86
86
|
use crate::error::{MnemoError, Result};
|
|
87
87
|
use crate::format::{PAGE_SIZE, PAYLOAD};
|
|
88
88
|
|
|
89
|
+
/// The database file with the advisory lock its opener took, released
|
|
90
|
+
/// explicitly when this is dropped.
|
|
91
|
+
///
|
|
92
|
+
/// `flock` locks belong to the open file description, not to one file
|
|
93
|
+
/// descriptor. While another thread of the process spawns a child, the
|
|
94
|
+
/// child holds a copy of the parent's file table until it `exec`s (the
|
|
95
|
+
/// descriptor is close-on-exec, but that only takes effect at the exec).
|
|
96
|
+
/// Without the explicit unlock, a handle dropped inside that window left
|
|
97
|
+
/// the lock held by the child's copy, and the next open of the file failed
|
|
98
|
+
/// with `Locked` (FLAKE-1). Unlocking releases it whatever copies exist.
|
|
99
|
+
/// On Windows the unlock is equally harmless: handles aren't inherited.
|
|
100
|
+
pub(crate) struct LockedFile(File);
|
|
101
|
+
|
|
102
|
+
impl LockedFile {
|
|
103
|
+
/// Wraps a file whose lock the caller has just taken.
|
|
104
|
+
pub(crate) fn new(file: File) -> Self {
|
|
105
|
+
Self(file)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
impl std::ops::Deref for LockedFile {
|
|
110
|
+
type Target = File;
|
|
111
|
+
fn deref(&self) -> &File {
|
|
112
|
+
&self.0
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
impl std::ops::DerefMut for LockedFile {
|
|
117
|
+
fn deref_mut(&mut self) -> &mut File {
|
|
118
|
+
&mut self.0
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
impl Drop for LockedFile {
|
|
123
|
+
fn drop(&mut self) {
|
|
124
|
+
// Nothing to do on failure: closing the file releases the lock once
|
|
125
|
+
// the last copy of the description goes.
|
|
126
|
+
let _ = fs4::fs_std::FileExt::unlock(&self.0);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
89
130
|
/// Default page-cache capacity, in pages (~8 MiB of decrypted payloads).
|
|
90
131
|
/// PERF-1 step 4 lowered it from 8192 (~64 MiB): at 10K and 100K memories
|
|
91
132
|
/// that cache was most of an open handle's RSS, for little hit rate on
|
|
@@ -100,7 +141,7 @@ pub const V9_DEFAULT_CACHE_PAGES: usize = 256;
|
|
|
100
141
|
|
|
101
142
|
/// Encrypted page reader/writer with a bounded write-back cache.
|
|
102
143
|
pub struct Pager {
|
|
103
|
-
file:
|
|
144
|
+
file: LockedFile,
|
|
104
145
|
dek: Zeroizing<[u8; KEY_LEN]>,
|
|
105
146
|
/// Monotonic write counter persisted in the header (lease / replay
|
|
106
147
|
/// machinery; see `Mnemo::prepare_for_flush`). **No longer used in
|
|
@@ -139,8 +180,8 @@ pub struct Pager {
|
|
|
139
180
|
|
|
140
181
|
impl Pager {
|
|
141
182
|
/// Wrap an open file with a pager. `write_counter` comes from the header.
|
|
142
|
-
pub fn new(
|
|
143
|
-
file:
|
|
183
|
+
pub(crate) fn new(
|
|
184
|
+
file: LockedFile,
|
|
144
185
|
dek: Zeroizing<[u8; KEY_LEN]>,
|
|
145
186
|
write_counter: u64,
|
|
146
187
|
version: u16,
|
|
@@ -9,7 +9,11 @@ use super::*;
|
|
|
9
9
|
/// the lock is scoped to this handle: cloning the file (or the returned
|
|
10
10
|
/// `File`) shares the lock, but a fresh `open()` from any process gets a
|
|
11
11
|
/// distinct handle and will collide.
|
|
12
|
-
|
|
12
|
+
///
|
|
13
|
+
/// The file comes back as a [`LockedFile`], which unlocks explicitly on
|
|
14
|
+
/// drop, so a failed open (a wrong key, say) releases the lock as promptly
|
|
15
|
+
/// as a closed handle does.
|
|
16
|
+
pub(super) fn open_with_lock(path: &Path, write: bool, create: bool) -> Result<LockedFile> {
|
|
13
17
|
let mut opts = OpenOptions::new();
|
|
14
18
|
opts.read(true);
|
|
15
19
|
if write {
|
|
@@ -33,7 +37,7 @@ pub(super) fn open_with_lock(path: &Path, write: bool, create: bool) -> Result<F
|
|
|
33
37
|
FileExt::try_lock_shared(&file)
|
|
34
38
|
};
|
|
35
39
|
match result {
|
|
36
|
-
Ok(()) => Ok(file),
|
|
40
|
+
Ok(()) => Ok(LockedFile::new(file)),
|
|
37
41
|
Err(e) if is_lock_conflict(&e) => Err(MnemoError::Locked {
|
|
38
42
|
path: path.to_path_buf(),
|
|
39
43
|
}),
|
|
@@ -51,7 +51,7 @@ use crate::memory::{
|
|
|
51
51
|
MNEMO_META_SUPERSEDES, MNEMO_META_THREAD, MNEMO_META_TURN_ID, MNEMO_META_UPDATED_AT,
|
|
52
52
|
THREAD_TOOL_RESULT_TRUNCATE_BYTES, THREAD_TURN_CHUNK_BYTES,
|
|
53
53
|
};
|
|
54
|
-
use crate::pager::Pager;
|
|
54
|
+
use crate::pager::{LockedFile, Pager};
|
|
55
55
|
use crate::result_cache::{
|
|
56
56
|
self, BatchState, CacheBudget, CacheDirectoryEntry, CacheEntry, CacheFlushPolicy, CachePutOpts,
|
|
57
57
|
CacheStats, CachedValue, CounterState, DirectoryIndex, SemanticCachePutOpts,
|