Skip to content

ACP session/cancel emits agent_error for MessageAbortedError before cancelled result #28453

@truenorth-lj

Description

@truenorth-lj

Summary

When ACP session/cancel interrupts an in-flight prompt, the prompt result should represent a user cancellation, not an agent failure. In the agent_error event path added for failed LLM turns, MessageAbortedError should be filtered out.

Reproducer

  1. Start an ACP session/prompt that streams for long enough to cancel.
  2. Send ACP session/cancel while the turn is still active.
  3. Observe the emitted session/update frames and final prompt result.

Expected

The final prompt result is:

{ "stopReason": "cancelled", "_meta": {} }

No agent_error session/update is emitted for the same user-cancel action.

Actual

Before the final cancelled result, the stream can emit:

{
  "sessionUpdate": "agent_error",
  "error": { "type": "unknown", "message": "Aborted", "retryable": true },
  "stopReason": "error"
}

followed by:

{ "stopReason": "cancelled", "_meta": {} }

Why this matters

ACP clients receive both an error and a cancellation for one user action. Since MessageAbortedError is the normal result of session/cancel, surfacing it as agent_error makes an intentional stop look like an agent/LLM failure.

Proposed fix

In the ACP event handler, ignore session.error events whose error name is MessageAbortedError. The prompt RPC result remains responsible for reporting stopReason: "cancelled".

Related: #25899, #26352

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions