Skip to content

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

fix(subagents): scope subagent control to the caller's profile

Steven Enamakelcb9cefa9d6e0
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
index 8e2a8b96d0..1fde8ca7da 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
@@ -9,7 +9,7 @@ use tinyagents_harness::ids::TaskId;
use tinyagents_orchestration::subagent::FinishedOutcome;
-use super::registry::registry;
+use super::registry::{control_admits, registry};
use super::resolve::task_id_for_session_in_workspace;
use super::task_ledger::record_cancelled;
@@ -34,11 +34,13 @@ pub(crate) struct CancelledSubagent {
/// caller can deliver a "cancelled" notice into the parent chat. Returns `None`
/// if no such sub-agent is registered (already finished, or unknown id).
///
-/// Unlike the parent-session-owned steering and close paths, this is keyed by
-/// `task_id` alone with no ownership check — it backs the user-facing "Cancel"
-/// affordance, and the desktop user owns every sub-agent in their own core.
+/// User controls check the captured profile in SaaS. The desktop user retains
+/// authority over every sub-agent in their own core.
pub(crate) fn cancel_by_task(task_id: &str) -> Option<CancelledSubagent> {
- let cancelled = registry().cancel_trusted(&TaskId::new(task_id)).ok()?;
+ let id = TaskId::new(task_id);
+ let snapshot = registry().snapshot_trusted(&id).ok()?;
+ if !control_admits(&snapshot.metadata) { return None; }
+ let cancelled = registry().cancel(&id, &snapshot.owner_id).ok()?;
// `AwaitingUser` is paused, not finished: cancelling it is a real cancel.
let already_finished = cancelled.status.finished_outcome();
let metadata = cancelled.metadata;
@@ -56,7 +58,7 @@ pub(crate) fn cancel_by_task(task_id: &str) -> Option<CancelledSubagent> {
);
Some(CancelledSubagent {
agent_id: metadata.agent_id,
- parent_session: cancelled.owner_id,
+ parent_session: metadata.parent_session,
subagent_session_id: metadata.subagent_session_id,
workspace_dir: metadata.workspace_dir,
parent_thread_id: metadata.parent_thread_id,
@@ -200,7 +202,7 @@ impl CallerWorkspace {
pub(crate) fn admits(&self, metadata: &super::registry::RunningSubagentMetadata) -> bool {
match self {
Self::All => true,
- Self::Only(dir) => metadata.workspace_dir == *dir,
+ Self::Only(dir) => metadata.workspace_dir == *dir && control_admits(metadata),
Self::Nothing => false,
}
}
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
index c3ab82510c..0c11011eb0 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
@@ -34,11 +34,15 @@ use tinyagents_tasks::DetachedTaskRegistry;
use super::task_ledger::{record_spawned, task_store_for_workspace};
use tinyagents_orchestration::subagent::{
- spawn_status_watcher, DetachedSubagentStatus, SubagentIdentity,
+ spawn_status_watcher, DetachedSubagentStatus, SubagentIdentity, WaitError,
};
#[derive(Clone)]
pub(crate) struct RunningSubagentMetadata {
+ /// Original profile authority, independent of caller-chosen session IDs.
+ pub(crate) profile: Option<String>,
+ /// Public/durable session ID; the registry owner uses an encoded key.
+ pub(crate) parent_session: String,
pub(crate) agent_id: String,
pub(crate) subagent_session_id: Option<String>,
pub(crate) workspace_dir: PathBuf,
@@ -49,6 +53,46 @@ pub(crate) struct RunningSubagentMetadata {
pub(crate) run_queue: Arc<RunQueue<crate::agent::queued_turn::QueuedTurn>>,
}
+/// Resolve the caller's profile without falling back to the operator in SaaS.
+fn caller_profile() -> Result<Option<String>, WaitError> {
+ let profile = crate::core::runtime::tenant::current_tenant()
+ .map_err(|_| WaitError::NotOwned)?
+ .profile;
+ if crate::core::runtime::is_saas() && profile.is_none() {
+ return Err(WaitError::NotOwned);
+ }
+ Ok(profile)
+}
+
+/// Host ownership adapter over TinyAgents' opaque owner string.
+pub(super) fn owner_key(parent_session: &str) -> Result<String, WaitError> {
+ let profile = caller_profile()?;
+ Ok(crate::core::runtime::tenant::tenant_key(
+ &crate::core::runtime::tenant::Tenant { profile, agent: None },
+ parent_session,
+ ))
+}
+
+/// Public user controls may reach any of their profile's parents; desktop
+/// controls retain the process user's existing authority over all workers.
+pub(super) fn control_admits(metadata: &RunningSubagentMetadata) -> bool {
+ !crate::core::runtime::is_saas()
+ || caller_profile().is_ok_and(|profile| profile == metadata.profile)
+}
+
+/// Durable fallback paths must stay in the caller's captured workspace.
+pub(super) fn admit_workspace(workspace: &std::path::Path) -> Result<(), WaitError> {
+ if !crate::core::runtime::is_saas() {
+ return Ok(());
+ }
+ caller_profile()?;
+ let context = crate::core::runtime::CoreContext::scoped().ok_or(WaitError::NotOwned)?;
+ if context.workspace_dir().map_err(|_| WaitError::NotOwned)? != workspace {
+ return Err(WaitError::NotOwned);
+ }
+ Ok(())
+}
+
impl SubagentIdentity for RunningSubagentMetadata {
fn agent_id(&self) -> &str {
&self.agent_id
@@ -108,6 +152,15 @@ pub(crate) fn register(
abort: AbortHandle,
status: watch::Receiver<DetachedSubagentStatus>,
) {
+ let Ok(profile) = caller_profile() else {
+ abort.abort();
+ log::warn!("[running_subagents] refusing registration without a SaaS profile");
+ return;
+ };
+ let owner = crate::core::runtime::tenant::tenant_key(
+ &crate::core::runtime::tenant::Tenant { profile: profile.clone(), agent: None },
+ &parent_session,
+ );
if let Some(thread_id) = parent_thread_id.as_deref() {
if crate::agent::orchestration::background_completions::mark_stopped_task_if_thread_stopped(
&workspace_dir,
@@ -148,6 +201,8 @@ pub(crate) fn register(
);
let metadata = RunningSubagentMetadata {
+ profile,
+ parent_session,
agent_id,
subagent_session_id,
workspace_dir,
@@ -157,7 +212,7 @@ pub(crate) fn register(
registry()
.register(
TaskId::new(task_id.clone()),
- parent_session,
+ owner,
metadata,
status,
// Cooperative cancellation is flipped before the registry invokes
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs
index b0cd01981d..9f518cbbf5 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs
@@ -11,7 +11,7 @@ use tinyagents_orchestration::subagent::{
WaitError,
};
-use super::registry::registry;
+use super::registry::{admit_workspace, owner_key, registry};
use super::task_ledger::{list_task_records, task_record_for_task_in_workspace};
/// Resolve a durable `subagent_session_id` to the currently-running transient
@@ -20,7 +20,7 @@ pub(crate) fn task_id_for_session(
subagent_session_id: &str,
parent_session: &str,
) -> Result<String, WaitError> {
- live_task_id(registry(), subagent_session_id, parent_session)
+ live_task_id(registry(), subagent_session_id, &owner_key(parent_session)?)
}
pub(crate) fn task_id_for_session_in_workspace(
@@ -28,6 +28,7 @@ pub(crate) fn task_id_for_session_in_workspace(
parent_session: &str,
workspace_dir: &Path,
) -> Result<String, WaitError> {
+ admit_workspace(workspace_dir)?;
match task_id_for_session(subagent_session_id, parent_session) {
Ok(task_id) => return Ok(task_id),
Err(WaitError::NotOwned) => return Err(WaitError::NotOwned),
@@ -53,7 +54,7 @@ pub(crate) fn resume_ref_for_task(
task_id: &str,
parent_session: &str,
) -> Result<SubagentResumeRef, WaitError> {
- live_resume_ref(registry(), task_id, parent_session)
+ live_resume_ref(registry(), task_id, &owner_key(parent_session)?)
}
pub(crate) fn resume_ref_for_task_in_workspace(
@@ -61,6 +62,7 @@ pub(crate) fn resume_ref_for_task_in_workspace(
parent_session: &str,
workspace_dir: &Path,
) -> Result<SubagentResumeRef, WaitError> {
+ admit_workspace(workspace_dir)?;
match resume_ref_for_task(task_id, parent_session) {
Ok(reference) => return Ok(reference),
Err(WaitError::NotOwned) => return Err(WaitError::NotOwned),
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs
index 5e780f2d5d..ff7e1b3451 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs
@@ -3,13 +3,14 @@
use tinyagents_orchestration::subagent::{snapshot_for_owner, SubagentSnapshot};
-use super::registry::registry;
+use super::registry::{admit_workspace, owner_key, registry};
use crate::agent::orchestration::fleet_tools::FleetToolSet;
/// Snapshot the sub-agents registered under `parent_session`, with each status
/// read live from its watch channel (ordered by `agent_id` then `task_id`).
pub(crate) fn snapshot_for_parent(parent_session: &str) -> Vec<SubagentSnapshot> {
- snapshot_for_owner(registry(), parent_session).unwrap_or_else(|err| {
+ let Ok(owner) = owner_key(parent_session) else { return Vec::new(); };
+ snapshot_for_owner(registry(), &owner).unwrap_or_else(|err| {
log::warn!(
"[running_subagents] roster unavailable parent_session={parent_session} err={err:?}"
);
@@ -80,6 +81,7 @@ pub(crate) fn active_subagents_context_block(
workspace_dir: &std::path::Path,
fleet: &FleetToolSet,
) -> Option<String> {
+ admit_workspace(workspace_dir).ok()?;
let workers = snapshot_for_parent(parent_session);
// Durable sessions not already represented by a live registry entry.
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
index eb4303e36d..d919453d4c 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
@@ -9,7 +9,7 @@ use tinyagents_tasks::DetachedTaskRegistryError;
use tinyinference_llm::message::Message as TaMessage;
use super::cancel::now_ms;
-use super::registry::registry;
+use super::registry::{control_admits, owner_key, registry};
/// Why a steer could not be delivered.
#[derive(Debug, PartialEq, Eq)]
@@ -84,15 +84,16 @@ pub async fn steer(
return Err(SteerError::UnsupportedLane);
}
let task_id_key = TaskId::new(task_id);
+ let owner = owner_key(parent_session).map_err(|_| SteerError::NotOwned)?;
let snapshot = registry()
- .snapshot(&task_id_key, parent_session)
+ .snapshot(&task_id_key, &owner)
.map_err(steer_error_from_registry)?;
if snapshot.status.is_terminal() {
return Err(SteerError::AlreadyDone);
}
let steered_via_registry = registry()
- .steering_handle(&task_id_key, parent_session)
+ .steering_handle(&task_id_key, &owner)
.map(|handle| send_registered_steering(&handle, text.clone(), lane))
.unwrap_or(false);
if steered_via_registry {
@@ -152,12 +153,13 @@ pub(crate) async fn steer_control(
let snapshot = registry()
.snapshot_trusted(&task_id_key)
.map_err(steer_error_from_registry)?;
+ if !control_admits(&snapshot.metadata) { return Err(SteerError::NotOwned); }
if snapshot.status.is_terminal() {
return Err(SteerError::AlreadyDone);
}
let steered_via_registry = registry()
- .steering_handle_trusted(&task_id_key)
+ .steering_handle(&task_id_key, &snapshot.owner_id)
.map(|handle| send_registered_steering(&handle, text.clone(), lane))
.unwrap_or(false);
if steered_via_registry {
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs
index aa35fabca9..a8d6936842 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/wait.rs
@@ -9,7 +9,7 @@ use tinyagents_orchestration::subagent::{
record_to_wait_outcome, task_status_label, wait_detached, WaitError, WaitOutcome,
};
-use super::registry::registry;
+use super::registry::{admit_workspace, owner_key, registry};
use super::task_ledger::task_record_for_task_in_workspace;
/// Block until `task_id` reaches a terminal status or `timeout` elapses.
@@ -18,7 +18,7 @@ pub(crate) async fn wait(
parent_session: &str,
timeout: Duration,
) -> Result<WaitOutcome, WaitError> {
- wait_detached(registry(), task_id, parent_session, timeout).await
+ wait_detached(registry(), task_id, &owner_key(parent_session)?, timeout).await
}
pub(crate) async fn wait_in_workspace(
@@ -27,6 +27,7 @@ pub(crate) async fn wait_in_workspace(
workspace_dir: &Path,
timeout: Duration,
) -> Result<WaitOutcome, WaitError> {
+ admit_workspace(workspace_dir)?;
match wait(task_id, parent_session, timeout).await {
Ok(outcome) => return Ok(outcome),
Err(WaitError::NotOwned) => return Err(WaitError::NotOwned),