Skip to content

fix(lemonade): find GAIA's own server everywhere, not the default port - #4309

Merged
kovtcharov-amd merged 71 commits into
amd:mainfrom
kovtcharov:claude/lemonade-one-resolver
Sep 26, 2026
Merged

kovtcharov-amd merged 71 commits into
amd:mainfrom
kovtcharov:claude/lemonade-one-resolver

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #4193 (which is stacked on #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

  • 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
  • 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.
  • 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
🔍 Technical details
  • 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.
API server health with only GAIA's own Lemonade running (Apple Silicon)
$ 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

Kalin Ovtcharov added 15 commits September 24, 2026 16:51
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.
…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.
After a reboot, GAIA's own Lemonade Server was stopped and every entry
point reported "Lemonade not running" until the user re-ran gaia init. The
daemon now starts it when it comes up and whenever a GAIA command finds it
stopped: LemonadeManager.ensure_ready() and gaia init --check ask the
daemon through a new POST /daemon/v1/lemonade/ensure (host API 1.2).

The daemon stops only a server it started itself, so one started by gaia
init, by hand, or by another daemon keeps running. It never kills a server
that is slow to answer (it may be loading a model) or replaces one running
a different version; it reports those and points at gaia init. With
LEMONADE_BASE_URL set it leaves Lemonade alone. It never installs anything.
…aits

`gaia daemon stop` waited 10 s, but the daemon's shutdown now also stops
the Lemonade Server it started (up to 20 s) and could wait up to 60 s
behind a start still in flight, so a normal stop printed "did not exit;
terminating" and killed the daemon before its custody store closed.
Shutdown now waits at most 5 s for an in-flight start and leaves that
server running, and the stop command waits 45 s.

The TUI's setup check allowed 90 s while the Python side could spend
over two minutes starting the daemon and the server after a reboot, so
a successful start read as "could not be checked". The ensure timeout
drops to 80 s (it never stops a stalled server) and the TUI allows
150 s, with a comment tying the two together.

Also: a server this daemon started that has since exited is forgotten
instead of logged as "pid None" on every stop, and --check's help and
docs say it may start the daemon.
Unit tests block the network, so on a developer machine with GAIA set up
the real ~/.gaia Lemonade Server looked stopped, and every test that
called LemonadeManager.ensure_ready() asked a real daemon to start it:
tests failed on start-lock timeouts and left daemons running. CI never
saw it because nothing is installed there. An autouse fixture now stubs
the start; tests of the start itself opt back in with
@pytest.mark.embedded_start.
…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.
About 20 places read LEMONADE_BASE_URL directly and fell back to
localhost:13305, so on a PC set up by `gaia init` they looked for
Lemonade on an empty port: the Agent UI's system status and onboarding,
the OpenAI-compatible API server's health check, the builder and
connectors-demo agents, and the email agent's model choice. They now go
through the one resolver: LEMONADE_BASE_URL, else GAIA's own running
server, else the old default.

The email agent's readiness probe also called GAIA's server without its
API key, got a 401, and reported the server's version as unknown; it now
sends the key, and every email probe resolves the key for the server it
actually calls. The API server's health probe sends it too. With no GAIA
server recorded nothing changes.
@github-actions github-actions Bot added documentation Documentation changes installer Installer changes devops DevOps/infrastructure changes llm LLM backend changes cli CLI changes tests Test changes performance Performance-critical changes agents agent::email Email agent changes agent::connectors-demo Connectors-demo agent changes tui Go terminal UI (gaia-tui) daemon Daemon supervisor / sidecar control plane sidecar Agent sidecar contract / harness labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes — one blocking break, everything else is solid.

This PR routes every "where is Lemonade?" lookup through the single resolver so GAIA's own server (which binds a private port) is actually found, and makes the email agent send that server's API key. The consolidation is the right call and the new tests pin GAIA_HOME so they no longer depend on whether the developer's machine has GAIA set up.

The one thing to fix before merge: the email agent's scorecard generator now asks the model server for its version at an address with the API path in it twice, so the lookup fails and the nightly scorecard-refresh job stops with an error. The workflow that runs it has a comment warning about exactly this doubling — the resolver's normalized URL now trips it. Strip the API suffix before handing the URL to that version query.

Reviewed the last commit only, per the PR description.

Real-world evidence

