diff --git a/codex-rs/core/src/tasks/user_shell.rs b/codex-rs/core/src/tasks/user_shell.rs index f0922a070c..5b5bd7043b 100644 --- a/codex-rs/core/src/tasks/user_shell.rs +++ b/codex-rs/core/src/tasks/user_shell.rs @@ -106,7 +106,7 @@ impl SessionTask for UserShellCommandTask { // default timeout now that cancellation is wired through ExecExpiration. expiration: ExecExpiration::from_timeout_ms( Some(USER_SHELL_TIMEOUT_MS), - cancellation_token.clone(), + cancellation_token.child_token(), ), sandbox: SandboxType::None, sandbox_permissions: SandboxPermissions::UseDefault, diff --git a/codex-rs/core/src/tools/handlers/apply_patch.rs b/codex-rs/core/src/tools/handlers/apply_patch.rs index 2223099892..8a4951969b 100644 --- a/codex-rs/core/src/tools/handlers/apply_patch.rs +++ b/codex-rs/core/src/tools/handlers/apply_patch.rs @@ -145,7 +145,7 @@ impl ToolHandler for ApplyPatchHandler { turn: turn.as_ref(), call_id: call_id.clone(), tool_name: tool_name.to_string(), - cancellation_token: cancellation_token.clone(), + cancellation_token: cancellation_token.child_token(), }; let out = orchestrator .run(&mut runtime, &req, &tool_ctx, &turn, turn.approval_policy) diff --git a/codex-rs/core/src/tools/handlers/shell.rs b/codex-rs/core/src/tools/handlers/shell.rs index 67f8f5cd5d..bf6229f6f6 100644 --- a/codex-rs/core/src/tools/handlers/shell.rs +++ b/codex-rs/core/src/tools/handlers/shell.rs @@ -115,7 +115,7 @@ impl ToolHandler for ShellHandler { ToolPayload::Function { arguments } => { let params: ShellToolCallParams = parse_arguments(&arguments)?; let exec_params = - Self::to_exec_params(params, turn.as_ref(), cancellation_token.clone()); + Self::to_exec_params(params, turn.as_ref(), cancellation_token.child_token()); Self::run_exec_like( tool_name.as_str(), exec_params, @@ -126,7 +126,7 @@ impl ToolHandler for ShellHandler { } ToolPayload::LocalShell { params } => { let exec_params = - Self::to_exec_params(params, turn.as_ref(), cancellation_token.clone()); + Self::to_exec_params(params, turn.as_ref(), cancellation_token.child_token()); Self::run_exec_like( tool_name.as_str(), exec_params, @@ -188,7 +188,7 @@ impl ToolHandler for ShellCommandHandler { params, session.as_ref(), turn.as_ref(), - cancellation_token.clone(), + cancellation_token.child_token(), ); ShellHandler::run_exec_like( tool_name.as_str(), @@ -265,7 +265,7 @@ impl ShellHandler { Some(&tracker), &call_id, tool_name, - cancellation_token.clone(), + cancellation_token.child_token(), ) .await? { diff --git a/codex-rs/core/src/tools/handlers/unified_exec.rs b/codex-rs/core/src/tools/handlers/unified_exec.rs index e71fb315e4..9474a2a92b 100644 --- a/codex-rs/core/src/tools/handlers/unified_exec.rs +++ b/codex-rs/core/src/tools/handlers/unified_exec.rs @@ -164,7 +164,7 @@ impl ToolHandler for UnifiedExecHandler { Some(&tracker), &context.call_id, tool_name.as_str(), - context.cancellation_token.clone(), + context.cancellation_token.child_token(), ) .await? { diff --git a/codex-rs/core/src/tools/parallel.rs b/codex-rs/core/src/tools/parallel.rs index d1e5875341..30ca574cca 100644 --- a/codex-rs/core/src/tools/parallel.rs +++ b/codex-rs/core/src/tools/parallel.rs @@ -64,7 +64,7 @@ impl ToolCallRuntime { let handle: AbortOnDropHandle> = AbortOnDropHandle::new(tokio::spawn(async move { - let dispatch_cancellation = cancellation_token.clone(); + let dispatch_cancellation = cancellation_token.child_token(); let mut dispatch_future = Box::pin(async { let _guard = if supports_parallel { Either::Left(lock.read().await) diff --git a/codex-rs/core/src/tools/runtimes/apply_patch.rs b/codex-rs/core/src/tools/runtimes/apply_patch.rs index 8f4e4745c3..c1d6c7f479 100644 --- a/codex-rs/core/src/tools/runtimes/apply_patch.rs +++ b/codex-rs/core/src/tools/runtimes/apply_patch.rs @@ -154,7 +154,7 @@ impl ToolRuntime for ApplyPatchRuntime { attempt: &SandboxAttempt<'_>, ctx: &ToolCtx<'_>, ) -> Result { - let spec = Self::build_command_spec(req, ctx.cancellation_token.clone())?; + let spec = Self::build_command_spec(req, ctx.cancellation_token.child_token())?; let env = attempt .env_for(spec) .map_err(|err| ToolError::Codex(err.into()))?; diff --git a/codex-rs/core/src/tools/runtimes/shell.rs b/codex-rs/core/src/tools/runtimes/shell.rs index 95f303ad79..3db0f89bba 100644 --- a/codex-rs/core/src/tools/runtimes/shell.rs +++ b/codex-rs/core/src/tools/runtimes/shell.rs @@ -157,7 +157,7 @@ impl ToolRuntime for ShellRuntime { }; let expiration = - ExecExpiration::from_timeout_ms(req.timeout_ms, ctx.cancellation_token.clone()); + ExecExpiration::from_timeout_ms(req.timeout_ms, ctx.cancellation_token.child_token()); let spec = build_command_spec( &command, &req.cwd, diff --git a/codex-rs/core/src/tools/runtimes/unified_exec.rs b/codex-rs/core/src/tools/runtimes/unified_exec.rs index bf1f008054..682c7e4acc 100644 --- a/codex-rs/core/src/tools/runtimes/unified_exec.rs +++ b/codex-rs/core/src/tools/runtimes/unified_exec.rs @@ -180,7 +180,7 @@ impl<'a> ToolRuntime for UnifiedExecRunt &command, &req.cwd, &req.env, - ExecExpiration::default(ctx.cancellation_token.clone()), + ExecExpiration::default(ctx.cancellation_token.child_token()), req.sandbox_permissions, req.justification.clone(), ) diff --git a/codex-rs/core/src/unified_exec/process_manager.rs b/codex-rs/core/src/unified_exec/process_manager.rs index d363edeb2f..59c711e082 100644 --- a/codex-rs/core/src/unified_exec/process_manager.rs +++ b/codex-rs/core/src/unified_exec/process_manager.rs @@ -543,7 +543,7 @@ impl UnifiedExecProcessManager { turn: context.turn.as_ref(), call_id: context.call_id.clone(), tool_name: "exec_command".to_string(), - cancellation_token: context.cancellation_token.clone(), + cancellation_token: context.cancellation_token.child_token(), }; orchestrator .run( diff --git a/codex-rs/core/tests/suite/abort_tasks.rs b/codex-rs/core/tests/suite/abort_tasks.rs index 985280533a..e44cb6bfa5 100644 --- a/codex-rs/core/tests/suite/abort_tasks.rs +++ b/codex-rs/core/tests/suite/abort_tasks.rs @@ -29,7 +29,7 @@ fn long_running_exec_command_with_output() -> (String, Option<&'static str>) { ) } else { ( - "sleep 0.2; printf 'partial output\\n'; sleep 60".to_string(), + "sleep 0.2; printf 'partial output\\n' >&2; sleep 60".to_string(), None, ) } @@ -47,7 +47,7 @@ fn long_running_shell_command_with_output() -> Vec { vec![ "/bin/sh".to_string(), "-c".to_string(), - "sleep 0.2; printf 'partial output\\n'; sleep 60".to_string(), + "sleep 0.2; printf 'partial output\\n' >&2; sleep 60".to_string(), ] } } @@ -64,7 +64,7 @@ fn long_running_local_shell_call_with_output() -> Vec<&'static str> { vec![ "/bin/sh", "-c", - "sleep 0.2; printf 'partial output\\n'; sleep 60", + "sleep 0.2; printf 'partial output\\n' >&2; sleep 60", ] } }