Conversation
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/server/routes/common.py | 89.66% | 88.33% | 🔴 -1.32% |
| src/a2a/server/routes/jsonrpc_dispatcher.py | 85.44% | 86.59% | 🟢 +1.15% |
| src/a2a/server/routes/rest_dispatcher.py | 94.25% | 92.43% | 🔴 -1.82% |
| Total | 92.97% | 92.96% | 🔴 -0.02% |
Generated by coverage-comment.yml
Use the literal 413 as the ImportError fallback instead of the Any special form, and move the ty ignore comment to the line that actually errors so the type checker suppression takes effect.
|
There are five |
Addresses review feedback on a2aproject#1184: there are five `EventSourceResponse` construction sites and the first revision covered the three v1 routes only. The two v0.3 compat adapters (`compat/v0_3/jsonrpc_adapter.py:280`, `compat/v0_3/rest_adapter.py:99`) still built the response bare, so with `enable_v0_3_compat=True` those streams kept the `ping=None` and unbounded `send_timeout` behaviour this PR removes elsewhere. Both sites now pass `ping` and `send_timeout` from `a2a.utils.constants`, matching the v1 routes. The added tests fail without the source change (`assert None == 300`), so they pin the behaviour rather than the construction itself.
|
You're right — five construction sites and I covered three. Fixed in 17c6f7c: both adapters now pass |
What changed
1. Configure SSE heartbeat and stream timeout explicitly
Problem:
EventSourceResponsewas created without explicitping/send_timeoutinsrc/a2a/server/routes/jsonrpc_dispatcher.py(_create_response) andsrc/a2a/server/routes/rest_dispatcher.py(_handle_streaming). With the installedsse-starlette, the defaultpingisNone— no heartbeat is emitted — so idle streams send nothing and dead clients are never detected; there is also no cap on how long a stream may sit without producing output.Fix (src/a2a/server/routes/jsonrpc_dispatcher.py, src/a2a/server/routes/rest_dispatcher.py):
SSE_PING_INTERVAL_SECONDS = 15andSSE_SEND_TIMEOUT_SECONDS = 300tosrc/a2a/utils/constants.py.EventSourceResponsecreated by both dispatchers now passesping=15(heartbeat frame every 15s) andsend_timeout=300(tear down a stream that makes no progress for 5 minutes).2. Enforce a request body size limit
Problem: No limit was enforced on the HTTP request body. A client could POST an arbitrarily large payload, which the JSON-RPC (
request.json()) and REST (request.body()) paths buffer fully in memory — a memory-exhaustion / DoS vector.Fix (src/a2a/server/routes/common.py, src/a2a/server/routes/jsonrpc_dispatcher.py, src/a2a/server/routes/rest_dispatcher.py):
MAX_REQUEST_BODY_SIZE = 10 MiBtosrc/a2a/utils/constants.py.read_request_body_with_limit()inroutes/common.py: it fast-rejects via theContent-Lengthheader when present, and otherwise streams the body in chunks with an incremental cap, so oversized chunked bodies are rejected while being read rather than buffered unboundedly. The body is cached on the request so existingrequest.body()/stream()consumers keep working.handle_requestsnow reads through the limited reader; the existingHTTPException(413)handling returnsInvalidRequestError("Payload too large")._handle_streamingpre-consume,on_message_send,on_message_send_stream,set_push_notification) now use a wrapper that converts the 413 intoInvalidRequestError("Payload too large")(400).Testing
./.venv/Scripts/python -m pytest tests/server/routes/test_jsonrpc_dispatcher.py tests/server/routes/test_rest_dispatcher.py -q→ 39 passed (includes new tests: oversized body rejected via body content and viaContent-Length, andping_interval/send_timeoutassertions on the returnedEventSourceResponsefor both dispatchers)../.venv/Scripts/python -m pytest tests/server/ tests/compat/ -q→ 924 passed, 90 skipped, 3 xfailed (pre-existing xfails reference upstream issue [Feat]: Improve server concurrency architecture #869)../.venv/Scripts/python -m ruff checkon all modified files: clean."Payload too large"instead of being buffered.