fix(sync): don't let a pull wipe the checkpointed transcript of a meeting this device is recording

Checkpoints stay local until stop, so a pull during recording replaced the
saved transcript with the server's empty one; a crash then recovered the
meeting as an error with nothing in it. Status, transcript, end time and
duration of a locally recording meeting are now kept on pull.
This commit is contained in:
Yun Chan 2026-10-20 16:31:08 +09:00
parent cf37fd5281
commit 69c4307eee
2 changed files with 82 additions and 1 deletions

View file

@ -19,6 +19,7 @@ import { getRAGService } from '../RAGService'
import { deleteHistoryLocally } from '../history-deletion'
import { purgeRemoteAudio } from './audio-sync'
import { pushMeetingSegments } from './transcript-sync'
import { syncStateRecordingLedger } from '../meeting/local-recording-ledger'
import { dropEntry } from './sync-outbox'
import {
SyncRemoteError,
@ -502,16 +503,29 @@ const meetingsAdapter: SyncAdapter = {
errorMessage: str(row.error_message),
updatedAt,
}
// 이 기기에서 녹음 중인 회의: 주기 저장한 전사는 정지 때에야 올라간다. 그 전에 pull 이 서버의
// 빈 전사·'recording' 행으로 덮으면, 그사이 앱이 죽었을 때 복구할 전사가 사라졌다.
const set = syncStateRecordingLedger.isLocal(id) ? omitRecordingProgress(values) : values
getDatabase()
.insert(meetingSessions)
.values({ id, ...values, createdAt: ms(row.created_at, updatedAt) })
.onConflictDoUpdate({ target: meetingSessions.id, set: values })
.onConflictDoUpdate({ target: meetingSessions.id, set })
.run()
return true
},
deleteLocal: deleteMeetingLocally,
}
const RECORDING_PROGRESS_FIELDS = ['status', 'rawTranscript', 'endedAt', 'durationMs'] as const
function omitRecordingProgress<T extends Record<(typeof RECORDING_PROGRESS_FIELDS)[number], unknown>>(
values: T
): Partial<T> {
const rest: Partial<T> = { ...values }
for (const field of RECORDING_PROGRESS_FIELDS) delete rest[field]
return rest
}
// ── meeting_memos ───────────────────────────────────────
function hasLocalMeeting(id: string): boolean {

View file

@ -0,0 +1,67 @@
// 녹음 중인 회의를 pull 이 덮지 않는다 — 주기 저장한 전사는 정지 때에야 올라가므로,
// 그 전에 서버의 빈 전사·'recording' 행으로 덮으면 충돌 복구 때 전사가 사라졌다.
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { eq } from 'drizzle-orm'
import { createTestDb } from '../../helpers/createTestDb'
import { bindTestDatabase, unbindTestDatabase } from '../../../src/main/db'
import { meetingSessions } from '../../../src/main/db/schema'
import { initInMemoryConfig, resetInMemoryConfig } from '../../../src/main/services/ConfigService'
import { TABLE_ADAPTERS } from '../../../src/main/services/sync/sync-adapters'
import { syncStateRecordingLedger } from '../../../src/main/services/meeting/local-recording-ledger'
const USER = '11111111-1111-4111-8111-111111111111'
let created: ReturnType<typeof createTestDb>
const meetings = TABLE_ADAPTERS.find((adapter) => adapter.entity === 'meetings')!
function seedRecording(id: string): void {
const now = Date.now()
created.db
.insert(meetingSessions)
.values({ id, title: '주간 회의', status: 'recording', startedAt: now, rawTranscript: '[00:01] 저장된 문장', createdAt: now, updatedAt: now })
.run()
}
function remoteRow(id: string): Record<string, unknown> {
return { id, title: '이름 바꾼 회의', status: 'recording', started_at: new Date().toISOString(), raw_transcript: null, updated_at: new Date().toISOString() }
}
function local(id: string) {
return created.db.select().from(meetingSessions).where(eq(meetingSessions.id, id)).get()
}
beforeEach(() => {
initInMemoryConfig()
created = createTestDb()
bindTestDatabase(created.db, USER)
})
afterEach(() => {
unbindTestDatabase()
resetInMemoryConfig()
created.close()
})
describe('meetings pull — 이 기기에서 녹음 중인 회의', () => {
it('주기 저장한 전사·상태는 지키고 다른 필드는 반영한다', async () => {
const id = crypto.randomUUID()
seedRecording(id)
syncStateRecordingLedger.mark(id)
await meetings.applyRemote(remoteRow(id), {} as never)
expect(local(id)?.rawTranscript).toBe('[00:01] 저장된 문장')
expect(local(id)?.status).toBe('recording')
expect(local(id)?.title).toBe('이름 바꾼 회의')
})
it('녹음이 끝난(표식 없는) 회의는 서버 값을 그대로 반영한다', async () => {
const id = crypto.randomUUID()
seedRecording(id)
await meetings.applyRemote(remoteRow(id), {} as never)
expect(local(id)?.rawTranscript).toBeNull()
})
})