pub async fn run_codex_cancellable<C>(
codex: &Codex,
args: Vec<String>,
cancel: C,
) -> Result<CommandOutput>Expand description
Run a codex command, stopping it gracefully if cancel resolves first.
On cancellation the run’s process group is sent the configured signal,
given the client’s termination_grace,
then killed.
This reaches descendants in the owned group. Detached tools require the
CLI’s cooperation; TerminationSignal::Interrupt
lets its interrupt handler run before the hard fallback. Output during
shutdown is drained and discarded, and the cancellation reason stays latched
even if the CLI exits successfully. If stopping or reaping the child fails,
the stop reason is returned inside Error::CleanupFailed rather than as a
bare Error::Cancelled or Error::Timeout.
Dropping the future instead kills the owned group abruptly: Drop cannot
wait out a grace period or allow cooperative cleanup of detached tools.
Retry does not apply. A cancelled run is a decision, not a transient failure.
On platforms without process groups this degrades to killing the child.