U+2028 in a JSON string cut A2A status events in two, because splitlines ends lines where SSE does not. a2a-python 1.3.1 splits only at CR and LF.
A status update that would not parse
Tanishka maintains the help-desk orchestrator at Belgavi's Book Store. It delegates long jobs, such as preparing a return label, to a remote agent over the A2A protocol and follows progress through a Server-Sent Events stream: each status-update event carries a JSON object with the task id and a short text.
One case, CASE-1042, never finished in the orchestrator's view. The remote agent had completed it; its logs showed the final event sent. The orchestrator's logs showed a JSON decoding error, Unterminated string, on an event whose payload looked complete when printed. The text field had been copied from a customer email and contained U+2028, the Unicode LINE SEPARATOR, which some word processors insert in place of a line break. The server serialized it raw. The Python client cut the event in two at that character.
Nothing in the payload was invalid. JSON allows U+2028 inside a string without escaping, and the SSE specification does not treat it as a line end. The client did.
What the specification says a line is
The HTML Living Standard defines the event stream format. A stream is a sequence of lines, and a line ends at a CRLF pair, a single LF or a single CR. Nothing else ends a line. Fields such as data: run to the end of their line, an empty line dispatches the event, and multiple data: lines in one event are joined with LF.
Python offers a method that looks like the right tool and is not: str.splitlines(). It splits at the three SSE line ends and also at vertical tab, form feed, the file, group and record separators (U+001C to U+001E), NEXT LINE (U+0085), LINE SEPARATOR (U+2028) and PARAGRAPH SEPARATOR (U+2029). httpx's Response.aiter_lines() follows the same rules, because its line decoder is built on the same splitting. Anything layered on either inherits ten line breaks where the protocol has three.
Which characters actually reach the wire
Half of those extra breaks never cause trouble, because JSON serializers escape every control character below U+0020. A vertical tab or record separator in a string is sent as \u000b or \u001e, which is plain ASCII on the wire. The three that cause trouble are U+0085, U+2028 and U+2029: they are not control characters in the JSON sense, so a serializer that emits raw UTF-8 sends them as they are.
Python's json.dumps escapes them by default, because ensure_ascii=True turns every non-ASCII character into an escape. The a2a-python SDK serializes with ensure_ascii=False, which is a reasonable choice for readable, compact UTF-8, and which sends the separators raw.
The companion example measures both readers on the same events, whole and in 7-byte and 1-byte chunks:
| Text contains | Sent raw | splitlines reader | Spec reader | splitlines reader, ensure_ascii=True |
|---|---|---|---|---|
| U+2028 line separator | yes | JSON error | ok | ok |
| U+2029 paragraph separator | yes | JSON error | ok | ok |
| U+0085 next line | yes | JSON error | ok | ok |
| Vertical tab, record separator, newline | no, escaped | ok | ok | ok |
| Plain ASCII | no | ok | ok | ok |
The a2a-python fix
In a2a-sdk 1.3.0, parse_sse_stream read the response with aiter_lines(). The live probe in the example runs the real function on all three characters and gets the same Unterminated string error for each, for the whole body and for chunked bodies. A fix, pull request 1456 for issue 1432, merged on 13 November 2026 and shipped in a2a-sdk 1.3.1 on 17 November 2026. It replaces aiter_lines() with a small reader over aiter_text() that splits only on CRLF, LF and CR. With 1.3.1 the probe parses every event.
The reader in the fix handles two details that a quick regex split would miss, and the companion example's spec reader does the same:
SSE_LINE_END = re.compile(r'\r\n|\r|\n')
def lines_per_spec(chunks):
"""Lines ended only by CRLF, LF or CR. A trailing CR is held back: the next chunk may start with LF."""
dec = codecs.getincrementaldecoder('utf-8')()
pending, held_cr = '', False
for chunk in chunks:
text = dec.decode(chunk)
if held_cr:
text = '\r' + text
held_cr = text.endswith('\r')
if held_cr:
text = text[:-1]
*done, rest = SSE_LINE_END.split(text)
if done:
done[0] = pending + done[0]
pending = ''
yield from done
pending += rest
if held_cr or pending:
yield pendingFirst, a CR at the end of a chunk is held back, because the next chunk may begin with the LF of the same CRLF. Splitting immediately would produce a spurious empty line, which in SSE dispatches an event early. Second, bytes are decoded incrementally: U+2028 is three bytes in UTF-8, and a 1-byte chunking cuts it into pieces that only decode correctly when the decoder keeps state. The fix in a2a-python decodes through aiter_text(), which does this; a custom byte reader has to do it explicitly.
Fixing it on either side
There are three places to fix this, and a robust system does more than one.
- Upgrade the client. If you use a2a-sdk, move to 1.3.1 or later. If you maintain your own SSE client in Python, find every
splitlines()andaiter_lines()on the stream path and replace it with a reader like the one above. - Escape on the server. Serializing event data with ASCII escapes (
ensure_ascii=Truein Python, or escaping U+0085, U+2028 and U+2029 explicitly) makes the stream immune to clients with this bug. It costs a few bytes per non-ASCII character. - Use a maintained SSE parser. If a library you already trust implements the specification's line rules, prefer it to a hand-rolled loop.
Server-side escaping alone is not enough, because you do not control every server you call. Client-side correctness alone is not enough either, because older clients stay deployed for months.
Failure modes this produces
- A task that never completes. The final event is lost, so the client waits until its own timeout and may retry work that already succeeded. In an agent system that can mean a duplicate action.
- Intermittent failures tied to content. Only events whose text contains one of the three characters fail, so the bug looks random and resists reproduction with synthetic test data.
- Corrupted rather than failed events. If the split happens to leave two fragments that each parse (for example, a text field split between two
data:lines in a format that tolerates it), the client sees wrong data with no error. - Silent drops. Some clients log and skip unparseable events. The stream continues, and only the missing state transition shows the problem.
Tradeoffs
Holding back a trailing CR adds a little latency to the last line of a chunk until the next chunk arrives or the stream ends; servers end every line with LF, so in practice the held CR is rare. ASCII escaping on the server increases payload size for non-English text, sometimes noticeably for scripts outside Latin; it is still the safer default for interoperability. A strict reader that rejects unexpected characters would be worse than either: the specification allows any character except the three line ends inside a field.
Verification
Add the three characters to your streaming tests. A useful fixture is one event whose text contains U+2028, U+2029 and U+0085, sent whole, in 1-byte chunks and with the CRLF of each line split across two chunks. The companion example does exactly that and records which reader parses what. For a running system, grep client logs for JSON decoding errors on stream events and check whether the raw payloads contain bytes E2 80 A8, E2 80 A9 or C2 85. In the example, the recorded files recorded_a2a_1.3.0.txt and recorded_a2a_1.3.1.txt show the real SDK's behaviour before and after the fix with httpx 0.28.1 and Python 3.13.5.
Running the companion code
cd examples/python/sse_line_endings
python example.py
python -m unittest -v test_example.py
pip install -r requirements.lock.txt && python live_probe.pyThe first two commands use only the standard library. The live probe installs a2a-sdk 1.3.0; install 1.3.1 instead to see the fix.