From 027944c64efb7810161676c495660d1fae106b70 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 11 Sep 2025 12:09:20 -0700 Subject: [PATCH] fix: improve handle_sandbox_error timeouts (#3435) ## Summary Handle timeouts the same way, regardless of approval mode. There's more to do here, but this is simple and should be zero-regret ## Testing - [x] existing tests pass - [x] test locally and verify rollout --- codex-rs/core/src/codex.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index b48093d8f..c82c50e45 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -2718,6 +2718,20 @@ async fn handle_sandbox_error( let sub_id = exec_command_context.sub_id.clone(); let cwd = exec_command_context.cwd.clone(); + // if the command timed out, we can simply return this failure to the model + if matches!(error, SandboxErr::Timeout) { + return ResponseInputItem::FunctionCallOutput { + call_id, + output: FunctionCallOutputPayload { + content: format!( + "command timed out after {} milliseconds", + params.timeout_duration().as_millis() + ), + success: Some(false), + }, + }; + } + // Early out if either the user never wants to be asked for approval, or // we're letting the model manage escalation requests. Otherwise, continue match turn_context.approval_policy { @@ -2735,20 +2749,6 @@ async fn handle_sandbox_error( AskForApproval::UnlessTrusted | AskForApproval::OnFailure => (), } - // similarly, if the command timed out, we can simply return this failure to the model - if matches!(error, SandboxErr::Timeout) { - return ResponseInputItem::FunctionCallOutput { - call_id, - output: FunctionCallOutputPayload { - content: format!( - "command timed out after {} milliseconds", - params.timeout_duration().as_millis() - ), - success: Some(false), - }, - }; - } - // Note that when `error` is `SandboxErr::Denied`, it could be a false // positive. That is, it may have exited with a non-zero exit code, not // because the sandbox denied it, but because that is its expected behavior,