Skip to content

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

refactor(channels): split channel startup into focused modules

Steven Enamakel418d9cc72885
diff --git a/crates/openhuman-core/src/channels/runtime/startup/delivery_import.rs b/crates/openhuman-core/src/channels/runtime/startup/delivery_import.rs
index 46ac3d4d1d..a5af7e1111 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/delivery_import.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/delivery_import.rs
@@ -64,11 +64,14 @@ pub(super) enum Outcome {
/// Import the legacy delivery file under `workspace` into the module's scope of
/// the installed storage backend.
-pub(super) async fn import_legacy_delivery(workspace: &Path) -> anyhow::Result<Outcome> {
+pub(super) async fn import_legacy_delivery(
+ ctx: &crate::core::runtime::DispatchCtx,
+ workspace: &Path,
+) -> anyhow::Result<Outcome> {
let Some(backend) = crate::storage::installed() else {
return Ok(Outcome::NoBackend);
};
- let scope = crate::modules::storage_host::current_module_scope(&crate::core::runtime::DispatchCtx::ambient(), MODULE_ID)
+ let scope = crate::modules::storage_host::current_module_scope(ctx, MODULE_ID)
.map_err(|error| anyhow::anyhow!("resolve the module scope: {:?}", error.kind()))?;
let scoped = backend
.for_scope(&scope)
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 d8b4977003..9a0afbbd8f 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/module_providers.rs
@@ -41,6 +41,7 @@ struct ModuleChannel {
impl ModuleChannelRuntime {
pub(super) async fn prepare(
+ dispatch_ctx: &crate::core::runtime::DispatchCtx,
config: Arc<Config>,
context: Arc<OnceLock<Weak<crate::channels::context::ChannelRuntimeContext>>>,
dispatch: mpsc::Sender<RuntimeChannelMessage>,
@@ -49,7 +50,7 @@ impl ModuleChannelRuntime {
// Queued deliveries from before the storage contract move into the
// module's storage before it starts and reads its queue. Best effort:
// a failure is retried at the next start, never fatal to channels.
- match super::delivery_import::import_legacy_delivery(&config.workspace_dir).await {
+ match super::delivery_import::import_legacy_delivery(dispatch_ctx, &config.workspace_dir).await {
Ok(outcome) => tracing::debug!("[channels] legacy delivery import: {outcome:?}"),
Err(error) => {
tracing::warn!("[channels] legacy delivery import failed, will retry: {error:#}");
diff --git a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
index 5f1343e8af..2d703c2cf9 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/start_channels.rs
@@ -164,6 +164,7 @@ async fn start_channels_inner(mut config: Config, session: CancellationToken) ->
let context_slot: Arc<OnceLock<Weak<crate::channels::context::ChannelRuntimeContext>>> =
Arc::new(OnceLock::new());
let preparing = ModuleChannelRuntime::prepare(
+ &dispatch,
Arc::new(config.clone()),
Arc::clone(&context_slot),
dispatch_tx.clone(),