Skip to content

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

refactor(agent_scope): simplify scope resolution logic

Steven Enamakel2c3144427586
diff --git a/crates/openhuman-core/src/core/runtime/agent_scope.rs b/crates/openhuman-core/src/core/runtime/agent_scope.rs
index 4f1e1a934f..86f8a3728d 100644
--- a/crates/openhuman-core/src/core/runtime/agent_scope.rs
+++ b/crates/openhuman-core/src/core/runtime/agent_scope.rs
@@ -74,9 +74,29 @@ static UNSCOPED: LazyLock<AgentScopedState> = LazyLock::new(AgentScopedState::de
/// The ambient context's slot of type `T`, or the unscoped one when no
/// context exists.
+///
+/// In SaaS only the task's own scope counts, and a task without one gets a
+/// throwaway slot: never the shared unscoped one (which every user's lost
+/// work would meet in) and never the operator's.
pub fn current_slot<T: Default + Send + Sync + 'static>() -> Arc<T> {
- match CoreContext::current() {
+ let saas = super::is_saas();
+ slot_in::<T>(saas, super::tenant::context_in(saas).as_deref())
+}
+
+/// [`current_slot`] as a function of the mode and the resolved context.
+pub fn slot_in<T: Default + Send + Sync + 'static>(
+ saas: bool,
+ ctx: Option<&CoreContext>,
+) -> Arc<T> {
+ match ctx {
Some(ctx) => ctx.agent_state().slot::<T>(),
+ None if saas => {
+ log::warn!(
+ "[core-context] unscoped state slot {} in SaaS; handing out a throwaway one",
+ std::any::type_name::<T>()
+ );
+ Arc::new(T::default())
+ }
None => UNSCOPED.slot::<T>(),
}
}