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(channels): add channel context tracking for runtime dispatch
Steven Enamakel601523d2224d
diff --git a/crates/openhuman-core/src/channels/context.rs b/crates/openhuman-core/src/channels/context.rsindex db0493b4ea..acf84c9397 100644--- a/crates/openhuman-core/src/channels/context.rs+++ b/crates/openhuman-core/src/channels/context.rs@@ -61,6 +61,17 @@ pub(crate) struct ChannelRuntimeContext {/// Full config for building crate-native turn models (Phase 3 P3-B). `Some` in/// production; `None` lets tests inject a model source directly.pub(crate) config: Option<Arc<crate::config::Config>>,+ /// The core context this channel runtime was built under. Held weakly: a+ /// channel runtime outlives no tenant. `None` in tests and bespoke hosts+ /// that never bound one.+ pub(crate) core: Option<std::sync::Weak<crate::core::runtime::CoreContext>>,+}++impl ChannelRuntimeContext {+ /// The dispatch context this runtime's work runs under.+ pub(crate) fn dispatch_ctx(&self) -> crate::core::runtime::DispatchCtx {+ crate::core::runtime::DispatchCtx::from_weak(self.core.as_ref())+ }}/// Resolve the configured module client; unit tests use an attested bus fixture.diff --git a/crates/openhuman-core/src/channels/context_tests.rs b/crates/openhuman-core/src/channels/context_tests.rsindex 3dbc00dfc6..acb0e96443 100644--- a/crates/openhuman-core/src/channels/context_tests.rs+++ b/crates/openhuman-core/src/channels/context_tests.rs@@ -51,6 +51,7 @@ fn runtime_context() -> ChannelRuntimeContext {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,}}diff --git a/crates/openhuman-core/src/channels/providers/relay/ops.rs b/crates/openhuman-core/src/channels/providers/relay/ops.rsindex 3c1e4c12cb..be4b4f9259 100644--- a/crates/openhuman-core/src/channels/providers/relay/ops.rs+++ b/crates/openhuman-core/src/channels/providers/relay/ops.rs@@ -154,7 +154,7 @@ pub(crate) async fn run_relay_turn(SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir).with_privacy_mode(config.privacy.mode),);- let parts = match build_channel_turn_parts(&config, &security, PromptToolDescs::Registered) {+ let parts = match build_channel_turn_parts(&dispatch_ctx, &config, &security, PromptToolDescs::Registered) {Ok(parts) => parts,Err(error) => {tracing::error!(@@ -185,6 +185,7 @@ pub(crate) async fn run_relay_turn(let mut channels_by_name: HashMap<String, Arc<dyn crate::channels::Channel>> = HashMap::new();channels_by_name.insert(params.channel.clone(), channel.clone());let mut runtime = runtime_context(+ &dispatch_ctx,&config,parts,Arc::new(channels_by_name),diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rsindex ca25fd4b39..5e8fe22c99 100644--- a/crates/openhuman-core/src/channels/routes_tests.rs+++ b/crates/openhuman-core/src/channels/routes_tests.rs@@ -85,6 +85,7 @@ fn runtime_context(workspace_dir: PathBuf) -> ChannelRuntimeContext {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,}}diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rsindex 7e7aa549b4..0eacd8df78 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs@@ -64,6 +64,7 @@ fn context(channel: Arc<Telegram>, config: Config) -> Arc<ChannelRuntimeContext>multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: Some(Arc::new(config)),+ core: None,})}diff --git a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rsindex ad3e107baf..1377e2654e 100644--- a/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/turn_parts.rs@@ -93,6 +93,7 @@ fn default_tool_descs(config: &Config) -> Vec<(&'static str, &'static str)> {/// `security`. Side-effect free apart from the workspace's audit logger: it/// installs no process-global policy and registers no subscriber.pub(crate) fn build_channel_turn_parts(+ dispatch: &DispatchCtx,config: &Config,security: &Arc<SecurityPolicy>,descs: PromptToolDescs,@@ -143,7 +144,7 @@ pub(crate) fn build_channel_turn_parts()?;let workspace = config.workspace_dir.clone();let capabilities =- crate::profiles::capabilities::ProfileCapabilities::in_ctx(&DispatchCtx::ambient());+ crate::profiles::capabilities::ProfileCapabilities::in_ctx(dispatch);let tools_registry = Arc::new(if capabilities.is_some() {// The profile host route builds the selected belt once with the exact// durable thread. No second, unnamed factory invocation is needed here.@@ -231,6 +232,7 @@ pub(crate) fn build_channel_turn_parts(/// The runtime context for `parts`, delivering replies to `channels_by_name`/// and starting with no per-chat history.pub(crate) fn runtime_context(+ dispatch: &DispatchCtx,config: &Config,parts: ChannelTurnParts,channels_by_name: Arc<HashMap<String, Arc<dyn crate::channels::Channel>>>,@@ -259,5 +261,6 @@ pub(crate) fn runtime_context(multimodal_files: config.multimodal_files.clone(),// Crate-native turn models for the channel turn (Phase 3 P3-B).config: Some(Arc::new(config.clone())),+ core: dispatch.downgrade(),}}diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rsindex 149e4008f5..acba794bd0 100644--- a/crates/openhuman-core/src/channels/runtime/test_support.rs+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs@@ -432,6 +432,7 @@ pub async fn run_dispatch_harness(options: DispatchHarnessOptions) -> DispatchHamultimodal: MultimodalConfig::default(),multimodal_files: MultimodalFileConfig::default(),config: None,+ core: None,});let expected_event_channel = options.channel_name.clone();diff --git a/crates/openhuman-core/src/channels/tests/discord_integration.rs b/crates/openhuman-core/src/channels/tests/discord_integration.rsindex d6eb6682e9..ce700773c3 100644--- a/crates/openhuman-core/src/channels/tests/discord_integration.rs+++ b/crates/openhuman-core/src/channels/tests/discord_integration.rs@@ -126,6 +126,7 @@ fn make_discord_ctx(multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,})}diff --git a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rsindex 02a30a97fc..cf8caedb59 100644--- a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs+++ b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs@@ -142,6 +142,7 @@ async fn message_dispatch_processes_messages_in_parallel() {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});(channel_impl, runtime_ctx)@@ -217,6 +218,7 @@ async fn process_channel_message_cancels_scoped_typing_task() {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});process_channel_message(@@ -306,6 +308,7 @@ async fn dispatch_routes_through_agent_run_turn_bus_handler() {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});process_channel_message(@@ -426,6 +429,7 @@ async fn resolved_route_ctx() -> Arc<ChannelRuntimeContext> {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,})}@@ -559,6 +563,7 @@ async fn process_channel_message_hardens_multimodal_files_against_smuggled_markemultimodal: crate::config::MultimodalConfig::default(),multimodal_files: permissive_operator_default,config: None,+ core: None,});// Attacker-shaped message: an absolute-path FILE marker dropped@@ -643,6 +648,7 @@ async fn process_channel_message_hardens_against_relative_path_markers() {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});process_channel_message(diff --git a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rsindex 11356dae45..979ee7063f 100644--- a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs+++ b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs@@ -48,6 +48,7 @@ async fn process_channel_message_executes_native_tool_calls() {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});process_channel_message(@@ -120,6 +121,7 @@ async fn process_channel_message_handles_models_command_without_llm_call() {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});let cmd_msg = traits::ChannelMessage {@@ -221,6 +223,7 @@ async fn process_channel_message_uses_route_override_provider_and_model() {multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});process_channel_message(runtime_ctx, routed_msg).await;@@ -272,6 +275,7 @@ async fn process_channel_message_respects_configured_max_tool_iterations_above_dmultimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});process_channel_message(@@ -331,6 +335,7 @@ async fn process_channel_message_reports_configured_max_tool_iterations_limit()multimodal: crate::config::MultimodalConfig::default(),multimodal_files: crate::config::MultimodalFileConfig::default(),config: None,+ core: None,});process_channel_message(