Skip to content

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

test(web_chat): harden turn lifecycle error event wait

Steven Enamakel6e28c970359c
diff --git a/crates/openhuman-core/src/web_chat/web_tests_turn_lifecycle_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_turn_lifecycle_tests.rs
index 831969c80c..0f80aff9cf 100644
--- a/crates/openhuman-core/src/web_chat/web_tests_turn_lifecycle_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests_turn_lifecycle_tests.rs
@@ -220,8 +220,35 @@ async fn a_turn_with_an_unavailable_local_provider_ends_in_one_classified_chat_e
.await
.expect("the message is accepted");
- let error = wait_for_event(&mut rx, &request_id, "chat_error").await;
let requests = server.received_requests().await.expect("captured requests");
+ let error = match timeout(Duration::from_secs(10), async {
+ loop {
+ match rx.recv().await {
+ Ok(event) if event.request_id == request_id && event.event == "chat_error" => {
+ return event;
+ }
+ Ok(_) | Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => continue,
+ Err(error) => panic!("event stream closed: {error}"),
+ }
+ }
+ })
+ .await
+ {
+ Ok(error) => error,
+ Err(_) => {
+ let in_flight = crate::web_chat::runner::runtime(&ctx)
+ .runner
+ .is_in_flight(&crate::web_chat::runner::scope_of(&ctx), thread_id)
+ .await;
+ panic!(
+ "no chat_error for {request_id}; provider requests={requests:?}; in_flight={in_flight}"
+ );
+ }
+ };
+ let requests = server
+ .received_requests()
+ .await
+ .expect("captured requests after terminal event");
assert!(
requests.iter().any(|request| {
request.method == "POST"