Skip to content

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

style(memory): reformat long calls to satisfy line width

Steven Enamakelc9fe43263ff9
diff --git a/crates/openhuman-core/src/memory/bus_tests.rs b/crates/openhuman-core/src/memory/bus_tests.rs
index 71218a741d..b066b757cc 100644
--- a/crates/openhuman-core/src/memory/bus_tests.rs
+++ b/crates/openhuman-core/src/memory/bus_tests.rs
@@ -28,13 +28,28 @@ async fn the_background_job_runs_the_due_queue() {
)
.await;
- run_system_job(&crate::core::runtime::DispatchCtx::ambient(), &config, BACKGROUND_JOB).await;
+ run_system_job(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ BACKGROUND_JOB,
+ )
+ .await;
let queue = jobs::snapshot(&config).await;
assert!(queue.pending.is_empty());
assert_eq!(queue.history.len(), 1);
- run_system_job(&crate::core::runtime::DispatchCtx::ambient(), &config, "someone_elses_job").await;
- run_system_job(&crate::core::runtime::DispatchCtx::ambient(), &config, SOURCES_SYNC_JOB).await;
+ run_system_job(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ "someone_elses_job",
+ )
+ .await;
+ run_system_job(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ SOURCES_SYNC_JOB,
+ )
+ .await;
}
#[test]
@@ -57,7 +72,15 @@ async fn a_sign_in_drains_the_deletions_queued_while_signed_out() {
},
);
bind_reference(&config);
- assert_eq!(drain_pending_deletions(&crate::core::runtime::DispatchCtx::ambient(), &config, "session").await, 1);
+ assert_eq!(
+ drain_pending_deletions(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ "session"
+ )
+ .await,
+ 1
+ );
assert!(pending(&config.workspace_dir).is_empty());
}
@@ -74,6 +97,11 @@ async fn the_background_job_retries_pending_deletions() {
},
);
bind_reference(&config);
- run_system_job(&crate::core::runtime::DispatchCtx::ambient(), &config, BACKGROUND_JOB).await;
+ run_system_job(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ BACKGROUND_JOB,
+ )
+ .await;
assert!(pending(&config.workspace_dir).is_empty());
}
diff --git a/crates/openhuman-core/src/memory/import.rs b/crates/openhuman-core/src/memory/import.rs
index bb067d273e..9b858e33b4 100644
--- a/crates/openhuman-core/src/memory/import.rs
+++ b/crates/openhuman-core/src/memory/import.rs
@@ -274,13 +274,20 @@ pub(crate) async fn resume_interrupted_with(
}
/// `memory_import_start`: requires `consent`, memory on, and a legacy store.
-pub async fn start(ctx: &crate::core::runtime::DispatchCtx, config: &Config, consent: bool) -> MemoryResult<ImportState> {
+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(ctx: &crate::core::runtime::DispatchCtx, config: &Config) -> MemoryResult<ImportState> {
+pub async fn retry_failed(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+) -> MemoryResult<ImportState> {
launch(ctx, config, Mode::Retry, true, None).await
}
diff --git a/crates/openhuman-core/src/memory/import_tests.rs b/crates/openhuman-core/src/memory/import_tests.rs
index 68306ff922..398d67c7aa 100644
--- a/crates/openhuman-core/src/memory/import_tests.rs
+++ b/crates/openhuman-core/src/memory/import_tests.rs
@@ -64,7 +64,13 @@ fn a_credits_pause_blocks_organizing_until_resumed() {
async fn starting_without_consent_is_refused_before_anything_runs() {
let tmp = tempfile::tempdir().unwrap();
let config = config_in(&tmp);
- let error = start(&crate::core::runtime::DispatchCtx::ambient(), &config, false).await.unwrap_err();
+ let error = start(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ false,
+ )
+ .await
+ .unwrap_err();
assert!(error.to_string().contains("consent"), "{error}");
assert!(!running(&config.workspace_dir));
assert_eq!(status(&config).phase, ImportPhase::Idle);
@@ -76,7 +82,11 @@ async fn retrying_with_nothing_failed_is_refused_and_releases_the_workspace() {
let config = config_in(&tmp);
// Either no engine is bound here or there is nothing to retry; either
// way the call fails and the workspace must not stay claimed.
- assert!(retry_failed(&crate::core::runtime::DispatchCtx::ambient(), &config).await.is_err());
+ assert!(
+ retry_failed(&crate::core::runtime::DispatchCtx::ambient(), &config)
+ .await
+ .is_err()
+ );
assert!(!running(&config.workspace_dir));
}
@@ -84,8 +94,13 @@ async fn retrying_with_nothing_failed_is_refused_and_releases_the_workspace() {
async fn nothing_resumes_when_no_import_was_started() {
let tmp = tempfile::tempdir().unwrap();
let config = config_in(&tmp);
- let resumed =
- resume_interrupted_with(&crate::core::runtime::DispatchCtx::ambient(), &config, Arc::new(|| false), Arc::new(|_: &Config| true)).await;
+ let resumed = resume_interrupted_with(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Arc::new(|| false),
+ Arc::new(|_: &Config| true),
+ )
+ .await;
assert!(!resumed);
}
@@ -98,8 +113,13 @@ async fn a_paused_scheduler_leaves_an_interrupted_import_for_later() {
FileCheckpointStore::new(&config.workspace_dir)
.save(&file)
.unwrap();
- let resumed =
- resume_interrupted_with(&crate::core::runtime::DispatchCtx::ambient(), &config, Arc::new(|| true), Arc::new(|_: &Config| true)).await;
+ let resumed = resume_interrupted_with(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Arc::new(|| true),
+ Arc::new(|_: &Config| true),
+ )
+ .await;
assert!(!resumed);
assert_eq!(
read_file(&config.workspace_dir).state.phase,
diff --git a/crates/openhuman-core/src/memory/layout_migration/service_tests.rs b/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
index 35b047e96e..b365043735 100644
--- a/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
+++ b/crates/openhuman-core/src/memory/layout_migration/service_tests.rs
@@ -34,7 +34,13 @@ async fn scan_finds_legacy_memory_and_nothing_after_the_move() {
shared: false
}
);
- assert!(start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));
+ assert!(start(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config.clone(),
+ host.clone(),
+ Trigger::Auto,
+ never()
+ ));
settle(&config).await;
assert!(!scan(host.as_ref()).await.unwrap().needed);
assert_eq!(status(&config).unwrap().state.phase, Phase::Cleaned);
@@ -53,9 +59,21 @@ async fn one_run_per_workspace_at_a_time() {
let tmp = tempfile::tempdir().unwrap();
let config = crate::memory::test_fixtures::config_in(&tmp);
let host = Arc::new(FakeHost::with(200, &config).await);
- assert!(start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));
+ assert!(start(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config.clone(),
+ host.clone(),
+ Trigger::Auto,
+ never()
+ ));
assert!(
- !start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()),
+ !start(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config.clone(),
+ host.clone(),
+ Trigger::Auto,
+ never()
+ ),
"a second start while one runs starts nothing"
);
settle(&config).await;
@@ -72,10 +90,23 @@ async fn a_stopped_run_reads_as_interrupted_and_a_tick_resumes_it() {
state::save(&config.workspace_dir, &stopped).unwrap();
assert!(status(&config).unwrap().interrupted);
- assert!(tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host.clone(), never()));
+ assert!(tick(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ host.clone(),
+ never()
+ ));
settle(&config).await;
assert_eq!(status(&config).unwrap().state.phase, Phase::Cleaned);
- assert!(!tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host, never()), "nothing left to do");
+ assert!(
+ !tick(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ host,
+ never()
+ ),
+ "nothing left to do"
+ );
}
#[tokio::test]
@@ -94,8 +125,19 @@ async fn nothing_starts_while_an_import_is_unfinished() {
)
.unwrap();
assert!(crate::memory::import::in_progress(&config));
- assert!(!start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));
- assert!(!tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host.clone(), never()));
+ assert!(!start(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config.clone(),
+ host.clone(),
+ Trigger::Auto,
+ never()
+ ));
+ assert!(!tick(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ host.clone(),
+ never()
+ ));
assert_eq!(count(host.tree.as_ref()).await, 0);
std::fs::write(
@@ -103,7 +145,13 @@ async fn nothing_starts_while_an_import_is_unfinished() {
r#"{"state":{"phase":"done","total":3,"imported":3}}"#,
)
.unwrap();
- assert!(start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));
+ assert!(start(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config.clone(),
+ host.clone(),
+ Trigger::Auto,
+ never()
+ ));
settle(&config).await;
assert_eq!(count(host.tree.as_ref()).await, 3);
}
@@ -113,7 +161,12 @@ async fn a_tick_starts_nothing_while_background_work_is_paused() {
let tmp = tempfile::tempdir().unwrap();
let config = crate::memory::test_fixtures::config_in(&tmp);
let host = Arc::new(FakeHost::with(3, &config).await);
- assert!(!tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host.clone(), Arc::new(|| true)));
+ assert!(!tick(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ host.clone(),
+ Arc::new(|| true)
+ ));
assert_eq!(count(host.tree.as_ref()).await, 0);
}
@@ -123,7 +176,13 @@ async fn retry_puts_a_lost_copy_back_in_line() {
let config = crate::memory::test_fixtures::config_in(&tmp);
let host = Arc::new(FakeHost::with(4, &config).await);
host.free.store(true, Ordering::SeqCst);
- assert!(start(&crate::core::runtime::DispatchCtx::ambient(), config.clone(), host.clone(), Trigger::Auto, never()));
+ assert!(start(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ config.clone(),
+ host.clone(),
+ Trigger::Auto,
+ never()
+ ));
settle(&config).await;
assert_eq!(status(&config).unwrap().state.phase, Phase::Cleaned);
@@ -152,5 +211,51 @@ async fn a_damaged_state_file_surfaces_as_the_hosts_engine_error() {
let error = status(&config).unwrap_err();
assert_eq!(error.code(), "ENGINE");
let host = Arc::new(FakeHost::with(1, &config).await);
- assert!(!tick(&crate::core::runtime::DispatchCtx::ambient(), &config, host, never()), "a torn state starts nothing");
+ assert!(
+ !tick(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ host,
+ never()
+ ),
+ "a torn state starts nothing"
+ );
+}
+
+/// The background run acts for the context it was handed, not for whichever
+/// context is active on the task that started it.
+#[tokio::test]
+async fn run_acts_under_the_handed_context_not_the_active_one() {
+ use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
+
+ let tmp = tempfile::tempdir().unwrap();
+ let config = crate::memory::test_fixtures::config_in(&tmp);
+ let host = Arc::new(FakeHost::with(3, &config).await);
+ let handed = CoreContext::for_test(DomainSet::full(), None);
+ let active = CoreContext::for_test(DomainSet::full(), None);
+ let seen = Arc::new(std::sync::Mutex::new(Vec::new()));
+ let recorder = Arc::clone(&seen);
+ let paused: Arc<dyn Fn() -> bool + Send + Sync> = Arc::new(move || {
+ recorder.lock().unwrap().push(CoreContext::scoped());
+ false
+ });
+ let dispatch = DispatchCtx::new(Arc::clone(&handed));
+ let started = CoreContext::scope(active, async {
+ start(
+ &dispatch,
+ config.clone(),
+ host.clone(),
+ Trigger::Auto,
+ paused,
+ )
+ })
+ .await;
+ assert!(started);
+ settle(&config).await;
+ let seen = seen.lock().unwrap();
+ assert!(!seen.is_empty(), "the run consulted the pause check");
+ for context in seen.iter() {
+ let context = context.as_ref().expect("the run has a context");
+ assert!(Arc::ptr_eq(context, &handed));
+ }
}
diff --git a/crates/openhuman-core/src/memory/lifecycle/prefetch.rs b/crates/openhuman-core/src/memory/lifecycle/prefetch.rs
index cb515b57e6..c56e32a717 100644
--- a/crates/openhuman-core/src/memory/lifecycle/prefetch.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch.rs
@@ -171,10 +171,11 @@ pub(crate) fn pre_turn(
if let Some(channel) = channel {
let workspace = config.workspace_dir.clone();
let thread = input.thread_id.clone();
- let _ = dispatch.spawn_blocking(move || {
- crate::memory::channels::record(&workspace, &channel, &thread)
- })
- .await;
+ let _ = dispatch
+ .spawn_blocking(move || {
+ crate::memory::channels::record(&workspace, &channel, &thread)
+ })
+ .await;
}
}
hooks::pre_turn_work(&dispatch, &config, &identity, input).await
diff --git a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
index ce99697d9a..bcc229201d 100644
--- a/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/prefetch_tests.rs
@@ -376,13 +376,15 @@ async fn queued_work_keeps_the_callers_core_context() {
enqueue(
cache.clone(),
key.clone(),
- Box::pin(crate::core::runtime::DispatchCtx::ambient().enter(async move {
- assert!(Arc::ptr_eq(
- &crate::core::runtime::CoreContext::scoped().unwrap(),
- &expected
- ));
- Some(pack("scoped"))
- })),
+ Box::pin(
+ crate::core::runtime::DispatchCtx::ambient().enter(async move {
+ assert!(Arc::ptr_eq(
+ &crate::core::runtime::CoreContext::scoped().unwrap(),
+ &expected
+ ));
+ Some(pack("scoped"))
+ }),
+ ),
);
drain(&cache, &key).await;
assert_eq!(completed(&cache, &key).unwrap().markdown, "scoped");
@@ -453,9 +455,12 @@ async fn an_erase_retires_queued_automatic_work_and_allows_later_work() {
);
// The current-thread executor has not polled the earlier job. Erasure
// advances the owner fence synchronously before its first suspension.
- let fence = crate::memory::tool_writes::fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config)
- .await
- .unwrap();
+ let fence = crate::memory::tool_writes::fence_and_clear(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ )
+ .await
+ .unwrap();
let new_count = later.clone();
enqueue(
cache.clone(),
@@ -503,10 +508,13 @@ async fn erase_waits_for_current_automatic_work_before_returning_its_barrier() {
);
started.notified().await;
let erase_config = config.clone();
- let mut fencing =
- tokio::spawn(
- async move { crate::memory::tool_writes::fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &erase_config).await },
- );
+ let mut fencing = tokio::spawn(async move {
+ crate::memory::tool_writes::fence_and_clear(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &erase_config,
+ )
+ .await
+ });
assert!(
tokio::time::timeout(Duration::from_secs(1), &mut fencing)
.await
diff --git a/crates/openhuman-core/src/memory/ops_tests.rs b/crates/openhuman-core/src/memory/ops_tests.rs
index 0f61bebb8e..8e54434dfc 100644
--- a/crates/openhuman-core/src/memory/ops_tests.rs
+++ b/crates/openhuman-core/src/memory/ops_tests.rs
@@ -432,9 +432,13 @@ async fn erase_all_needs_its_confirmation() {
let config = config_in(&tmp);
let engine = bind_reference(&config);
learn(&config, learn_params("a fact"), None).await.unwrap();
- let error = erase_all(&crate::core::runtime::DispatchCtx::ambient(), &config, EraseAllParams { confirm: false })
- .await
- .unwrap_err();
+ let error = erase_all(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ EraseAllParams { confirm: false },
+ )
+ .await
+ .unwrap_err();
assert_eq!(error.code(), INVALID_REQUEST);
assert_eq!(stored(&engine, MetaFilter::default()).await.len(), 1);
}
@@ -448,9 +452,13 @@ async fn erase_all_erases_everything_the_engine_holds() {
learn(&config, learn_params("another fact"), None)
.await
.unwrap();
- let view = erase_all(&crate::core::runtime::DispatchCtx::ambient(), &config, EraseAllParams { confirm: true })
- .await
- .unwrap();
+ let view = erase_all(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ EraseAllParams { confirm: true },
+ )
+ .await
+ .unwrap();
assert!(view.erased_scopes >= 1, "{view:?}");
assert!(stored(&engine, MetaFilter::default()).await.is_empty());
}
@@ -459,9 +467,13 @@ async fn erase_all_erases_everything_the_engine_holds() {
async fn erase_all_reports_memory_off_without_an_engine() {
let tmp = tempfile::tempdir().unwrap();
let config = config_in(&tmp);
- let error = erase_all(&crate::core::runtime::DispatchCtx::ambient(), &config, EraseAllParams { confirm: true })
- .await
- .unwrap_err();
+ let error = erase_all(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ EraseAllParams { confirm: true },
+ )
+ .await
+ .unwrap_err();
assert_eq!(error.code(), MEMORY_OFF);
}
@@ -481,9 +493,13 @@ async fn erasing_memory_cancels_queued_learning_so_restart_cannot_restore_it() {
)
.unwrap();
assert!(queued["status"].as_str().unwrap().starts_with("queued"));
- erase_all(&crate::core::runtime::DispatchCtx::ambient(), &config, EraseAllParams { confirm: true })
- .await
- .unwrap();
+ erase_all(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ EraseAllParams { confirm: true },
+ )
+ .await
+ .unwrap();
let restarted = config.clone();
crate::memory::tool_writes::drain(&restarted).await;
assert!(stored(&engine, MetaFilter::default()).await.is_empty());
diff --git a/crates/openhuman-core/src/memory/schemas/handlers.rs b/crates/openhuman-core/src/memory/schemas/handlers.rs
index 0dd41fee7f..aa3e025270 100644
--- a/crates/openhuman-core/src/memory/schemas/handlers.rs
+++ b/crates/openhuman-core/src/memory/schemas/handlers.rs
@@ -266,7 +266,8 @@ pub(super) fn sources_sync(ctx: DispatchCtx, params: Map<String, Value>) -> Cont
Box::pin(async move {
let params = parse::<SourcesSyncParams>(params)?;
let config = load(&ctx).await?;
- let started = sources::start_sync(&ctx, &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 })
})
}
diff --git a/crates/openhuman-core/src/memory/sources/sync.rs b/crates/openhuman-core/src/memory/sources/sync.rs
index 058612e262..aef249c028 100644
--- a/crates/openhuman-core/src/memory/sources/sync.rs
+++ b/crates/openhuman-core/src/memory/sources/sync.rs
@@ -232,7 +232,11 @@ pub fn start_sync(
/// The scheduled tick: starts every source whose `schedule_mins` has elapsed.
/// Returns the ids started. Memory off starts nothing.
-pub fn sync_due(ctx: &crate::core::runtime::DispatchCtx, 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();
}
diff --git a/crates/openhuman-core/src/memory/sources/sync_tests.rs b/crates/openhuman-core/src/memory/sources/sync_tests.rs
index e60f322e8d..43a918f9c9 100644
--- a/crates/openhuman-core/src/memory/sources/sync_tests.rs
+++ b/crates/openhuman-core/src/memory/sources/sync_tests.rs
@@ -118,7 +118,12 @@ async fn start_sync_walks_syncing_then_idle_and_records_items() {
.sources
.push(folder_source("src-ok", &dir, None));
- let started = start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, Some("src-ok")).unwrap();
+ let started = start_sync(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Some("src-ok"),
+ )
+ .unwrap();
assert_eq!(started, vec!["src-ok".to_string()]);
let done = wait_for_idle(&config, "src-ok").await;
assert_eq!(done.status, SourceStatus::Idle);
@@ -155,16 +160,26 @@ fn start_sync_refuses_unknown_ids_and_memory_off() {
let tmp = tempfile::tempdir().unwrap();
let config = config_in(&tmp);
assert_eq!(
- start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, None).unwrap_err().code(),
+ start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, None)
+ .unwrap_err()
+ .code(),
crate::memory::error::MEMORY_OFF
);
bind_reference(&config);
assert_eq!(
- start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, Some("src-nope")).unwrap_err().code(),
+ start_sync(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Some("src-nope")
+ )
+ .unwrap_err()
+ .code(),
INVALID_REQUEST
);
assert!(
- start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, None).unwrap().is_empty(),
+ start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, None)
+ .unwrap()
+ .is_empty(),
"no sources, nothing started"
);
}
@@ -182,9 +197,24 @@ async fn a_source_already_syncing_is_not_started_twice() {
// Hold a claim as a running sync would: a second request starts nothing.
let held = syncer_for(&config).start(Some("src-once")).unwrap();
assert_eq!(held.len(), 1);
- assert!(start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, Some("src-once")).unwrap().is_empty());
+ assert!(start_sync(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Some("src-once")
+ )
+ .unwrap()
+ .is_empty());
drop(held);
- assert_eq!(start_sync(&crate::core::runtime::DispatchCtx::ambient(), &config, Some("src-once")).unwrap().len(), 1);
+ assert_eq!(
+ start_sync(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Some("src-once")
+ )
+ .unwrap()
+ .len(),
+ 1
+ );
wait_for_idle(&config, "src-once").await;
}
@@ -216,7 +246,11 @@ async fn sync_due_starts_only_scheduled_sources_that_are_due() {
wait_for_idle(&config, "src-sched").await;
// Fifteen minutes later everything scheduled is due again; manual never is.
- let later = sync_due(&crate::core::runtime::DispatchCtx::ambient(), &config, now + chrono::Duration::minutes(16));
+ let later = sync_due(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ now + chrono::Duration::minutes(16),
+ );
assert!(later.contains(&"src-sched".to_string()));
assert!(later.contains(&"src-fresh".to_string()));
assert!(!later.contains(&"src-manual".to_string()));
@@ -232,7 +266,12 @@ fn sync_due_with_memory_off_starts_nothing() {
.memory
.sources
.push(folder_source("s", tmp.path(), Some(15)));
- assert!(sync_due(&crate::core::runtime::DispatchCtx::ambient(), &config, Utc::now()).is_empty());
+ assert!(sync_due(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Utc::now()
+ )
+ .is_empty());
}
#[test]
diff --git a/crates/openhuman-core/src/memory/tool_writes.rs b/crates/openhuman-core/src/memory/tool_writes.rs
index aae3a8292a..55dc1a773b 100644
--- a/crates/openhuman-core/src/memory/tool_writes.rs
+++ b/crates/openhuman-core/src/memory/tool_writes.rs
@@ -423,7 +423,10 @@ impl Drop for WriteFence {
/// Stops each owner partition after its current mutation, durably clears
/// earlier pending writes, and fences subsequent writes through explicit erase.
/// Other owners sharing a workspace keep independent queues and barriers.
-pub(crate) async fn fence_and_clear(ctx: &crate::core::runtime::DispatchCtx, config: &Config) -> MemoryResult<WriteFence> {
+pub(crate) async fn fence_and_clear(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+) -> MemoryResult<WriteFence> {
let state = owner_state(config);
let token = state.gate.begin_fence();
let fencing_generation = token.generation();
@@ -456,7 +459,11 @@ pub(crate) async fn fence_and_clear(ctx: &crate::core::runtime::DispatchCtx, con
/// Starts a scoped background drain, retaining config only in memory.
///
/// `root` is the layout root the write was queued under (`CallFacts::reach`).
-pub(super) fn schedule(ctx: &crate::core::runtime::DispatchCtx, config: Arc<Config>, root: &Namespace) {
+pub(super) fn schedule(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: Arc<Config>,
+ root: &Namespace,
+) {
let file = queue_path(&config, root);
schedule_partition(ctx, config, file);
}
@@ -469,19 +476,19 @@ pub(super) fn schedule_all(ctx: &crate::core::runtime::DispatchCtx, config: Arc<
let scan_ctx = ctx.clone();
ctx.spawn(async move {
let scan_config = config.clone();
- let files =
- match scan_ctx.spawn_blocking(move || partitions(&scan_config))
- .await
- {
- Ok(Ok(files)) => files,
- _ => {
- tracing::debug!(
- code = "QUEUE_UNAVAILABLE",
- "[memory:tool_writes] retry discovery deferred"
- );
- return;
- }
- };
+ let files = match scan_ctx
+ .spawn_blocking(move || partitions(&scan_config))
+ .await
+ {
+ Ok(Ok(files)) => files,
+ _ => {
+ tracing::debug!(
+ code = "QUEUE_UNAVAILABLE",
+ "[memory:tool_writes] retry discovery deferred"
+ );
+ return;
+ }
+ };
for file in files {
schedule_partition(&scan_ctx, config.clone(), file);
}
diff --git a/crates/openhuman-core/src/memory/tool_writes_tests.rs b/crates/openhuman-core/src/memory/tool_writes_tests.rs
index 7a821ba722..c04ec8e9f4 100644
--- a/crates/openhuman-core/src/memory/tool_writes_tests.rs
+++ b/crates/openhuman-core/src/memory/tool_writes_tests.rs
@@ -392,7 +392,9 @@ async fn an_erase_fence_clears_prior_pending_learnings_across_restart() {
&facts(&config),
)
.unwrap();
- let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config).await.unwrap();
+ let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config)
+ .await
+ .unwrap();
assert!(read(&config.workspace_dir).unwrap().is_empty());
drop(fence);
let restarted = config_in(&tmp);
@@ -424,10 +426,16 @@ async fn an_erase_fence_waits_for_only_the_current_write_and_preserves_later_enq
&facts(&config),
)
.unwrap();
- schedule(&crate::core::runtime::DispatchCtx::ambient(), Arc::new(config.clone()), &Namespace::ROOT);
+ schedule(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ Arc::new(config.clone()),
+ &Namespace::ROOT,
+ );
engine.entered.notified().await;
let fence_config = config.clone();
- let fencing = tokio::spawn(async move { fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &fence_config).await });
+ let fencing = tokio::spawn(async move {
+ fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &fence_config).await
+ });
let state = owner_state(&config);
while !state.gate.is_fenced() {
tokio::task::yield_now().await;
@@ -458,7 +466,11 @@ async fn an_erase_fence_waits_for_only_the_current_write_and_preserves_later_enq
&facts(&config),
)
.unwrap();
- schedule(&crate::core::runtime::DispatchCtx::ambient(), Arc::new(config.clone()), &Namespace::ROOT);
+ schedule(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ Arc::new(config.clone()),
+ &Namespace::ROOT,
+ );
assert_eq!(read(&config.workspace_dir).unwrap().len(), 2);
drop(fence);
drain(&config).await;
@@ -491,7 +503,9 @@ async fn separate_owner_roots_share_a_workspace_without_blocking_or_erasing_each
&facts(&second),
)
.unwrap();
- let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &first).await.unwrap();
+ let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &first)
+ .await
+ .unwrap();
assert_eq!(
drain(&second).await,
1,
@@ -524,7 +538,9 @@ async fn erasing_one_owner_fences_pending_writes_from_every_team_root() {
&facts(&second),
)
.unwrap();
- let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &first).await.unwrap();
+ let fence = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &first)
+ .await
+ .unwrap();
assert!(read_at(&queue_path(&first, &facts(&first).reach.at))
.unwrap()
.is_empty());
@@ -542,7 +558,9 @@ async fn erasing_one_owner_fences_pending_writes_from_every_team_root() {
async fn a_later_erase_clears_pending_writes_admitted_during_the_first_erase() {
let tmp = tempfile::tempdir().unwrap();
let config = config_in(&tmp);
- let first = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config).await.unwrap();
+ let first = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config)
+ .await
+ .unwrap();
enqueue(
&config,
&json!({"action":"learn","text":"Queued after the first erase began"}),
@@ -550,7 +568,9 @@ async fn a_later_erase_clears_pending_writes_admitted_during_the_first_erase() {
)
.unwrap();
drop(first);
- let second = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config).await.unwrap();
+ let second = fence_and_clear(&crate::core::runtime::DispatchCtx::ambient(), &config)
+ .await
+ .unwrap();
assert!(
read(&config.workspace_dir).unwrap().is_empty(),
"the second erase must discard a learning admitted before it started"
diff --git a/crates/openhuman-core/src/memory/tools.rs b/crates/openhuman-core/src/memory/tools.rs
index 0448d82567..e9d1530cea 100644
--- a/crates/openhuman-core/src/memory/tools.rs
+++ b/crates/openhuman-core/src/memory/tools.rs
@@ -391,10 +391,9 @@ impl Tool for MemoryTool {
let config = self.config.clone();
let write_args = args.clone();
let queued_root = facts.reach.at.clone();
- let queued = dispatch.spawn_blocking(move || {
- super::tool_writes::enqueue(&config, &write_args, &facts)
- })
- .await;
+ let queued = dispatch
+ .spawn_blocking(move || super::tool_writes::enqueue(&config, &write_args, &facts))
+ .await;
return Ok(
match queued.unwrap_or_else(|_| {
Err(MemoryError::Unavailable(
diff --git a/crates/openhuman-core/src/threads/ops/edit.rs b/crates/openhuman-core/src/threads/ops/edit.rs
index ceb4e4c1c4..57dc8990ad 100644
--- a/crates/openhuman-core/src/threads/ops/edit.rs
+++ b/crates/openhuman-core/src/threads/ops/edit.rs
@@ -181,19 +181,20 @@ pub async fn regenerate(
let store_for_blocking = store.clone();
let thread_id_for_blocking = thread_id.clone();
let target_for_blocking = target_request_id.clone();
- let (prompt, cut_request_id) = ctx.spawn_blocking(move || {
- truncate_transcript_for_regenerate(
- &store_for_blocking,
- &thread_id_for_blocking,
- target_for_blocking.as_deref(),
- )
- })
- .await
- .map_err(|e| ThreadsError::Message(format!("truncate transcript task: {e}")))?
- .map_err(ThreadsError::Message)?
- .ok_or_else(|| {
- ThreadsError::Message(format!("thread {thread_id} has no turn to regenerate"))
- })?;
+ let (prompt, cut_request_id) = ctx
+ .spawn_blocking(move || {
+ truncate_transcript_for_regenerate(
+ &store_for_blocking,
+ &thread_id_for_blocking,
+ target_for_blocking.as_deref(),
+ )
+ })
+ .await
+ .map_err(|e| ThreadsError::Message(format!("truncate transcript task: {e}")))?
+ .map_err(ThreadsError::Message)?
+ .ok_or_else(|| {
+ ThreadsError::Message(format!("thread {thread_id} has no turn to regenerate"))
+ })?;
clear_dropped_turn_states(&dir, &thread_id, &cut_request_id).await;
super::delete_after(ctx, &thread_id, &run_reply_message_id(&cut_request_id)).await?;