From a14bb52b7f65c151c7564e56b4338d54b440acec Mon Sep 17 00:00:00 2001 From: Yun Chan Date: Tue, 20 Oct 2026 22:53:07 +0900 Subject: [PATCH] fix(meeting-chat): don't send a cancelled answer back to the panel Clearing the chat mid-answer emptied the panel and then the truncated answer reappeared, a turn the model's history never recorded. --- .../src/main/services/MeetingModeService.ts | 17 ++++++----- .../meeting-recording-redteam-r2-1.test.ts | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/apps/desktop/src/main/services/MeetingModeService.ts b/apps/desktop/src/main/services/MeetingModeService.ts index aa4b7e7..3e9d37f 100644 --- a/apps/desktop/src/main/services/MeetingModeService.ts +++ b/apps/desktop/src/main/services/MeetingModeService.ts @@ -1418,14 +1418,15 @@ ${excerpt.text}` this._sendToRenderer(IPC_CHANNELS.MEETING_CHAT.DELTA, { sessionId, token }) } - if (!signal.aborted) { - const updated = [ - ...history, - { role: 'user' as const, content: userMessage }, - { role: 'assistant' as const, content: fullResponse }, - ] - this._chatHistories.set(sessionId, updated.slice(-MAX_CHAT_HISTORY_MESSAGES)) - } + // 취소(대화 지우기·패널 떠남·같은 회의의 새 질문)된 답변은 보내지 않는다 — 비운 대화에 잘린 답변이 + // 다시 나타났고, 기록에 없는 턴이라 화면과 모델의 대화가 어긋났다. + if (signal.aborted) return + const updated = [ + ...history, + { role: 'user' as const, content: userMessage }, + { role: 'assistant' as const, content: fullResponse }, + ] + this._chatHistories.set(sessionId, updated.slice(-MAX_CHAT_HISTORY_MESSAGES)) this._sendToRenderer(IPC_CHANNELS.MEETING_CHAT.MESSAGE, { sessionId, role: 'assistant', diff --git a/apps/desktop/tests/red/meeting-recording-redteam-r2-1.test.ts b/apps/desktop/tests/red/meeting-recording-redteam-r2-1.test.ts index 9185c30..0945596 100644 --- a/apps/desktop/tests/red/meeting-recording-redteam-r2-1.test.ts +++ b/apps/desktop/tests/red/meeting-recording-redteam-r2-1.test.ts @@ -12,6 +12,7 @@ import { EventEmitter } from 'events' import { eq } from 'drizzle-orm' import type { CaptionSegment } from '@d3ro/core/types' import { LLM_PROXY_CHAT_LIMITS } from '@d3ro/core/llm-chat' +import { IPC_CHANNELS } from '@d3ro/core/ipc-channels' import { useRedHarness } from './harness' const caption = vi.hoisted(() => ({ @@ -55,6 +56,8 @@ vi.mock('../../src/main/services/AudioCaptureService', () => ({ const llm = vi.hoisted(() => ({ generateInputs: [] as string[], chatCalls: [] as Array>, + /** 채팅 스트림 첫 토큰 뒤를 붙잡아 두는 게이트 */ + chatGate: null as Promise | null, })) vi.mock('../../src/main/services/LocalLLMService', async (importOriginal) => { @@ -65,6 +68,10 @@ vi.mock('../../src/main/services/LocalLLMService', async (importOriginal) => { isAvailable: () => true, async *chatStream(messages: Array<{ role: string; content: string }>): AsyncGenerator { llm.chatCalls.push(messages) + if (llm.chatGate) { + yield '잘린 ' + await llm.chatGate + } yield '답변' return '답변' }, @@ -258,4 +265,26 @@ describe('회의 채팅 범위', () => { expect(meeting.getMeetingChatHistory('chat-a')).toEqual([]) expect(meeting.getMeetingChatHistory('chat-b')).toHaveLength(2) }) + + it('답변 도중 지우면(취소) 잘린 답변을 화면으로 보내지 않는다', async () => { + insertSession('chat-c', { rawTranscript: '[00:01] C' }) + const send = vi.fn() + const { getMainWindow } = await import('../../src/main/windows/WindowManager') + vi.mocked(getMainWindow).mockReturnValue({ isDestroyed: () => false, webContents: { send } } as never) + let release = (): void => undefined + llm.chatGate = new Promise((resolve) => { release = resolve }) + const meeting = getMeetingModeService() + + const answering = meeting.chatWithMeeting('chat-c', 'C?') + await vi.waitFor(() => expect(send).toHaveBeenCalledWith(IPC_CHANNELS.MEETING_CHAT.DELTA, expect.anything())) + meeting.cancelMeetingChat('chat-c') + meeting.clearMeetingChatHistory('chat-c') + release() + await answering + llm.chatGate = null + vi.mocked(getMainWindow).mockReturnValue(undefined as never) + + expect(send.mock.calls.some(([channel]) => channel === IPC_CHANNELS.MEETING_CHAT.MESSAGE)).toBe(false) + expect(meeting.getMeetingChatHistory('chat-c')).toEqual([]) + }) })