Skip to content

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

fix: retain scoped runtime context in module and voice tasks

Steven Enamakel528f40e7829e
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod.rs b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
index c6d5ef281c..1e8a24b16d 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/mod.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
@@ -414,9 +414,7 @@ mod repl_module_tests;
pub async fn query(
request: tinyjuice_bus::wire::QueryRequest,
) -> Result<tinyjuice_bus::wire::QueryResponse, String> {
- let config = crate::config::Config::load_or_init()
- .await
- .map_err(|e| e.to_string())?;
+ let config = crate::config::ops::load_config_with_timeout().await?;
query_for_config(&config, request).await
}
@@ -433,9 +431,7 @@ pub(crate) async fn query_for_config(
/// Extract HTML through the compiled module independently of compression settings.
pub async fn extract_html(html: String) -> Result<String, String> {
- let config = crate::config::Config::load_or_init()
- .await
- .map_err(|e| e.to_string())?;
+ let config = crate::config::ops::load_config_with_timeout().await?;
let response: tinyjuice_bus::wire::HtmlResponse = client(&config)
.call("tinyjuice", methods::EXTRACT_HTML, (html,))
.await
diff --git a/crates/openhuman-core/src/integrations/composio/trigger_history.rs b/crates/openhuman-core/src/integrations/composio/trigger_history.rs
index a271a24751..2e6ddf633b 100644
--- a/crates/openhuman-core/src/integrations/composio/trigger_history.rs
+++ b/crates/openhuman-core/src/integrations/composio/trigger_history.rs
@@ -84,7 +84,7 @@ impl TriggerHistory {
let client = self.client(&config);
// Keep ownership installation running if the caller is cancelled while
// OpenArchive completes. A later close can still release the handle.
- tokio::spawn(async move {
+ crate::core::runtime::spawn_scoped(async move {
let mut guard = lease.lock_owned().await;
Self::ensure_lease(&config, &mut guard, client).await?;
Ok(guard)
@@ -154,9 +154,11 @@ impl TriggerHistory {
/// Release the module resource while retaining all persisted documents.
pub async fn close(&self) -> Result<(), String> {
let lease = Arc::clone(&self.lease);
- tokio::spawn(async move { Self::release(&mut *lease.lock_owned().await).await })
- .await
- .map_err(|_| "trigger archive release task failed".to_owned())?
+ crate::core::runtime::spawn_scoped(async move {
+ Self::release(&mut *lease.lock_owned().await).await
+ })
+ .await
+ .map_err(|_| "trigger archive release task failed".to_owned())?
}
}
diff --git a/crates/openhuman-core/src/voice/audio_capture.rs b/crates/openhuman-core/src/voice/audio_capture.rs
index 4b5e8d4204..84f67c94f8 100644
--- a/crates/openhuman-core/src/voice/audio_capture.rs
+++ b/crates/openhuman-core/src/voice/audio_capture.rs
@@ -170,10 +170,12 @@ pub async fn start_recording(config: &Config) -> Result<RecordingHandle, String>
.microphone_permission(true)
.await
.map_err(|e| e.to_string())?;
- let inner = tokio::task::spawn_blocking(|| tinyvoice::capture::start_recording(|| Ok(())))
- .await
- .map_err(|e| format!("microphone setup task failed: {e}"))?
- .map_err(|e| e.to_string())?;
+ let inner = crate::core::runtime::spawn_blocking_scoped(|| {
+ tinyvoice::capture::start_recording(|| Ok(()))
+ })
+ .await
+ .map_err(|e| format!("microphone setup task failed: {e}"))?
+ .map_err(|e| e.to_string())?;
Ok(RecordingHandle {
inner: Some(inner),
#[cfg(test)]
diff --git a/crates/openhuman-core/src/voice/server/hotkey_listener.rs b/crates/openhuman-core/src/voice/server/hotkey_listener.rs
index 4d325ed981..7c95f0741c 100644
--- a/crates/openhuman-core/src/voice/server/hotkey_listener.rs
+++ b/crates/openhuman-core/src/voice/server/hotkey_listener.rs
@@ -86,7 +86,7 @@ pub(super) async fn start_hotkey_listener(
let (handle, mut source) =
hotkey::start_listener(combo, mode).map_err(|e| e.to_string())?;
let (tx, rx) = tokio::sync::mpsc::channel(65);
- tokio::spawn(async move {
+ crate::core::runtime::spawn_scoped(async move {
loop {
let event = tokio::select! {
_ = tx.closed() => break,
@@ -143,7 +143,7 @@ async fn start_globe_with_client(
let (ready_tx, ready_rx) = tokio::sync::oneshot::channel();
let cancel = server_cancel.child_token();
let task_cancel = cancel.clone();
- let task = tokio::spawn(async move {
+ let task = crate::core::runtime::spawn_scoped(async move {
let _admission = admission;
let started = match client.globe_start().await {
Ok(started) => started,
diff --git a/crates/openhuman-core/src/voice/server/runtime.rs b/crates/openhuman-core/src/voice/server/runtime.rs
index 92bd606426..5df42fea59 100644
--- a/crates/openhuman-core/src/voice/server/runtime.rs
+++ b/crates/openhuman-core/src/voice/server/runtime.rs
@@ -217,7 +217,7 @@ impl VoiceServer {
// event loop remains responsive to Release.
let (tx, rx) = tokio::sync::oneshot::channel();
let capture_config = app_config.clone();
- tokio::spawn(async move {
+ crate::core::runtime::spawn_scoped(async move {
let expected_app = capture_expected_app_name(&capture_config).await;
let result = audio_capture::start_recording(&capture_config).await
.map(|handle| (handle, expected_app));
@@ -416,7 +416,7 @@ impl VoiceServer {
"{LOG_PREFIX} [pipeline={pipeline_id}] spawning process_recording (generation={generation})"
);
- tokio::spawn(async move {
+ crate::core::runtime::spawn_scoped(async move {
process_recording_bg(
&pipeline_id,
handle,
diff --git a/scripts/ci/saas-ambient-baseline.json b/scripts/ci/saas-ambient-baseline.json
index cabd83d85b..afc69eb95f 100644
--- a/scripts/ci/saas-ambient-baseline.json
+++ b/scripts/ci/saas-ambient-baseline.json
@@ -671,13 +671,6 @@
"text": "tokio::spawn(async move { on_connection_created(toolkit, connection_id).await });",
"occurrence": 1
},
- {
- "rule": "bare-spawn",
- "path": "crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs",
- "line": 103,
- "text": "match tokio::task::spawn_blocking(move || {",
- "occurrence": 1
- },
{
"rule": "bare-spawn",
"path": "crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber.rs",
@@ -1161,27 +1154,6 @@
"text": "tokio::spawn(async move {",
"occurrence": 1
},
- {
- "rule": "bare-spawn",
- "path": "crates/openhuman-core/src/voice/server/hotkey_listener.rs",
- "line": 120,
- "text": "tokio::spawn(async move {",
- "occurrence": 1
- },
- {
- "rule": "bare-spawn",
- "path": "crates/openhuman-core/src/voice/server/runtime.rs",
- "line": 218,
- "text": "tokio::task::spawn_blocking(move || {",
- "occurrence": 1
- },
- {
- "rule": "bare-spawn",
- "path": "crates/openhuman-core/src/voice/server/runtime.rs",
- "line": 418,
- "text": "tokio::spawn(async move {",
- "occurrence": 1
- },
{
"rule": "bare-spawn",
"path": "crates/openhuman-core/src/voice/server/singleton.rs",