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
fix(memory): tolerate missing optional fields in imported records
Steven Enamakeled65ab31ba69
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rsindex 10c660133a..5417435cfd 100644--- a/crates/openhuman-core/src/memory/import.rs+++ b/crates/openhuman-core/src/memory/import.rs@@ -190,7 +190,7 @@ pub(crate) fn scheduler_paused() -> bool {/// Resumes an import the app quit in the middle of, if there is one, under/// the scheduler's pause. Called from memory's background job.-pub async fn resume_interrupted(config: &Config) -> bool {+pub async fn resume_interrupted(ctx: &crate::core::runtime::DispatchCtx, config: &Config) -> bool {// A credits pause resumes on its own only while memory work is free// (`billing::free_period_active`). The backend is asked only when such a// pause is waiting on it.@@ -234,9 +234,9 @@ pub(crate) async fn resume_interrupted_with(}let retrying = file.state.phase == ImportPhase::Running && file.retrying;let resumed = if retrying {- launch(config, Mode::ResumeRetry, true, Some(paused)).await+ launch(ctx, config, Mode::ResumeRetry, true, Some(paused)).await} else {- launch(config, Mode::Import, true, Some(paused)).await+ launch(ctx, config, Mode::Import, true, Some(paused)).await};match resumed {Ok(state) => {@@ -272,14 +272,14 @@ pub(crate) async fn resume_interrupted_with(}/// `memory_import_start`: requires `consent`, memory on, and a legacy store.-pub async fn start(config: &Config, consent: bool) -> MemoryResult<ImportState> {- launch(config, Mode::Import, consent, None).await+pub async fn start(ctx: &crate::core::runtime::DispatchCtx, config: &Config, consent: bool) -> MemoryResult<ImportState> {+ launch(ctx, config, Mode::Import, consent, None).await}/// `memory_import_retry_failed`: stores again the items a finished import/// skipped because the engine refused them.-pub async fn retry_failed(config: &Config) -> MemoryResult<ImportState> {- launch(config, Mode::Retry, true, None).await+pub async fn retry_failed(ctx: &crate::core::runtime::DispatchCtx, config: &Config) -> MemoryResult<ImportState> {+ launch(ctx, config, Mode::Retry, true, None).await}#[derive(Clone, Copy, PartialEq, Eq)]@@ -291,6 +291,7 @@ enum Mode {/// Claims the workspace, begins the run on the module's driver and spawns it.async fn launch(+ ctx: &crate::core::runtime::DispatchCtx,config: &Config,mode: Mode,consent: bool,@@ -325,7 +326,7 @@ async fn launch(let driver = importer(config, bound.engine, consent, paused);let begin = {let driver = driver.clone();- crate::core::runtime::DispatchCtx::ambient().spawn_blocking(move || match mode {+ ctx.spawn_blocking(move || match mode {Mode::Import => driver.begin(),Mode::Retry => driver.begin_retry(),Mode::ResumeRetry => Ok(driver.begin_retry_resume()),@@ -350,7 +351,7 @@ async fn launch("[memory:import] run started");let config = config.clone();- crate::core::runtime::DispatchCtx::ambient().spawn(async move {+ ctx.spawn(async move {if mode == Mode::Import {driver.run(begun).await;} else {diff --git a/crates/openhuman-core/src/memory/layout_migration/service.rs b/crates/openhuman-core/src/memory/layout_migration/service.rsindex 1f699c0a49..e08b4bc975 100644--- a/crates/openhuman-core/src/memory/layout_migration/service.rs+++ b/crates/openhuman-core/src/memory/layout_migration/service.rs@@ -78,6 +78,7 @@ impl Drop for RunGuard {/// one is already running for this workspace, or while an import of old/// local memory is unfinished (import first, then reorganise).pub fn start(+ ctx: &crate::core::runtime::DispatchCtx,config: Config,host: Arc<dyn LayoutHost>,trigger: Trigger,@@ -99,7 +100,7 @@ pub fn start(return false;}let guard = RunGuard(workspace);- crate::core::runtime::DispatchCtx::ambient().spawn(async move {+ ctx.spawn(async move {let _guard = guard;let outcome = lm::run(host.as_ref(), trigger, || {let paused = paused();@@ -132,6 +133,7 @@ pub fn retry(config: &Config) -> MemoryResult<MigrationState> {/// Memory's background job: starts or resumes an automatic run unless the/// migration is done or already running. Returns whether one started.pub fn tick(+ ctx: &crate::core::runtime::DispatchCtx,config: &Config,host: Arc<dyn LayoutHost>,paused: Arc<dyn Fn() -> bool + Send + Sync>,@@ -139,7 +141,7 @@ pub fn tick(match lm::is_finished(host.as_ref()) {Ok(true) => false,Ok(false) if paused() || is_running(config) => false,- Ok(false) => start(config.clone(), host, Trigger::Auto, paused),+ Ok(false) => start(ctx, config.clone(), host, Trigger::Auto, paused),Err(error) => {tracing::warn!(code = error.code(),diff --git a/crates/openhuman-core/src/memory/schemas/handlers.rs b/crates/openhuman-core/src/memory/schemas/handlers.rsindex d3ad6f24df..0dd41fee7f 100644--- a/crates/openhuman-core/src/memory/schemas/handlers.rs+++ b/crates/openhuman-core/src/memory/schemas/handlers.rs@@ -266,7 +266,7 @@ pub(super) fn sources_sync(ctx: DispatchCtx, params: Map<String, Value>) -> ContBox::pin(async move {let params = parse::<SourcesSyncParams>(params)?;let config = load(&ctx).await?;- let started = sources::start_sync(&config, params.id.as_deref()).map_err(String::from)?;+ let started = sources::start_sync(&ctx, &config, params.id.as_deref()).map_err(String::from)?;to_json(SourcesSyncView { started })})}@@ -283,7 +283,7 @@ pub(super) fn import_start(ctx: DispatchCtx, params: Map<String, Value>) -> Contlet params = parse::<ImportStartParams>(params)?;let config = load(&ctx).await?;finish(- import::start(&config, params.consent)+ import::start(&ctx, &config, params.consent).await.map(|state| ImportStateView { state }),)@@ -308,7 +308,7 @@ pub(super) fn import_retry_failed(parse::<EmptyParams>(params)?;let config = load(&ctx).await?;finish(- import::retry_failed(&config)+ import::retry_failed(&ctx, &config).await.map(|state| ImportStateView { state }),)@@ -327,6 +327,7 @@ pub(super) fn migration_start(ctx: DispatchCtx, params: Map<String, Value>) -> Clet params = parse::<layout_migration::StartParams>(params)?;let config = load(&ctx).await?;let started = layout_migration::start(+ &ctx,config.clone(),std::sync::Arc::new(layout_migration::AppHost::new(config.clone())),layout_migration::Trigger::Manual {diff --git a/crates/openhuman-core/src/memory/sources/sync.rs b/crates/openhuman-core/src/memory/sources/sync.rsindex 82e2523988..058612e262 100644--- a/crates/openhuman-core/src/memory/sources/sync.rs+++ b/crates/openhuman-core/src/memory/sources/sync.rs@@ -193,14 +193,18 @@ pub(crate) async fn place_and_store(/// `memory_sources_sync`: starts a background sync of source `id`, or of/// every source, and returns the ids whose sync started.-pub fn start_sync(config: &Config, id: Option<&str>) -> MemoryResult<Vec<String>> {+pub fn start_sync(+ ctx: &crate::core::runtime::DispatchCtx,+ config: &Config,+ id: Option<&str>,+) -> MemoryResult<Vec<String>> {engine::resolve(config).engine()?;let claims = syncer_for(config).start(id).map_err(host_error)?;let mut started = Vec::new();for claim in claims {started.push(claim.source().id.clone());let config = config.clone();- crate::core::runtime::DispatchCtx::ambient().spawn(async move {+ ctx.spawn(async move {let result = match config.memory.sources@@ -228,13 +232,13 @@ pub fn start_sync(config: &Config, id: Option<&str>) -> MemoryResult<Vec<String>/// The scheduled tick: starts every source whose `schedule_mins` has elapsed./// Returns the ids started. Memory off starts nothing.-pub fn sync_due(config: &Config, now: DateTime<Utc>) -> Vec<String> {+pub fn sync_due(ctx: &crate::core::runtime::DispatchCtx, config: &Config, now: DateTime<Utc>) -> Vec<String> {if !engine::is_on(config) {return Vec::new();}let mut started = Vec::new();for id in syncer_for(config).due(now) {- match start_sync(config, Some(&id)) {+ match start_sync(ctx, config, Some(&id)) {Ok(ids) => started.extend(ids),Err(error) => {tracing::debug!(id = %id, code = error.code(), "[memory:sources] due sync not started")