a2aproject / a2aproject/a2a-js

[Bug]: SSE clients silently drop events with standalone CR line endings

未关闭
#714 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
615
派生
169
平均合并
1 天 6 小时
30 天内合并 PR
21

描述

## What happened

JSON-RPC and HTTP+JSON clients silently yield no updates when a valid SSE response uses standalone CR (`\r`) line endings. The same event works with LF (`\n`) or CRLF (`\r\n`). A finite response completes without an error or an event.

## What I expected

All three SSE line endings should deliver the same task update, including when line delimiters cross network chunk boundaries.

## Steps to reproduce

1. Create a `RestTransport` with a mock fetch returning HTTP 200 and `Content-Type: text/event-stream`.
2. Use this response body (JavaScript string literal):

```js
'data: {"task":{"id":"task-1","contextId":"ctx-1","status":{"state":"TASK_STATE_WORKING"}}}\r\r'
```

3. Iterate `resubscribeTask({ id: 'task-1', tenant: '' })` until completion. It yields **0** events.
4. Replace `\r\r` with `\n\n` or `\r\n\r\n`. Both yield **1** event.
5. Repeat with `JsonRpcTransport`, wrapping the task payload in `{ jsonrpc: '2.0', id: , result: }`. The results are identical.

## Additional context

Reproduced with the response split into one-byte chunks; the relevant client/parser code matches upstream main `ae20aca7d6fbc94c839a37d945ec637642289227`.

The HTML SSE standard explicitly allows CRLF, LF, and standalone CR as line endings:
https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream

This can silently discard task updates from a conforming remote agent. Please cover standalone CR as well as split CRLF delimiters, so adding CR support does not introduce duplicate event boundaries.

贡献指南

打开贡献指南

调研方向

查看 client/transport 代码中的 SSE 解析逻辑,可能位于 `RestTransport` 和 `JsonRpcTransport` 中。测试用例已经提供;先使用给定的响应正文设置 mock fetch。运行现有测试以查看失败情况,然后修改解析器,使其按照 HTML 规范处理独立的 CR 换行符。确保该修复也能处理跨 chunk 边界拆分的分隔符。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
backend-api-design, networking
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
65/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。