Skip to content

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

feat(agent): route background completions through tenant runtime

Steven Enamakel4ffb8d312041
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions.rs b/crates/openhuman-core/src/agent/orchestration/background_completions.rs
index b9b789697b..936222a801 100644
--- a/crates/openhuman-core/src/agent/orchestration/background_completions.rs
+++ b/crates/openhuman-core/src/agent/orchestration/background_completions.rs
@@ -22,6 +22,9 @@
//! [`super::completion_notice`].
use std::collections::{HashMap, HashSet, VecDeque};
+
+// Keys of `HostState`'s thread and session maps: per profile (see `profile_key`).
+use crate::core::runtime::tenant::profile_key as key;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, OnceLock};
use std::time::Duration;
@@ -85,18 +88,6 @@ pub(super) struct HostState {
pub(super) recovered_workspaces: HashSet<PathBuf>,
}
-/// The key of `id` (a thread or a parent session id, both caller chosen) in
-/// [`HostState`]'s maps: [`tenant_key`](crate::core::runtime::tenant_key) of
-/// the calling tenant's profile. Two SaaS users on thread `t1` hold two
-/// entries, so one user's Stop or delete never gates the other's work. The
-/// agents of one profile share entries, and with no profile (the desktop,
-/// embedded agents) the key is the bare id, as before.
-pub(super) fn key(id: &str) -> String {
- let tenant =
- crate::core::runtime::tenant::current_tenant_or_isolated("background_completions");
- crate::core::runtime::tenant_key(&tenant.profile_only(), id)
-}
-
pub(super) fn state() -> std::sync::MutexGuard<'static, HostState> {
static STATE: OnceLock<Mutex<HostState>> = OnceLock::new();
STATE
diff --git a/crates/openhuman-core/src/core/runtime/tenant.rs b/crates/openhuman-core/src/core/runtime/tenant.rs
index 3fb7259385..dceda28c16 100644
--- a/crates/openhuman-core/src/core/runtime/tenant.rs
+++ b/crates/openhuman-core/src/core/runtime/tenant.rs
@@ -110,6 +110,15 @@ pub fn current_tenant_or_isolated(site: &str) -> Tenant {
})
}
+/// [`tenant_key`] of `id` under the calling tenant's profile alone: for
+/// process-wide tables keyed by a caller-chosen id (thread or session ids)
+/// that must keep SaaS profiles apart but that the agents of one profile
+/// share. With no profile (the desktop, embedded agents) it is the bare id,
+/// as before. A SaaS task with no scope gets a key nothing else shares.
+pub fn profile_key(id: &str) -> String {
+ tenant_key(&current_tenant_or_isolated("profile_key").profile_only(), id)
+}
+
/// Profile prefix byte of a [`tenant_key`].
const PROFILE_MARK: char = '\u{1e}';
/// Agent prefix byte of a [`tenant_key`] (and of the web-chat keys before it).