Skip to content

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

fix: preserve Claude timeout controls and coverage

Steven Enamakel278f932dc5d4
diff --git a/src/openhuman/inference/provider/claude_code/driver.rs b/src/openhuman/inference/provider/claude_code/driver.rs
index e3f32f1566..d715ca3384 100644
--- a/src/openhuman/inference/provider/claude_code/driver.rs
+++ b/src/openhuman/inference/provider/claude_code/driver.rs
@@ -16,7 +16,16 @@ use tokio::sync::mpsc;
/// Hard timeout per turn (PLAN §8). If the CLI hangs (network stall,
/// infinite loop, MCP deadlock) we kill the child and surface a timeout.
-const TURN_TIMEOUT: Duration = Duration::from_secs(300);
+const DEFAULT_TURN_TIMEOUT_SECS: u64 = 900;
+
+fn turn_timeout() -> Duration {
+ let secs = std::env::var("OPENHUMAN_CLAUDE_CODE_TURN_TIMEOUT_SECS")
+ .ok()
+ .and_then(|raw| raw.trim().parse::<u64>().ok())
+ .filter(|secs| *secs > 0)
+ .unwrap_or(DEFAULT_TURN_TIMEOUT_SECS);
+ Duration::from_secs(secs)
+}
fn parse_error_line_shape(line: &str) -> &'static str {
match line.trim_start().chars().next() {
@@ -486,7 +495,8 @@ pub async fn run_turn(ctx: TurnContext<'_>) -> anyhow::Result<ChatResponse> {
// Wrap the streaming + wait in a timeout so a stuck CLI doesn't
// block this task forever (PLAN §8).
- let timed = tokio::time::timeout(TURN_TIMEOUT, async {
+ let timeout = turn_timeout();
+ let timed = tokio::time::timeout(timeout, async {
loop {
let n = stdout
.read(&mut buf)
@@ -528,16 +538,11 @@ pub async fn run_turn(ctx: TurnContext<'_>) -> anyhow::Result<ChatResponse> {
let status = match timed {
Ok(inner) => inner?,
Err(_elapsed) => {
- log::error!(
- "[claude-code][driver] turn timeout ({TURN_TIMEOUT:?}) exceeded; killing child"
- );
+ log::error!("[claude-code][driver] turn timeout ({timeout:?}) exceeded; killing child");
// kill_on_drop handles cleanup, but explicit kill gives us
// a chance to collect stderr.
let _ = child.kill().await;
- anyhow::bail!(
- "[claude-code][driver] turn timed out after {:?}",
- TURN_TIMEOUT
- );
+ anyhow::bail!("[claude-code][driver] turn timed out after {:?}", timeout);
}
};
diff --git a/src/openhuman/inference/provider/claude_code/version_check_tests.rs b/src/openhuman/inference/provider/claude_code/version_check_tests.rs
index 99a883ed0a..1e3a7977a3 100644
--- a/src/openhuman/inference/provider/claude_code/version_check_tests.rs
+++ b/src/openhuman/inference/provider/claude_code/version_check_tests.rs
@@ -25,3 +25,23 @@ fn version_compare() {
fn version_compare_strips_prerelease() {
assert!(!version_lt("2.0.0-rc.1", "2.0.0"));
}
+
+#[test]
+fn first_existing_skips_missing_candidates_and_returns_first_file() {
+ let dir = tempfile::tempdir().expect("tempdir");
+ let missing = dir.path().join("missing/claude");
+ let real = dir.path().join("claude");
+ std::fs::write(&real, b"#!/bin/sh\n").expect("write fake binary");
+
+ assert_eq!(first_existing(std::slice::from_ref(&missing)), None);
+ assert_eq!(first_existing(&[missing, real.clone()]), Some(real));
+}
+
+#[test]
+fn well_known_candidates_put_native_install_first() {
+ let candidates = well_known_candidates();
+ assert!(!candidates.is_empty());
+ if let Some(home) = dirs::home_dir() {
+ assert_eq!(candidates[0], home.join(".local/bin/claude"));
+ }
+}