Repository navigation
fix(lemonade): stop the model servers a dead lemond leaves behind - #5352
Conversation
|
Verdict: Approve with suggestions When GAIA's private Lemonade server crashes or is killed, its model servers keep running and hold gigabytes of memory. This PR stops those leftovers the next time GAIA starts the server, or when a status check finds the server gone. The guard is narrow: a process is stopped only if it runs from GAIA's own install and the server that started it is no longer running. A live server's model servers and anything from a Lemonade the user runs themselves are left alone. The PR includes tests that start real processes and fail on main. I found no blocking issues. One thing worth confirming: a model server counts as protected only if its direct parent is a running GAIA server. If a backend under the install ever starts its own helper process from the same folder, the cleanup would kill that helper while the server is still healthy. Checking every ancestor instead of just the parent would rule this out. Real-world evidenceN/A: no evidence bundle was produced for this run. This change affects server lifecycle, not a CLI command, flag, or API response. The PR shows real-process proof instead: four Windows tests start a real process tree, kill the stand-in server, and fail on main. The author also reports a read-only dry run on the affected machine that singled out exactly the two orphans. Beyond what the PR shows, this verdict rests on static review. 🔍 Technical detailsIssues found 🟢 Only the direct parent is checked ( You would also need a small 🟢 Strengths
|
When GAIA's lemond crashed or was killed without its process tree, its llama-server, whisper-server and kokoro children kept running, each holding gigabytes of memory, and the next start loaded the same models again beside them. Two such servers ran for about 30 hours on a developer machine. GAIA now stops them when it starts its server and when it finds the recorded one gone. A process qualifies only when its executable is under this install's cache/bin and its parent is not a running lemond from this install's dist tree; a parent the OS hides counts as running. Each one stopped, or one GAIA may not stop, is logged with its pid. The scan matches names first, so it costs ~0.1 s, and waits for the killed servers to exit so the next load sees their memory free.
The first version treated any cache/bin process whose parent was not a running lemond as an orphan, so a llama-bench or llama-cli the user ran from a terminal was killed on the next start. Now a process is reaped only when its anchor is gone, or its pid was taken by a younger process: the parent on Windows, which never reparents, and the session leader on POSIX, where an orphan is reparented to init or a subreaper but stays in dead lemond's session. A user's tool has a live shell as its anchor and is left alone. status() clears the gone server's record only if no start recorded a new one meanwhile, and a start scans once instead of twice. Denied inspections are logged at debug level.
A status check can reap while another process starts the server. That is safe because the new server's backends have a live anchor; say so where someone might otherwise move the reap under the lock.
a501345 to
fb33b56
Compare
# Conflicts: # src/gaia/llm/lemonade_embedded.py
When GAIA's own Lemonade server crashed or was killed by itself, its model servers kept running. Each one holds gigabytes of memory, and the next start loaded the same models again beside them, doubling GPU and RAM use. On one machine a Gemma and an embedding server ran for about 30 hours after their server died. Now GAIA stops them when it starts its server, and when it finds the old one gone. It stops a process only when it runs from GAIA's own install and the process that started it has exited. Another Lemonade's processes, a live server's, and a tool such as
llama-benchthat you run from a terminal are never touched.Reproduced by
tests/unit/test_lemonade_orphaned_backends.py: on main, two of its real-process tests fail with the symptom ("the dead lemond's llama-server is still running"), and the others fail because the reaper doesn't exist yet. All pass here. Each runs a real process tree on Windows: a copy of the interpreter stands in forllama-server.exeunder the install'scache/bin, and the test kills its stand-in lemond without the tree.🔍 Technical details
EmbeddedLemonade._reap_orphaned_backends()runs from_start_lockedbefore spawning, and fromstatus()only when the recorded lemond is gone. A healthystatus()never scans, and a test pins that.<GAIA_HOME>/lemonade/cache/binand its anchor is gone, or its pid now names a younger process. The anchor is the parent on Windows, which never reparents. On POSIX it is the session leader: lemond starts its own session, and an orphan reparented to init or a subreaper stays in it. An anchor the OS hides counts as alive.cache/binbefore reading any process's path or parent, which takes ~0.1 s instead of ~5–8 s on a machine with ~400 processes. It then waits up to 5 s for the killed servers to exit, so the next model load sees their memory free.whisper-serverand akoko). They were left running for the user to decide.cache/binwas killed. That one is fixed by the anchor rule above, with a real-process test, plus POSIX reparenting and pid-reuse cases. A gone server's record is now cleared only if no new start recorded itself meanwhile, and a start scans once. Removing each of those guards fails its test. The real-process tests are Windows-only; Linux and macOS run the portableTestOrphanedBackendscases.status(), so they conflict on text: keep both.Test plan
python -m pytest tests/unit/test_lemonade_orphaned_backends.py tests/unit/test_lemonade_embedded.py: 91 passed, no stray processes left (Windows)origin/main: the status and start cases fail with the symptomtest_lemonade_embedded*,test_daemon_lemonade*,test_init_command,test_cli_lemonade_embedded, uninstall, restart and child-env tests): 660 passed, isolatedGAIA_HOMEpython util/lint.py --black --isort --flake8 --pylint --test-lanes: all pass