Skip to main content

run_agent_cancellable

Function run_agent_cancellable 

Source
pub fn run_agent_cancellable(
    files: &[(PathBuf, TaskFile)],
    name: &str,
    args: &[String],
    cwd: &Path,
    cancel: &Cancel,
) -> Result<Output, RunError>
Expand description

run_agent, stoppable through a Cancel handle held by another thread.

The agent surface is the one that needs this. A person at a terminal has Ctrl-C; an MCP client has only notifications/cancelled, so unless something else can reach the running task, a task that serves, sleeps, or waits on the network runs to completion whatever the client says.

The gate is identical to run_agent’s: same allowlist, same injection refusal, same in-file dependency resolution. Cancelling mid-chain stops before the next step and returns RunError::Cancelled, which is deliberately not a failure: nothing went wrong, someone asked it to stop.