The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(inbound): clamp debounce deadlines instead of overflowing
oxoxDevbd09f9a2e337
diff --git a/crates/openhuman-core/src/inbound_debounce/README.md b/crates/openhuman-core/src/inbound_debounce/README.mdindex ac1f22a8a1..c0be07617b 100644--- a/crates/openhuman-core/src/inbound_debounce/README.md+++ b/crates/openhuman-core/src/inbound_debounce/README.md@@ -26,6 +26,8 @@ from `channels/runtime/dispatch/processor.rs`; other hosts reach it through`debounce` otherwise.- A batch never waits past `first push + max_wait`. `max_wait` is raised toat least the longer of the two windows.+- Windows and waits longer than `MAX_WINDOW` (one year) are clamped, so an+ oversized setting can never overflow the deadline arithmetic.- A zero window seals the item at once, so `DebounceSettings::immediate()`gives one batch per item while still serializing each key.diff --git a/crates/openhuman-core/src/inbound_debounce/mod.rs b/crates/openhuman-core/src/inbound_debounce/mod.rsindex eed3cb3a8b..0a9128450b 100644--- a/crates/openhuman-core/src/inbound_debounce/mod.rs+++ b/crates/openhuman-core/src/inbound_debounce/mod.rs@@ -15,6 +15,9 @@ use tokio::time::Instant;/// quiet window but is still serialized.pub const MAX_TRACKED_KEYS: usize = 2048;+/// Longest window or wait the debouncer arms; longer settings are clamped.+pub const MAX_WINDOW: Duration = Duration::from_secs(365 * 24 * 60 * 60);+/// What the debouncer needs to know about a buffered item.pub trait DebounceItem {/// Size counted against [`DebounceSettings::max_batch_chars`].@@ -203,14 +206,14 @@ impl<K: Eq + Hash + Clone, T: DebounceItem> KeyedDebouncer<K, T> {chars: 0,media: false,quiet_at: now,- deadline: now + settings.effective_max_wait(),+ deadline: after(now, settings.effective_max_wait()),}});open.media |= item.carries_media();open.chars = open.chars.saturating_add(item_chars);open.items.push(item);let window = settings.window(open.media);- open.quiet_at = (now + window).min(open.deadline);+ open.quiet_at = after(now, window).min(open.deadline);if window.is_zero() {counters.seal_open(lane, now);}@@ -322,6 +325,10 @@ impl<K: Eq + Hash + Clone, T: DebounceItem> KeyedDebouncer<K, T> {}}+fn after(now: Instant, window: Duration) -> Instant {+ now.checked_add(window.min(MAX_WINDOW)).unwrap_or(now)+}+#[cfg(test)]#[path = "mod_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/inbound_debounce/mod_tests.rs b/crates/openhuman-core/src/inbound_debounce/mod_tests.rsindex bfb5f4aec7..65ab361bc7 100644--- a/crates/openhuman-core/src/inbound_debounce/mod_tests.rs+++ b/crates/openhuman-core/src/inbound_debounce/mod_tests.rs@@ -308,3 +308,24 @@ fn immediate_settings_and_default_constructor() {assert!(d.is_empty());assert_eq!(d.next_wakeup(), None);}++#[test]+fn oversized_windows_are_clamped_instead_of_overflowing() {+ let t0 = Instant::now();+ let huge = DebounceSettings {+ debounce: Duration::MAX,+ media_debounce: Duration::MAX,+ max_wait: Duration::MAX,+ ..settings()+ };+ let mut d = Debouncer::new();+ assert_eq!(d.push("k", text("a"), &huge, t0), Push::Opened);+ assert_eq!(d.push("k", media("b"), &huge, t0), Push::Buffered);+ let wakeup = d.next_wakeup().expect("open window has a wakeup");+ assert!(wakeup > t0 && wakeup <= t0 + MAX_WINDOW);+ assert!(d.poll_ready(ms(t0, 60_000)).is_empty());+ d.flush_all(t0);+ let ready = d.poll_ready(t0);+ assert_eq!(ready.len(), 1);+ assert_eq!(texts(&ready[0].1), ["a", "b"]);+}