N/A — no evidence bundle was produced for this run, so the verdict rests on static review plus reading the tests (I could not execute them; pytest isn't installed in this environment).

Worth noting as a 🟡 on its own: this change moves user-visible surfaces — the Agent UI's system-status and onboarding screens, the OpenAI-compatible API server's /health, and the CLI — and the description carries no matching evidence for any of them. The third test-plan item (the on-PC check that status shows the model server running and the email init reports a version) is the one that would prove the bug is actually fixed, and it is unticked. The API and CLI evidence is text and cheap to paste in; the Agent UI screenshot can reasonably wait for the strix-halo lane.

🔍 Technical details

Issues

🔴 Version probe gets /api/v1 twice — breaks email_scorecard_refresh (hub/agents/email/python/packaging/gen_scorecard.py:895)

_query_lemonade_version() builds base_url.rstrip("/") + "/api/v1/health" (line 738). The old value was os.environ.get("LEMONADE_BASE_URL", "http://localhost:13305") — a bare origin. resolve_lemonade_base_url() normalizes bare origins to …/api/v1, so the request goes to http://…:13305/api/v1/api/v1/health → HTTPError → RuntimeError → main() returns 1.

This is not hypothetical: .github/workflows/email_scorecard_refresh.yml:185-187 sets LEMONADE_BASE_URL: "http://127.0.0.1:13305" with the comment "Bare host (no /api/v1): … gen_scorecard.py appends /api/v1/health itself — a suffixed value would double to /api/v1/api/v1." The resolver now re-adds the suffix that comment exists to avoid, and line 456 turns the non-zero exit into throw "gen_scorecard failed".

        from gaia.llm.lemonade_client import resolve_lemonade_base_url

        # _query_lemonade_version appends /api/v1 itself.
        base_url = resolve_lemonade_base_url().rstrip("/").removesuffix("/api/v1")

No test covers this path, which is why it passed — a small unit test asserting the URL _query_lemonade_version builds would have caught it.

🟡 No real-world evidence for the surfaces that moved

See the visible section. Suggested minimum: curl against the API server's /health (request + status + body) and the gaia CLI output on a box where only GAIA's own Lemonade is running — that is the exact state the PR targets and the one a warm/default-port machine cannot reproduce.

Nits

🟢 src/gaia/llm/lemonade_manager.py:248 — this commit removed the last use of the module-local DEFAULT_LEMONADE_URL = "http://localhost:13305"; nothing else in the tree imports it. Deleting it removes one more hard-coded copy of the port, which is the point of the PR.

🟢 src/gaia/llm/lemonade_client.py:564 — LemonadeStatus.url's default_factory is still os.getenv("LEMONADE_BASE_URL", DEFAULT_LEMONADE_URL), the last in-tree copy of the pattern being retired. Harmless today (both construction sites pass url= explicitly), but it's a loaded gun pointed at the default port. default_factory=resolve_lemonade_base_url would close it.

Strengths

  • The key resolution is correctly scoped to the endpoint being called — resolve_lemonade_api_key(base_url=probe_base) rather than a bare call — so the embedded key can't leak to a non-local server. Applied consistently across api_routes.py, model_select.py, and openai_server.py.
  • The two tests that previously depended on the developer's machine (test_stdio, test_model_select) now pin an empty GAIA_HOME; tests/unit/test_lemonade_one_resolver.py asserts both directions — GAIA's server is followed, and a configured LEMONADE_BASE_URL still wins.
  • Every removed import os really is unused afterward (checked all eight files), and the lemonade-server serve instruction in the email reachability error was replaced with gaia init — that binary no longer exists on current installs.
  • Both the npm and python CHANGELOGs were updated, in plain user-facing terms.

Kalin Ovtcharov added 17 commits September 25, 2026 19:26
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.
…ade-one-resolver

# Conflicts:
#	hub/agents/email/npm/CHANGELOG.md
…ade-one-resolver

# Conflicts:
#	hub/agents/email/npm/CHANGELOG.md
The expected substrings use "/" but Windows prints "\", so the dry-run
test could never pass there.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
Merged via the queue into amd:main with commit b842759 Sep 26, 2026
94 of 95 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/lemonade-one-resolver branch September 26, 2026 03:44
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 26, 2026
Main landed the provider half of this change independently (amd#4309's
ttft hooks plus Claude/Lemonade finish-reason capture), so the merge
kept main's version and dropped this branch's duplicate assignment in
ClaudeProvider._stream_chat. What remains here is the agent-loop
cut-off guard the PR is actually about.
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Sep 26, 2026
amd#4325)

Agent UI Settings showed a red "Processor: darwin" on every Mac and
flagged Linux machines and most Ryzen AI laptops as unsupported. The
check still required a Ryzen AI Max or a 24 GB Radeon, the bar for the
old Qwen3.5-35B default, but the default model is now the 4B Gemma.
Nothing acts on that verdict, and memory fit is already covered by the
Memory row and the per-agent memory warning. So the verdict is removed,
and the Processor row now just names the real CPU (e.g. "Apple M4"
instead of "darwin"). The silent `except Exception: pass` around the
check is gone too.

Overlap: amd#4176, amd#4265 and amd#4309 also edit
`src/gaia/ui/routers/system.py`, but not the device block, so any
conflict is textual only.

## Test plan
- [x] Backend tests fail before the fix and pass after: all 7 new
`tests/unit/test_device_check.py` tests and the new
`test_system_status_names_the_processor_without_a_support_verdict`
failed on `main`, and all pass with the fix.
- [x] `GAIA_HOME=<tmp> GAIA_DAEMON_HOME=<tmp> python -m pytest
tests/unit/chat/ui/ tests/unit/test_device_check.py -q`: 1038 passed.
- [x] Agent UI, run with Node 22 from `src/gaia/apps/webui`: `npx tsc
--noEmit -p .` is clean and `npx vitest run` passes 398/398.
- [x] On a Mac, `GET /api/system/status` against a real `create_app()`
returns `processor_name: "Apple M4"` and no `device_supported` field. On
`main` it returned `"darwin"` / `false`.
- [x] black, isort, and pylint (errors-only config) pass on the changed
Python files.
- [ ] Open Settings in the Agent UI on Windows and Linux and confirm the
Processor row shows the CPU name without the warning colour.

Fixes amd#4230

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::connectors-demo Connectors-demo agent changes agent::email Email agent changes agents cli CLI changes daemon Daemon supervisor / sidecar control plane devops DevOps/infrastructure changes documentation Documentation changes installer Installer changes llm LLM backend changes performance Performance-critical changes sidecar Agent sidecar contract / harness tests Test changes tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants