Skip to content

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

fix(time): handle midnight and out-of-range durations

Steven Enamakel215a9b7a3f63
diff --git a/crates/openhuman-core/src/tools/impl/system/resolve_time.rs b/crates/openhuman-core/src/tools/impl/system/resolve_time.rs
index 643af9d2e5..c6a8b171ca 100644
--- a/crates/openhuman-core/src/tools/impl/system/resolve_time.rs
+++ b/crates/openhuman-core/src/tools/impl/system/resolve_time.rs
@@ -130,7 +130,7 @@ fn parse_relative_duration(raw: &str) -> Option<Duration> {
if !any {
return None;
}
- let magnitude = Duration::seconds(seconds);
+ let magnitude = Duration::try_seconds(seconds)?;
Some(if future { magnitude } else { -magnitude })
}
@@ -221,7 +221,9 @@ fn resolve_calendar_phrase(
};
let today = zone.civil_date(now);
let date = match anchor.as_str() {
- "today" | "tonight" => today,
+ "today" => today,
+ "tonight" if time == NaiveTime::from_hms_opt(0, 0, 0)? => today + Duration::days(1),
+ "tonight" => today,
"yesterday" => today - Duration::days(1),
"tomorrow" => today + Duration::days(1),
_ => {
diff --git a/crates/openhuman-core/src/tools/impl/system/resolve_time_tests.rs b/crates/openhuman-core/src/tools/impl/system/resolve_time_tests.rs
index 07e489ed1f..e9758d964b 100644
--- a/crates/openhuman-core/src/tools/impl/system/resolve_time_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/system/resolve_time_tests.rs
@@ -97,6 +97,7 @@ fn conversational_dates_resolve_in_the_requested_timezone() {
("last Wednesday", "2025-12-30T18:30:00Z"),
("2026-01-09 at 9am", "2026-01-09T03:30:00Z"),
("11 PM tonight", "2026-01-07T17:30:00Z"),
+ ("tonight at midnight", "2026-01-07T18:30:00Z"),
("9am next Friday", "2026-01-09T03:30:00Z"),
("tomorrow at noon", "2026-01-08T06:30:00Z"),
] {
@@ -227,3 +228,13 @@ async fn execute_bad_timezone_errors() {
assert!(result.is_error);
assert!(result.output().contains("unknown IANA timezone"));
}
+
+#[tokio::test]
+async fn execute_rejects_out_of_range_duration_without_panicking() {
+ let result = ResolveTimeTool::new()
+ .execute(json!({ "expr": "in 9223372036854776s" }))
+ .await
+ .unwrap();
+ assert!(result.is_error);
+ assert!(result.output().contains("could not parse"));
+}