# Cancel and Pause

What cancel and pause do to a running task.

Cancellation carries a cause since v1.0.10 (`context.WithCancelCause`). Only a cancel that names `runtime.ErrUserCanceled` — Ctrl+C in the TUI, **Yes** in the Esc popup, or **Cancel task** in a confirmation (v1.3.3) — deletes the pending task; since v1.3.9 the task is first written to chat history with a `[Canceled]` reply (plus the last error when it had failed), so `chat_history` still finds it. Any other cancel, including the popup's **Pause** and, since v1.3.3, **Abort task** in a confirmation (`runtime.ErrUserAborted`), tears down the run but leaves the pending record in place, so `/pending` or `GET /v1/session/:id/task` can resume it. Since v1.2.0 the TUI's `/pending` resumes through the daemon with a `pending` frame; a saved question is asked inline over the socket and the resumed run streams back to the same window. A TUI run is bound to its socket connection: closing the TUI cancels the run without `runtime.ErrUserCanceled`, so its pending task is kept. Since v1.3.0 cancel and pause also stop the task's background jobs; cancel then deletes the pending task, while pause keeps it. A single leg is cancelled from the TUI background-task menu (v1.3.8). The `/pending` `[Active]` mark that kept a task with running background jobs from being picked was Removed in v1.3.8. A resume that finds the task already claimed by a run fails with `[Conflict] pending task: running`. Since v1.3.3 a cancelled task no longer leaves an empty resumable pending entry behind.

The TUI's Ctrl+C and popup choices travel as a `cancel` frame (with `pause` for **Pause**), which the daemon applies through `exec.Cancel(taskHash, cause)` only for tasks that connection started. Since v1.2.0 `exec.Run` (named `exec.Start` before v1.2.1) generates the task hash and registers the cancel function before it emits the first event, so a cancel works from the first event onward; a cancel requested before the TUI has seen any task hash is held and sent once the first one arrives. Outside a popup, `Esc` first closes an open `/` command picker, then the notice box, then cancels the run (immediately if nothing has been shown yet, otherwise through the popup), then clears the input, then — since v1.3.8 — opens the background-task menu when the session has legs running: **No**, each leg, and **All** (two or more), followed by a confirmation; the TUI sends the pick as a `background_cancel` frame, and the daemon cancels the leg, drops its late result and settles its job. An `ask_user` reply that fails for a reason other than user cancellation no longer discards the pending task either.
