mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
0e787632a3
Pressing Stop mid-stream against a CopilotRuntime + HttpAgent proxy aborts the upstream agent, which emits a live RUN_ERROR while a text message is still open. finalizeRunEvents then appended a trailing TEXT_MESSAGE_END *after* that RUN_ERROR. Because the runners stream finalization events after everything the agent already emitted, the closer landed past the terminal and the AG-UI verifier rejected it with "the run has already errored with 'RUN_ERROR'. No further events can be sent." — crashing the chat. finalizeRunEvents (in @copilotkit/shared, consumed by the in-memory, intelligence, and sqlite runners) now returns early and appends nothing when the stream already contains a terminal event (RUN_FINISHED or RUN_ERROR): any message or tool call still open is closed by the terminal on the client. The abrupt-end path (no terminal -> close open streams + synthesize a terminal) is unchanged. Tests: - finalize-events.test.ts: terminal-present appends nothing (both RUN_FINISHED and RUN_ERROR) + a named #5812 case. - in-memory-runner.test.ts: end-to-end mid-stream-stop regression that asserts no events follow RUN_ERROR and the stream passes AG-UI verifyEvents (the verifier the browser runs). - intelligence-runner.test.ts: corrected an assertion that had encoded the buggy post-terminal TEXT_MESSAGE_END. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>