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.
This commit is contained in:
Yun Chan 2026-10-20 22:53:07 +09:00
parent 95656b098a
commit a14bb52b7f
2 changed files with 38 additions and 8 deletions

View file

@ -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',

View file

@ -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<Array<{ role: string; content: string }>>,
/** 채팅 스트림 첫 토큰 뒤를 붙잡아 두는 게이트 */
chatGate: null as Promise<void> | 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<string, string> {
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<void>((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([])
})
})