Repository navigation
feat(init): set up GAIA's embedded Lemonade Server - #4192
kovtcharov wants to merge 28 commits into
Conversation
A new user should install with npx, optionally run gaia init, and start GAIA from the TUI, web UI, desktop app or Claude Code. Scopes GAIA's embedded Lemonade replacing a system-wide install, start on demand from every entry point, the removal of the system-Lemonade code, and the follow-on PRs for npx install, TUI /init and the Claude Code plugin.
gaia opens the terminal UI, gaia web the web app and gaia app the desktop app; gaia chat --ui and the top-level --ui/--cli flags are removed as legacy. Adds this as its own PR in the sequence.
Records the decisions: the GAIA daemon starts and stops embedded Lemonade, GAIA never falls back to another Lemonade on the default port and reports the Lemonade app when it holds memory or the NPU, and a second PR removes gaia chat and every command that is neither useful nor exercised by CI, collapsing init profiles to gaia, npu and sd.
gaia init used to install Lemonade system-wide (MSI, PPA or .pkg, with an admin prompt on macOS), upgrade or uninstall existing installs, and try to start whatever it found. It now downloads GAIA's own Lemonade Server into ~/.gaia/lemonade (checksum-verified, no admin rights) and starts it on a private port. Re-running init restarts a stopped server, replaces an older one, and recovers one that stopped answering. LEMONADE_BASE_URL still names another server; init then only checks that it answers and meets the profile's minimum version. --remote now requires it. gaia init --check reports the embedded server's real state and targets it explicitly, so it can no longer call a profile ready because some other Lemonade answered on the default port. Removes --skip-lemonade (nothing used it), init's system install, upgrade and auto-start paths, and catch-all handlers in the steps touched.
Request changes
One thing should be fixed before merge:
Two smaller things worth a look:
Real-world evidenceN/A — no 🔍 Technical details🟡
|
…aged gaia init --check could call a user-chosen Lemonade Server ready that gaia init then refused as too old, so the TUI skipped setup and failed later. Both now share one minimum-version rule, and a server that reports no readable version is logged rather than silently passed. A shell that sourced GAIA's own credentials file set LEMONADE_BASE_URL to GAIA's server, which turned off init's management of it and kept a dead port and key after a restart. The file now also exports GAIA_LEMONADE_EMBEDDED=1, and GAIA follows its live state instead of those values. Also: --check reports a failure to list profile models instead of a traceback, the Linux troubleshooting entry about the Lemonade PPA is replaced with the embedded download's failure modes, and stale references to removed init helpers are fixed.
…ade-onboarding # Conflicts: # tests/unit/test_init_command.py
Windows CI failed to reach Lemonade on a port GAIA's own server had used: test_sd's `gaia init` now starts that server on a shared self-hosted runner, the job ended without stopping it, and its state file stayed in the runner's home. Every later client on that runner, in any job, followed the record to a dead port instead of the system Lemonade the job had started. The resolver now ignores a record whose process no longer exists (a standard-library check, cheap enough for every lookup). In CI, the scripts that start the system Lemonade name it through LEMONADE_BASE_URL for the rest of the job, and test_sd stops GAIA's server when it ends.
…ade-onboarding # Conflicts: # hub/agents/email/python/gaia_agent_email/api_routes.py # src/gaia/installer/init_command.py
…ade-onboarding # Conflicts: # src/gaia/installer/init_command.py
…ade-onboarding # Conflicts: # src/gaia/installer/init_command.py
With the system installer gone nothing imports gaia.llm.lemonade_embedded at collection time, so pyfakefs unloaded it after the first purge-guard case and the second case patched an orphaned class.
|
🟡 The three issues the first review flagged are fixed — the
The fix is to set 🔍 Technical details
elif current.running and current.version != embedded.version:
self._print(f" Replacing ... v{current.version} with v{embedded.version}...")
embedded.stop()
# …
if self.force_reinstall or not embedded.is_installed(): # ← binary still on disk → skipped
embedded.install(force=self.force_reinstall)
status = embedded.start(install_if_missing=False) # ← old binary starts
Suggested fix (two options — either is fine): # Option A: widen the guard
needs_new_binary = self.force_reinstall or not embedded.is_installed() or \
(current.version != embedded.version and not current.running)
if needs_new_binary:
embedded.install(force=True)# Option B: set a flag in the mismatch branch
version_mismatch = current.running and current.version != embedded.version
if version_mismatch:
embedded.stop()
if self.force_reinstall or not embedded.is_installed() or version_mismatch:
embedded.install(force=self.force_reinstall or version_mismatch)
|
…sion Each version unpacks into its own directory, so the old binary on disk does not count as installed and init downloads the new one before starting it. The existing test mocked the install check and could not show that.
…r test A client launched by an earlier test keeps a fake server handle, so when the collector finalizes it mid-test its __del__ runs the port cleanup against that test's patched listener list and trips the "kills nothing" assertion. Collect before each test and keep the fake-launched clients alive.
On Windows the system temp dir lives under the user's home, so the "outside" target was inside home, nothing escaped, and the 403 never fired. Use a private home with the outside dir beside it.
Same Windows trap as the home-escape test: tmp_path sits inside the user's profile, so the outside dir was readable on home's account and nothing escaped.
The message formats the path with %r, which doubles every backslash on Windows, so a substring check against sys.executable could never match there.
|
🟡 The version-mismatch install bug flagged in the last re-review is still unresolved. When 🔍 Technical details
elif current.running and current.version != embedded.version:
embedded.stop() # old binary still on disk
# …
if self.force_reinstall or not embedded.is_installed(): # ← skipped: file exists
embedded.install(...)
status = embedded.start(install_if_missing=False) # ← old binary startsSuggested fix (Option B from the previous review): version_mismatch = current.running and current.version != embedded.version
if version_mismatch:
embedded.stop()
if self.force_reinstall or not embedded.is_installed() or version_mismatch:
embedded.install(force=self.force_reinstall or version_mismatch)
|
Each version unpacks into its own dist dir, so is_installed() is false for a new version even with the old binary on disk.
A Windows checkout converted install.sh to CRLF, and dash then rejected `case ... in\r` as a syntax error, failing the Windows parse test and breaking the script for anyone running it from such a checkout.
On Windows the models and Hugging Face caches resolve from LOCALAPPDATA/HF_HOME before the home dir, so the purge-models test got the runner's real cache path instead of the fake home's. Clear both in the fixture.
The expected substrings use "/" but Windows prints "\", so the dry-run test could never pass there.
amd#4309) **Stacked on amd#4193 (which is stacked on amd#4192).** Until those merge, this diff includes their commits; review only the last commit here. On a PC set up by `gaia init`, GAIA's own Lemonade Server runs on a private port, but about 20 places still looked for Lemonade on the old default port and found nothing. The Agent UI's status and onboarding screens, the OpenAI-compatible API server's health check, the builder agent and the email agent all reported the model server as missing. Now every lookup goes through one resolver: `LEMONADE_BASE_URL` if set, otherwise GAIA's own running server, otherwise the old default. With no GAIA server recorded, nothing changes. The email agent had a second problem on the same path: its readiness check called GAIA's server without the API key, got a 401, and reported the server's version as unknown. It now sends the key, as does the API server's health check. ## Test plan - [x] `pytest tests/unit` (14,472 passed; the one failure needs a live transcription server) plus the email and flagship agents' own tests with those packages on the path - [x] New tests: the Agent UI's system and onboarding lookups follow GAIA's recorded server, and a configured URL still wins. The API server and email agent health probes send that server's key. The flagship's health report names the URL the client would really have used. - [x] With only GAIA's own Lemonade running (scratch `GAIA_HOME`, no `LEMONADE_BASE_URL`): `gaia api start`, then `curl localhost:8611/health` reports the model backend ready at GAIA's server (output below) - [ ] On a PC with only GAIA's own Lemonade (no system install): the Agent UI's system status shows the model server as running, and the email agent's `GET /v1/email/init` reports the server's version <details> <summary>🔍 Technical details</summary> - Removing the fallback to the default port, which the self-hosted CI runners still rely on, is a separate change. - Several email-agent messages still say `lemonade-server serve`, and two tests assert them. They are left for a repo-wide sweep of that command's mentions. - Two tests that assumed the default port (flagship `test_stdio`, email `test_model_select`) now pin an empty `GAIA_HOME`, so they no longer depend on whether the developer's machine has GAIA set up. </details> <details> <summary>API server health with only GAIA's own Lemonade running (Apple Silicon)</summary> ``` $ gaia lemonade embedded status Running: yes on http://localhost:52461/api/v1 (pid 9670) $ gaia api start --port 8611 & $ curl -s localhost:8611/health {"status":"ok","service":"gaia-api","components":{"api":{"status":"ready"},"llm":{"status":"ready","backend":"lemonade","model":"Gemma-4-E4B-it-GGUF","url":"http://localhost:52461/api/v1"},"rag":{"status":"not_configured"}}} HTTP 200 ``` </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
**Stacked on amd#4192. Land after amd#4301**, which stops unit tests from spawning real daemons. With this PR a daemon starts GAIA's Lemonade Server in the real `~/.gaia`, so a test-spawned one would start and stop the developer's server. Until that merges, this diff includes its commit; review only the last commit here. After a reboot, GAIA's own Lemonade Server is stopped, and every entry point said "Lemonade not running" until you re-ran `gaia init`. Now the daemon starts it when the daemon comes up, and again whenever a GAIA command finds it stopped. Agents, the TUI's first-launch check (`gaia init --check`) and the Agent UI just work after a restart. The daemon is careful about what it stops. `gaia daemon stop` stops the server only if that daemon started it, so one started by `gaia init`, by hand, or by another daemon (a second one used for testing, say) keeps running. It never kills a server that is slow to answer (it may be loading a large model) and never replaces one running a different version: it reports both and points at `gaia init`. With `LEMONADE_BASE_URL` set it leaves Lemonade alone, and it never installs anything. A daemon from before this change doesn't have the new endpoint. Instead of a bare 404, clients get "restart it with `gaia daemon restart`" (host API bumped to 1.2). ## Test plan - [x] `pytest tests/unit/test_daemon_lemonade.py tests/unit/test_daemon_clock_wiring.py tests/unit/test_init_command.py tests/unit/test_daemon_agents_routes.py`; `go test ./internal/gaiainit/ ./internal/daemon/` - [x] With `GAIA_HOME`, `GAIA_DAEMON_HOME` and `GAIA_CONFIG_DIR` in a scratch dir and the server stopped: `gaia init --check` has a new daemon start it and prints READY (1.4 s); `gaia daemon stop` then stops it - [x] Server started with `gaia lemonade embedded start`, then `gaia daemon start` / `gaia daemon stop`: the server keeps running - [x] Server stopped: `LemonadeManager.ensure_ready()` gets it started through the daemon, loads Gemma and returns True - [ ] Windows and Linux: reboot, then launch `gaia-tui` without running `gaia init`; it should go straight to chat <details> <summary>Terminal output: the reboot case on Apple Silicon (GAIA set up, no daemon or server running)</summary> ``` $ gaia daemon status GAIA daemon: not running $ gaia lemonade embedded status Running: no $ time gaia init --check --profile minimal READY: profile 'minimal' is already set up (exit 0, 1 s) $ gaia lemonade embedded status Running: yes on http://localhost:59768/api/v1 (pid 88967) $ time gaia daemon stop ✅ GAIA daemon stopped (pid 88966) (5 s) $ gaia lemonade embedded status Running: no ``` </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
…ade-onboarding # Conflicts: # docs/plans/embedded-onboarding.mdx # src/gaia/installer/init_command.py # tests/unit/test_init_command.py
|
This PR is now empty — its branch tip is byte-identical to a commit already on The one finding left open from the last two reviews is a false positive and needs no follow-up anywhere. 🔍 Technical detailsEmpty diff, verified at the tree level. Evidence the feature landed by another route: The version-mismatch install bug does not exist. The finding rested on @property
def dist_dir(self) -> Path:
return self.root / "dist" / self.version # lemonade_embedded.py:361
@property
def daemon_path(self) -> Path:
suffix = ".exe" if platform.system() == "Windows" else ""
return self.dist_dir / f"lemond{suffix}" # :396After a version change, # is_installed() checks this version's own dist dir, so an older
# binary left on disk after a version change does not count.
if self.force_reinstall or not embedded.is_installed():Both suggested fixes (Option A / Option B) would have forced a redundant re-download on every version change. One part of that review does still hold and belongs on |
|
Closing as superseded — this branch is empty relative to main. Verified: branch tip `d6f16ca8`'s tree hash is byte-identical to the merge-base with `origin/main` (`4e28784ef`), so there's no diff to land. The feature itself is already live on main — `src/gaia/installer/init_command.py` has a full `_start_embedded_server`, version-scoped via `dist_dir = root/"dist"/self.version` in `src/gaia/llm/lemonade_embedded.py` (so `is_installed()` is not version-blind, contrary to what the bot review assumed twice) — and this PR's own stated "Next" item, #4193, is merged. Reopen if there's content here that genuinely isn't on main yet. |
gaia initno longer installs Lemonade system-wide. Before, it ran an MSI, PPA or.pkginstall (with an admin prompt on macOS), offered to uninstall and upgrade whatever Lemonade it found, and then tried to start it. Now it downloads GAIA's own Lemonade Server into~/.gaia/lemonade(checksum-verified, no admin rights), starts it on a private port, and leaves any Lemonade app on the machine alone. Re-running init restarts a stopped server, replaces an older one, and recovers one that stopped answering.gaia init --checknow reports that server's real state and asks it directly. It can no longer call a profile ready because some other Lemonade happened to answer on the default port.LEMONADE_BASE_URLstill points GAIA at a server you run yourself, and init then only checks that server.This is the first of three PRs from
docs/plans/embedded-onboarding.mdx:gaia inituses embedded Lemonade.gaia install --lemonadeare removed.Also cleaned up:
--skip-lemonadeis removed (nothing used it);--remotewithoutLEMONADE_BASE_URLis now an error instead of a guess; catch-all handlers in the touched steps now catch Lemonade's own error type; setup no longer suggests alemonadeCLI that isn't onPATH.Test plan
pytest tests/unit/test_init_command.py tests/unit/installer tests/unit/test_lemonade_embedded.py tests/unit/test_webui_build.py(new tests cover install, reuse, version replacement, recovering an unresponsive server,--force-reinstall, a configured server that is unreachable or too old, and every--checkstate)GAIA_HOMEon Apple Silicon:gaia init --check --profile minimalsays not installed, thengaia init --profile minimal --yesinstalls and starts the server, verifies Gemma at 32K context, and--checksays ready--checkreports "installed but not running", and re-runninggaia initrestarts it in seconds without downloading anything againgaia init --yesfrom an emptyGAIA_HOMEon Windows and on Linux (Strix Halo)gaia init --profile npu --yeson a Ryzen AI machine installsflm:npuinto the embedded serverTerminal output: empty
GAIA_HOMEon Apple Silicon (progress bar and log lines trimmed)