Skip to content

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

chore(runtime): add debug tracking for derived context leaks

Steven Enamakel369630f99d76
diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rs
index 35ecce5aa2..b6ab56aeee 100644
--- a/crates/openhuman-core/src/core/runtime/context.rs
+++ b/crates/openhuman-core/src/core/runtime/context.rs
@@ -308,7 +308,9 @@ impl CoreContext {
profile_admission,
agent,
bare: self.bare,
- })
+ });
+ if dbg_shares { DBG_DERIVED.lock().unwrap().push((Arc::downgrade(&dbg_new), std::backtrace::Backtrace::force_capture().to_string())); }
+ dbg_new
}
/// The agent a host session store scopes work under this context to, if
@@ -511,3 +513,5 @@ mod test_support;
#[cfg(test)]
#[path = "context_tests.rs"]
mod tests;
+
+pub static DBG_DERIVED: std::sync::Mutex<Vec<(std::sync::Weak<CoreContext>, String)>> = std::sync::Mutex::new(Vec::new());
diff --git a/crates/openhuman-core/src/core/runtime/context_agent.rs b/crates/openhuman-core/src/core/runtime/context_agent.rs
index 97e0f794d4..070c17aabe 100644
--- a/crates/openhuman-core/src/core/runtime/context_agent.rs
+++ b/crates/openhuman-core/src/core/runtime/context_agent.rs
@@ -90,7 +90,7 @@ impl CoreContext {
///
/// A host must not close or evict a tenant while this is `true`: its
/// in-flight tables (turns, queues, caches) live in those slots.
- pub fn debug_counts(self: &Arc<Self>) -> usize { Arc::strong_count(&self.agent.state) }
+ pub fn debug_counts(self: &Arc<Self>) -> usize { let n = Arc::strong_count(&self.agent.state); if n > 1 { for (w, bt) in super::DBG_DERIVED.lock().unwrap().iter() { if let Some(c) = w.upgrade() { if Arc::ptr_eq(&c.agent.state, &self.agent.state) && !Arc::ptr_eq(&c, self) { log::warn!("DBGLEAK {}", bt.lines().filter(|l| l.contains("openhuman")).take(14).collect::<Vec<_>>().join(" | ")); } } } } n }
pub fn tenant_in_use(self: &Arc<Self>) -> bool {
Arc::strong_count(self) > 1 || Arc::strong_count(&self.agent.state) > 1