Skip to content

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

feat(runtime): add slot-based context management

Steven Enamakel52269f4b34a7
diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rs
index 02cc3fc271..1a31da59b5 100644
--- a/crates/openhuman-core/src/core/runtime/context.rs
+++ b/crates/openhuman-core/src/core/runtime/context.rs
@@ -450,6 +450,21 @@ impl CoreContext {
&self.extensions
}
+ /// The hook registrations of the context this call runs under, for
+ /// [`HookSlot`](crate::core::slots::HookSlot) lookups.
+ ///
+ /// Outside SaaS that is the ambient context (the process default when the
+ /// task has no scope). In SaaS only the task's own scope counts: a task that
+ /// lost its scope must not read the operator's registrations.
+ pub fn current_extensions() -> Option<crate::core::slots::Extensions> {
+ let ctx = if crate::core::runtime::is_saas() {
+ Self::scoped()
+ } else {
+ Self::current()
+ };
+ ctx.map(|ctx| ctx.extensions.clone())
+ }
+
/// The backend transport bound to this context, if the host supplied one.
pub fn backend_transport(
&self,
diff --git a/crates/openhuman-core/src/core/slots.rs b/crates/openhuman-core/src/core/slots.rs
index 9335c28d65..a46959e6b4 100644
--- a/crates/openhuman-core/src/core/slots.rs
+++ b/crates/openhuman-core/src/core/slots.rs
@@ -279,8 +279,8 @@ impl<V: Clone + Send + Sync + 'static> HookSlot<V> {
}
fn context_table(&self) -> Option<Arc<Registry<V>>> {
- crate::core::runtime::context::CoreContext::current()
- .and_then(|ctx| ctx.extensions().existing::<V>(self.name))
+ crate::core::runtime::context::CoreContext::current_extensions()
+ .and_then(|extensions| extensions.existing::<V>(self.name))
}
/// The value for `id`: the ambient context's, else the process-wide one.