Skip to content

[Feat]: Allow configuring shutdown_grace_period for SSE responses #1221

Description

@ftnext

Is your feature request related to a problem? Please describe.

A2A SDK v1 creates sse-starlette EventSourceResponse instances for JSON-RPC and REST streaming endpoints, but there is currently no supported way to pass shutdown_grace_period.

Because sse-starlette defaults this value to 0, an in-progress SSE response is cancelled immediately when the server receives SIGTERM. This can prevent a finite message/stream request from delivering its remaining events and terminal event, even when the ASGI server is configured to wait for in-flight requests during graceful shutdown.

Relevant response creation sites include:

  • src/a2a/server/routes/jsonrpc_dispatcher.py
  • src/a2a/server/routes/rest_dispatcher.py

Describe the solution you'd like

Please provide a supported way to configure shutdown_grace_period and pass it to every EventSourceResponse created by the A2A HTTP server.

For example, this could be exposed through create_jsonrpc_routes() and create_rest_routes(), through their dispatchers, or through a general EventSourceResponse options/factory parameter.

The existing default of 0 could be preserved for backward compatibility:

routes = create_jsonrpc_routes(
    request_handler,
    rpc_url="/",
    shutdown_grace_period=30.0,
)

With this configuration, a finite A2A stream should be allowed to finish naturally within the grace period before being force-cancelled.

Describe alternatives you've considered

  • Subclassing or replacing the A2A dispatchers solely to customize EventSourceResponse.
  • Monkey-patching EventSourceResponse.
  • Globally disabling sse-starlette automatic graceful drain and relying on the ASGI server timeout. This may cause indefinite streams to block shutdown and is too broad for this use case.

Additional context

This is separate from #545. That issue concerned send_timeout and was marked obsolete for the v1 implementation; this request concerns cooperative shutdown after SIGTERM.

sse-starlette already supports shutdown_grace_period,
https://github.com/sysid/sse-starlette#cooperative-shutdown
so the missing piece is a configuration path from the A2A SDK API to EventSourceResponse.

The configured value should be documented as being shorter than the ASGI server's graceful-shutdown timeout.

Code of Conduct

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

Metadata

Metadata

Assignees

Labels

component: serverIssues related to frameworks for agent execution, HTTP/event handling, database persistence logic.status:awaiting response

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions