Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

Merge remote-tracking branch 'upstream/main' into saas-phase4c

Steven Enamakeld1e887cbbfdf
diff --cc crates/openhuman-core/src/memory/engine.rs
index 933d6a2fb3,f65688f204..e9c591d3e5
--- a/crates/openhuman-core/src/memory/engine.rs
+++ b/crates/openhuman-core/src/memory/engine.rs
@@@ -176,18 -217,88 +217,93 @@@ pub fn resolve(config: &Config) -> Bind
}
}
if let Some(bound) = host_engine() {
- return Binding::On(bound);
+ // A host engine is one store for the whole process: in SaaS it would
+ // put every user in one engine, so it is ignored there.
+ if !crate::core::runtime::is_saas() {
+ return Binding::On(bound);
+ }
+ tracing::warn!("[memory:engine] ignoring the host engine in SaaS mode");
}
+ let root = if super::scope::layout_is_v3(config) {
+ match super::scope::user_root(config) {
+ Some(root) => Some(root),
+ None => return off(None, None, "sign in to use memory in its own layout"),
+ }
+ } else {
+ None
+ };
+ resolve_configured(config, root.as_deref())
+ }
+
+ /// The engine the layout migration needs, for an explicit layout whatever
+ /// `[memory] layout` says: `None` the legacy tree, `Some("org:<id>")` the
+ /// person's v3 subtree, with the actor `user:<id>` as its owner. Same endpoint,
+ /// credential, headers and scrubbing as [`resolve`]; the two layouts are
+ /// cached apart, so both can be held at once.
+ ///
+ /// # Errors
+ ///
+ /// Memory is off for `config`, or an embedding host's (or a test's)
+ /// installed engine is bound, which has one layout of its own and cannot be
+ /// bound below a scope root.
+ pub fn bind_with_root(config: &Config, root: Option<&str>) -> MemoryResult<BoundEngine> {
+ #[cfg(test)]
+ {
+ let installed = TEST_ROOT_ENGINES
+ .read()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .get(&(config.workspace_dir.clone(), root.map(str::to_string)))
+ .cloned();
+ if let Some(engine) = installed {
+ return Ok(BoundEngine {
+ id: engine.descriptor().id.to_string(),
+ endpoint: "test://engine".to_string(),
+ engine: super::guard::ScrubbingEngine::wrap(engine),
+ });
+ }
+ let one_engine = TEST_ENGINES
+ .read()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .contains_key(&config.workspace_dir);
+ if one_engine {
+ return match root {
+ None => resolve(config).engine(),
+ Some(_) => Err(MemoryError::Engine(
+ "the installed test engine cannot be bound below a scope root".to_string(),
+ )),
+ };
+ }
+ }
+ if host_engine().is_some() && root.is_some() {
+ return Err(MemoryError::Engine(
+ "the host's memory engine cannot be bound below a scope root".to_string(),
+ ));
+ }
+ if root.is_none() {
+ if let Some(bound) = host_engine() {
+ return Ok(bound);
+ }
+ }
+ resolve_configured(config, root).engine()
+ }
+
+ /// The configured engine with its scope root (`None` legacy).
+ fn resolve_configured(config: &Config, root: Option<&str>) -> Binding {
let engine_id = config.memory.engine.trim().to_string();
match engine_id.as_str() {
- TINYHUMANS_ENGINE => resolve_tinyhumans(config),
- CORTEXDB_ENGINE => resolve_cortexdb(config),
- "" => off(None, None, "no memory engine selected"),
+ TINYHUMANS_ENGINE => resolve_tinyhumans(config, root),
+ CORTEXDB_ENGINE => resolve_cortexdb(config, root),
+ "" => {
+ let reason = if config.memory.legacy_backend_unsupported
+ || config.memory.legacy_backend.is_some()
+ {
+ "legacy memory backend is unsupported; select an explicit v2 memory engine"
+ .to_string()
+ } else {
+ "no memory engine selected".to_string()
+ };
+ off(None, None, &reason)
+ }
other => {
tracing::warn!(engine = %other, "[memory:engine] unknown engine id in config");
off(
diff --cc crates/openhuman-core/src/memory/ops.rs
index 3a359d4f6a,e796b05cc9..89153348bf
--- a/crates/openhuman-core/src/memory/ops.rs
+++ b/crates/openhuman-core/src/memory/ops.rs
@@@ -8,8 -8,8 +8,8 @@@
use chrono::Utc;
use tinymemory_api::{
- FetchRequest, ForgetTarget, ItemId, LearningKind, ListRequest, MemoryMeta, MetaFilter,
- RecallRequest, StoreItem, StoreReceipt,
+ EraseRequest, FetchRequest, ForgetTarget, ItemId, LearningKind, ListRequest, MemoryMeta,
- RecallRequest, StoreItem, StoreReceipt, TimeHint, WriteOptions,
++ MetaFilter, RecallRequest, StoreItem, StoreReceipt, TimeHint, WriteOptions,
};
use crate::config::Config;
@@@ -147,9 -158,10 +158,10 @@@ pub async fn recall(config: &Config, pa
let bound = bound(config)?;
let request = RecallRequest {
question: params.question,
- filter: params.filter.unwrap_or_default(),
+ filter: confine_filter(config, params.filter.unwrap_or_default()),
limit: clamp_limit(params.limit),
instructions: None,
+ refers_to: time_hint(config, params.refers_to)?,
};
request.validate()?;
let answer = bound.engine.recall(request).await?;
diff --cc tests/saas_mode_e2e.rs
index 02504e50c6,6ad1f28d2c..b8b2ccc192
--- a/tests/saas_mode_e2e.rs
+++ b/tests/saas_mode_e2e.rs
@@@ -635,41 -682,38 +682,77 @@@ fn chat_events_reach_only_the_user_whos
drop(server);
}
+#[test]
+fn users_reach_their_memory_but_not_its_configuration() {
+ let d = deployment(true);
+ let (server, base, client) = start(&d);
+ provision(&client, &base, "alice");
+ let call = |method: &str, params: Value| {
+ user_rpc_with(&client, &base, BEARER, "alice", None, method, params)
+ };
+
+ // Reachable: with no backend in this test the engine is off, so recall
+ // answers with memory's own error — not "unknown method".
+ let (_, body) = call(
+ "openhuman.memory_recall",
+ json!({ "question": "anything?" }),
+ );
+ let text = body.to_string();
+ assert!(
+ !text.contains("unknown method"),
+ "memory_recall is on the surface: {text}"
+ );
+ let (_, body) = call("openhuman.memory_engine_get", json!({}));
+ assert!(body.get("result").is_some(), "{body}");
+
+ // Not reachable: anything that changes where memory lives or reads the host.
+ for method in [
+ "openhuman.memory_engine_set",
+ "openhuman.memory_policy_set",
+ "openhuman.memory_sources_add",
+ "openhuman.memory_import_start",
+ ] {
+ let (_, body) = call(method, json!({}));
+ assert!(
+ body.to_string().contains("unknown method"),
+ "{method} must be absent: {body}"
+ );
+ }
+ drop(server);
+}
++
+ #[test]
+ fn a_duplicate_or_unreadable_user_header_is_refused() {
+ use openhuman_core::user_agents::gateway::USER_HEADER;
+ let d = deployment(true);
+ let (server, base, client) = start(&d);
+ let body =
+ json!({ "jsonrpc": "2.0", "id": 1, "method": "openhuman.user_agents_list", "params": {} });
+
+ // Two user headers: refused, never run as the operator.
+ let status = client
+ .post(format!("{base}/rpc"))
+ .bearer_auth(BEARER)
+ .header(USER_HEADER, "alice")
+ .header(USER_HEADER, "bob")
+ .json(&body)
+ .send()
+ .unwrap()
+ .status()
+ .as_u16();
+ assert_eq!(status, 400);
+
+ // A header value that is valid HTTP but not text: refused too.
+ let unreadable = reqwest::header::HeaderValue::from_bytes(b"alice\xff").unwrap();
+ let status = client
+ .post(format!("{base}/rpc"))
+ .bearer_auth(BEARER)
+ .header(USER_HEADER, unreadable)
+ .json(&body)
+ .send()
+ .unwrap()
+ .status()
+ .as_u16();
+ assert_eq!(status, 400);
+ drop(server);
+ }