Symptom: your onEnd cleanup (saving partial results, logging aborts) runs on normal completion but never when the user hits stop().

Cause: on abort the response terminates immediately. Without consumeSseStream, the abort event is never forwarded through the SSE layer, so onEnd never executes.

Confirmation:
1. Add logging at the top of onEnd. Complete a generation normally: log appears. Abort one mid-stream: log missing.
2. Check the createUIMessageStreamResponse call. If it only passes stream with no consumeSseStream option, that is the bug.

Fix:

import { consumeStream, createUIMessageStreamResponse, toUIMessageStream } from 'ai';

return createUIMessageStreamResponse({
  stream: toUIMessageStream({
    stream: result.stream,
    onEnd: async ({ isAborted }) => {
      if (isAborted) { /* save partial, log abort */ }
      else { /* normal completion */ }
    },
  }),
  consumeSseStream: consumeStream,
});

Verification: start a long generation, abort it, and confirm the onEnd log line appears with isAborted true. Then let one complete and confirm isAborted is false.

Note the callback receives isAborted. Branch on it: partial-save on abort, full-save on completion. And keep onEnd fast; heavy work belongs in a background queue.