Skip to content

ACP: handle session/cancel — baseline MUST the spec requires #178

Closed

Description

@ajianaz

What problem does this solve?

Found during the issue #176 ACP spec review (prompt-turn spec):

As a baseline, all Agents MUST support session/new, session/prompt, session/cancel, and session/update.

tole acp handles session/new / session/prompt / session/update but ignores session/cancel — the notification falls into the unknown-method arm (no id → silently dropped). A client that stops a generating turn (Termul's stop button, Zed) therefore gets a turn that keeps running to completion: the provider keeps burning tokens, tool calls keep executing, and the late session/prompt response races the client's post-cancel state. The spec requires the agent to stop model requests and tool invocations ASAP and answer the original prompt request with stopReason: "cancelled".

Also related: on session/cancel, clients MUST respond cancelled to pending session/request_permission requests — tole already fail-closes those to Deny (the routing exists), but the turn then continues instead of unwinding.

Proposed solution

  1. Plumb a cancellation token into run_session_turn (per ACP session): session/cancel sets it; the turn loop checks it between steps (before each provider call and before each tool execution) and unwinds to a cancelled stop reason. Tool execution mid-flight is allowed to finish its current step (match tole's synchronous turn loop); provider calls are bounded by the existing 120 s timeout.
  2. When the cancel lands while a permission request is pending, the Deny verdict + cancellation token combine so the turn settles as cancelled, not refusal.
  3. Keep serve behavior unchanged (REST has no cancel endpoint today; the token is simply never set).

Alternatives considered

  • Advertise only what we support — not possible: session/cancel support is a baseline MUST, not capability-gated, so hosts are entitled to send it unconditionally.
  • Kill the turn thread on cancel — rejected: no safe kill of a thread holding the storage mutex; cooperative checkpoints are the honest scope for the synchronous turn loop.

Are you willing to contribute the implementation?

Yes, I can do it

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions