fix(desktop): harden session, meeting, caption and LLM lifecycles; route LLM calls through the gateway

This commit is contained in:
Yun Chan 2026-09-28 02:16:15 +09:00
parent 3a46437f28
commit ddc78546f0
62 changed files with 4786 additions and 648 deletions

View file

@ -435,7 +435,7 @@ export interface OpenForUserResult {
/**
* 사용자별 DB 열기 — userData/users/${userId}/d3ro.db
* 이미 다른 사용자 DB가 열려있으면 먼저 close 후 오픈.
* 이미 다른 사용자 DB가 열려있으면 새 DB 를 연 뒤에 닫는다(실패하면 이전 DB 유지).
* 동일 사용자면 no-op.
*/
export function openForUser(userId: string): OpenForUserResult {
@ -448,11 +448,6 @@ export function openForUser(userId: string): OpenForUserResult {
return { created: false, dbPath: getUserDbPath(userId) }
}
// 다른 사용자가 열려있으면 먼저 닫기
if (sqlite) {
closeCurrent()
}
// 레거시 DB는 첫 오픈 직전 silent archive
archiveLegacyDbIfExists()
@ -466,26 +461,33 @@ export function openForUser(userId: string): OpenForUserResult {
logger.info(`Opening database for user ${userId} at: ${dbPath} (existed=${existed})`)
// 원자적 교체: 새 DB 를 열고 스키마까지 적용한 뒤에야 이전 DB 를 닫는다.
// 예전엔 먼저 닫고 열었다 — 계정 DB 가 손상되면(applySchema 실패) 로컬 DB 도 이미 닫혀 앱이
// 재시작 전까지 모든 저장·조회에 실패했다. 실패하면 이전 DB 가 그대로 열려 있다.
let next: Database.Database | null = null
let nextDb: BetterSQLite3Database<typeof schema>
try {
sqlite = new Database(dbPath)
applySchema(sqlite)
db = drizzle(sqlite, { schema })
currentUserId = userId
next = new Database(dbPath)
applySchema(next)
nextDb = drizzle(next, { schema })
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
logger.error(`Failed to open database for user ${userId}: ${message}`)
// 부분 상태 초기화
logger.error(`Failed to open database for user ${userId}: ${message} (keeping ${currentUserId ?? 'none'} open)`)
try {
sqlite?.close()
next?.close()
} catch {
// ignore
}
sqlite = null
db = null
currentUserId = null
throw new D3ROError(ErrorCode.DBOpenFailed, `Failed to open user DB: ${message}`)
}
if (sqlite) {
closeCurrent()
}
sqlite = next
db = nextDb
currentUserId = userId
logger.info(`Database opened for user: ${userId}`)
// 계정 범위 저장소(명령·템플릿)도 이 사용자로 바꾼다 — 동기화 엔진이 만들어지기 전에 동기적으로 끝난다.
emitAccountScopeChanged(userId)