mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
3edf06339c
Fixes #5966. Follow-up to #5812 / #5885. ## Problem After #5885 stopped the post-terminal `TEXT_MESSAGE_END` crash, pressing **Stop** no longer breaks the chat — but for an agent that emits a terminal `RUN_ERROR` (code `abort`) as its cancellation signal (e.g. pydantic-ai's `AGUIAdapter`), the client still surfaces that as an **error banner** ("This operation was aborted"). A user-initiated stop is expected cancellation, not a failure. Traced path (no abort suppression at any hop): `RUN_ERROR(code:"abort")` → `RunHandler.onRunErrorEvent` (`run-handler.ts`) → `emitAgentError(AGENT_RUN_ERROR_EVENT)` → `onError` → CopilotChat/react-ui `triggerChatError` → banner. The only existing abort suppression is for the *local* fetch-abort rejection (`run-handler.ts:318`), a different path. ## Fix Suppress the error emission in `onRunErrorEvent` when the run was user-aborted — mirroring the local-abort suppression already on the `runAgent`/`connectAgent` paths: ```ts const runWasAborted = this._runAbortController?.signal.aborted === true; if (runWasAborted || event?.code === "abort") { return; } ``` Prefers the client's own `_runAbortController.signal.aborted` (robust — the agent-supplied `code` isn't standardized across agents; the `code:"abort"` in the repro comes from the agent, not CopilotKit) with `code === "abort"` as a secondary signal. Normal `RUN_ERROR`s are unaffected. ## Testing - **TDD** (`core-error-handling.test.ts`): two new tests fail pre-fix and pass after — - agent emits `RUN_ERROR` code `"abort"` → no `AGENT_RUN_ERROR_EVENT` surfaced. - run user-aborted mid-stream (via `agent.abortRun()`, which RunHandler intercepts to abort the controller) → a subsequent `RUN_ERROR` with a *non-abort* code is still suppressed (exercises the `signal.aborted` path). - The pre-existing test — normal `RUN_ERROR` (code `"bad_request"`) still emits `AGENT_RUN_ERROR_EVENT` — continues to pass (control against over-suppression). - Full `@copilotkit/core` suite green: **578/578**. `tsc` 0 errors; `oxlint` 0. Note: this is a UX/product call (a user Stop shouldn't render as an error). Suppressing in core fixes it for both the default chat banner and app-level `onError` handlers; the run lifecycle still reflects the termination. 🤖 Generated with [Claude Code](https://claude.com/claude-code)