Repository navigation
Description
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, andsession/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
- Plumb a cancellation token into
run_session_turn(per ACP session):session/cancelsets it; the turn loop checks it between steps (before each provider call and before each tool execution) and unwinds to acancelledstop 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. - When the cancel lands while a permission request is pending, the Deny verdict + cancellation token combine so the turn settles as
cancelled, notrefusal. - Keep
servebehavior unchanged (REST has no cancel endpoint today; the token is simply never set).
Alternatives considered
- Advertise only what we support — not possible:
session/cancelsupport 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
Activity
feat(acp): session/cancel — cooperative turn cancellation (issue #178) (
feat(cancel): REST cancel endpoint + tole_session_cancel MCP tool (is…
chore(release): v0.6.0 (#192)
chore(release): v0.6.0 (#194)
feat(cli): run ergonomics — --prompt-file, --name, --timeout (#216) (#…
chore(release): v0.7.0 (#225)
refactor(cli): a session registry that owns admission, eviction and t…