Skip to content

Honor $/cancel_request for a prompt and a sign-in - #228

Merged
setoelkahfi merged 1 commit into
developmentfrom
feature/acp-cancel-request
Oct 13, 2026
Merged

setoelkahfi merged 1 commit into
developmentfrom
feature/acp-cancel-request

Conversation

@setoelkahfi

@setoelkahfi setoelkahfi commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

The SDK records a $/cancel_request against the request it names, but a handler has to read responder.cancellation() for anything to happen, and none did. A client that cancels by JSON-RPC id instead of session/cancel was ignored.

  • session/prompt: the handler watches the marker and stops the turn through cancel_turn, the path session/cancel already takes, so the running command is killed too. The prompt is still answered with a result and the cancelled stop reason, which keeps what was streamed.
  • authenticate: the sign-in is dropped, which closes the loopback listener, and the request is answered -32800.
  • The other handlers still ignore the notification, as the spec allows.

The select polls the turn before the marker. A turn registers for cancellation on its first poll, and a cancel that arrived while the prompt was queued on the session lock would otherwise run before there was anything to cancel.

Test: a_cancel_request_for_the_prompt_ends_the_turn_cancelled in tests/acp_client_terminal.rs drives the binary, sends $/cancel_request while a command runs in the client's terminal, and checks for terminal/kill and the cancelled stop reason.

@setoelkahfi
setoelkahfi added this pull request to stack #232 October 12, 2026 07:49
@setoelkahfi setoelkahfi self-assigned this Oct 12, 2026
@setoelkahfi
setoelkahfi marked this pull request as ready for review October 12, 2026 08:16

@sigit-code-review sigit-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change enables the agent to honor $/cancel_request notifications for both prompt and sign-in requests, which previously required explicit handler support and were ignored if sent by JSON-RPC id. The main.rs changes ensure that prompt and authenticate handlers now check for cancellation and terminate appropriately: prompts are stopped via cancel_turn (which also kills any running command), and sign-ins are dropped with an error. The select! in the prompt handler ensures that cancellation is registered after the first poll, avoiding a race where cancellation could be missed if it arrived before the handler registered. The test suite adds a case to verify that $/cancel_request for a prompt id cancels the turn, kills the terminal, and returns the correct stop reason, using a new helper to generalize mid-command cancellation. Previous findings about cancellation not being honored for $/cancel_request are addressed by these changes.


Automated review by siGit Code Review · commit 3c5f670 · see the review dashboard

@paydii paydii added bug Something isn't working ACP v1 Agent Client Protocol v1 specification. labels Oct 12, 2026
The SDK records a $/cancel_request against the request it names, but a
handler has to read responder.cancellation() for anything to happen, and
none did. A client that cancels by JSON-RPC id instead of session/cancel
was ignored.

The prompt handler now watches the marker and stops the turn through
cancel_turn, the path session/cancel already takes, so the running
command is killed too. The prompt is still answered with a result and
the cancelled stop reason, which keeps what was streamed. authenticate
is dropped instead, which closes the loopback listener, and answers
-32800. The other handlers still ignore the notification, as the spec
allows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: siGit Code v1.6.7-acp <noreply@sigit.si>
@setoelkahfi
setoelkahfi force-pushed the feature/acp-cancel-request branch from 3c5f670 to 0f3d1f0 Compare October 12, 2026 13:36
@setoelkahfi
setoelkahfi merged commit 0bbc154 into development Oct 13, 2026
9 checks passed
@setoelkahfi
setoelkahfi deleted the feature/acp-cancel-request branch October 13, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ACP v1 Agent Client Protocol v1 specification. bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants