Skip to content

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

style: reformat long lines and add a close test

Steven Enamakel3107b57d12ea
diff --git a/crates/openhuman-core/src/integrations/composio/trigger_history.rs b/crates/openhuman-core/src/integrations/composio/trigger_history.rs
index 4b1fbc5aa1..5c8c644923 100644
--- a/crates/openhuman-core/src/integrations/composio/trigger_history.rs
+++ b/crates/openhuman-core/src/integrations/composio/trigger_history.rs
@@ -159,10 +159,7 @@ impl TriggerHistory {
}
/// Release the module resource while retaining all persisted documents.
- pub async fn close(
- &self,
- ctx: &crate::core::runtime::DispatchCtx,
- ) -> Result<(), String> {
+ pub async fn close(&self, ctx: &crate::core::runtime::DispatchCtx) -> Result<(), String> {
let lease = Arc::clone(&self.lease);
ctx.spawn(async move { Self::release(&mut *lease.lock_owned().await).await })
.await
@@ -193,9 +190,7 @@ pub fn global() -> Option<Arc<TriggerHistory>> {
}
/// Close an existing lease on sign-out or runtime shutdown; never load at exit.
-pub(crate) async fn close_global(
- ctx: &crate::core::runtime::DispatchCtx,
-) -> Result<(), String> {
+pub(crate) async fn close_global(ctx: &crate::core::runtime::DispatchCtx) -> Result<(), String> {
match global() {
Some(store) => store.close(ctx).await,
None => Ok(()),
diff --git a/crates/openhuman-core/src/integrations/composio/trigger_history_tests.rs b/crates/openhuman-core/src/integrations/composio/trigger_history_tests.rs
index 8fd509e52f..0ed9992c27 100644
--- a/crates/openhuman-core/src/integrations/composio/trigger_history_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/trigger_history_tests.rs
@@ -23,7 +23,30 @@ async fn disabled_archive_operations_leave_the_host_filesystem_untouched() {
.contains("module unavailable"));
assert!(!workspace.path().join("state").exists());
assert!(owner.lease.lock().await.is_none());
- owner.close(&crate::core::runtime::DispatchCtx::default()).await.unwrap();
+ owner
+ .close(&crate::core::runtime::DispatchCtx::default())
+ .await
+ .unwrap();
+}
+
+#[tokio::test]
+async fn close_releases_under_the_explicit_ctx_not_the_scoped_one() {
+ use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
+ let owner = TriggerHistory {
+ initial_workspace: std::path::PathBuf::from("unused"),
+ lease: Arc::new(Mutex::new(None)),
+ #[cfg(feature = "modules")]
+ fixture: None,
+ };
+ let scoped = Arc::new(CoreContext::for_test(DomainSet::full(), None));
+ let explicit = DispatchCtx::new(Arc::new(CoreContext::for_test(DomainSet::full(), None)));
+ // A scope for another context is active; the release task is spawned by the
+ // explicit context and completes without consulting the scoped one.
+ CoreContext::scope(scoped, async {
+ owner.close(&explicit).await.unwrap();
+ })
+ .await;
+ assert!(owner.lease.lock().await.is_none());
}
#[cfg(feature = "modules")]
@@ -133,8 +156,14 @@ async fn changing_users_releases_the_old_archive_before_opening_the_next_scope()
)
.await
.unwrap();
- owner.close(&crate::core::runtime::DispatchCtx::default()).await.unwrap();
- owner.close(&crate::core::runtime::DispatchCtx::default()).await.unwrap();
+ owner
+ .close(&crate::core::runtime::DispatchCtx::default())
+ .await
+ .unwrap();
+ owner
+ .close(&crate::core::runtime::DispatchCtx::default())
+ .await
+ .unwrap();
assert_eq!(
*calls.lock().await,
vec![
@@ -176,7 +205,10 @@ async fn cancelling_a_pending_open_retains_a_handle_that_shutdown_can_release()
opening.abort();
assert!(opening.await.unwrap_err().is_cancelled());
observed.open_continue.notify_one();
- owner.close(&crate::core::runtime::DispatchCtx::default()).await.unwrap();
+ owner
+ .close(&crate::core::runtime::DispatchCtx::default())
+ .await
+ .unwrap();
assert_eq!(
*observed.calls.lock().await,
vec!["open:cancelled/state", "close:cancelled/state"]
diff --git a/crates/openhuman-core/src/voice/cli.rs b/crates/openhuman-core/src/voice/cli.rs
index cfcd5042d4..5a7a6620e3 100644
--- a/crates/openhuman-core/src/voice/cli.rs
+++ b/crates/openhuman-core/src/voice/cli.rs
@@ -101,9 +101,13 @@ pub(crate) fn run_standalone_subcommand(args: &[String]) -> Result<()> {
custom_dictionary: config.voice_server.custom_dictionary.clone(),
};
- run_standalone(&crate::core::runtime::DispatchCtx::host_default(), config, server_config)
- .await
- .map_err(anyhow::Error::msg)
+ run_standalone(
+ &crate::core::runtime::DispatchCtx::host_default(),
+ config,
+ server_config,
+ )
+ .await
+ .map_err(anyhow::Error::msg)
})?;
Ok(())
diff --git a/crates/openhuman-core/src/voice/server/hotkey_listener_tests.rs b/crates/openhuman-core/src/voice/server/hotkey_listener_tests.rs
index 72ce731e65..873c809b4e 100644
--- a/crates/openhuman-core/src/voice/server/hotkey_listener_tests.rs
+++ b/crates/openhuman-core/src/voice/server/hotkey_listener_tests.rs
@@ -227,7 +227,13 @@ async fn listener_fixture() -> (
async fn cancelling_startup_still_closes_the_module_owned_listener_fixture() {
let (client, fixture, _service) = listener_fixture().await;
let startup = tokio::spawn(async move {
- start_globe_with_client(&crate::core::runtime::DispatchCtx::default(), client, Push, &CancellationToken::new()).await
+ start_globe_with_client(
+ &crate::core::runtime::DispatchCtx::default(),
+ client,
+ Push,
+ &CancellationToken::new(),
+ )
+ .await
});
fixture.entered.notified().await;
startup.abort();
@@ -246,9 +252,14 @@ async fn cancelling_startup_still_closes_the_module_owned_listener_fixture() {
async fn stopping_listener_joins_its_bus_cleanup_fixture() {
let (client, fixture, _service) = listener_fixture().await;
fixture.allow_start.notify_one();
- let (handle, _rx) = start_globe_with_client(&crate::core::runtime::DispatchCtx::default(), client, Push, &CancellationToken::new())
- .await
- .unwrap();
+ let (handle, _rx) = start_globe_with_client(
+ &crate::core::runtime::DispatchCtx::default(),
+ client,
+ Push,
+ &CancellationToken::new(),
+ )
+ .await
+ .unwrap();
handle.stop().await;
assert_eq!(fixture.closes.load(std::sync::atomic::Ordering::SeqCst), 1);
}
@@ -260,11 +271,14 @@ async fn lost_start_reply_recovers_the_lease_before_releasing_admission_fixture(
.lose_start_reply
.store(true, std::sync::atomic::Ordering::SeqCst);
fixture.allow_start.notify_one();
- assert!(
- start_globe_with_client(&crate::core::runtime::DispatchCtx::default(), client, Push, &CancellationToken::new())
- .await
- .is_err()
- );
+ assert!(start_globe_with_client(
+ &crate::core::runtime::DispatchCtx::default(),
+ client,
+ Push,
+ &CancellationToken::new()
+ )
+ .await
+ .is_err());
tokio::time::timeout(
std::time::Duration::from_secs(5),
fixture.stopped.notified(),
@@ -281,9 +295,14 @@ async fn failed_close_retains_ownership_until_the_module_confirms_cleanup_fixtur
.fail_close
.store(true, std::sync::atomic::Ordering::SeqCst);
fixture.allow_start.notify_one();
- let (handle, _rx) = start_globe_with_client(&crate::core::runtime::DispatchCtx::default(), client, Push, &CancellationToken::new())
- .await
- .unwrap();
+ let (handle, _rx) = start_globe_with_client(
+ &crate::core::runtime::DispatchCtx::default(),
+ client,
+ Push,
+ &CancellationToken::new(),
+ )
+ .await
+ .unwrap();
handle.stop().await;
assert_eq!(fixture.closes.load(std::sync::atomic::Ordering::SeqCst), 1);
}