Skip to content

[Bug]: Agent Execution Cancelled by Client-Side Cancellation During message/stream #296

@yokonao

Description

@yokonao

What happened?

Currently, with the default DefaultRequestHandler implementation, if a client that sent a message/stream request cancels the request or unexpectedly loses connection, the agent's execution is cancelled.

I've confirmed this behavior using the following steps:

  1. Modified a2a-samples/samples/python/agents/helloworld to include await asyncio.sleep(1) to simulate a slightly longer agent execution time.

  2. Started the A2A server.

  3. Sent a message/stream request using curl and immediately cancelled it.

    curl -X POST \
        -i -s \
        --header "Content-Type: application/json" \
        --data "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"message/stream\",\"params\":{\"message\":{\"role\":\"user\",\"parts\":[{\"kind\":\"text\",\"text\":\"テストメッセージ\"}],\"messageId\":\"some-id\"}}}" \
        http://localhost:9999/
    

The server displayed the following error:

asyncio.exceptions.CancelledError: Cancelled by cancel scope 1074c75d0

Considering the existence of the tasks/resubscribe RPC method, it seems unintended for agent execution to be cancelled due to a disconnection mid-request. I've confirmed that this behavior does not occur with message/send requests.

Environment

❯ uv run python --version
Python 3.11.13

a2a-sample commit hash: 3ac8e0b44446edede8f7ea398d48c758285f9eeb

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions