Skip to content

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

refactor(agent): keep the request journal map in the agent context's slot (#7032)

oxoxDeve3270e29587a
diff --git a/crates/openhuman-core/src/agent/tinyagents/journal.rs b/crates/openhuman-core/src/agent/tinyagents/journal.rs
index 6a1e3eb52a..ea918d060a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/journal.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/journal.rs
@@ -47,7 +47,6 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
-use once_cell::sync::Lazy;
use tinyagents_harness::events::{EventSink, HarnessRunStatus};
use tinyagents_harness::ids::{ComponentId, HarnessPhase, RunId, ThreadId};
@@ -62,11 +61,14 @@ use tinyagents_session::transcript::import::ops::open_session_stores;
/// Best-effort live request → durable tinyagents journal stream map. The web
/// progress bridge uses this at turn end to shadow-project spans from the
/// journal and compare them against the live `SpanCollector` path during C4 S3.
-static REQUEST_JOURNAL_RUNS: Lazy<Mutex<HashMap<String, String>>> =
- Lazy::new(|| Mutex::new(HashMap::new()));
+fn request_journal_runs() -> std::sync::Arc<RequestJournalRuns> {
+ crate::core::runtime::current_slot::<RequestJournalRuns>()
+}
+
+type RequestJournalRuns = Mutex<HashMap<String, String>>;
pub(crate) fn register_request_journal_run(request_id: &str, run_id: &str) {
- match REQUEST_JOURNAL_RUNS.lock() {
+ match request_journal_runs().lock() {
Ok(mut runs) => {
runs.insert(request_id.to_string(), run_id.to_string());
log::debug!(
@@ -85,7 +87,7 @@ pub(crate) fn register_request_journal_run(request_id: &str, run_id: &str) {
}
pub(crate) fn take_request_journal_run(request_id: &str) -> Option<String> {
- REQUEST_JOURNAL_RUNS
+ request_journal_runs()
.lock()
.ok()
.and_then(|mut runs| runs.remove(request_id))
diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rs
index ed5e060ae9..77fe2d2ced 100644
--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs
+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs
@@ -333,7 +333,7 @@ pub(crate) fn spawn_progress_bridge(
std::sync::Mutex<Option<super::turn_timing::TurnTimingSnapshot>>,
> = std::sync::Arc::new(std::sync::Mutex::new(None));
let timing_snapshot_for_task = timing_snapshot.clone();
- tokio::spawn(async move {
+ crate::core::runtime::spawn_scoped(async move {
log::debug!(
"[web_channel][bridge] spawned client_id={} thread_id={} request_id={} speak_reply={:?} source={:?} session_id={:?}",
client_id,