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(skills): keep the dispatching tenant on a workflow run's log writes
M3gA-Minda809f8ec38b7
diff --git a/crates/openhuman-core/src/skills/run_log.rs b/crates/openhuman-core/src/skills/run_log.rsindex b29ce90484..7c7d2c5a68 100644--- a/crates/openhuman-core/src/skills/run_log.rs+++ b/crates/openhuman-core/src/skills/run_log.rs@@ -433,6 +433,19 @@ pub async fn drain_to_log(stop}+/// [`drain_to_log`] on its own task, acting for `ctx`. The log store resolves+/// its storage scope from the acting context, so a bare spawn would write the+/// steps under the default scope (or, in SaaS, fail closed) while the header+/// sits under the dispatching tenant's.+pub fn spawn_drain_to_log(+ ctx: &crate::core::runtime::DispatchCtx,+ rx: Receiver<AgentProgress>,+ workspace: PathBuf,+ path: PathBuf,+) -> tokio::task::JoinHandle<Option<tinyagents_harness::turn_stop::TurnStop>> {+ ctx.spawn(drain_to_log(rx, workspace, path))+}+#[cfg(test)]#[path = "run_log_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/skills/run_log_tests.rs b/crates/openhuman-core/src/skills/run_log_tests.rsindex 2d67ac8695..171f5d0207 100644--- a/crates/openhuman-core/src/skills/run_log_tests.rs+++ b/crates/openhuman-core/src/skills/run_log_tests.rs@@ -122,3 +122,62 @@ fn a_compaction_is_logged_as_a_step() {"{line}");}++/// The run's progress bridge is spawned from the detached run task. The log+/// store resolves its storage scope from the acting context, so the bridge+/// must act for the dispatching agent: spawned bare, its steps land under the+/// default scope while the header sits under the agent's, and the agent's log+/// never shows them.+#[tokio::test]+async fn the_progress_bridge_writes_under_the_dispatching_agents_scope() {+ use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};++ let ctx = CoreContext::for_test(DomainSet::full(), None).derive_with(+ ContextOverlay::new(+ crate::config::Config::default(),+ DomainSet::full(),+ Default::default(),+ )+ .session_agent("u-asha"),+ );+ let dir = tempfile::tempdir().expect("tempdir");+ let path = run_log_path(dir.path(), "workflow", "run-scope-123");+ CoreContext::scope(+ ctx.clone(),+ write_header(+ dir.path(),+ &path,+ "workflow",+ "run-scope-123",+ &serde_json::json!({}),+ "prompt",+ ),+ )+ .await+ .unwrap();+ let (tx, rx) = tokio::sync::mpsc::channel(4);+ tx.send(AgentProgress::TurnCompleted {+ iterations: 5,+ stop: Some(tinyagents_harness::turn_stop::TurnStop::iteration_cap()),+ })+ .await+ .unwrap();+ drop(tx);++ // Spawned from outside any scope, as the run task's bridge is.+ spawn_drain_to_log(+ &DispatchCtx::new(ctx.clone()),+ rx,+ dir.path().to_path_buf(),+ path.clone(),+ )+ .await+ .unwrap();++ let log = CoreContext::scope(ctx, async {+ read_run_log_slice(dir.path(), &path, 0, 4096)+ })+ .await+ .unwrap();+ assert!(log.content.contains("stopped: iteration_cap"), "{log:?}");+}diff --git a/crates/openhuman-core/src/skills/runtime/run_machinery.rs b/crates/openhuman-core/src/skills/runtime/run_machinery.rsindex 81f5073a99..ac39497966 100644--- a/crates/openhuman-core/src/skills/runtime/run_machinery.rs+++ b/crates/openhuman-core/src/skills/runtime/run_machinery.rs@@ -27,7 +27,7 @@ pub struct WorkflowRunStarted {pub log_path: std::path::PathBuf,}-/// Spawn a single autonomous workflow_run as a detached `tokio::spawn`. Used by+/// Spawn a single autonomous workflow_run as a detached task acting for `ctx`. Used by/// both the `openhuman.skills_run` JSON-RPC controller and the `run_workflow`/// agent tool (which lets the orchestrator chain one skill into another —/// e.g. `github-issue-crusher` → `pr-review-shepherd` once the draft PR is@@ -163,7 +163,8 @@ pub async fn spawn_workflow_run_background(let workspace = workspace.clone();let inherited_origin = inherited_origin.clone();let ctx = ctx.clone();- tokio::spawn(async move {+ let dispatch = ctx.clone();+ dispatch.spawn(async move {if let Err(e) = run_log::write_header(&workspace,&log_path,@@ -232,11 +233,8 @@ pub async fn spawn_workflow_run_background());let (tx, rx) = tokio::sync::mpsc::channel(256);agent.set_on_progress(Some(tx));- let bridge = tokio::spawn(run_log::drain_to_log(- rx,- workspace.clone(),- log_path.clone(),- ));+ let bridge =+ run_log::spawn_drain_to_log(&ctx, rx, workspace.clone(), log_path.clone());// Register the cancellation token now (after the run can actually// start) so `skills_cancel` can stop it; a config/agent-builddiff --git a/scripts/ci/saas-ambient-baseline.json b/scripts/ci/saas-ambient-baseline.jsonindex bd8d04daa2..1a48fdbad5 100644--- a/scripts/ci/saas-ambient-baseline.json+++ b/scripts/ci/saas-ambient-baseline.json@@ -706,13 +706,6 @@"text": "let config_snapshot = match Config::load_or_init().await {","occurrence": 1},- {- "rule": "bare-spawn",- "path": "crates/openhuman-core/src/skills/runtime/run_machinery.rs",- "line": 162,- "text": "tokio::spawn(async move {",- "occurrence": 1- },{"rule": "ambient-config","path": "crates/openhuman-core/src/skills/runtime/run_machinery.rs",@@ -720,13 +713,6 @@"text": "let mut config = match Config::load_or_init().await {","occurrence": 1},- {- "rule": "bare-spawn",- "path": "crates/openhuman-core/src/skills/runtime/run_machinery.rs",- "line": 222,- "text": "let bridge = tokio::spawn(run_log::drain_to_log(rx, log_path.clone()));",- "occurrence": 1- },{"rule": "ambient-config","path": "crates/openhuman-core/src/skills/runtime/schemas.rs",