From a24d308b7c2f4a28ddb65733300216d1ad2dc10b Mon Sep 17 00:00:00 2001 From: pakrym-oai Date: Mon, 15 Jun 2026 23:30:19 -0700 Subject: [PATCH] Avoid reserving process IDs before exec --- .../core/src/tools/handlers/unified_exec/exec_command.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs b/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs index b6ca28dd52..8b25df929c 100644 --- a/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs +++ b/codex-rs/core/src/tools/handlers/unified_exec/exec_command.rs @@ -149,7 +149,6 @@ impl ExecCommandHandler { &cwd, ) .await; - let process_id = manager.allocate_process_id().await; let shell_mode = shell_mode_for_environment(&turn.unified_exec_shell_mode, environment.as_ref()); let shell = if environment.is_remote() { @@ -223,7 +222,6 @@ impl ExecCommandHandler { ) { let approval_policy = context.turn.approval_policy.value(); - manager.release_process_id(process_id).await; return Err(FunctionCallError::RespondToModel(format!( "approval policy is {approval_policy:?}; reject command — you cannot ask for escalated permissions if the approval policy is {approval_policy:?}" ))); @@ -248,10 +246,7 @@ impl ExecCommandHandler { |permissions| Ok(Some(permissions)), ) { Ok(normalized) => normalized, - Err(err) => { - manager.release_process_id(process_id).await; - return Err(FunctionCallError::RespondToModel(err)); - } + Err(err) => return Err(FunctionCallError::RespondToModel(err)), }; if let Some(output) = intercept_apply_patch( @@ -267,7 +262,6 @@ impl ExecCommandHandler { ) .await? { - manager.release_process_id(process_id).await; return Ok(boxed_tool_output(ExecCommandToolOutput { event_call_id: String::new(), chunk_id: String::new(), @@ -283,6 +277,7 @@ impl ExecCommandHandler { } emit_unified_exec_tty_metric(&turn.session_telemetry, tty); + let process_id = manager.allocate_process_id().await; match manager .exec_command( ExecCommandRequest {