Skip to content

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

chore: remove unused code across core modules

Steven Enamakel3954d3eaf52b
diff --git a/crates/openhuman-core/src/agent/tinyagents/reaper.rs b/crates/openhuman-core/src/agent/tinyagents/reaper.rs
index 33fe8af741..4d6123b04f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/reaper.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/reaper.rs
@@ -19,7 +19,11 @@ use std::path::Path;
/// sweep visits `local` and then each known agent (`crate::storage::agents`).
pub(crate) async fn reap_orphaned_runs(workspace: &Path) -> usize {
let shared = crate::storage::installed_is_shared();
- crate::storage::agents::for_each_scope("run reaper", |_| reap_unless_shared(workspace, shared))
+ crate::storage::agents::for_each_scope(
+ &crate::core::runtime::DispatchCtx::host_default(),
+ "run reaper",
+ |_| reap_unless_shared(workspace, shared),
+ )
.await
.into_iter()
.map(|(_, reaped)| reaped)
diff --git a/crates/openhuman-core/src/desktop/notifications/bus.rs b/crates/openhuman-core/src/desktop/notifications/bus.rs
index 5e67a9c686..95bb2d92c2 100644
--- a/crates/openhuman-core/src/desktop/notifications/bus.rs
+++ b/crates/openhuman-core/src/desktop/notifications/bus.rs
@@ -478,6 +478,7 @@ fn translate(event: &DomainEvent) -> Option<CoreNotificationEvent> {
///
/// When no scope reported the job and a scope's lookup failed.
async fn event_owner(
+ ctx: &crate::core::runtime::DispatchCtx,
config: &crate::config::Config,
event: &DomainEvent,
) -> Result<Option<String>, crate::storage::agents::LookupFailed> {
@@ -492,7 +493,7 @@ async fn event_owner(
if crate::storage::installed().is_none() {
return Ok(None);
}
- let owner = crate::storage::agents::find_owner("notification owner", |_| async {
+ let owner = crate::storage::agents::find_owner(ctx, "notification owner", |_| async {
match crate::cron::get_job(config, job_id) {
Ok(_) => Ok(true),
// tinyflows reports a missing job as `Cron job '<id>' not found`
@@ -530,12 +531,14 @@ impl EventHandler<DomainEvent> for NotificationBridgeSubscriber {
// A workspace-bound event is stored in ITS OWN workspace, not
// whichever one this bridge was registered with (#5931).
let config = self.store_target(config, event);
+ // The bridge serves the host's own notifications.
+ let dispatch = crate::core::runtime::DispatchCtx::host_default();
// Stored with the record that raised it: a cron job's
// completion goes to the agent the job belongs to
// (`crate::storage`), `local` otherwise.
- let stored = match event_owner(&config, event).await {
+ let stored = match event_owner(&dispatch, &config, event).await {
Ok(owner) => {
- crate::storage::agents::within_agent(owner.as_deref(), async {
+ crate::storage::agents::within_agent(&dispatch, owner.as_deref(), async {
super::store::insert_core_notification(&config, &notification)
})
.await
diff --git a/crates/openhuman-core/src/flows/bus/owner.rs b/crates/openhuman-core/src/flows/bus/owner.rs
index 5438e79e46..3f8244db4e 100644
--- a/crates/openhuman-core/src/flows/bus/owner.rs
+++ b/crates/openhuman-core/src/flows/bus/owner.rs
@@ -25,6 +25,7 @@ static OWNERS: LazyLock<Mutex<HashMap<String, Option<String>>>> = LazyLock::new(
/// When no scope reported the flow and a scope's lookup failed: the event
/// is then not handled, rather than handled in the wrong scope.
pub(super) async fn flow_owner(
+ ctx: &DispatchCtx,
config: &Config,
flow_id: &str,
) -> Result<Option<String>, LookupFailed> {
@@ -32,7 +33,7 @@ pub(super) async fn flow_owner(
if crate::storage::installed().is_none() {
return Ok(None);
}
- resolve(config, flow_id).await
+ resolve(ctx, config, flow_id).await
}
/// Whether the current scope has `flow_id`.
@@ -43,7 +44,11 @@ async fn has_flow(config: &Config, flow_id: &str) -> Result<bool, String> {
}
/// [`flow_owner`]'s cache and lookup, across whatever scopes exist.
-async fn resolve(config: &Config, flow_id: &str) -> Result<Option<String>, LookupFailed> {
+async fn resolve(
+ ctx: &DispatchCtx,
+ config: &Config,
+ flow_id: &str,
+) -> Result<Option<String>, LookupFailed> {
let cached = OWNERS
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
@@ -52,7 +57,7 @@ async fn resolve(config: &Config, flow_id: &str) -> Result<Option<String>, Looku
if let Some(owner) = cached {
// Still there? A removed flow's id may be reused, or the flow moved:
// re-check the cached scope and resolve again when it lost the flow.
- match within_agent(owner.as_deref(), has_flow(config, flow_id)).await {
+ match within_agent(ctx, owner.as_deref(), has_flow(config, flow_id)).await {
Some(Ok(true)) => return Ok(owner),
Some(Err(error)) => {
return Err(LookupFailed {
@@ -63,7 +68,7 @@ async fn resolve(config: &Config, flow_id: &str) -> Result<Option<String>, Looku
Some(Ok(false)) | None => forget(flow_id),
}
}
- let Some(owner) = find_owner("flow owner", |_| has_flow(config, flow_id)).await? else {
+ let Some(owner) = find_owner(ctx, "flow owner", |_| has_flow(config, flow_id)).await? else {
return Ok(None);
};
tracing::debug!(
@@ -81,14 +86,19 @@ async fn resolve(config: &Config, flow_id: &str) -> Result<Option<String>, Looku
/// Runs `step`, handed the owner's context, as `flow_id`'s owner; logs and skips it when the owner is
/// unknown (a failed lookup) or no context can act for it.
-pub(super) async fn as_owner<F, Fut>(config: &Config, flow_id: &str, step: F)
+pub(super) async fn as_owner<F, Fut>(
+ ctx: &DispatchCtx,
+ config: &Config,
+ flow_id: &str,
+ step: F,
+)
where
F: FnOnce(DispatchCtx) -> Fut,
Fut: std::future::Future<Output = ()>,
{
- match flow_owner(config, flow_id).await {
+ match flow_owner(ctx, config, flow_id).await {
Ok(owner) => {
- within_agent_ctx(owner.as_deref(), step).await;
+ within_agent_ctx(ctx, owner.as_deref(), step).await;
}
Err(failed) => tracing::warn!(
target: "flows",
diff --git a/crates/openhuman-core/src/flows/ops/run_management.rs b/crates/openhuman-core/src/flows/ops/run_management.rs
index 172e1dd1ef..1e47eb6328 100644
--- a/crates/openhuman-core/src/flows/ops/run_management.rs
+++ b/crates/openhuman-core/src/flows/ops/run_management.rs
@@ -269,9 +269,13 @@ pub async fn sweep_orphaned_running_runs_on_boot(config: &Config) -> usize {
0
}
rm::BootSweepPlan::EveryScope => {
- crate::storage::agents::for_each_scope("flows boot sweep", |_| {
- sweep_orphaned_running_runs_in_scope(config)
- })
+ crate::storage::agents::for_each_scope(
+ &crate::core::runtime::DispatchCtx::host_default(),
+ "flows boot sweep",
+ |_| {
+ sweep_orphaned_running_runs_in_scope(config)
+ },
+ )
.await
.into_iter()
.map(|(_, swept)| swept)
diff --git a/crates/openhuman-core/src/flows/ops/triggers.rs b/crates/openhuman-core/src/flows/ops/triggers.rs
index d1c10a4272..f231f742d2 100644
--- a/crates/openhuman-core/src/flows/ops/triggers.rs
+++ b/crates/openhuman-core/src/flows/ops/triggers.rs
@@ -179,9 +179,11 @@ pub async fn reconcile_schedule_triggers_on_boot(config: &Config) -> Result<(),
// that scope, where the scheduler visits them.
let mut errors = Vec::new();
for (agent, result) in
- crate::storage::agents::for_each_scope("flows schedule reconcile", |_| {
- reconcile_schedule_triggers_in_scope(config)
- })
+ crate::storage::agents::for_each_scope(
+ &crate::core::runtime::DispatchCtx::host_default(),
+ "flows schedule reconcile",
+ |_| reconcile_schedule_triggers_in_scope(config),
+ )
.await
{
if let Err(error) = result {
diff --git a/crates/openhuman-core/src/integrations/task_sources/periodic.rs b/crates/openhuman-core/src/integrations/task_sources/periodic.rs
index 82f57c9956..bc5b1b0846 100644
--- a/crates/openhuman-core/src/integrations/task_sources/periodic.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/periodic.rs
@@ -101,7 +101,7 @@ async fn run_loop() {
// `local`, then every agent that keeps its sources in its own storage
// scope (`crate::storage::agents`).
for (agent, result) in
- crate::storage::agents::for_each_live_scope("task_sources", |ctx| async move {
+ crate::storage::agents::for_each_live_scope(&DispatchCtx::host_default(), "task_sources", |ctx| async move {
run_one_tick(&ctx).await
})
.await
diff --git a/crates/openhuman-core/src/security/devices/bus.rs b/crates/openhuman-core/src/security/devices/bus.rs
index 3d3807e075..3f7043e3fb 100644
--- a/crates/openhuman-core/src/security/devices/bus.rs
+++ b/crates/openhuman-core/src/security/devices/bus.rs
@@ -101,6 +101,7 @@ impl EventHandler<DomainEvent> for DeviceTunnelSubscriber {
match super::owner::owner_of(&ctx, channel_id, pending.as_ref()).await {
Ok(owner) => {
let handled = crate::storage::agents::within_agent(
+ &ctx,
owner.as_deref(),
handle_tunnel_frame(&ctx, channel_id, payload_b64),
)
diff --git a/crates/openhuman-core/src/security/devices/owner.rs b/crates/openhuman-core/src/security/devices/owner.rs
index aa95f6c92a..e05f352505 100644
--- a/crates/openhuman-core/src/security/devices/owner.rs
+++ b/crates/openhuman-core/src/security/devices/owner.rs
@@ -113,8 +113,9 @@ pub(super) async fn owner_of(
return Ok(session.agent.clone());
}
let revoked = crate::storage::agents::within_agent(
+ ctx,
session.agent.as_deref(),
- is_revoked(&ctx, channel_id),
+ is_revoked(ctx, channel_id),
)
.await;
return match revoked {
@@ -135,8 +136,9 @@ pub(super) async fn owner_of(
}
if let Some(owner) = cached(channel_id) {
match crate::storage::agents::within_agent(
+ ctx,
owner.as_deref(),
- has_live_device(&ctx, channel_id),
+ has_live_device(ctx, channel_id),
)
.await
{
@@ -150,7 +152,7 @@ pub(super) async fn owner_of(
Some(Ok(false)) | None => forget(channel_id),
}
}
- let lookups = crate::storage::agents::for_each_scope("device owner", |scope_ctx| async move {
+ let lookups = crate::storage::agents::for_each_scope(ctx, "device owner", |scope_ctx| async move {
has_live_device(&scope_ctx, channel_id).await
})
.await;
diff --git a/crates/openhuman-core/src/storage/blob_sweep.rs b/crates/openhuman-core/src/storage/blob_sweep.rs
index f1956cd585..a3fa1fa4de 100644
--- a/crates/openhuman-core/src/storage/blob_sweep.rs
+++ b/crates/openhuman-core/src/storage/blob_sweep.rs
@@ -100,7 +100,7 @@ pub(crate) async fn sweep_profiles(backend: &dyn StorageBackend, profile_ids: &[
/// Agent scopes are enumerated from the installed backend (the only caller,
/// [`sweep_installed`], passes that one).
pub async fn sweep_all(backend: Arc<dyn StorageBackend>) -> u64 {
- let scoped: u64 = super::agents::for_each_scope("blob sweep", |_| {
+ let scoped: u64 = super::agents::for_each_scope(&crate::core::runtime::DispatchCtx::host_default(), "blob sweep", |_| {
let backend = Arc::clone(&backend);
async move {
match super::current_scope() {