Skip to content

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

refactor(shell): extract command failure handling into a helper function

Steven Enamakelb16d3eccde97
diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rs
index ac8ceab885..edb5dfc964 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs
@@ -50,6 +50,18 @@ fn tool_timeout_message(secs: u64) -> String {
format!("Command timed out after {secs}s and was killed: the shell tool's timeout_secs limit fired.")
}
+/// [`tinytools::command_failure`], plus [`COMMAND_TIMEOUT_NOTE`] on exit 124.
+fn command_failure(code: Option<i32>, stdout: &str, stderr: &str) -> ToolResult {
+ let mut failure = tinytools::command_failure(code, stdout, stderr);
+ if code == Some(COMMAND_TIMEOUT_EXIT_CODE) {
+ tracing::debug!("[shell] exit 124: attributing it to the command's own timeout");
+ failure.content.push(tinytools::ToolContent::Text {
+ text: COMMAND_TIMEOUT_NOTE.to_string(),
+ });
+ }
+ failure
+}
+
/// Shell command execution tool with sandboxing
pub struct ShellTool {
security: Arc<SecurityPolicy>,
@@ -455,15 +467,7 @@ impl ShellTool {
// Surface the exit code AND both streams so the agent can
// diagnose the failure (e.g. 127 missing dependency, 126
// sandbox/permission wall) instead of looping on it (#4095).
- let mut failure =
- tinytools::command_failure(output.status.code(), &stdout, &stderr);
- if output.status.code() == Some(COMMAND_TIMEOUT_EXIT_CODE) {
- tracing::debug!("[shell] exit 124: attributing to the command's own timeout");
- failure.content.push(tinytools::ToolContent::Text {
- text: COMMAND_TIMEOUT_NOTE.to_string(),
- });
- }
- failure
+ command_failure(output.status.code(), &stdout, &stderr)
}
}
Ok(Err(e)) => ToolResult::error(format!("Failed to execute command: {e}")),
@@ -526,10 +530,7 @@ impl ShellTool {
{
Ok(result) => {
let tool_result = if result.timed_out {
- ToolResult::error(format!(
- "Command timed out after {}s and was killed",
- effective.as_secs()
- ))
+ ToolResult::error(tool_timeout_message(effective.as_secs()))
} else if result.success() {
if result.stderr.is_empty() {
ToolResult::success(result.stdout)
@@ -542,7 +543,7 @@ impl ShellTool {
} else {
// Same exit-code + both-streams surfacing as the native path
// (#4095); the sandbox `-1` sentinel renders as a signal.
- tinytools::command_failure(
+ command_failure(
tinytools::sandbox_exit_code(result.exit_code),
&result.stdout,
&result.stderr,