Skip to content

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

agent: the late note supersedes the half-time note

killbill28f2376aeb83
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable.rs
index 565f905fef..94726e6bf0 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable.rs
@@ -363,8 +363,13 @@ impl<C: Send + Sync> Middleware<(), C> for UnmetDeliverableMiddleware {
}
};
if band >= LATE_BAND && !late_noted {
+ // The late note supersedes the half-time one: a run whose first
+ // observation is already past 80% must not get the half-time
+ // note on its next tool result.
if let Ok(mut runs) = self.runs.lock() {
- runs.entry(ctx.instance_id()).or_default().late_noted = true;
+ let run = runs.entry(ctx.instance_id()).or_default();
+ run.late_noted = true;
+ run.half_noted = true;
}
tracing::debug!(
band,
@@ -373,7 +378,7 @@ impl<C: Send + Sync> Middleware<(), C> for UnmetDeliverableMiddleware {
append_note(result, &late_note(&clock));
return Ok(());
}
- if band >= HALF_TIME_BAND && !half_noted {
+ if (HALF_TIME_BAND..LATE_BAND).contains(&band) && !half_noted {
let missing = Self::missing(&candidates);
if let Ok(mut runs) = self.runs.lock() {
runs.entry(ctx.instance_id()).or_default().half_noted = true;
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable_tests.rs
index 58040674b9..da0b327c71 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/unmet_deliverable_tests.rs
@@ -348,7 +348,9 @@ async fn the_half_time_and_late_notes_ride_a_tool_result_once_each() {
let missing = std::env::temp_dir().join(format!("oh-unmet-clock-{}.csv", std::process::id()));
let _ = std::fs::remove_dir_all(&missing);
std::fs::create_dir_all(&missing).expect("a directory at the csv path");
- let middleware = UnmetDeliverableMiddleware::new(Some(std::time::Duration::from_millis(1_000)));
+ // A 4 s budget: the sleeps land a full band away from each threshold,
+ // so a second of scheduler slop cannot move a call across one.
+ let middleware = UnmetDeliverableMiddleware::new(Some(std::time::Duration::from_millis(4_000)));
let mut ctx = RunContext::new(RunConfig::new("clock"), ());
let mut request = ModelRequest {
messages: vec![Message::user(format!(
@@ -375,7 +377,7 @@ async fn the_half_time_and_late_notes_ride_a_tool_result_once_each() {
"nothing before half-time"
);
- std::thread::sleep(std::time::Duration::from_millis(600));
+ std::thread::sleep(std::time::Duration::from_millis(2_200));
let half = run(&middleware, &mut ctx).await;
assert!(half.contains("Half the turn's budget is gone"), "{half:?}");
assert!(
@@ -388,7 +390,7 @@ async fn the_half_time_and_late_notes_ride_a_tool_result_once_each() {
"the half-time note is given once"
);
- std::thread::sleep(std::time::Duration::from_millis(450));
+ std::thread::sleep(std::time::Duration::from_millis(1_300));
let late = run(&middleware, &mut ctx).await;
assert!(late.contains("Stop exploring"), "{late:?}");
assert!(
@@ -413,3 +415,36 @@ fn a_directory_at_the_path_is_still_missing() {
assert_eq!(UnmetDeliverableMiddleware::missing(&candidates), candidates);
let _ = std::fs::remove_dir_all(&dir);
}
+
+/// A run whose first tool result arrives past 80% gets the late note and
+/// never the half-time one: the later rung supersedes the earlier.
+#[tokio::test]
+async fn a_late_first_observation_skips_the_half_time_note() {
+ let missing = std::env::temp_dir().join(format!("oh-unmet-late-{}.csv", std::process::id()));
+ let _ = std::fs::remove_file(&missing);
+ let middleware = UnmetDeliverableMiddleware::new(Some(std::time::Duration::from_millis(1)));
+ let mut ctx = RunContext::new(RunConfig::new("late-first"), ());
+ let mut request = ModelRequest {
+ messages: vec![Message::user(format!("write {}", missing.display()))],
+ ..ModelRequest::default()
+ };
+ Middleware::<(), ()>::before_model(&middleware, &mut ctx, &(), &mut request)
+ .await
+ .expect("before_model");
+ std::thread::sleep(std::time::Duration::from_millis(5));
+ let identity = tinyagents_harness::middleware::ToolInvocationIdentity::new("c0", "shell");
+ let mut first = TaToolResult::success("output");
+ Middleware::<(), ()>::after_tool(&middleware, &mut ctx, &(), &identity, &mut first)
+ .await
+ .expect("after_tool");
+ assert!(result_text(&first).contains("Stop exploring"));
+ let mut second = TaToolResult::success("output");
+ Middleware::<(), ()>::after_tool(&middleware, &mut ctx, &(), &identity, &mut second)
+ .await
+ .expect("after_tool");
+ assert_eq!(
+ result_text(&second),
+ "output",
+ "no half-time note after the late one"
+ );
+}