Skip to content

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

fix(version_check): require executable permission for candidate binaries

Steven Enamakel3944165286d8
diff --git a/pr5736-body.md b/pr5736-body.md
index ebc0f42386..f76bc1d9c4 100644
--- a/pr5736-body.md
+++ b/pr5736-body.md
@@ -96,3 +96,4 @@ https://claude.ai/code/session_01UMNxXS5ucxpzNoHnuhyQPu
- Improved authentication status checks when Claude is launched outside a terminal.
- Claude operations now use a five-minute timeout.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
+
diff --git a/src/openhuman/inference/provider/claude_code/version_check.rs b/src/openhuman/inference/provider/claude_code/version_check.rs
index d5aa033be9..dae736ed82 100644
--- a/src/openhuman/inference/provider/claude_code/version_check.rs
+++ b/src/openhuman/inference/provider/claude_code/version_check.rs
@@ -67,7 +67,24 @@ fn well_known_candidates() -> Vec<PathBuf> {
/// First candidate that resolves to a file (follows symlinks — the native
/// installer's `~/.local/bin/claude` is a symlink into a versioned dir).
fn first_existing(candidates: &[PathBuf]) -> Option<PathBuf> {
- candidates.iter().find(|p| p.is_file()).cloned()
+ candidates
+ .iter()
+ .find(|p| p.is_file() && is_executable(p))
+ .cloned()
+}
+
+#[cfg(unix)]
+fn is_executable(path: &std::path::Path) -> bool {
+ use std::os::unix::fs::PermissionsExt;
+
+ path.metadata()
+ .map(|metadata| metadata.permissions().mode() & 0o111 != 0)
+ .unwrap_or(false)
+}
+
+#[cfg(not(unix))]
+fn is_executable(path: &std::path::Path) -> bool {
+ path.is_file()
}
fn which_on_path(name: &str) -> Option<PathBuf> {
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 1e3a7977a3..f18ff337c1 100644
--- a/src/openhuman/inference/provider/claude_code/version_check_tests.rs
+++ b/src/openhuman/inference/provider/claude_code/version_check_tests.rs
@@ -32,11 +32,35 @@ fn first_existing_skips_missing_candidates_and_returns_first_file() {
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");
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt;
+ std::fs::set_permissions(&real, std::fs::Permissions::from_mode(0o755))
+ .expect("set permissions");
+ }
assert_eq!(first_existing(std::slice::from_ref(&missing)), None);
assert_eq!(first_existing(&[missing, real.clone()]), Some(real));
}
+#[cfg(unix)]
+#[test]
+fn first_existing_skips_non_executable_files() {
+ use std::os::unix::fs::PermissionsExt;
+
+ let dir = tempfile::tempdir().expect("tempdir");
+ let non_executable = dir.path().join("not-executable");
+ let executable = dir.path().join("executable");
+ std::fs::write(&non_executable, b"#!/bin/sh\n").expect("write file");
+ std::fs::write(&executable, b"#!/bin/sh\n").expect("write file");
+ std::fs::set_permissions(&non_executable, std::fs::Permissions::from_mode(0o644))
+ .expect("set permissions");
+ std::fs::set_permissions(&executable, std::fs::Permissions::from_mode(0o755))
+ .expect("set permissions");
+
+ assert_eq!(first_existing(&[non_executable, executable.clone()]), Some(executable));
+}
+
#[test]
fn well_known_candidates_put_native_install_first() {
let candidates = well_known_candidates();