Skip to content

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

refactor(tinymemes): always carry the caller's scoped context

Steven Enamakelf559cfbc9bdd
diff --git a/crates/openhuman-core/src/tinymemes/callbacks.rs b/crates/openhuman-core/src/tinymemes/callbacks.rs
index 977307a4b5..b4d84e1319 100644
--- a/crates/openhuman-core/src/tinymemes/callbacks.rs
+++ b/crates/openhuman-core/src/tinymemes/callbacks.rs
@@ -24,7 +24,7 @@ use tinymemes_bus::{
use super::{docs, inference, jev, search};
use crate::config::Config;
-use crate::core::runtime::{is_saas, CoreContext};
+use crate::core::runtime::CoreContext;
use crate::memory::scope::MemoryIdentity;
/// How long an entry may live without its `End`.
@@ -35,7 +35,7 @@ const MAX_AGE: Duration = Duration::from_secs(15 * 60);
/// Callbacks arrive on the module bus, outside the task that asked for the
/// remix, so the caller's context and memory identity are captured when the
/// remix is registered and re-entered for each callback ([`Session::enter`]).
-/// In SaaS only the caller's own scope counts, so an unscoped caller's
+/// Only the caller's own scope counts, so in SaaS an unscoped caller's
/// callbacks fail closed instead of acting as the operator.
pub(super) struct Session {
config: Config,
@@ -49,11 +49,10 @@ impl Session {
Self {
config: config.clone(),
jev: tokio::sync::OnceCell::new(),
- context: if is_saas() {
- CoreContext::scoped()
- } else {
- CoreContext::current()
- },
+ // Only the caller's own task scope is carried. Without one, a
+ // single-user process falls back to its default context on the
+ // callback side as anywhere else, and SaaS fails closed.
+ context: CoreContext::scoped(),
identity: crate::memory::scope::current(),
}
}
diff --git a/scripts/ci/process-statics.json b/scripts/ci/process-statics.json
index fe51488c70..a993635381 100644
--- a/scripts/ci/process-statics.json
+++ b/scripts/ci/process-statics.json
@@ -1 +1,22 @@
-[]
+[
+ {
+ "file": "crates/openhuman-core/src/tinymemes/callbacks.rs",
+ "scope": "",
+ "name": "REGISTRY",
+ "type": "LazyLock<Mutex<HashMap<String,Entry>>>",
+ "count": 1,
+ "category": "B",
+ "reason": "Keyed by a random per-remix correlation id; each entry holds the registering caller's config, CoreContext and memory identity, which every callback re-enters. Callbacks are accepted only from the module peer (bus name owner) for a live id, and the entry is retired by End, a failed call, or an age sweep.",
+ "verification": "tinymemes/service_tests.rs: only_the_module_may_call_back_and_only_for_a_live_remix; tinymemes/callbacks_tests.rs: callbacks_run_as_the_identity_that_registered_the_remix"
+ },
+ {
+ "file": "crates/openhuman-core/src/tinymemes/service.rs",
+ "scope": "",
+ "name": "FOREGROUND",
+ "type": "std::sync::LazyLock<std::sync::Mutex<std::collections::HashMap<String,std::sync::Arc<tokio::sync::Mutex<()>>>>, >",
+ "count": 1,
+ "category": "B",
+ "reason": "Holds only unit mutexes. The key is the workspace directory plus the acting memory identity, so different scopes never share or wait on a lock and no tenant data is stored.",
+ "verification": "tinymemes/service_tests.rs: foreground_remixes_share_a_lock_per_workspace_and_never_across_workspaces"
+ }
+]