Skip to content

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

refactor(tests): update harness embed test logic

Steven Enamakelcf4ae0b35d38
diff --git a/crates/openhuman-embed/tests/harness_embed.rs b/crates/openhuman-embed/tests/harness_embed.rs
index 934381fd51..ba2cd42291 100644
--- a/crates/openhuman-embed/tests/harness_embed.rs
+++ b/crates/openhuman-embed/tests/harness_embed.rs
@@ -13,16 +13,17 @@
//! (same thing, more code) or race. So the process builds exactly one harness
//! and checks everything against it.
//!
-//! No live LLM call is made: `wiremock` stands in for the provider, which is
+//! No live LLM call is made: a local mock stands in for the provider, which is
//! also what makes the routing assertion possible — if the turn had gone
//! anywhere else, the mock would have recorded no request.
mod common;
-use common::{chat_completion, offline_config, runtime};
+use common::gated_provider::GatedProvider;
+use common::{offline_config, runtime};
use openhuman_embed::{Access, Harness, Provider, Workspace};
use serde_json::json;
-use wiremock::matchers::{any, method, path};
+use wiremock::matchers::any;
use wiremock::{Mock, MockServer, ResponseTemplate};
/// A runtime whose drop waits at most `RUNTIME_SHUTDOWN` for blocking work.
@@ -45,12 +46,8 @@ impl Drop for BoundedRuntime {
const REPLY: &str = "harness-embed-ok";
-/// How long the mock provider holds every reply.
-///
-/// This is the test's clock. 100 turns taken one after another cannot finish in
-/// under `100 * PROVIDER_DELAY`, so any budget below that figure is what makes
-/// serialization observable.
-const PROVIDER_DELAY: std::time::Duration = std::time::Duration::from_secs(2);
+/// How many independent turns the overlap proof runs at once.
+const CONCURRENT_TURNS: usize = 100;
/// Upper bound for any single step that has no clock of its own (building the
/// harness, one turn, removing the agent).
@@ -65,8 +62,8 @@ const STEP_BUDGET: std::time::Duration = std::time::Duration::from_secs(180);
///
/// `Runtime::drop` joins every `spawn_blocking` task without a limit. After a
/// failed assertion, 100 agents' unfinished work then holds the panic back for
-/// as long as the slowest of them runs, which is how a missed
-/// `CONCURRENT_BUDGET` turned into a silent timeout.
+/// as long as the slowest of them runs, which is how a missed wall-clock budget
+/// once turned into a silent timeout.
const RUNTIME_SHUTDOWN: std::time::Duration = std::time::Duration::from_secs(10);
/// Runs `step` for at most `STEP_BUDGET`, failing with its `name` otherwise.
@@ -76,16 +73,18 @@ async fn bounded<T>(name: &str, step: impl std::future::IntoFuture<Output = T>)
.unwrap_or_else(|_| panic!("{name} did not finish within {STEP_BUDGET:?}"))
}
-/// Wall-clock allowance for the 100 overlapping turns below.
+/// Deadlock guard for the overlapping turns below. Not a speed budget.
///
-/// Overlapped, they cost one `PROVIDER_DELAY` plus per-agent construction and
-/// session persistence — and it is that overhead, not the delay, that an
-/// instrumented build inflates. A 250 ms delay used to put the serialization
-/// floor at 25 s against a 20 s budget: 20% of headroom, which `cargo llvm-cov`
-/// on a shared hosted runner spent, failing a run that had not serialized at
-/// all (#6758). The floor is now 200 s, so this budget can absorb an
-/// instrumented run and still catch a serialized one by a factor of two.
-const CONCURRENT_BUDGET: std::time::Duration = std::time::Duration::from_secs(90);
+/// Overlap is proven structurally: the provider holds every reply until all
+/// `CONCURRENT_TURNS` requests are in flight together, which turns run one
+/// after another can never reach. A wall-clock budget used to stand in for
+/// that proof, and an instrumented build on a loaded 4-vCPU runner kept
+/// spending it on agent construction alone (#6758, EX63 run 39357699152), so a
+/// run that had not serialized failed anyway. This bound only stops a
+/// serialized (or capped) host from waiting at the gate until the runner's
+/// 10-minute kill; a correct run opens the gate as soon as its last turn
+/// reaches the provider, however slow the machine.
+const CONCURRENT_HANG_GUARD: std::time::Duration = std::time::Duration::from_secs(300);
#[test]
fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
@@ -117,16 +116,8 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
.mount(&backend)
.await;
- let provider_server = MockServer::start().await;
- Mock::given(method("POST"))
- .and(path("/v1/chat/completions"))
- .respond_with(
- ResponseTemplate::new(200)
- .set_delay(PROVIDER_DELAY)
- .set_body_json(chat_completion(REPLY)),
- )
- .mount(&provider_server)
- .await;
+ // Answers at once until the overlap proof arms its gate.
+ let provider_server = GatedProvider::start(REPLY).await;
let harness = std::sync::Arc::new(
bounded(
@@ -199,9 +190,8 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
);
// The turn went to the endpoint we named, not to the account's route.
- let requests = common::chat_requests(&provider_server).await;
assert!(
- !requests.is_empty(),
+ provider_server.chat_requests() > 0,
"the provider endpoint received nothing — the per-call route was ignored"
);
@@ -214,15 +204,18 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
.expect("second turn runs");
assert_eq!(second.session_id, first.session_id);
- // One core must support many live agents. The delayed provider makes
- // serialization observable: sequential execution would take at least
- // `100 * PROVIDER_DELAY` before agent construction and persistence
- // overhead, which is well past `CONCURRENT_BUDGET`. All futures are
- // created together and each receives a distinct session, matching a
- // host such as OpenCompany running independent agents.
+ // One core must support many live agents. The gate makes overlap
+ // observable without a clock: no reply leaves the provider until
+ // all `CONCURRENT_TURNS` requests are in flight at once. Turns that
+ // ran one after another would leave one request waiting forever;
+ // a host capping concurrency below that would stall at its cap. All
+ // futures are created together and each receives a distinct
+ // session, matching a host such as OpenCompany running independent
+ // agents.
+ provider_server.hold_until(CONCURRENT_TURNS);
let started = std::time::Instant::now();
let mut turns = tokio::task::JoinSet::new();
- for index in 0..100 {
+ for index in 0..CONCURRENT_TURNS {
let harness = std::sync::Arc::clone(&harness);
turns.spawn(async move {
harness
@@ -232,8 +225,8 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
.await
});
}
- let outcomes = tokio::time::timeout(CONCURRENT_BUDGET, async {
- let mut outcomes = Vec::with_capacity(100);
+ let outcomes = tokio::time::timeout(CONCURRENT_HANG_GUARD, async {
+ let mut outcomes = Vec::with_capacity(CONCURRENT_TURNS);
while let Some(outcome) = turns.join_next().await {
outcomes.push(outcome.expect("concurrent turn task did not panic"));
}
@@ -241,14 +234,27 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
})
.await
.unwrap_or_else(|_| {
- panic!("100 concurrent turns did not settle within {CONCURRENT_BUDGET:?}")
+ panic!(
+ "{CONCURRENT_TURNS} turns did not overlap: at most {} of them were \
+ ever in flight at the provider together ({} waiting at the gate \
+ after {CONCURRENT_HANG_GUARD:?}); the gate opens only when all \
+ {CONCURRENT_TURNS} are, so turns serialized or are capped",
+ provider_server.peak_in_flight(),
+ provider_server.in_flight(),
+ )
});
- let elapsed = started.elapsed();
- eprintln!("100 concurrent library turns completed in {elapsed:?}");
+ // Informational only; nothing asserts on it.
+ eprintln!(
+ "{CONCURRENT_TURNS} concurrent library turns completed in {:?} \
+ (peak {} in flight)",
+ started.elapsed(),
+ provider_server.peak_in_flight()
+ );
+ assert!(provider_server.is_open(), "the overlap gate never opened");
assert!(
- elapsed < CONCURRENT_BUDGET,
- "100 turns serialized instead of overlapping: {elapsed:?} is past \
- the {CONCURRENT_BUDGET:?} budget"
+ provider_server.peak_in_flight() >= CONCURRENT_TURNS,
+ "only {} turns were in flight together, not {CONCURRENT_TURNS}",
+ provider_server.peak_in_flight()
);
let mut session_ids = std::collections::HashSet::new();
for outcome in outcomes {
@@ -256,10 +262,13 @@ fn a_harness_runs_a_turn_against_the_provider_it_was_given() {
assert!(outcome.reply.contains(REPLY));
assert!(session_ids.insert(outcome.session_id));
}
- assert_eq!(session_ids.len(), 100);
+ assert_eq!(session_ids.len(), CONCURRENT_TURNS);
- let requests = common::chat_requests(&provider_server).await;
- assert_eq!(requests.len(), 102, "two serial + 100 concurrent turns");
+ assert_eq!(
+ provider_server.chat_requests(),
+ 2 + CONCURRENT_TURNS,
+ "two serial + {CONCURRENT_TURNS} concurrent turns"
+ );
// The first session's transcript landed in the harness agent's
// own store under the workspace (the path-based transcript files