fix(desktop): stop pinning local models in memory and cap audio buffers
Some checks failed
ci / 정본·보안·린트·타입·테스트 (push) Successful in 56s
ci / .NET API 서버 테스트 (push) Successful in 10s
deploy-site / deploy (push) Successful in 38s
ci / 모바일 린트·타입·Jest (push) Successful in 44s
ci / 워크스페이스 빌드 검증 (push) Successful in 54s
ci / Supabase Edge Functions + Cloudflare Worker (push) Successful in 22s
portable-unsigned / portable-windows (push) Failing after 35s
release / release-windows (push) Failing after 13s

The PC-wide slowdown was not a leak but model residency: boot warmup loaded
gemma4:e4b (~11.6 GB RAM incl. 5.9 GB pinned host buffer, no mmap on Windows
CUDA) and kept it for 30m, next to the large-v3 sidecar. Measured on the HEAD
build: free RAM 7.9 GB -> 32 MB within 20 s; after this change 10.8 GB with no
Ollama model loaded until typing starts.

- single LOCAL_LLM_KEEP_ALIVE (10m) for every local request; no boot warmup
- unload this app's resident Ollama models (keep_alive 0) on quit
- sidecar POST /unload for the aux slot; captions release it on stop
- partial dictation copies only the tail window, not the whole recording
- cap the voice-conversation listen buffer at 5 minutes
- mic test: generation guard so re-entry cannot orphan lease/timers
- startRealtime: single-flight and removeChannel to stop duplicate bindings
- meeting WAV save writes header and PCM without a concat copy

Docs: AI-01 policy note, GAP-PERF-01 with remaining work.
This commit is contained in:
Yun Chan 2026-10-11 11:35:15 +09:00
parent a7c0d6fb21
commit d63854db67
19 changed files with 268 additions and 45 deletions

View file

@ -113,6 +113,8 @@ class CloudSyncService extends EventEmitter {
private _realtimeRetryTimer: NodeJS.Timeout | null = null
private _initialized = false
private _realtimeChannel: RealtimeChannel | null = null
/** 진행 중인 startRealtime — 동시 호출을 하나로 합친다 */
private _realtimeStarting: Promise<void> | null = null
private _engine: SyncEngine | null = null
/** 로그인 시작(startSignIn) 후 콜백을 받아들이는 기한. null이면 진행 중인 로그인이 없다 */
private _pendingSignInUntil: number | null = null
@ -803,14 +805,27 @@ class CloudSyncService extends EventEmitter {
* devices 변경이 오면 이 기기의 연결 해제 여부를 확인한다.
* 중복 호출 방지를 위해 기존 채널이 있으면 먼저 해제.
*/
async startRealtime(): Promise<void> {
startRealtime(): Promise<void> {
// heartbeat·재시도 타이머·인증 처리가 동시에 부를 수 있다. 겹치면 realtime-js 가 같은 topic 의
// 기존 채널 객체를 돌려줘 postgres_changes 바인딩이 호출마다 중복으로 쌓였다 — 한 번에 하나만 돈다.
if (!this._realtimeStarting) {
this._realtimeStarting = this._startRealtime().finally(() => {
this._realtimeStarting = null
})
}
return this._realtimeStarting
}
private async _startRealtime(): Promise<void> {
if (!this._client || !this._session) {
logger.warn('Realtime 시작 불가 — 로그인 필요')
return
}
if (this._realtimeChannel) {
await this._realtimeChannel.unsubscribe()
const previous = this._realtimeChannel
this._realtimeChannel = null
// unsubscribe 만 하면 클라이언트 레지스트리에 채널이 남아 같은 topic 으로 재사용된다
await this._client.removeChannel(previous)
}
const userId = this._session.user.id
@ -843,8 +858,9 @@ class CloudSyncService extends EventEmitter {
{ event: '*', schema: 'public', table: 'devices', filter: `user_id=eq.${userId}` },
() => void this._checkInDevice('heartbeat')
)
this._realtimeChannel = channel
.subscribe((status) => {
const subscribed = channel.subscribe((status) => {
// 교체된 이전 채널의 CLOSED 는 무시한다 — 재구독을 다시 예약해 채널이 겹치게 된다
if (this._realtimeChannel !== subscribed) return
logger.info(`Realtime 채널 상태: ${status}`)
// U1: TIMED_OUT / CHANNEL_ERROR / CLOSED 시 지수 백오프 자동 재구독.
// Supabase realtime은 네트워크 jitter로 간헐적 TIMED_OUT이 발생할 수 있고,
@ -862,6 +878,7 @@ class CloudSyncService extends EventEmitter {
this._scheduleRealtimeRetry()
}
})
this._realtimeChannel = subscribed
}
/**
@ -907,8 +924,10 @@ class CloudSyncService extends EventEmitter {
}
this._realtimeRetryCount = 0
if (this._realtimeChannel) {
await this._realtimeChannel.unsubscribe()
const channel = this._realtimeChannel
this._realtimeChannel = null
if (this._client) await this._client.removeChannel(channel)
else await channel.unsubscribe()
logger.info('Realtime 채널 종료')
}
}