Skip to content

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

fix(orchestration): enforce profile ownership on subagent controls

Steven Enamakel9b1191ee4e1e
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents.rs
index 360dc27d78..bc5db97e71 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents.rs
@@ -21,7 +21,8 @@
//!
//! TinyAgents owns the process-local watch/cancel/abort/steering mechanics.
//! OpenHuman retains product metadata, durable task-store projection, and the
-//! legacy `RunQueue` steering fallback. Ownership is enforced by parent session;
+//! legacy `RunQueue` steering fallback. Ownership is enforced by captured profile
+//! and parent session; user controls retain the profile without requiring a parent ID.
//! terminal entries are pruned on `wait` and swept at the registry soft cap.
//!
//! ## Typed lifecycle ledger (issue #4249)
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 1fde8ca7da..8044e94117 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs
@@ -39,7 +39,9 @@ pub(crate) struct CancelledSubagent {
pub(crate) fn cancel_by_task(task_id: &str) -> Option<CancelledSubagent> {
let id = TaskId::new(task_id);
let snapshot = registry().snapshot_trusted(&id).ok()?;
- if !control_admits(&snapshot.metadata) { return None; }
+ 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();
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 0c11011eb0..23834f4008 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/registry.rs
@@ -17,7 +17,8 @@
//!
//! TinyAgents owns the process-local watch/cancel/abort/steering mechanics.
//! OpenHuman retains product metadata, durable task-store projection, and the
-//! legacy `RunQueue` steering fallback. Ownership is enforced by parent session;
+//! legacy `RunQueue` steering fallback. Ownership is enforced by captured profile
+//! and parent session;
//! terminal entries are pruned on `wait` and swept at the registry soft cap.
use std::path::PathBuf;
@@ -68,7 +69,10 @@ fn caller_profile() -> Result<Option<String>, WaitError> {
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 },
+ &crate::core::runtime::tenant::Tenant {
+ profile,
+ agent: None,
+ },
parent_session,
))
}
@@ -158,7 +162,10 @@ pub(crate) fn register(
return;
};
let owner = crate::core::runtime::tenant::tenant_key(
- &crate::core::runtime::tenant::Tenant { profile: profile.clone(), agent: None },
+ &crate::core::runtime::tenant::Tenant {
+ profile: profile.clone(),
+ agent: None,
+ },
&parent_session,
);
if let Some(thread_id) = parent_thread_id.as_deref() {
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 ff7e1b3451..63383904d0 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/roster.rs
@@ -9,7 +9,9 @@ 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> {
- let Ok(owner) = owner_key(parent_session) else { return Vec::new(); };
+ 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:?}"
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 d919453d4c..2b04ebd5c0 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/steering.rs
@@ -130,12 +130,12 @@ pub async fn steer(
Ok(())
}
-/// Trusted-control variant used by JSON-RPC sub-agent controls.
+/// User-control variant used by JSON-RPC sub-agent controls.
///
/// This intentionally does not require the caller to provide `parent_session`:
-/// the RPC layer is already bearer-protected and mirrors the existing
-/// `subagent_cancel` control surface, which can abort a task by id. The function
-/// still refuses unknown or terminal tasks and never logs the steered text.
+/// the captured profile is checked against the caller in SaaS. Desktop controls
+/// retain authority over the process user's workers. Unknown, foreign or
+/// terminal tasks are refused, and steered text is never logged.
pub(crate) async fn steer_control(
task_id: &str,
text: String,
@@ -153,7 +153,9 @@ 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 !control_admits(&snapshot.metadata) {
+ return Err(SteerError::NotOwned);
+ }
if snapshot.status.is_terminal() {
return Err(SteerError::AlreadyDone);
}
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
index 47c65375b1..07e19cd79d 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tenant_tests.rs
@@ -289,6 +289,23 @@ async fn missing_saas_scope_cannot_observe_or_control_workers() {
CoreContext::sync_scope(pair.alice.clone(), || {
assert!(resume_ref_for_task(&pair.a.task, PARENT).is_ok())
});
+ // A scoped kernel context without an admitted profile is not authority.
+ CoreContext::scope(CoreContext::for_test(DomainSet::full(), None), async {
+ assert!(snapshot_for_parent(PARENT).is_empty());
+ assert!(matches!(
+ resume_ref_for_task(&pair.a.task, PARENT),
+ Err(WaitError::NotOwned)
+ ));
+ assert_eq!(
+ field(&control("steer", &pair.a.task).await, "steered"),
+ Some(false)
+ );
+ assert_eq!(
+ field(&control("cancel", &pair.a.task).await, "cancelled"),
+ Some(false)
+ );
+ })
+ .await;
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_control.rs b/crates/openhuman-core/src/agent/orchestration/subagent_control.rs
index c2eb6d3b70..be497e97ee 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_control.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_control.rs
@@ -209,12 +209,8 @@ fn handle_subagent_steer(params: Map<String, Value>) -> ControllerFuture {
let reason = match err {
SteerError::Unknown => "unknown",
SteerError::AlreadyDone => "already_done",
- // `steer_control` is trusted UI/RPC control and currently
- // does not perform parent ownership checks, so this arm is
- // unreachable on THIS path. The variant is not dead overall:
- // the agent-tool `running_subagents::steer` path enforces
- // ownership and returns `NotOwned`. Kept here for the Phase 4
- // SteeringRegistry ownership consolidation.
+ // SaaS user controls check the captured worker profile,
+ // independently of the caller-supplied task ID.
SteerError::NotOwned => "not_owned",
SteerError::UnsupportedLane => "unsupported_lane",
};