From cf37fd5281dfed26d702b370bef1fdb82a097dc0 Mon Sep 17 00:00:00 2001 From: Yun Chan Date: Tue, 20 Oct 2026 16:29:29 +0900 Subject: [PATCH] fix(meeting): save the recording when the app quits while a stop is still flushing Quitting during the few seconds a stop waits for the last caption skipped the shutdown save, so the in-memory audio and every sentence since the last checkpoint were lost. Shutdown now saves unless post-processing already wrote the final result. --- .../src/main/services/MeetingModeService.ts | 7 ++++++- .../red/meeting-recording-redteam-r2-1.test.ts | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/main/services/MeetingModeService.ts b/apps/desktop/src/main/services/MeetingModeService.ts index cfb2b0c..aa4b7e7 100644 --- a/apps/desktop/src/main/services/MeetingModeService.ts +++ b/apps/desktop/src/main/services/MeetingModeService.ts @@ -142,6 +142,8 @@ class MeetingModeService extends EventEmitter { private readonly _unsubscribeScope: () => void /** 회의별 자막 인식 실패 수 — 전사가 비었을 때 'completed' 대신 'error' 로 닫는 근거 */ private readonly _captionFailures = new Map() + /** 정지 후처리가 최종 저장을 마친 회의 — 종료(shutdown) 때 다시 쓰지 않는다. */ + private _finalizedSessionId: string | null = null private _unsubscribeCaptionFailure: (() => void) | null = null private _lastCaptionFailureNoticeAt = 0 @@ -457,7 +459,9 @@ class MeetingModeService extends EventEmitter { this._stopTimers() const session = this._current if (!session) return - if (!session.isStopping) { + // 정지 중(마지막 문장 flush 대기)이어도 아직 최종 저장 전이면 지금까지를 저장한다 — 건너뛰면 + // 메모리에만 있던 녹음과 마지막 주기 저장 이후 전사가 사라졌다. + if (this._finalizedSessionId !== session.id) { try { this._persistSnapshot(session.checkpoint({ includeAudio: true }), { interrupted: false }) logger.info(`종료 중 회의 저장: sessionId=${session.id}`) @@ -533,6 +537,7 @@ class MeetingModeService extends EventEmitter { // Step 2: DB 저장 (rawTranscript + completed) + Step 2.5: 오디오 WAV 파일 저장 (화자 구분용) this._sendProgress(sessionId, 'saving', 80) this._persistSnapshot(snapshot, { interrupted: false }) + this._finalizedSessionId = sessionId // Step 3: 알림 this._sendProgress(sessionId, 'notifying', 95) 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 545c7d1..9185c30 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 @@ -162,6 +162,24 @@ describe('앱 종료·중단 복구', () => { expect(meeting.getState()).toBe('idle') }) + it('정지 처리(마지막 문장 대기) 중에 종료돼도 지금까지의 전사를 저장한다', async () => { + const meeting = getMeetingModeService() + const { sessionId } = await meeting.startRecording() + caption.bus?.emit('segment', { id: 'seg-b', text: '정지 직전 문장', timestamp: Date.now(), isFinal: true } satisfies CaptionSegment) + let release = (): void => undefined + caption.gate = new Promise((resolve) => { release = resolve }) + const stopping = meeting.stopRecording() + + await meeting.shutdown() + + const saved = row(sessionId) + expect(saved?.status).toBe('completed') + expect(saved?.rawTranscript).toContain('정지 직전 문장') + release() + caption.gate = null + await stopping.catch(() => undefined) + }) + it('남은 recording/processing 행을 닫는다 — 전사가 있으면 completed, 없으면 error', () => { insertSession('stuck-with-text', { status: 'recording', rawTranscript: '[00:01] 저장된 부분' }) // 전사가 없는 행은 이 기기에서 시작한 녹음(원장 표식)일 때만 닫는다 — redteam r3: 폰의 진행 중 회의 보호