From 9a9b61b9a3a162962a44611ee8c09c402f5d7201 Mon Sep 17 00:00:00 2001 From: claude_code Date: Sun, 21 Jun 2026 21:21:48 +0300 Subject: [PATCH] feat(ai-chat): log aborted stream turns in onAbort The onAbort terminal path persisted the partial turn but wrote nothing to the log, so a turn killed by a client disconnect / proxy drop / stop() was invisible in the logs (unlike onError and the controller catch, which both log). Add a logger.warn with the chat id, completed step count and partial-text length so an aborted turn is traceable. --- apps/server/src/core/ai-chat/ai-chat.service.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/server/src/core/ai-chat/ai-chat.service.ts b/apps/server/src/core/ai-chat/ai-chat.service.ts index 4f6f4f47..e9a8590a 100644 --- a/apps/server/src/core/ai-chat/ai-chat.service.ts +++ b/apps/server/src/core/ai-chat/ai-chat.service.ts @@ -394,6 +394,14 @@ export class AiChatService { // Client disconnected / request aborted: persist the partial answer, // including any completed tool steps so the turn replays faithfully. const text = steps.map((s) => s.text ?? '').join(''); + // Unlike onError/onFinish, this terminal path otherwise writes nothing, + // so an aborted turn (client disconnect / proxy drop / stop()) would be + // invisible in the logs. Log it (warn) so the abort is traceable, with + // the step count and how much partial text was produced before the cut. + this.logger.warn( + `AI chat stream aborted (chat ${chatId}) after ${steps.length} ` + + `step(s), ${text.length} chars partial text; persisting partial turn.`, + ); await persistAssistant({ text, toolCalls: serializeSteps(steps),