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
fix(agent): deliver background results after approval resumes
Steven Enamakel60a48b52c8a5
diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rsindex a443fb2db5..0f207f17bc 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs@@ -242,7 +242,12 @@ pub(super) fn drain_schedule_in(/// Schedule a debounced delivery attempt for a thread, fenced by the calling/// profile's lease ([`DrainFence::current`]).fn schedule_delivery(thread_id: String, delay: Duration) {- schedule_delivery_inner(thread_id, delay, false, DrainFence::current());+ schedule_delivery_inner(+ thread_id,+ delay,+ false,+ DrainFence::current(&DispatchCtx::ambient()),+ );}/// `wait_idle`: after the delay, keep waiting while the thread's user turn is in@@ -297,7 +302,7 @@ fn scheduled_for_test() -> &'static Mutex<Vec<(String, Duration)>> {/// calling profile's lease when there is one. Returns the number of threads/// scheduled.pub(crate) fn recover_on_boot(ctx: &DispatchCtx, workspace_dir: &Path) -> usize {- recover_fenced(ctx, workspace_dir, DrainFence::current())+ recover_fenced(ctx, workspace_dir, DrainFence::current(ctx))}fn recover_fenced(ctx: &DispatchCtx, workspace_dir: &Path, fence: DrainFence) -> usize {diff --git a/crates/openhuman-core/src/agent/orchestration/delivery_drain.rs b/crates/openhuman-core/src/agent/orchestration/delivery_drain.rsindex 70ac1ef4fe..2ed4d042db 100644--- a/crates/openhuman-core/src/agent/orchestration/delivery_drain.rs+++ b/crates/openhuman-core/src/agent/orchestration/delivery_drain.rs@@ -45,8 +45,8 @@ impl DrainFence {/// The fence of the profile the calling task serves, when this node hosts/// it. `None` outside SaaS or outside a profile.- pub(crate) fn current() -> Self {- Self(crate::profiles::host::current().map(|profile| Arc::clone(profile.lease_fence())))+ pub(crate) fn current(ctx: &crate::core::runtime::DispatchCtx) -> Self {+ Self(crate::profiles::host::current(ctx).map(|profile| Arc::clone(profile.lease_fence())))}/// Whether this node may still act for the profile: the fence is notdiff --git a/crates/openhuman-core/src/memory/engine.rs b/crates/openhuman-core/src/memory/engine.rsindex a1dadf6f8c..f1f30fe706 100644--- a/crates/openhuman-core/src/memory/engine.rs+++ b/crates/openhuman-core/src/memory/engine.rs@@ -211,12 +211,12 @@ pub fn resolve(config: &Config) -> Binding {}if let Some(capabilities) = crate::profiles::capabilities::ProfileCapabilities::current() {if let Some(engine) = &capabilities.memory_engine {- if let Err(reason) = crate::profiles::host::ensure_hosted() {+ // The hosted profile's engine is bound for the calling task's own tenant.+ let ctx = crate::core::runtime::DispatchCtx::ambient();+ if let Err(reason) = crate::profiles::host::ensure_hosted(&ctx) {return off(None, None, &reason);}- let profile = crate::core::runtime::current_tenant()- .ok()- .and_then(|tenant| tenant.profile);+ let profile = ctx.tenant().ok().and_then(|tenant| tenant.profile);let valid = profile.as_ref().is_some_and(|id| {config.memory.agent_id.as_ref() == Some(id)&& config.memory.root.as_deref() == Some(format!("user:{id}").as_str())diff --git a/crates/openhuman-core/src/profiles/host.rs b/crates/openhuman-core/src/profiles/host.rsindex b7f8ad52c4..e24f80b1bb 100644--- a/crates/openhuman-core/src/profiles/host.rs+++ b/crates/openhuman-core/src/profiles/host.rs@@ -671,8 +671,8 @@ pub fn host() -> Option<Arc<ProfileHost>> {}/// The profile the current work runs for, if any.-pub fn current() -> Option<Arc<Profile>> {- let profile = crate::core::runtime::current_tenant().ok()?.profile?;+pub fn current(ctx: &crate::core::runtime::DispatchCtx) -> Option<Arc<Profile>> {+ let profile = ctx.tenant().ok()?.profile?;let id = ProfileId::parse(&profile).ok()?;host()?.get(&id)}@@ -680,14 +680,11 @@ pub fn current() -> Option<Arc<Profile>> {/// Refuse to start work for a profile this node no longer hosts: one whose/// lease was lost (fenced) or that was closed under a request still running/// for it. `Ok` outside SaaS, and for work that serves no profile.-pub fn ensure_hosted() -> Result<(), String> {+pub fn ensure_hosted(ctx: &crate::core::runtime::DispatchCtx) -> Result<(), String> {let Some(host) = host() else {return Ok(());};- let Some(profile) = crate::core::runtime::current_tenant()- .ok()- .and_then(|tenant| tenant.profile)- else {+ let Some(profile) = ctx.tenant().ok().and_then(|tenant| tenant.profile) else {return Ok(());};// The latch, and the grant's expiry by this node's clock: a node whosediff --git a/crates/openhuman-core/src/profiles/tools.rs b/crates/openhuman-core/src/profiles/tools.rsindex 51d3ccd51a..770bffb948 100644--- a/crates/openhuman-core/src/profiles/tools.rs+++ b/crates/openhuman-core/src/profiles/tools.rs@@ -218,11 +218,11 @@ pub fn gate_verdict_with(tool: &str, groups: &[SaasToolGroup]) -> Result<(), Str}/// [`gate_verdict_with`] for the running deployment.-pub fn gate_verdict(tool: &str) -> Result<(), String> {+pub fn gate_verdict(ctx: &crate::core::runtime::DispatchCtx, tool: &str) -> Result<(), String> {let verdict = if super::capabilities::ProfileCapabilities::current().is_some_and(|caps| caps.authorizes_approval(tool)){- super::host::ensure_hosted()+ super::host::ensure_hosted(ctx)} else {gate_verdict_with(tool, &allowlisted())};diff --git a/crates/openhuman-core/src/security/approval/gate_forced_tests.rs b/crates/openhuman-core/src/security/approval/gate_forced_tests.rsindex 68f2646f75..b90f6764aa 100644--- a/crates/openhuman-core/src/security/approval/gate_forced_tests.rs+++ b/crates/openhuman-core/src/security/approval/gate_forced_tests.rs@@ -130,13 +130,13 @@ async fn forced_approval_still_denies_automation_and_channel_origins() {#[test]fn saas_outcome_is_absent_outside_saas() {- assert!(saas_outcome_with(false, "shell").is_none());+ assert!(saas_outcome_with(&crate::core::runtime::DispatchCtx::ambient(), false, "shell").is_none());}#[test]fn saas_outcome_never_parks_and_denies_without_an_allowlisted_group() {// No agent host is installed here, so no tool group is allowlisted.- match saas_outcome_with(true, "shell") {+ match saas_outcome_with(&crate::core::runtime::DispatchCtx::ambient(), true, "shell") {Some(GateOutcome::Deny { reason }) => {assert!(reason.starts_with(POLICY_DENIED_MARKER), "{reason}");assert!(reason.contains("no approval surface"), "{reason}");diff --git a/crates/openhuman-core/src/security/approval/gate_intercept.rs b/crates/openhuman-core/src/security/approval/gate_intercept.rsindex 8c6a00ead0..5a23f8b51c 100644--- a/crates/openhuman-core/src/security/approval/gate_intercept.rs+++ b/crates/openhuman-core/src/security/approval/gate_intercept.rs@@ -79,7 +79,11 @@ impl ApprovalGate {}// SaaS has no per-user approval surface: never park, allow only what// the deployment's sandboxed tool groups open.- if let Some(outcome) = saas_outcome_with(crate::core::runtime::is_saas(), tool_name) {+ if let Some(outcome) = saas_outcome_with(+ &crate::core::runtime::DispatchCtx::ambient(),+ crate::core::runtime::is_saas(),+ tool_name,+ ) {return (outcome, None);}if forced@@ -714,12 +718,16 @@ impl ApprovalGate {/// The gate's outcome in SaaS, `None` outside it. SaaS has no per-user approval/// surface, so the gate never parks there; the verdict comes from the/// deployment's allowlisted tool groups.-pub(crate) fn saas_outcome_with(saas: bool, tool_name: &str) -> Option<GateOutcome> {+pub(crate) fn saas_outcome_with(+ ctx: &crate::core::runtime::DispatchCtx,+ saas: bool,+ tool_name: &str,+) -> Option<GateOutcome> {if !saas {return None;}Some(saas_outcome(crate::profiles::tools::gate_verdict(- tool_name,+ ctx, tool_name,)))}diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rsindex 4e052604ad..95d8cff89f 100644--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs@@ -189,7 +189,7 @@ async fn start_chat_inner(}// A profile this node no longer hosts (its lease was lost or released)// starts no new turn here. No-op outside SaaS.- crate::profiles::host::ensure_hosted().map_err(StartChatError::Other)?;+ crate::profiles::host::ensure_hosted(ctx).map_err(StartChatError::Other)?;// Save originals before scanning, history, memory, or queue persistence.// A missing config/root cannot safely accept an upload.