Skip to content

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

fix(agent): bind the turn's live progress sink to the parent snapshot

M3gA-Minde71e579a6c6a
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index 1267c9486b..8c9ee79522 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -745,7 +745,7 @@ impl OpenHumanTurnPrelude {
}
self.apply_pending_announcements(&mut enriched);
- run_context.parent = Some(parent);
+ run_context.attach_parent(parent);
run_context.prepared_context_sources = Arc::new(prepared_sources);
run_context.attachment_placeholders = Arc::new(
crate::agent::multimodal::extract_image_placeholders_in_text(original_user_message),
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index 2d80d3eb46..5ced16e9f5 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -364,6 +364,25 @@ impl OpenHumanRunContext {
self
}
+ /// Installs this turn's parent snapshot, binding the run's live progress
+ /// sink to it.
+ ///
+ /// The snapshot is built from a prelude that captured `on_progress` when
+ /// the runtime session was first created. A web-chat turn checks out a
+ /// cached session — so that build is a no-op — and only afterwards calls
+ /// `set_on_progress`, leaving the prelude's copy `None` for the rest of the
+ /// session's life. Sub-agent spawn and completion are the only progress
+ /// events that ride this parent sink instead of the harness event
+ /// projection, so a stale `None` drops them outright: no `subagent_spawned`
+ /// socket event, no run-ledger row, and a "Background tasks" panel that
+ /// reads "none running" while sub-agents are working. The run context's own
+ /// sink is the live one (it is what `driver.rs` hands the turn graph), so
+ /// prefer it and keep the snapshot as the fallback.
+ pub(crate) fn attach_parent(&mut self, mut parent: ParentExecutionContext) {
+ parent.on_progress = self.progress.clone().or(parent.on_progress);
+ self.parent = Some(parent);
+ }
+
/// Sets the same cancellation token on this context and its TinyAgents run.
pub fn with_cancellation(
mut self,
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
index 445919788f..9086a000c9 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
@@ -218,3 +218,86 @@ fn children_inherit_attachment_placeholders() {
["[Image: x #att:1]"]
);
}
+
+/// A parent snapshot as a cached web-chat session produces one: the prelude
+/// captured `on_progress` before `set_on_progress` ran, so it carries `None`.
+fn stale_parent_snapshot() -> ParentExecutionContext {
+ ParentExecutionContext {
+ agent_definition_id: "orchestrator".into(),
+ allowed_subagent_ids: std::collections::HashSet::new(),
+ turn_model_source: crate::agent::tinyagents::TurnModelSource::from_model(Arc::new(
+ tinyagents_harness::testkit::ScriptedModel::replies(vec!["done"]),
+ )),
+ all_tools: Arc::new(Vec::new()),
+ all_tool_specs: Arc::new(Vec::new()),
+ visible_tool_specs: Arc::new(Vec::new()),
+ visible_tool_names: std::collections::HashSet::new(),
+ subagent_tool_ceiling_names: std::collections::HashSet::new(),
+ model_name: "test-model".into(),
+ temperature: 0.0,
+ workspace_dir: std::path::PathBuf::from("/tmp/openhuman-attach-parent"),
+ workspace_descriptor: None,
+ memory: crate::memory::test_support::noop_memory(),
+ agent_config: crate::config::AgentConfig::default(),
+ workflows: Arc::new(Vec::new()),
+ memory_context: Arc::new(None),
+ session_id: "parent-session".into(),
+ channel: "test".into(),
+ connected_integrations: Vec::new(),
+ tool_call_format: crate::agent::prompts::ToolCallFormat::Native,
+ session_key: "parent-key".into(),
+ session_parent_prefix: None,
+ on_progress: None,
+ run_queue: None,
+ }
+}
+
+/// Sub-agent spawn/completion are the only progress events that ride the
+/// parent snapshot rather than the harness event projection. The snapshot's
+/// own sink is `None` for the whole life of a checked-out session, so binding
+/// the run's live sink here is what keeps `subagent_spawned` reaching the
+/// progress bridge — and with it the run-ledger row and the "Background tasks"
+/// panel. Without the bind the panel reads "none running" while sub-agents run.
+#[test]
+fn attach_parent_binds_the_runs_live_progress_sink_over_a_stale_snapshot() {
+ let (tx, _rx) = tokio::sync::mpsc::channel(4);
+ let mut context = OpenHumanRunContext::new();
+ context.progress = Some(tx);
+
+ context.attach_parent(stale_parent_snapshot());
+
+ assert!(
+ context
+ .parent
+ .as_ref()
+ .expect("parent installed")
+ .on_progress
+ .is_some(),
+ "the parent snapshot handed to tools must carry the turn's live \
+ progress sink; with `None` here spawn_async_subagent drops its \
+ SubagentSpawned event and the Background tasks panel stays empty"
+ );
+}
+
+/// The bind must not blank a sink the snapshot did carry: a turn with no
+/// progress subscriber of its own (CLI, cron) leaves the snapshot intact.
+#[test]
+fn attach_parent_keeps_the_snapshot_sink_when_the_run_has_none() {
+ let (tx, _rx) = tokio::sync::mpsc::channel(4);
+ let mut snapshot = stale_parent_snapshot();
+ snapshot.on_progress = Some(tx);
+ let mut context = OpenHumanRunContext::new();
+ assert!(context.progress.is_none(), "run has no sink of its own");
+
+ context.attach_parent(snapshot);
+
+ assert!(
+ context
+ .parent
+ .as_ref()
+ .expect("parent installed")
+ .on_progress
+ .is_some(),
+ "a run without its own sink must keep the snapshot's"
+ );
+}