Skip to content

fix(acp): honor session/cancel by aborting the running turn#30145

Merged
nexxeln merged 3 commits into
anomalyco:devfrom
smagnuso:fix/acp-cancel-abort
Jun 1, 2026
Merged

fix(acp): honor session/cancel by aborting the running turn#30145
nexxeln merged 3 commits into
anomalyco:devfrom
smagnuso:fix/acp-cancel-abort

Conversation

@smagnuso
Copy link
Copy Markdown
Contributor

@smagnuso smagnuso commented May 31, 2026

Exercising opencode with hydra-acp and could no longer cancel in ACP.

The ACP agent rejected every session/cancel with UnsupportedOperationError, so clients could not stop an in-flight turn — the prompt ran to completion regardless. This restores the pre-"next" behavior of aborting the backing session via sdk.session.abort, mirroring the closeSession abort path but leaving the ACP session in place so the client can keep prompting.

Adds regression coverage: cancel aborts the backing session and keeps the ACP session usable, and a failed abort is swallowed best-effort.

Issue for this PR

Closes #30146

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The ACP cancel handler in src/acp/service.ts just returns UnsupportedOperationError, so session/cancel does nothing — the running turn keeps going. The old (pre-#29929) implementation actually aborted the session, and that got dropped when the "next" implementation was promoted.

The fix puts the abort back. cancel now looks up the session and calls sdk.session.abort({ directory, sessionID }), which is the same call closeSession already uses to stop a turn — I just reuse the existing request("session") wrapper and the same best-effort Effect.catch/log.error so a failed abort doesn't blow up the cancel. The one difference from closeSession is that cancel does not remove the ACP session, so the client can send another prompt afterwards instead of having to reopen the session.

cancel is a notification (no reply), so there's nothing to return; logging on failure matches how closeSession handles the same abort call.

How did you verify your code works?

  • bun typecheck from packages/opencode — clean.
  • bun test test/acp test/cli/acp --timeout 60000 — 130 pass / 0 fail (includes the two new tests).
  • There was no existing test exercising session/cancel, which is how this regressed, so I added two in test/acp/service-session.test.ts: one asserts cancel calls session.abort and the session is still usable afterward (unlike closeSession), the other asserts a rejected abort is swallowed.
  • Manually: ran opencode acp, started a long-running turn from an ACP client, sent session/cancel, confirmed the turn stops and a follow-up prompt still works.

Screenshots / recordings

N/A — not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The ACP agent rejected every session/cancel with UnsupportedOperationError,
so clients could not stop an in-flight turn — the prompt ran to completion
regardless. This restores the pre-"next" behavior of aborting the backing
session via sdk.session.abort, mirroring the closeSession abort path but
leaving the ACP session in place so the client can keep prompting.

Adds regression coverage: cancel aborts the backing session and keeps the
ACP session usable, and a failed abort is swallowed best-effort.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels May 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Copy link
Copy Markdown
Member

@nexxeln nexxeln left a comment

Choose a reason for hiding this comment

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

tysm!

@nexxeln nexxeln merged commit 50b4ad8 into anomalyco:dev Jun 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACP: session/cancel is rejected with UnsupportedOperationError, so in-flight turns can't be cancelled

2 participants