Skip to content

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

refactor(channels): update channel progress and relay behavior

Steven Enamakel23409091bc56
diff --git a/crates/openhuman-core/src/channels/providers/relay/README.md b/crates/openhuman-core/src/channels/providers/relay/README.md
index ac9cbfe9e3..d7c7f5e0be 100644
--- a/crates/openhuman-core/src/channels/providers/relay/README.md
+++ b/crates/openhuman-core/src/channels/providers/relay/README.md
@@ -39,7 +39,8 @@ Each reply arrives on the caller's `GET /events?client_id=<client_id>` stream as
}
```
-Replies are final messages only: the relay sink takes no streaming drafts or reactions.
+Replies and progress use the compiled TinyChannels progressive contract; the
+relay sink does not expose provider reactions.
## How a message runs
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rs
index cbeec9d1c4..3a9072da33 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs
@@ -106,6 +106,13 @@ pub(crate) async fn run_relay_turn(
request_id: String,
) -> Vec<String> {
let workspace_dir = config.workspace_dir.clone();
+ // Keep background deliveries off this thread through the adapter's
+ // durable reply-recording tail. Execution, profile serialization,
+ // cancellation and progressive delivery are owned by the shared runner.
+ let busy = crate::agent::orchestration::busy_guard::TurnBusy::start_on_thread(
+ &dispatch_ctx,
+ &thread_id,
+ );
// The thread is busy for the whole turn, so a background result due on it
// waits instead of landing mid-turn. The pipeline's session id does not
// name the thread, so the guard is taken on the thread itself; this task
@@ -309,6 +316,7 @@ pub(crate) async fn run_relay_turn(
record(&dispatch_ctx, &workspace_dir, &params, &thread_id, &replies).await;
// Idle again: deliver anything that finished while the turn ran. No
// `AgentTurnCompleted` maps to this thread, so nothing else would.
+ drop(busy);
crate::agent::orchestration::background_delivery::kick_delivery(&dispatch_ctx, &thread_id);
tracing::info!(
channel = %params.channel,
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
index 066816cfda..dd089b10c1 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/mod.rs
@@ -5,7 +5,8 @@
//! through the host agent resolver ([`crate::agent::host_agents`]) and run as
//! that agent -- its definition, its host tools, its context -- instead of
//! going over the bus to the orchestrator. Everything else about the channel
-//! stays: per-chat history, typing, drafts, the reply back to the chat.
+//! stays: durable session identity, typing, progressive events, and the reply
+//! back to the chat.
//!
//! A binding the resolver cannot satisfy (the embedder has not created the
//! agent yet, or dropped it) is **refused**, with a short reply to the chat
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs
index 13a23a473e..463a8edf2d 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs
@@ -25,7 +25,7 @@ pub(crate) struct HostChannelTurn {
pub(crate) message: String,
/// Who asked: the channel's `ExternalChannel` origin.
pub(crate) origin: AgentTurnOrigin,
- /// Live progress for the channel's draft updates.
+ /// Live progress projected through the compiled channel module.
pub(crate) progress: Option<mpsc::Sender<AgentProgress>>,
pub(crate) run_queue: Option<std::sync::Arc<RunQueue<crate::agent::queued_turn::QueuedTurn>>>,
/// Where this turn's parked approvals surface; default for a channel
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
index 9d6a5504a0..ce4d384354 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
@@ -251,16 +251,16 @@ impl NativeHost {
// profile-wide chat/cron gate. Both acquisitions happen in checkout,
// after TurnRunner admission, and cancellation drops either future.
let profile_turn = crate::profiles::turn_gate::acquire(dispatch).await;
- let busy = match trusted.relay_thread.as_deref() {
- Some(thread_id) => Some(
- crate::agent::orchestration::busy_guard::TurnBusy::start_on_thread(
- dispatch, thread_id,
- ),
- ),
- None => Some(crate::agent::orchestration::busy_guard::TurnBusy::start(
+ // Relay keeps its thread busy through the small post-run durable
+ // reply-recording tail in `run_relay_turn`; other native turns can
+ // release their busy guard with progressive terminal delivery.
+ let busy = if trusted.relay_thread.is_none() {
+ Some(crate::agent::orchestration::busy_guard::TurnBusy::start(
dispatch,
&session_id,
- )),
+ ))
+ } else {
+ None
};
let native_reply = match trusted.native_target.as_ref() {
Some(target) => Some(
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
index 4b79855aee..318d339041 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
@@ -37,16 +37,14 @@ async fn terminal_delivery_releases_session_profile_and_busy_guards() {
let dispatch = crate::core::runtime::DispatchCtx::unbound();
let profile = format!("native-runner-test-{}", uuid::Uuid::new_v4());
let session = format!("native-session-{}", uuid::Uuid::new_v4());
- let lease = crate::agent::session_lease::SessionLease::acquire(
- crate::agent::session_lease::SessionLeaseKey::new("native-test-tenant", "agent", &session),
- None,
- )
- .await
- .expect("session lease");
+ let lease_key =
+ crate::agent::session_lease::SessionLeaseKey::new("native-test-tenant", "agent", &session);
+ let lease = crate::agent::session_lease::SessionLease::acquire(lease_key.clone(), None)
+ .await
+ .expect("session lease");
let profile_turn = crate::profiles::turn_gate::acquire_profile(&profile).await;
- let busy = crate::agent::orchestration::busy_guard::TurnBusy::start_on_thread(
- &dispatch, &session,
- );
+ let busy =
+ crate::agent::orchestration::busy_guard::TurnBusy::start_on_thread(&dispatch, &session);
let shared = NativeShared::default();
shared.begin_delivery_wait("guarded-request");
shared.with("guarded-request", |slot| {
@@ -55,20 +53,44 @@ async fn terminal_delivery_releases_session_profile_and_busy_guards() {
slot.busy = Some(busy);
});
- assert!(crate::agent::orchestration::busy_guard::is_busy(&dispatch, &session));
+ assert!(crate::agent::orchestration::busy_guard::is_busy(
+ &dispatch, &session
+ ));
let waiting = tokio::spawn({
let profile = profile.clone();
async move { crate::profiles::turn_gate::acquire_profile(&profile).await }
});
+ let waiting_session = tokio::spawn({
+ let lease_key = lease_key.clone();
+ async move {
+ crate::agent::session_lease::SessionLease::acquire(lease_key, None)
+ .await
+ .expect("next session lease")
+ }
+ });
tokio::task::yield_now().await;
- assert!(!waiting.is_finished(), "profile gate stays held through delivery");
+ assert!(
+ !waiting.is_finished(),
+ "profile gate stays held through delivery"
+ );
+ assert!(
+ !waiting_session.is_finished(),
+ "session lease stays held through delivery"
+ );
shared.record_delivery("guarded-request", true);
- assert!(!crate::agent::orchestration::busy_guard::is_busy(&dispatch, &session));
+ assert!(!crate::agent::orchestration::busy_guard::is_busy(
+ &dispatch, &session
+ ));
let next = tokio::time::timeout(std::time::Duration::from_secs(1), waiting)
.await
.expect("profile gate is released after delivery")
.expect("profile waiter does not panic");
drop(next);
+ let next_session = tokio::time::timeout(std::time::Duration::from_secs(1), waiting_session)
+ .await
+ .expect("session lease is released after delivery")
+ .expect("session waiter does not panic");
+ drop(next_session);
}
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor.rs
index 0d5eb6b29c..2ea7771459 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor.rs
@@ -6,7 +6,7 @@
//! * [`try_route_approval_reply`] (in [`approval`]) — intercepts yes/no
//! approval replies before dispatching a fresh agent turn.
//! * [`process_channel_message`] — full per-message pipeline: typing, ACK
-//! reaction, history, agent turn, draft updates, reply.
+//! reaction, durable session, agent turn, progressive events and reply.
//! * [`bus_turn`] — the orchestrator path: an unbound channel's turn over
//! the native bus. A channel bound to a host agent runs through
//! [`super::host_agent`] instead.
diff --git a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
index 4febf5edb4..200ff5bf51 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
@@ -435,7 +435,6 @@ impl Channel for ModuleChannel {
fn supports_reactions(&self) -> bool {
self.interaction.supports_reactions
}
-
}
impl ModuleChannel {
diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rs
index 14c9d4d2c5..bb81dc69e8 100644
--- a/crates/openhuman-core/src/channels/runtime/test_support.rs
+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs
@@ -178,8 +178,6 @@ impl Channel for HarnessChannel {
fn supports_reactions(&self) -> bool {
self.supports_reactions
}
-
-
}
struct HarnessModel;
diff --git a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
index 3b7cd02a09..599930fc37 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
@@ -131,7 +131,7 @@ async fn message_dispatch_processes_messages_in_parallel() {
model: Arc::new("test-model".to_string()),
temperature: 0.0,
max_tool_iterations: 10,
- turn_model_source_cache: Arc::new(Mutex::new(HashMap::new())),
+ turn_model_source_cache: Arc::new(Mutex::new(HashMap::new())),
route_overrides: Arc::new(Mutex::new(HashMap::new())),
api_url: None,
inference_url: None,
diff --git a/crates/openhuman-core/src/web_chat/turn_host.rs b/crates/openhuman-core/src/web_chat/turn_host.rs
index f56b928f75..f19372a914 100644
--- a/crates/openhuman-core/src/web_chat/turn_host.rs
+++ b/crates/openhuman-core/src/web_chat/turn_host.rs
@@ -122,11 +122,10 @@ impl WebHost {
// then the profile-wide chat/cron gate. This keeps native, relay and
// web runner instances from forming an inverse-lock cycle.
let profile_turn = crate::profiles::turn_gate::acquire(&ctx).await;
- self.shared
- .with(id, |slot| {
- slot.session_lease = Some(lease);
- slot.profile_turn = profile_turn;
- });
+ self.shared.with(id, |slot| {
+ slot.session_lease = Some(lease);
+ slot.profile_turn = profile_turn;
+ });
// A follow-up the runner dispatches after its predecessor finished was
// admitted when it was queued; one started directly still has its
// admission to answer.