ag-ui-protocol / ag-ui-protocol/ag-ui

abortRun() emits RUN_FINISHED and does not release the source

未關閉
#2,417 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
15.9k
分支
1.4k
平均合併
1 天 17 小時
30 天內合併 PR
163

描述

**Versions:** `@ag-ui/mastra@1.1.2` (also reproduces on 1.1.1), `@ag-ui/core` / `@ag-ui/client@0.0.58`, `@mastra/core@1.59.0`, Node 22.

Related: #2416 (same audit, different invariant).

## Expected

`abortRun()` cancels the current execution. A cancelled run should not be reported as a successful completion, and the underlying stream should stop being consumed.

## Actual

Both fail.

1. The run emits a full `RUN_FINISHED` — indistinguishable from success.
2. The source keeps being drained after the abort. `MastraAgent.run()`'s Observable teardown is `() => {}`, so nothing propagates cancellation to the `fullStream` iteration.

## Repro

Same mock local agent as #2416, with a script that spaces chunks 200ms apart:

```js
{ type: "start", payload: { messageId: "m1" } }
{ type: "text-delta", payload: { text: "one" } }
// … 200ms …
{ type: "text-delta", payload: { text: "two" } }
// … 200ms …
{ type: "text-delta", payload: { text: "three" } }
{ type: "finish", payload: {} }
```

Start via `runAgent()`, call `agent.abortRun()` ~120ms in, and count chunks pulled from the generator after that point.

## Observed

```
events = [RUN_STARTED, TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT ×3,
TEXT_MESSAGE_END, RUN_FINISHED]
terminals = 1
chunks fed AFTER abortRun() = 3
```

## Impact

In a composition with `@assistant-ui/react-ag-ui`, the client marks itself `{status:{type:"incomplete",reason:"cancelled"}}` locally when the user hits Stop; the late `RUN_FINISHED` then arrives and overwrites that with a completed run. **The user stops a generation and is told it finished.**

The continued draining is also a resource leak on any real provider stream.

## Adjacent note

`EventType` has 33 members and no `RUN_CANCELLED` at 0.0.57, 0.0.58 or 0.0.59-canary, so there is no wire frame for cancellation at all — consumers close that gap client-side. That may be intentional, but it means `RUN_FINISHED` is currently the only thing a cancelled run can say, which is what makes the behaviour above actively misleading rather than merely incomplete.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。