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

@ -115,7 +115,7 @@ afterEach(async () => {
})
describe('SuggestionService warm-up', () => {
it('동시 warm-up 호출을 하나의 1토큰 요청으로 합치고 30분간 유지한다', async () => {
it('동시 warm-up 호출을 하나의 1토큰 요청으로 합치고 공통 keep-alive(10분)로 유지한다', async () => {
localLlm.streamGenerate.mockImplementation(async function* () {
yield 'ok'
})
@ -129,7 +129,7 @@ describe('SuggestionService warm-up', () => {
expect(localLlm.streamGenerate).toHaveBeenCalledTimes(1)
expect(localLlm.streamGenerate).toHaveBeenCalledWith(
'hi',
expect.objectContaining({ maxTokens: 1, keepAlive: '30m' })
expect.objectContaining({ maxTokens: 1, keepAlive: '10m' })
)
expect(warmingStates).toEqual([true, false])
})

View file

@ -152,7 +152,6 @@ describe('VoiceConversationService local response ownership', () => {
signal: expect.any(AbortSignal),
maxTokens: 512,
timeoutMs: 60_000,
keepAlive: '2m',
}),
)

View file

@ -179,3 +179,48 @@ describe('LocalLLMService request lifecycle', () => {
service.stopPolling()
})
})
describe('LocalLLMService model residency (2026-10-11 memory policy)', () => {
beforeEach(() => {
initInMemoryConfig()
resetLocalLLMServiceForTests()
markAvailable()
})
afterEach(() => {
resetLocalLLMServiceForTests()
resetInMemoryConfig()
vi.unstubAllGlobals()
})
it('applies the shared 10m keep_alive when a caller does not set one', async () => {
const bodies: Array<{ keep_alive?: string | number }> = []
vi.stubGlobal('fetch', vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
bodies.push(JSON.parse(String(init?.body)) as { keep_alive?: string })
return completedGenerateResponse()
}))
await getLocalLLMService().generate('hi', { model: 'gemma4:e4b' })
expect(bodies[0].keep_alive).toBe('10m')
})
it('unloads only the models this app loaded, once, with keep_alive 0', async () => {
const bodies: Array<{ model: string; keep_alive?: string | number; prompt?: string }> = []
vi.stubGlobal('fetch', vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
bodies.push(JSON.parse(String(init?.body)) as { model: string; keep_alive?: string })
return completedGenerateResponse()
}))
const service = getLocalLLMService()
await service.unloadResidentModels()
expect(bodies).toHaveLength(0)
await service.generate('hi', { model: 'gemma4:e4b' })
await service.unloadResidentModels()
await service.unloadResidentModels()
const unloads = bodies.filter((body) => body.keep_alive === 0)
expect(unloads).toEqual([{ model: 'gemma4:e4b', keep_alive: 0 }])
})
})

View file

@ -172,6 +172,7 @@ vi.mock('@supabase/supabase-js', () => {
},
from: () => query(),
channel: () => channel,
removeChannel: async () => "ok",
realtime: { setAuth: async () => undefined },
functions: {
invoke: vi.fn(async () => ({ data: { ok: true }, error: null })),

View file

@ -181,6 +181,7 @@ vi.mock('@supabase/supabase-js', () => {
},
from: () => query(),
channel: () => channel,
removeChannel: async () => "ok",
realtime: { setAuth: async () => undefined },
}),
}