Skip to content

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

feat(tinymemes): add callback handling to the service

Steven Enamakel059ea758f3f4
diff --git a/crates/openhuman-core/src/tinymemes/callbacks.rs b/crates/openhuman-core/src/tinymemes/callbacks.rs
index df47c5f814..ffbed0d9e9 100644
--- a/crates/openhuman-core/src/tinymemes/callbacks.rs
+++ b/crates/openhuman-core/src/tinymemes/callbacks.rs
@@ -32,8 +32,9 @@ const MAX_AGE: Duration = Duration::from_secs(15 * 60);
/// The workspace one remix runs for, and who it runs for.
///
/// 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`]).
+/// remix, so the caller's context is captured when the remix is registered and
+/// re-entered for each callback ([`Session::enter`]). A remix acts for the
+/// host, never for an agent, so there is no memory identity to carry.
/// 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 {
@@ -57,14 +58,8 @@ impl Session {
/// Run `fut` as the registering caller.
pub(super) async fn enter<F: Future>(&self, fut: F) -> F::Output {
let fut = Box::pin(fut);
- let fut = async {
- match self.context.clone() {
- Some(context) => CoreContext::scope(context, fut).await,
- None => fut.await,
- }
- };
- match self.identity.clone() {
- Some(identity) => crate::memory::scope::within(identity, fut).await,
+ match self.context.clone() {
+ Some(context) => CoreContext::scope(context, fut).await,
None => fut.await,
}
}
diff --git a/crates/openhuman-core/src/tinymemes/callbacks_tests.rs b/crates/openhuman-core/src/tinymemes/callbacks_tests.rs
index 0675064b25..ebe04e985c 100644
--- a/crates/openhuman-core/src/tinymemes/callbacks_tests.rs
+++ b/crates/openhuman-core/src/tinymemes/callbacks_tests.rs
@@ -158,39 +158,3 @@ fn the_correlation_id_is_read_from_the_first_argument_only() {
assert_eq!(correlation_of(&bad), None, "{bad}");
}
}
-
-#[tokio::test]
-async fn callbacks_run_as_the_identity_that_registered_the_remix() {
- let dir = tempfile::tempdir().unwrap();
- let config = config_in(dir.path());
- let identity = MemoryIdentity {
- agent_id: Some("tenant-agent".into()),
- team: Some("team-a".into()),
- };
- // Registered inside the caller's task...
- let session =
- crate::memory::scope::within(identity.clone(), async { Session::new(&config) }).await;
- // ...and answered later, on a task that has no scope of its own.
- assert_eq!(crate::memory::scope::current(), None);
- let seen = session
- .enter(async { crate::memory::scope::current() })
- .await;
- assert_eq!(seen, Some(identity));
- assert_eq!(
- crate::memory::scope::current(),
- None,
- "the scope does not leak out"
- );
-}
-
-#[tokio::test]
-async fn a_session_registered_without_a_scope_adds_none() {
- let dir = tempfile::tempdir().unwrap();
- let session = Session::new(&config_in(dir.path()));
- assert_eq!(
- session
- .enter(async { crate::memory::scope::current() })
- .await,
- None
- );
-}
diff --git a/crates/openhuman-core/src/tinymemes/service.rs b/crates/openhuman-core/src/tinymemes/service.rs
index 7dab866c0f..79506c3112 100644
--- a/crates/openhuman-core/src/tinymemes/service.rs
+++ b/crates/openhuman-core/src/tinymemes/service.rs
@@ -92,7 +92,7 @@ pub(crate) async fn install(connection: &Connection) -> tinybus::Result<()> {
.await
}
-/// One foreground remix at a time per workspace and acting identity.
+/// One foreground remix at a time per workspace.
///
/// The module reads its learned-state documents at the start of a remix and
/// writes them at the end, so two remixes for one scope at once would each
@@ -104,13 +104,7 @@ static FOREGROUND: std::sync::LazyLock<
> = std::sync::LazyLock::new(Default::default);
fn scope_lock(config: &Config) -> std::sync::Arc<tokio::sync::Mutex<()>> {
- let identity = crate::memory::scope::current().unwrap_or_default();
- let key = format!(
- "{}\0{}\0{}",
- config.workspace_dir.display(),
- identity.agent_id.as_deref().unwrap_or("-"),
- identity.team.as_deref().unwrap_or("-")
- );
+ let key = config.workspace_dir.display().to_string();
FOREGROUND
.lock()
.unwrap_or_else(|e| e.into_inner())