Skip to content

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

test(web_chat): add tests for bounded reaction timeout behaviour

Steven Enamakel5f7d6c59d317
diff --git a/crates/openhuman-core/src/web_chat/presentation_tests.rs b/crates/openhuman-core/src/web_chat/presentation_tests.rs
index 89743bffa4..9f93c56f1d 100644
--- a/crates/openhuman-core/src/web_chat/presentation_tests.rs
+++ b/crates/openhuman-core/src/web_chat/presentation_tests.rs
@@ -228,3 +228,56 @@ async fn delivery_without_a_workspace_persists_nothing() {
)
.await;
}
+
+/// Sets its flag when dropped — i.e. when the task holding it is aborted.
+struct DropFlag(std::sync::Arc<std::sync::atomic::AtomicBool>);
+
+impl Drop for DropFlag {
+ fn drop(&mut self) {
+ self.0.store(true, std::sync::atomic::Ordering::SeqCst);
+ }
+}
+
+/// The reply must not wait on its reaction. A reaction parked on a paused
+/// scheduler gate used to stall `deliver_response` before it stored or
+/// announced anything, so the UI sat on "Thinking..." indefinitely.
+#[tokio::test]
+async fn a_reaction_that_never_finishes_does_not_hold_back_delivery() {
+ let dropped = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
+ let flag = DropFlag(dropped.clone());
+ let stuck = tokio::spawn(async move {
+ let _flag = flag;
+ std::future::pending::<Option<String>>().await
+ });
+
+ let started = std::time::Instant::now();
+ let emoji = bounded_reaction(stuck, std::time::Duration::from_millis(50), "req-stuck").await;
+
+ assert_eq!(emoji, None, "an unfinished reaction delivers without an emoji");
+ assert!(
+ started.elapsed() < std::time::Duration::from_secs(2),
+ "delivery must not wait past the reaction budget (took {:?})",
+ started.elapsed()
+ );
+ // Let the aborted task unwind, then confirm it was torn down rather than
+ // left running against the local model.
+ tokio::time::sleep(std::time::Duration::from_millis(20)).await;
+ assert!(
+ dropped.load(std::sync::atomic::Ordering::SeqCst),
+ "the timed-out reaction task must be aborted"
+ );
+}
+
+#[tokio::test]
+async fn a_reaction_that_finishes_in_time_is_kept() {
+ let ready = tokio::spawn(async { Some("🎉".to_string()) });
+ let emoji = bounded_reaction(ready, REACTION_BUDGET, "req-ready").await;
+ assert_eq!(emoji.as_deref(), Some("🎉"));
+}
+
+#[tokio::test]
+async fn a_panicked_reaction_delivers_without_an_emoji() {
+ let panicked = tokio::spawn(async { panic!("reaction blew up") });
+ let emoji = bounded_reaction(panicked, REACTION_BUDGET, "req-panic").await;
+ assert_eq!(emoji, None);
+}