The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(orchestration): track driver task owner scope
Steven Enamakel49f0b4ea19ea
diff --git a/crates/openhuman-core/src/agent/orchestration/completion_owners.rs b/crates/openhuman-core/src/agent/orchestration/completion_owners.rsindex aecca6f9e2..45baaed9c5 100644--- a/crates/openhuman-core/src/agent/orchestration/completion_owners.rs+++ b/crates/openhuman-core/src/agent/orchestration/completion_owners.rs@@ -17,6 +17,7 @@//! [`record_outcome`]: super::background_completions::record_outcomeuse std::collections::{HashMap, VecDeque};+use std::path::PathBuf;use std::sync::{Arc, Mutex, MutexGuard, OnceLock};use crate::core::runtime::CoreContext;@@ -31,6 +32,18 @@ const PROFILES_PER_ID: usize = 16;struct Owners {by_id: HashMap<String, Vec<String>>,order: VecDeque<String>,+ driver_tasks: HashMap<String, DriverTaskOwner>,+ driver_task_order: VecDeque<String>,+}++#[derive(Clone)]+pub(crate) struct DriverTaskOwner {+ pub(crate) task_id: String,+ pub(crate) profile: Option<String>,+ pub(crate) workspace_dir: PathBuf,+ pub(crate) workspace: tinytools::WorkspaceDescriptor,+ pub(crate) parent_session: String,+ pub(crate) parent_thread_id: Option<String>,}fn owners() -> MutexGuard<'static, Owners> {@@ -41,6 +54,74 @@ fn owners() -> MutexGuard<'static, Owners> {.unwrap_or_else(|poisoned| poisoned.into_inner())}+fn driver_task_key(ctx: &crate::core::runtime::DispatchCtx, task_id: &str) -> String {+ use crate::core::runtime::tenant;+ tenant::profile_key_in(+ &tenant::isolated_unless_tenant(ctx.tenant(), "driver_task_owner"),+ task_id,+ )+}++/// Remember the exact scope needed to resolve and control a live driver task.+/// The job registry owns the lifecycle; this bounded index recovers its+/// parent/session scope from the product-facing task id.+pub(crate) fn note_driver_task(+ ctx: &crate::core::runtime::DispatchCtx,+ task_id: &str,+ workspace_dir: PathBuf,+ workspace: tinytools::WorkspaceDescriptor,+ parent_session: String,+ parent_thread_id: Option<String>,+) {+ let owner = DriverTaskOwner {+ task_id: task_id.to_owned(),+ profile: ctx.tenant().ok().and_then(|tenant| tenant.profile),+ workspace_dir,+ workspace,+ parent_session,+ parent_thread_id,+ };+ let key = driver_task_key(ctx, task_id);+ let mut st = owners();+ if !st.driver_tasks.contains_key(&key) {+ st.driver_task_order.push_back(key.clone());+ }+ st.driver_tasks.insert(key, owner);+ while st.driver_task_order.len() > OWNERS_CAP {+ if let Some(oldest) = st.driver_task_order.pop_front() {+ st.driver_tasks.remove(&oldest);+ }+ }+}++/// Return the exact parent scope cached when the current process registered+/// this task. A missing entry means the process has no live owner metadata.+pub(crate) fn driver_task_owner(+ ctx: &crate::core::runtime::DispatchCtx,+ task_id: &str,+) -> Option<DriverTaskOwner> {+ owners().driver_tasks.get(&driver_task_key(ctx, task_id)).cloned()+}++/// Return registered task scopes for one exact workspace/thread pair.+pub(crate) fn driver_tasks_for_thread(+ ctx: &crate::core::runtime::DispatchCtx,+ workspace_dir: &std::path::Path,+ thread_id: &str,+) -> Vec<(String, DriverTaskOwner)> {+ let profile = ctx.tenant().ok().and_then(|tenant| tenant.profile);+ owners()+ .driver_tasks+ .iter()+ .filter_map(|(key, owner)| {+ (owner.profile == profile+ && owner.workspace_dir == workspace_dir+ && owner.parent_thread_id.as_deref() == Some(thread_id))+ .then(|| (owner.task_id.clone(), owner.clone()))+ })+ .collect()+}+/// Note the calling task's profile as an owner of each id. A no-op outside a/// profile (the desktop, embedded agents).pub(crate) fn note(ctx: &crate::core::runtime::DispatchCtx, ids: &[&str]) {