Repository navigation
fix(final): stop each final pass from keeping 2.7 GB of models, which filled the disk with swap - #179
Merged
Merged
Conversation
A final pass ends in terminate, and a terminated Bun Worker never runs the sherpa-onnx finalizers still pending, so every pass left its model set in the app: about 2.7 GB of Parakeet and Silero per pass, for the life of the app. The first-start catch-up runs every unfinalized call back to back, so a backlog of four calls held about 10 GB, all of it pushed to swap. The pass now drops its models and collects until their finalizers have run before it answers. scripts/measure-final-memory.ts measures it.
|
Warning Review limit reachedNext included review available in 16 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: GeiserX/akou/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Sep 29, 2026
GeiserX
added a commit
that referenced
this pull request
Oct 4, 2026
…ng go of models nothing uses (#322) akou held about 3.7 GB while sitting idle on the reference Mac, hours after the last call, with only 56 MB of it resident. On a 24 GB Mac that is enough to start freezing it. Nothing was leaking. With dictation on, the live Worker loaded Parakeet (about 2.2 GB) and the streaming model (about 1.8 GB) at start and kept both for good, even though a live dictation never decodes with Parakeet. A call loaded Parakeet too, and nothing ever let it go. Now the dictation warm-up loads Parakeet only when the dictation's text comes from it (`dictation.final` `parakeet`, or no streaming model). A new setting, `asr.modelIdleMinutes` (default 5; 0 lets go at once, as `server.model_idle_minutes` does; up to 10080 keeps them loaded on a Mac with memory to spare), lets the live Worker drop every model once no call and no dictation has used it for that long. The app then loads back only what a dictation needs to start fast. The method is `LiveAsr.releaseIdle()`, named and shaped like the job Worker's idle release in #270. That PR covers file-job Workers, this one covers the live Worker. They share no code because they are different Workers. Footprint (`footprint -p`, which counts the compressed and swapped pages RSS hides) of the app process, measured on a 16 GB M4 with dictation on in English and Spanish: | | main | this branch | |---|---|---| | fresh start | 3,612 to 4,104 MB | 1,692 to 1,921 MB | | after a 30 s call and its final pass | 3,889 MB | 4,111 MB | | after 5 to 30 dictations | 3,903 MB | 3,941 MB | | idle, before the timer | 3,899 MB (unchanged after 3 min) | 3,938 MB (4 min) | | idle, after the timer (5 min) | n/a | 2,031 MB (the streaming model loaded back) | Thirty dictations did not grow the footprint on main (3,904 MB after 10, 3,903 after 20 and 30). Each finished final pass already lets go of its models (#179). The cost is load time. These numbers come from a loaded machine: - A `fast` dictation, a retry on `fast`, or a live dictation whose stream fails and falls back to `fast` now waits for Parakeet when it is not loaded. The first `fast` clip after a fresh start took 8.4 s wall time on this branch against 1.4 s on main. Parakeet loads in 2 to 3 s on an idle machine. - A call's first lines wait for Parakeet the same way. - A press while the streaming model reloads after an idle period waits for it, about 1 to 2 s. - Live dictations, the default, are unaffected: 1.3 to 2.3 s for a 6 s clip on both. `tests/idle-memory.e2e.test.ts` runs the app in its own process on the real models: a fresh start, a 20 s call with its final pass, 5 dictations, then an idle minute (`asr.modelIdleMinutes: 1`). It asserts that the call adds Parakeet to the fresh start (over 1.5 GB) and that the idle app is back within 1000 MB of its fresh start. Over seven runs on a busy 16 GB Mac the idle app read from 1,158 MB under to 529 MB over its fresh start (the allocator's freed small regions and swap), so the margin sits above that spread and below Parakeet; the run without a release read 2,300 MB over. It is skipped off macOS or without `AKOU_LIVE_MODELS`, and floors go +1 skip. Final runs, on this branch merged with main: - main: red. Fresh 3,439 MB, after the call 4,303 MB (+864), idle 3,998 MB. The fresh start already holds Parakeet. - this branch: green three times. Fresh 1,427 MB, after the call 4,375 MB, idle 1,429 MB; fresh 1,787 MB, after 4,411 MB, idle 2,193 MB; and, at the 1000 MB margin, fresh 1,781 MB, after 4,463 MB, idle 2,194 MB. - this branch with the idle setting at 1440: red on the idle check. Fresh 1,542 MB, idle 3,842 MB. Unit tests in `tests/asr-live.test.ts` drive `releaseIdle` with a manual clock: release after a call, a long call holding the models, an open dictation holding them, and nothing released without the setting. There is one test per busy rule (a call on the Worker, an open dictation, a decode, a speech check and a warm-up in flight), and replacing any one rule with `false` turns exactly its own test red. The warm-up rule means a release never undoes a warm-up still loading. The Settings page has a row for the new setting under Speech engines. DC-E7 in DICTATION.md and its tests now say that Parakeet loads ahead only when the dictation's text comes from it. Not changed: `asr.qwenIdleMinutes` (the `best` dictation server) still defaults to never, and its memory is in a separate llama-server process. Next step, not built here: int8 variants of Parakeet and the streaming model could cut the idle footprint further, but that trades accuracy against the fp32 choice the benchmark made, so it is a decision for later.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After its first start, 0.5.0 ran the final pass over four earlier calls whose pass had failed on 0.4.0. All four finished. Two hours later the app's main process had a 10 GB footprint with 49 MB resident, so almost all of it sat in swap. Swap grew until the disk had 0 bytes free. No call was recording. Quitting and reopening akou brought the footprint back to 195 MB.
Cause
Each final pass runs in its own Worker, and
finalizeCallterminates that Worker as soon as the pass answers. sherpa-onnx frees Parakeet and Silero only in their finalizers. Bun runs a collected object's finalizer on a later turn of the event loop, and a Worker terminated before that turn never runs it. So every pass left its whole model set in the process, about 2.7 GB with Parakeet fp32. The catch-up at start runs the backlog one call after another, which is how four passes added up to 10 GB.I measured it on a 16 GB Apple silicon Mac mini with
scripts/measure-final-memory.ts. The run creates three ended calls of two 20-minute stereo Opus parts each, written byakou-capture run --from-wav, and runs their final passes back to back throughfinalizeCallwith the real models: Parakeet TDT v3 fp32, Silero, and Nemotron throughakou-diarize. After each pass and every minute of a 10-minute idle it records the process footprint (macOSfootprint, which counts swapped and compressed memory).To find which part keeps the memory, I ran pieces of the pass in a Worker, terminated it, and read the footprint afterwards:
Inside the Worker, the first collection freed under a quarter of the models and the second freed the rest, which is why one
Bun.gc(true)was not enough.The ~1 GB left after the third pass is not live memory.
heapfinds 6 MB of live malloc allocations in the idle process. The rest is freed memory that the allocator keeps for reuse (736 MB ofMALLOC_LARGE, 308 MB ofMALLOC_SMALL). A second run with six passes shows it does not grow: 246, 223, 1225, 1270, 1270 and 1196 MiB after passes 1 to 6. Six minutes into the idle that followed, the allocator gave it back and the footprint fell to 126 MiB.Fix
ModelSet.release()lets go of every model the set holds.SherpaModels.release()drops its references and runs four rounds ofBun.gc(true)plus a turn of the event loop, so the finalizers run while the Worker is still alive.release()before it sendsdone. The host terminates it only after that.releaseis slow must have finished releasing by the timefinalizeCallreturns. I checked that it fails when the Worker answers before the release finishes.Not changed
catchUpFinals, so I left it alone.