The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(memory): answer recall_relevant_by_vector on DriverMemory so Lane B injects again
Shanu7de4d8942216
diff --git a/.claude/memory.md b/.claude/memory.mdindex aeb5dca058..4c6471c300 100644--- a/.claude/memory.md+++ b/.claude/memory.md@@ -11,6 +11,7 @@ Quick reference for anyone starting with Claude on this project. Updated by the- **Cargo incremental builds can serve stale UI** — If the app shows old frontend after a Rust rebuild, run `cargo clean --manifest-path app/src-tauri/Cargo.toml` before rebuilding.- **`build.rs` missing `rerun-if-changed` causes stale ACL / "Command not found" at runtime** — `app/src-tauri/build.rs` had no `cargo:rerun-if-changed` directives for `permissions/` or `capabilities/`. Adding/changing TOML or JSON files there did not re-trigger `tauri-build`, so ACL tables were stale and registered commands silently failed. Fixed by adding `println!("cargo:rerun-if-changed=permissions")` and `println!("cargo:rerun-if-changed=capabilities")` in `build.rs` (issue #270). Also: any new Tauri command must have a matching entry in a `permissions/` TOML file or it will hit the same error even if it is in `generate_handler!`.- **macOS deep links require .app bundle** — `pnpm tauri dev` does NOT support deep links. Must use `pnpm tauri build --debug --bundles app`.+- **A `Memory` trait method left on its default is a silent no-op in production (issue #6041)** — the session's `Arc<dyn Memory>` is `agent/experience/ops.rs::DriverMemory` (since `7a4278378`), and `tinymemory-api`'s `Memory::recall_relevant_by_vector` defaults to `Ok(vec![])`, so situational preferences (Lane B) injected nothing on every module-backed install while every turn test stayed green — the harness tests bind the embedded `tinymemory_core::store::create_memory`, which overrides it. `DriverMemory` now answers through `preferences::recall_by_vector_over` (one body with the guard path). Rule: a turn-level test that pins production behaviour must bind `DriverMemory` over `guard::test_support::RecordingProvider` (`with_namespace_hits`, `with_list_result`), not the embedded store; and before leaving a trait default in place, grep who actually holds the handle. Costs measured on the desktop once the lane was live: the vector recall is one query-embed round trip, 0.8–3 s per turn, so `recall_situational_preferences_on` lists the namespace first (no embed) and skips the recall when nothing is stored; Lane B's budget is 5 s (3 s lost the block on both on-topic turns). Floor tuning data: `[pref_recall] namespace= kept= top_similarity= floor= elapsed_ms=` — with the managed embedder, unrelated message↔preference pairs score 0.28–0.33, a rule-phrased travel preference vs a trip-planning message 0.349, a coffee preference vs a café question 0.575; the 0.35 floor is thin but lowering it pulls cross-topic preferences in.## Strict Rulesdiff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.mdindex 902b1f0021..7ead5aa79b 100644--- a/docs/TEST-COVERAGE-MATRIX.md+++ b/docs/TEST-COVERAGE-MATRIX.md@@ -346,7 +346,7 @@ End-to-end coverage of the agent harness via the web-chat RPC surface against an| ----- | ------------------------------------------ | ----- | -------------------------------------------------------------------------------------------------------------- | ------ | ----------------------------------------------------------------------- || 8.4.1 | Save Preference (general / situational) | RU | `src/openhuman/agent/tools/save_preference_tests.rs` | ✅ | `save_preference` tool → `user_pref_{general,situational}`, topic-keyed || 8.4.2 | Lane A — Standing Prefs in System Prompt | RU | `src/openhuman/agent/learning/prompt_sections.rs`, `src/openhuman/agent/harness/session/turn_tests.rs` | ✅ | General prefs rendered into the system prompt at thread start |-| 8.4.3 | Lane B — Situational Recall (vector-gated) | RU | `src/openhuman/memory/store/namespace_store/query_tests.rs::recall_relevant_by_vector_gates_on_similarity` | ✅ | Per-turn; relevant query injects, unrelated suppresses |+| 8.4.3 | Lane B — Situational Recall (vector-gated) | RU | `src/openhuman/agent/harness/session/turn_tests_part_04_tests.rs::situational_preference_reaches_the_model_through_driver_memory`, `src/openhuman/agent/experience/ops_tests.rs::recall_relevant_by_vector_*`, `src/openhuman/memory/preferences/preferences_tests.rs` | ✅ | Per-turn through the production `DriverMemory` handle (#6041); relevant query injects, below-floor suppresses || 8.4.4 | Same-Topic Contradiction (replace) | RU | `src/openhuman/agent/tools/save_preference_tests.rs::recategorising_moves_pref_between_namespaces` | ✅ | `ON CONFLICT REPLACE`; a topic lives in exactly one scope || 8.4.5 | Cross-Topic Contradiction Surfacing | RU | `src/openhuman/agent/tools/save_preference_tests.rs::save_surfaces_related_preference_for_contradiction_check` | ✅ | Related prefs surfaced in the tool result for the chat agent to resolve || 8.4.6 | vector_chunks Model-Signature Recall Guard | RU | `src/openhuman/memory/store/namespace_store/query_tests.rs::vector_recall_excludes_other_model_signature` | ✅ | Excludes cross-model vectors; dim-guards legacy rows |diff --git a/src/openhuman/agent/experience/ops.rs b/src/openhuman/agent/experience/ops.rsindex 2e3279c34f..98f00e494e 100644--- a/src/openhuman/agent/experience/ops.rs+++ b/src/openhuman/agent/experience/ops.rs@@ -179,14 +179,36 @@ impl Memory for DriverMemory {.await?)}- // `recall_relevant_by_vector` is deliberately left on the trait's default.- // The contract has no vector-threshold recall member, and the trait- // defines the default as the documented opt-out for a backend that cannot- // answer it ("keyword-only / mock backends opt out"), not as a swallowed- // failure. The consumer that cares — situational preferences- // (`memory::preferences`, Lane B) — already treats an empty answer as "no- // block to inject" rather than as a broken turn, and it is reached through- // the session's own memory handle, not through this adapter.+ /// Situational preferences (Lane B) reach memory through **this** adapter:+ /// the session's `Arc<dyn Memory>` is a `DriverMemory` on every+ /// module-backed install. This used to sit on the trait's default — empty,+ /// "the documented opt-out for a backend that cannot answer it" — on the+ /// belief that Lane B was reached through some other handle. It was not,+ /// so the lane silently injected nothing for everyone (#6041).+ ///+ /// The contract has no vector-threshold member; the body is the guard+ /// path's, over `MemoryRetrieval::recall_namespace_scored`, filtered on the+ /// vector component. A driver without the retrieval family still answers+ /// empty; a driver that has it and fails answers `Err`, which Lane B reads+ /// as "no block" rather than as a broken turn.+ async fn recall_relevant_by_vector(+ &self,+ namespace: &str,+ query: &str,+ limit: usize,+ min_vector_similarity: f64,+ ) -> anyhow::Result<Vec<(String, String)>> {+ Ok(+ crate::openhuman::memory::preferences::recall_by_vector_over(+ self.provider.as_ref(),+ namespace,+ query,+ limit,+ min_vector_similarity,+ )+ .await?,+ )+ }async fn get(&self, namespace: &str, key: &str) -> anyhow::Result<Option<MemoryEntry>> {Ok(self.provider.get(namespace, key).await?)diff --git a/src/openhuman/agent/experience/ops_tests.rs b/src/openhuman/agent/experience/ops_tests.rsindex eb5332db47..e8e6fb7dda 100644--- a/src/openhuman/agent/experience/ops_tests.rs+++ b/src/openhuman/agent/experience/ops_tests.rs@@ -142,3 +142,70 @@ async fn experience_store_round_trips_over_the_bound_driver() {"a record written through the bound driver must read back");}++// ── recall_relevant_by_vector (#6041) ────────────────────────────────────────+//+// The adapter used to leave this on the trait's empty default, which made Lane B+// a silent no-op on every module-backed install. These pin the override against+// a scripted driver: the vector floor, the mapping, and the two degradations.++fn driver_over(+ provider: crate::openhuman::memory::guard::test_support::RecordingProvider,+) -> DriverMemory {+ DriverMemory::new(Arc::new(provider) as Arc<dyn MemoryProvider>)+}++#[tokio::test]+async fn recall_relevant_by_vector_keeps_hits_above_the_vector_floor_only() {+ use crate::openhuman::memory::guard::test_support::{namespace_hit, RecordingProvider};+ let memory = driver_over(RecordingProvider::new().with_namespace_hits(vec![+ namespace_hit("user_pref_situational", "editor", "Prefers vim.", 0.9),+ namespace_hit(+ "user_pref_situational",+ "lexical",+ "Shares words only.",+ 0.1,+ ),+ namespace_hit("user_pref_situational", "blank", " ", 0.95),+ ]));++ let out = memory+ .recall_relevant_by_vector("user_pref_situational", "which editor?", 5, 0.35)+ .await+ .expect("a driver with retrieval answers");+ assert_eq!(+ out,+ vec![("editor".to_string(), "Prefers vim.".to_string())],+ "below-floor and empty-bodied hits must be dropped"+ );+}++#[tokio::test]+async fn recall_relevant_by_vector_asks_the_driver_not_the_trait_default() {+ use crate::openhuman::memory::guard::test_support::RecordingProvider;+ let provider = Arc::new(RecordingProvider::new());+ let memory = DriverMemory::new(provider.clone() as Arc<dyn MemoryProvider>);++ let out = memory+ .recall_relevant_by_vector("user_pref_situational", "anything", 5, 0.35)+ .await+ .expect("an empty page is not an error");+ assert!(out.is_empty());+ assert_eq!(+ provider.only_call().method,+ "retrieval.recall_namespace_scored",+ "the lookup must reach the driver's retrieval family"+ );+}++#[tokio::test]+async fn recall_relevant_by_vector_over_a_driver_without_retrieval_answers_empty() {+ // The null driver advertises nothing, so there is no retrieval family to+ // ask: the documented degradation is an empty answer, not an error.+ let memory = DriverMemory::new(Arc::new(tinymemory_api::null::NullMemoryProvider));+ let out = memory+ .recall_relevant_by_vector("user_pref_situational", "anything", 5, 0.35)+ .await+ .expect("no retrieval family is a degradation, not a failure");+ assert!(out.is_empty());+}diff --git a/src/openhuman/agent/harness/session/turn/core_turn.rs b/src/openhuman/agent/harness/session/turn/core_turn.rsindex 4a862472eb..fc534ce0ff 100644--- a/src/openhuman/agent/harness/session/turn/core_turn.rs+++ b/src/openhuman/agent/harness/session/turn/core_turn.rs@@ -347,10 +347,12 @@ impl Agent {// critical path, and on a cold launch the memory module may still// be downloading behind it. A turn without a preference block is// an ordinary turn; a turn that waits minutes for one is the- // outage this bound exists to prevent. The citation and autosave- // work above is already spawned off the path.+ // outage this bound exists to prevent. 5 s, not 3: the module's+ // lookup (a query embed round trip, queued behind the citation and+ // autosave calls spawned above) measured over 3 s on a live desktop+ // and lost the block on both on-topic turns of the #6041 field test.const SITUATIONAL_RECALL_BUDGET: std::time::Duration =- std::time::Duration::from_secs(3);+ std::time::Duration::from_secs(5);let situational = match tokio::time::timeout(SITUATIONAL_RECALL_BUDGET,crate::openhuman::memory::preferences::recall_situational_preferences_on(diff --git a/src/openhuman/agent/harness/session/turn_tests_part_04_tests.rs b/src/openhuman/agent/harness/session/turn_tests_part_04_tests.rsindex 410176bcb7..415adcfa82 100644--- a/src/openhuman/agent/harness/session/turn_tests_part_04_tests.rs+++ b/src/openhuman/agent/harness/session/turn_tests_part_04_tests.rs@@ -462,3 +462,148 @@ fn skill_retraction_note_names_removed_skills_and_warns_against_run_skill() {"retraction note must not look like an install announcement: {note}");}++// ── Lane B through the production memory handle (#6041) ─────────────────────+//+// Every other turn test binds the embedded store, whose `Memory` impl answers+// `recall_relevant_by_vector` itself. Production binds `DriverMemory`, which+// sat on the trait's empty default — so Lane B never injected anything on a+// module-backed install and no test noticed. These run the real `turn()` over+// `DriverMemory` on a scripted driver.++use crate::openhuman::agent::experience::ops::DriverMemory;+use crate::openhuman::memory::api::provider::MemoryProvider;+use crate::openhuman::memory::guard::test_support::{entry, namespace_hit, RecordingProvider};+use crate::openhuman::memory::preferences::USER_PREF_SITUATIONAL_NAMESPACE;++const PREFERENCES_BANNER: &str = "## Relevant preferences for this message";++fn scripted_reply(text: &str) -> Arc<SequenceProvider> {+ Arc::new(SequenceProvider {+ responses: AsyncMutex::new(vec![Ok(ChatResponse {+ text: Some(text.into()),+ tool_calls: vec![],+ usage: None,+ reasoning_content: None,+ })]),+ requests: AsyncMutex::new(Vec::new()),+ tool_counts: AsyncMutex::new(Vec::new()),+ })+}++/// A turn-capable agent whose memory is the production adapter over `driver`.+fn make_agent_over_driver(+ provider: Arc<dyn ChatModel<()>>,+ driver: Arc<RecordingProvider>,+) -> Agent {+ let workspace = tempfile::TempDir::new().expect("temp workspace");+ let workspace_path = workspace.path().to_path_buf();+ std::mem::forget(workspace);+ let mem: Arc<dyn Memory> = Arc::new(DriverMemory::new(driver as Arc<dyn MemoryProvider>));++ Agent::builder()+ .chat_model(provider)+ .tools(vec![])+ .memory(mem)+ .tool_dispatcher(Box::new(XmlToolDispatcher))+ .config(crate::openhuman::config::AgentConfig::default())+ .context_config(crate::openhuman::config::ContextConfig::default())+ .workspace_dir(workspace_path)+ .event_context("turn-test-session", "turn-test-channel")+ .build()+ .unwrap()+}++/// The user messages the model was sent on the first (only) request.+async fn first_request_user_messages(provider: &SequenceProvider) -> Vec<String> {+ let requests = provider.requests.lock().await;+ let request = requests.first().expect("the model was called once");+ request+ .iter()+ .filter(|m| m.role == "user")+ .map(|m| m.content.clone())+ .collect()+}++#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn situational_preference_reaches_the_model_through_driver_memory() {+ // The namespace must look populated (`list`) before Lane B pays for the+ // vector recall; then the scored hits decide what is injected.+ let driver = Arc::new(+ RecordingProvider::new()+ .with_list_result(vec![entry("Prefers vim for editing code.")])+ .with_namespace_hits(vec![+ namespace_hit(+ USER_PREF_SITUATIONAL_NAMESPACE,+ "editor",+ "Prefers vim for editing code.",+ 0.9,+ ),+ namespace_hit(+ USER_PREF_SITUATIONAL_NAMESPACE,+ "lexical_only",+ "Shares words, means nothing.",+ 0.1,+ ),+ ]),+ );+ let provider_impl = scripted_reply("vim it is.");+ let provider: Arc<dyn ChatModel<()>> = provider_impl.clone();+ let mut agent = make_agent_over_driver(provider, driver.clone());++ agent+ .turn("which editor should I use for this rust project?")+ .await+ .expect("turn succeeds");++ assert!(+ driver+ .calls()+ .iter()+ .any(|c| c.method == "retrieval.recall_namespace_scored"),+ "Lane B must ask the driver, not the trait default: {:?}",+ driver.calls()+ );+ let user = first_request_user_messages(&provider_impl).await;+ let last = user.last().expect("a user message");+ assert!(+ last.contains(PREFERENCES_BANNER) && last.contains("Prefers vim for editing code."),+ "the situational preference must ride the user message: {last}"+ );+ assert!(+ !last.contains("Shares words, means nothing."),+ "a hit below the vector floor must not be injected: {last}"+ );+}++#[tokio::test(flavor = "multi_thread", worker_threads = 2)]+async fn no_situational_preference_means_no_block_and_no_embed_through_driver_memory() {+ // Nothing stored under the situational namespace: the lane must find that+ // out from the cheap listing and never reach the vector recall, which is+ // the call that embeds the message.+ let driver = Arc::new(RecordingProvider::new());+ let provider_impl = scripted_reply("Sunny.");+ let provider: Arc<dyn ChatModel<()>> = provider_impl.clone();+ let mut agent = make_agent_over_driver(provider, driver.clone());++ agent+ .turn("what's the weather today")+ .await+ .expect("turn succeeds");+ let user = first_request_user_messages(&provider_impl).await;+ assert!(+ user.iter().all(|u| !u.contains(PREFERENCES_BANNER)),+ "an empty answer must inject nothing: {user:?}"+ );+ let methods: Vec<String> = driver.calls().into_iter().map(|c| c.method).collect();+ assert!(+ methods.iter().any(|m| m == "core.list"),+ "the lane must ask whether anything is stored: {methods:?}"+ );+ assert!(+ !methods+ .iter()+ .any(|m| m == "retrieval.recall_namespace_scored"),+ "an empty namespace must not cost an embed round trip: {methods:?}"+ );+}diff --git a/src/openhuman/memory/guard/test_support.rs b/src/openhuman/memory/guard/test_support.rsindex 714e06dfdf..dbc81c3000 100644--- a/src/openhuman/memory/guard/test_support.rs+++ b/src/openhuman/memory/guard/test_support.rs@@ -11,3 +11,4 @@include!("test_support_part_01.rs");include!("test_support_part_02.rs");+include!("test_support_part_03.rs");diff --git a/src/openhuman/memory/guard/test_support_part_01.rs b/src/openhuman/memory/guard/test_support_part_01.rsindex ac165e9afc..1415d2adcc 100644--- a/src/openhuman/memory/guard/test_support_part_01.rs+++ b/src/openhuman/memory/guard/test_support_part_01.rs@@ -77,6 +77,12 @@ pub struct RecordingProvider {calls: Mutex<Vec<Call>>,/// What `recall` returns, so budget tests can drive a known result set.recall_result: Mutex<Vec<MemoryEntry>>,+ /// What `recall_namespace_scored` returns, so the vector-floored recall+ /// paths (Lane B, the contradiction check) can be driven with known scores.+ namespace_hits: Mutex<Vec<NamespaceMemoryHit>>,+ /// What `list` returns, so a namespace can look populated (Lane B asks+ /// before it pays for an embed) without wiring a real store.+ list_result: Mutex<Vec<MemoryEntry>>,}impl Default for RecordingProvider {@@ -90,6 +96,8 @@ impl RecordingProvider {Self {calls: Mutex::new(Vec::new()),recall_result: Mutex::new(Vec::new()),+ namespace_hits: Mutex::new(Vec::new()),+ list_result: Mutex::new(Vec::new()),}}@@ -98,6 +106,16 @@ impl RecordingProvider {self}+ pub fn with_namespace_hits(self, hits: Vec<NamespaceMemoryHit>) -> Self {+ *self.namespace_hits.lock().unwrap() = hits;+ self+ }++ pub fn with_list_result(self, entries: Vec<MemoryEntry>) -> Self {+ *self.list_result.lock().unwrap() = entries;+ self+ }+fn record(&self, call: Call) {self.calls.lock().unwrap().push(call);}@@ -256,7 +274,7 @@ impl MemoryCore for RecordingProvider {_session_id: Option<&str>,) -> Result<Vec<MemoryEntry>, MemoryError> {self.record(Call::plain("core.list"));- Ok(vec![])+ Ok(self.list_result.lock().unwrap().clone())}async fn namespaces(&self) -> Result<Vec<NamespaceSummary>, MemoryError> {diff --git a/src/openhuman/memory/guard/test_support_part_02.rs b/src/openhuman/memory/guard/test_support_part_02.rsindex 6fd9432244..c55598d2a6 100644--- a/src/openhuman/memory/guard/test_support_part_02.rs+++ b/src/openhuman/memory/guard/test_support_part_02.rs@@ -538,7 +538,7 @@ impl MemoryRetrieval for RecordingProvider {_exclude_session_id: Option<&str>,) -> Result<Vec<NamespaceMemoryHit>, MemoryError> {self.record(Call::plain("retrieval.recall_namespace_scored"));- Ok(vec![])+ Ok(self.namespace_hits.lock().unwrap().clone())}async fn recall_namespace_recent(diff --git a/src/openhuman/memory/guard/test_support_part_03.rs b/src/openhuman/memory/guard/test_support_part_03.rsnew file mode 100644index 0000000000..9f009f11bf--- /dev/null+++ b/src/openhuman/memory/guard/test_support_part_03.rs@@ -0,0 +1,32 @@+// Fixtures for the retrieval family's scored answers. Included into+// `test_support.rs` after the provider parts, so the imports there are in scope.++/// A [`NamespaceMemoryHit`] with only the vector component set — the signal the+/// vector-floored recall paths (Lane B, the contradiction check) filter on.+pub fn namespace_hit(+ namespace: &str,+ key: &str,+ content: &str,+ vector_similarity: f64,+) -> NamespaceMemoryHit {+ NamespaceMemoryHit {+ id: format!("{namespace}/{key}"),+ kind: crate::openhuman::memory::api::types::MemoryItemKind::Kv,+ namespace: namespace.into(),+ key: key.into(),+ title: None,+ content: content.into(),+ category: "core".into(),+ source_type: None,+ updated_at: 0.0,+ score: vector_similarity,+ score_breakdown: crate::openhuman::memory::api::types::RetrievalScoreBreakdown {+ vector_similarity,+ ..Default::default()+ },+ document_id: None,+ chunk_id: None,+ supporting_relations: Vec::new(),+ taint: MemoryTaint::default(),+ }+}diff --git a/src/openhuman/memory/preferences/mod.rs b/src/openhuman/memory/preferences/mod.rsindex 3bbc4d8cab..ee627ce4a6 100644--- a/src/openhuman/memory/preferences/mod.rs+++ b/src/openhuman/memory/preferences/mod.rs@@ -37,7 +37,8 @@//! degradations, whereas an error would fail a chat turn or a preference write//! over a capability the operator chose not to have.-use crate::openhuman::memory::api::provider::{MemoryCore as _, MemoryProvider as _};+use crate::openhuman::memory::api::error::MemoryError;+use crate::openhuman::memory::api::provider::{MemoryCore as _, MemoryProvider};use crate::openhuman::memory::guard::MemoryGuard;/// Always-on preferences — injected into the system prompt every thread.@@ -66,7 +67,8 @@ pub const SITUATIONAL_MIN_SIMILARITY: f64 = 0.35;pub const CONTRADICTION_SIMILARITY: f64 = 0.6;/// Recall entries in `namespace` whose **vector** similarity alone clears-/// `min_vector_similarity`, as `(key, content)` pairs, most-relevant first.+/// `min_vector_similarity`, as `(key, content)` pairs, most-relevant first —+/// over any [`MemoryProvider`], guarded or not.////// Reproduces what the engine's `recall_relevant_by_vector` did: ask for the/// scored hits, keep those whose `vector_similarity` component clears the@@ -74,27 +76,77 @@ pub const CONTRADICTION_SIMILARITY: f64 = 0.6;/// final score is the point — the combined score folds in keyword, graph and/// freshness signals, so a lexically-similar but semantically-unrelated/// preference would otherwise clear the bar.-async fn recall_by_vector(- memory: &MemoryGuard,+///+/// This is the one body behind both doors into Lane B: the guard path+/// ([`recall_by_vector`], used by the contradiction check) and the session's+/// `Memory` handle (`DriverMemory::recall_relevant_by_vector`, #6041). A driver+/// without the retrieval family answers empty — the documented degradation —+/// while a driver that has it and fails answers `Err`, so each caller decides+/// what an error means for its turn.+pub(crate) async fn recall_by_vector_over(+ provider: &dyn MemoryProvider,namespace: &str,query: &str,limit: usize,min_vector_similarity: f64,-) -> Vec<(String, String)> {- let Some(retrieval) = memory.as_retrieval() else {- return Vec::new();+) -> Result<Vec<(String, String)>, MemoryError> {+ let Some(retrieval) = provider.as_retrieval() else {+ return Ok(Vec::new());};- let Ok(hits) = retrieval+ let started = std::time::Instant::now();+ let hits = retrieval.recall_namespace_scored(namespace, query, limit, None)- .await- else {- return Vec::new();- };- hits.into_iter()+ .await?;+ // The floor is "tunable against live data", and this line is that data:+ // how close the best candidate came, whether or not it cleared. Keys and+ // scores only — never the preference text or the message.+ let top = hits+ .iter()+ .map(|h| h.score_breakdown.vector_similarity)+ .fold(f64::NEG_INFINITY, f64::max);+ let kept: Vec<(String, String)> = hits+ .into_iter().filter(|h| h.score_breakdown.vector_similarity >= min_vector_similarity).filter(|h| !h.content.trim().is_empty()).map(|h| (h.key, h.content))- .collect()+ .collect();+ if top.is_finite() {+ log::info!(+ "[pref_recall] namespace={namespace} kept={} top_similarity={top:.3} floor={min_vector_similarity} elapsed_ms={}",+ kept.len(),+ started.elapsed().as_millis()+ );+ } else {+ log::debug!(+ "[pref_recall] namespace={namespace} no candidates elapsed_ms={}",+ started.elapsed().as_millis()+ );+ }+ Ok(kept)+}++/// [`recall_by_vector_over`] through the guard, with a failed lookup read as+/// "nothing to inject": an absent Lane-B block or an absent contradiction check+/// is a degradation, whereas an error here would fail a chat turn or a+/// preference write.+async fn recall_by_vector(+ memory: &MemoryGuard,+ namespace: &str,+ query: &str,+ limit: usize,+ min_vector_similarity: f64,+) -> Vec<(String, String)> {+ match recall_by_vector_over(memory, namespace, query, limit, min_vector_similarity).await {+ Ok(hits) => hits,+ Err(err) => {+ // Degrade, but say so: a driver that has retrieval and fails is an+ // infrastructure signal, not the documented "no vectors" opt-out.+ log::warn!(+ "[pref_recall] vector recall failed namespace={namespace}; continuing without it: {err}"+ );+ Vec::new()+ }+ }}/// Load the latest-`limit` general preferences as plain-language strings,@@ -167,6 +219,9 @@ pub async fn load_general_preferences_on(/// `recall_relevant_by_vector` is a contract-trait method, so this stays/// engine-neutral; a backend without vectors answers empty, which is the/// documented degradation for Lane B — an absent block, never a failed turn.+/// The session handle is a `DriverMemory` on every module-backed install, and+/// that adapter answers through [`recall_by_vector_over`] (#6041) — it used to+/// sit on the trait's empty default, which made this lane a silent no-op.pub async fn recall_situational_preferences_on(memory: &std::sync::Arc<dyn crate::openhuman::memory::Memory>,query: &str,@@ -174,7 +229,22 @@ pub async fn recall_situational_preferences_on(if query.trim().is_empty() {return Vec::new();}- memory+ // The vector recall embeds the message — a round trip to the embedder,+ // measured at 0.8–3 s on the desktop — and it runs on every turn. Most+ // users have never saved a topic-scoped preference, so ask the store the+ // cheap question first (a namespace listing, no embedding) and only pay+ // for the embed when there is something to match. A failed listing falls+ // through to the recall rather than silently disabling the lane.+ let has_candidates = memory+ .list(Some(USER_PREF_SITUATIONAL_NAMESPACE), None, None)+ .await+ .map(|entries| !entries.is_empty())+ .unwrap_or(true);+ if !has_candidates {+ log::debug!("[pref_recall] no situational preferences stored; skipping the vector recall");+ return Vec::new();+ }+ let recalled = match memory.recall_relevant_by_vector(USER_PREF_SITUATIONAL_NAMESPACE,query,@@ -182,7 +252,18 @@ pub async fn recall_situational_preferences_on(SITUATIONAL_MIN_SIMILARITY,).await- .unwrap_or_default()+ {+ Ok(recalled) => recalled,+ Err(err) => {+ // An absent block, never a failed turn — but a failed lookup is+ // worth one line, or a broken driver reads as "no preferences".+ log::warn!(+ "[pref_recall] situational recall failed; continuing without a preference block: {err}"+ );+ Vec::new()+ }+ };+ recalled.into_iter().map(|(_topic, value)| value).filter(|value| !value.trim().is_empty())