Skip to content

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

refactor(memory): thread dispatch context through memory job runners

Steven Enamakel089f4338ac21
diff --git a/crates/openhuman-core/src/memory/bus.rs b/crates/openhuman-core/src/memory/bus.rs
index 71d3421a1f..9efc2f9c26 100644
--- a/crates/openhuman-core/src/memory/bus.rs
+++ b/crates/openhuman-core/src/memory/bus.rs
@@ -69,14 +69,18 @@ impl EventHandler<DomainEvent> for PendingDeletionsSubscriber {
return;
}
};
- drain_pending_deletions(&config, kind).await;
+ drain_pending_deletions(&ctx, &config, kind).await;
}
}
/// Runs the deletions queued while memory was off, after a credential of
/// `kind` was stored.
-pub(crate) async fn drain_pending_deletions(config: &crate::config::Config, kind: &str) -> usize {
- super::tool_writes::schedule_all(Arc::new(config.clone()));
+pub(crate) async fn drain_pending_deletions(
+ ctx: &DispatchCtx,
+ config: &crate::config::Config,
+ kind: &str,
+) -> usize {
+ super::tool_writes::schedule_all(ctx, Arc::new(config.clone()));
let settled = super::deletion::drain(config).await;
tracing::debug!(kind = %kind, settled, "[memory:bus] pending deletions drained after sign-in");
settled
@@ -112,7 +116,7 @@ impl EventHandler<DomainEvent> for SystemJobsSubscriber {
return;
}
};
- run_system_job(&config, job).await;
+ run_system_job(&ctx, &config, job).await;
if job == SOURCES_SYNC_JOB {
sync_live_agent_sources().await;
}
@@ -128,7 +132,7 @@ async fn sync_live_agent_sources() {
match crate::config::ops::load_current_or_init(&dispatch).await {
Ok(config) => {
tracing::debug!(agent = %agent_id, "[memory:bus] agent source sync");
- run_system_job(&config, SOURCES_SYNC_JOB).await;
+ run_system_job(&dispatch, &config, SOURCES_SYNC_JOB).await;
}
Err(error) => {
tracing::debug!(agent = %agent_id, %error, "[memory:bus] agent config unavailable");
@@ -140,19 +144,20 @@ async fn sync_live_agent_sources() {
}
/// Runs one memory cron job against `config`.
-pub async fn run_system_job(config: &crate::config::Config, job: &str) {
+pub async fn run_system_job(ctx: &DispatchCtx, config: &crate::config::Config, job: &str) {
match job {
SOURCES_SYNC_JOB => {
- let started = super::sources::sync_due(config, Utc::now());
+ let started = super::sources::sync_due(ctx, config, Utc::now());
tracing::debug!(
started = started.len(),
"[memory:bus] due source syncs started"
);
}
BACKGROUND_JOB => {
- super::tool_writes::schedule_all(Arc::new(config.clone()));
- super::import::resume_interrupted(config).await;
+ super::tool_writes::schedule_all(ctx, Arc::new(config.clone()));
+ super::import::resume_interrupted(ctx, config).await;
super::layout_migration::tick(
+ ctx,
config,
std::sync::Arc::new(super::layout_migration::AppHost::new(config.clone())),
std::sync::Arc::new(super::import::scheduler_paused),
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rs
index 5417435cfd..25191b2042 100644
--- a/crates/openhuman-core/src/memory/import.rs
+++ b/crates/openhuman-core/src/memory/import.rs
@@ -351,6 +351,7 @@ async fn launch(
"[memory:import] run started"
);
let config = config.clone();
+ let task_ctx = ctx.clone();
ctx.spawn(async move {
if mode == Mode::Import {
driver.run(begun).await;
@@ -362,6 +363,7 @@ async fn launch(
// screen the user is, once the import is done.
if mode == Mode::Import && read_file(&workspace_dir).state.phase == ImportPhase::Done {
let started = super::layout_migration::start(
+ &task_ctx,
config.clone(),
Arc::new(super::layout_migration::AppHost::new(config)),
// Migration is free: organizing follows a finished import