Repository navigation
fix(daemon): tests stop the daemons they start, and a daemon exits when its home is gone - #5294
Merged
Merged
Conversation
…en its home is gone Test runs left GAIA daemons running forever, and those daemons owned the developer's real Lemonade Server. Building an agent outside tests/unit asked a fresh daemon to start GAIA's Lemonade whenever it looked stopped; that daemon lived under the session's temp home but managed the real ~/.gaia server, and kept polling after the temp home was deleted. - The daemon shuts down on its own, logging why, once its home or instance.json is gone. GAIA_DAEMON_EXIT_WITH_PID (opt-in, set only by the test suite) also ties it to one process, so a killed test run cannot leak. - The root conftest fails a session that leaves a daemon running, naming the test that started it, and fails any test that would start, stop or unload the real ~/.gaia Lemonade or spawn a daemon for it. - The embedded-Lemonade start stub moves from tests/unit to every test, at session scope so class- and module-scoped agent fixtures are covered too. - tests/integration/test_daemon.py points GAIA_HOME at a tmp folder and stops its daemon in fixture teardown, even when a test fails. - `gaia kill --daemons` lists daemons with pid, age and home, and stops the orphaned ones; the daemon this home registered is never stopped. - CI checks no daemon outlived the tests on Linux, macOS and Windows. Closes #5293
…daemon It ran the CLI's Lemonade setup, which starts a real daemon for the user's GAIA home; on CI that daemon was left running after every run. The fixture HTTP server is the model server, so the daemon step is stubbed.
On a machine with GAIA installed, `gaia init --check` started a daemon for the real Lemonade Server, and the daemon outlived the test run.
5 tasks done
kovtcharov-amd
added a commit
to kovtcharov/gaia
that referenced
this pull request
Oct 19, 2026
…it for two hours (amd#5359) A GAIA daemon started for a temporary home (an eval, a demo, a test drive) kept running forever once its users were gone, as long as the folder still existed. A cleanup on one dev machine found 15 of them running at once, up to 43 hours old, along with the agent sidecars some still supervised. Now a daemon for any home other than `~/.gaia` shuts itself down after two hours with no connected client, no busy sidecar, no model-slot lease held or queued, and no pending scheduled job, and the next GAIA command starts a fresh one. The everyday `~/.gaia` daemon is unaffected. This completes amd#5294, which made a daemon exit when its home folder is deleted. ## Test plan - [x] `pytest tests/unit/test_daemon_lifetime.py` (45 passed) and every daemon and broker test (705 passed) - [x] `python util/lint.py --black --isort` - [x] Real daemon, scratch `GAIA_HOME`, `GAIA_DAEMON_IDLE_EXIT_MINUTES=1`, no client: logged "nothing has used it for 1 minutes" and exited 60 s after start - [x] Same, with a registered app client: still running at 90 s. Once the client process ended, the daemon dropped it within 4 s and exited 60 s later - [x] The `~/.gaia` daemon never idles out: pinned by `test_the_default_home_never_idles_out`, and `is_default_home` by `test_the_machine_home_is_the_default` <details> <summary>🔍 Technical details</summary> - `lifetime.exit_reason` gains an idle reason that applies only when `paths.host_dir()` isn't `~/.gaia/host`. `LifetimeWatch` takes `idle` and `idle_limit`. - The idle measure is `lifetime.DaemonIdle`. A held or queued `ModelSlotBroker` lease counts as use. The broker now reports `last_activity_s_ago` (stamped on grant, release and reclaim), so even leases shorter than the 5 s check restart the clock. Underneath it is `LemonadeClients.snapshot()["idle_seconds"]`: `None` while any client lease is held, and reset by every sweep while a sidecar connection runs. Once that passes the limit, `clock.job_counts()["pending"]` is checked too, so the scheduler DB is read only near the limit. - `GAIA_DAEMON_IDLE_EXIT_MINUTES`: unset means 120, `0` means off, and anything that isn't a non-negative integer raises `DaemonStartError` at startup. - Docs: the daemon section of `docs/reference/cli.mdx`. </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]>
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.
Test runs left GAIA daemons running for days (57 on one dev box), and those daemons managed the developer's real Lemonade Server. A test that built an agent asked a fresh daemon to start GAIA's Lemonade whenever it looked stopped; that daemon lived in the session's temp home, so nothing ever stopped it, but it owned the real
~/.gaiaserver, which may explain #5261. Now a daemon shuts itself down once its home orinstance.jsonis gone, a test session fails if it leaves one running, tests can no longer touch the real~/.gaiaLemonade, andgaia kill --daemonscleans up the strays already out there.Test plan
pytest tests/integration/test_daemon_lifetime.py: a real daemon exits after itsinstance.jsonor home is deleted, and after its tied process exits; a child test session that leaks a daemon fails and the daemon is killed; tests that act on the real~/.gaiafailpytest tests/unit/test_daemon_lifetime.py tests/unit/test_daemon_strays.pypytest tests/unit -n autoleaves no newpython -m gaia.daemonprocess behindgaia kill --daemonslists daemons with pid, age and home, stops only the orphaned ones, and leaves the daemon registered in your own home running🔍 Technical details
LemonadeClient._follow_gaia_lemonadeandLemonadeManager.start_embedded_if_stoppedboth callensure_lemonade→start_or_attach, which spawns a daemon when none is registered. Outsidetests/unitnothing stubbed that, andGAIA_HOMEwas unset, so the daemon managed the real~/.gaiaLemonade.tests/test_sdk.pyandtests/test_hardware_advisor_agent.pyboth hit this on a machine wheregaia initinstalled GAIA's Lemonade and it was stopped.gaia daemon startfirst) instead of quietly starting it through a daemon that never exits. CI runners have no~/.gaiaLemonade, so CI is unaffected.tests/integration/test_daemon.pyspawned real daemons withoutGAIA_HOME(they started and stopped the real Lemonade);tests/integration/test_context_override_reload.pyspawned one on every CI run via the CLI's Lemonade setup;tests/unit/installer/test_init_default_profile.pyrangaia init --checkin a subprocess, which started one against an installed GAIA.GAIA_DAEMON_EXIT_WITH_PIDis opt-in and set only by the root conftest. Production daemon lifetime changes only when the home orinstance.jsondisappears, at which point no client can reach the daemon anyway.gaia kill --daemonskills only the daemon process (and its venv-launcher child), never the rest of its tree, so a Lemonade Server it started is left alone. It protects the daemon whose pid this home'sinstance.jsonrecords, because an older daemon could register in~/.gaiawhile its environment pointed at a deleted test home.gaia-chat-test-*home). The daemon-side exit covers that case; the Go tests are unchanged.