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.
This commit is contained in:
@@ -394,6 +394,14 @@ export class AiChatService {
|
|||||||
// Client disconnected / request aborted: persist the partial answer,
|
// Client disconnected / request aborted: persist the partial answer,
|
||||||
// including any completed tool steps so the turn replays faithfully.
|
// including any completed tool steps so the turn replays faithfully.
|
||||||
const text = steps.map((s) => s.text ?? '').join('');
|
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({
|
await persistAssistant({
|
||||||
text,
|
text,
|
||||||
toolCalls: serializeSteps(steps),
|
toolCalls: serializeSteps(steps),
|
||||||
|
|||||||
Reference in New Issue
Block a user