Skip to content

fix(lemonade): restart on GAIA's port, timeout key, gaia llm errors - #5166

Merged
kovtcharov-amd merged 2 commits into
mainfrom
fix/restart-keeps-port-and-cli-errors
Oct 16, 2026
Merged

kovtcharov-amd merged 2 commits into
mainfrom
fix/restart-keeps-port-and-cli-errors

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

After GAIA's Lemonade Server stopped (the idle timeout, or any stop), the next start went to the default port 13305: on one Strix Halo lab host GAIA silently used another Lemonade already there, and on another the daemon answered a bare "Internal Server Error". A stopped GAIA server now always comes back through the daemon on its recorded port, and a failed start says why. Two smaller bugs the same hardware CI pinned are fixed too: gaia config set lemonade_idle_timeout_minutes N, the command the docs give, is accepted and validated (0 = never) instead of always rejected, and gaia llm shows the "Not enough free memory… needs about X GB" refusal word for word and exits 1, rather than generic restart advice and exit 0. Every gaia llm failure now exits non-zero and prints its own error; the install/start advice appears only when Lemonade really does not answer, so a stalled stream is no longer reported as "not installed".

These are the three strict xfails in #5163's tests/hardware/test_linux_halo_user_issues.py; the markers come off there once this merges.

Test plan

  • pytest tests/unit/test_lemonade_restart_keeps_port.py tests/unit/test_llm_memory_refusal.py tests/unit/test_cli_config.py tests/unit/test_gaia_lemonade_start_path.py plus the daemon/Lemonade supervisor, service, embedded, choice and manager suites: 826 passed on Windows. Every new test fails on main before this change.
  • Adversarial cases: an idle stop then a restart lands on GAIA's port while another Lemonade answers on the default port, which receives zero requests; a restart with nothing on the default port returns 200, not 500; a transparent restart (fix(daemon): never stop GAIA's Lemonade while a process is using it #5159) follows to the recorded port; GAIA's last port taken moves it and the client follows; the test fake for the daemon's owner is now a subclass of the real one, so a removed attribute fails the test as it fails the daemon.
  • python util/lint.py --black --isort
  • Linux Strix Halo hardware job on ci(linux-halo): check the Linux user issues on a real Strix Halo #5163 passes with its three xfail markers removed

…fusal

After GAIA's Lemonade Server stopped (idle timeout or any stop), the next
start resolved to the default port 13305: a client used whatever other
Lemonade answered there, and with nothing there the daemon's
/lemonade/start answered a bare 500, because the supervisor read the
owner's started_pid, which #5118 removed. A stopped GAIA server is now
always started by the daemon on its recorded port, and a start failure is
an actionable error, never a bare 500.

`gaia config set lemonade_idle_timeout_minutes N`, the documented command,
was always rejected: every lemonade_* key went to the "use my Lemonade"
handler. Only the three keys that pick a server go there now; the timeout
is an ordinary setting (0 = never, negative or non-numeric refused).

`gaia llm` replaced the "Not enough free memory" refusal with generic
restart advice and exited 0. The refusal is now shown unchanged and the
command exits 1. Any other `gaia llm` failure also exits 1 and prints its
own error; the install/start advice is added only when Lemonade really
does not answer, so a stalled stream is no longer reported as "not
installed".
@kovtcharov-amd kovtcharov-amd changed the title fix(lemonade): restart on GAIA's own port; accept the idle-timeout key; show the memory refusal fix(lemonade): restart on GAIA's port, timeout key, gaia llm errors Oct 16, 2026
@github-actions github-actions Bot added llm LLM backend changes cli CLI changes tests Test changes performance Performance-critical changes daemon Daemon supervisor / sidecar control plane labels Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This PR fixes three bugs found on Strix Halo hardware. After an idle stop, GAIA's own Lemonade now always restarts through the daemon on its recorded port, so it no longer quietly connects to another Lemonade on 13305 or fails with a bare 500. gaia config set lemonade_idle_timeout_minutes N now saves the value instead of always refusing it. And gaia llm shows the out-of-memory refusal word for word and exits 1 on every failure. The fixes go after the actual causes: the daemon was reading an attribute the owner never had, and the CLI was sending every key starting with lemonade_ to the "switch Lemonade" handler. Each fix comes with a test that fails on main.

Nothing blocks merge. One small gap remains: when gaia llm fails, it decides whether to show the "not installed / start it" advice by checking the default address. On a machine where GAIA's own server is stopped, a different Lemonade on 13305 could answer that check and hide the advice. That's the same stand-in address this PR stops trusting elsewhere.

Real-world evidence

The evidence stage ran the real CLI and daemon at f9e3334d on ubuntu-latest (no Lemonade or GPU), with before and after runs:

$ (parent commit) gaia config set lemonade_idle_timeout_minutes 30
❌ lemonade_idle_timeout_minutes is set by `gaia lemonade connect <url>`, which stores the key in the OS credential store.
[exit 1]
$ gaia config set lemonade_idle_timeout_minutes '30'
✅ Set lemonade_idle_timeout_minutes = 30
[exit 0]
$ gaia config set lemonade_idle_timeout_minutes '-1'
❌ Config key 'lemonade_idle_timeout_minutes' takes a whole number of 0 or more, but got '-1'.
[exit 1]
$ (parent commit) LEMONADE_BASE_URL=http://127.0.0.1:59999/api/v1 gaia llm "Hello"
❌ The local model server is not running, and neither is the GAIA background service that owns it — so nothing can start it.
[exit 0]
$ LEMONADE_BASE_URL=http://127.0.0.1:59999/api/v1 gaia llm "Hello"
❌ The local model server is not running, and neither is the GAIA background service that owns it — so nothing can start it.
[exit 1]
$ POST /daemon/v1/lemonade/start        (real `gaia daemon start`)
HTTP 503
{"detail": "The local model server is not running at http://localhost:13305/api/v1, and GAIA could not find one to start.\nTo fix: Lemonade Server is not installed. Run `gaia init` to install it, ..."}

Spot checks of nearby behavior all came back as expected: a call without a token gets 401, GET /lemonade/status gets 200, a bad lemonade_mode value is still refused, and lemonade_base_url still saves and switches. Two things are pending the strix-halo lane: an embedded Lemonade actually restarting on GAIA's port, and the real memory refusal during a model load. My verdict on those rests on static review plus the PR's unit tests, which run the real owner, supervisor and route against a real HTTP server on the default port. I couldn't run pytest myself because this runner doesn't have it installed. The new catch-all 500 branch in /lemonade/start can't be triggered from outside the process, so it was also left untested here.

🔍 Technical details

🟢 Minor

  • 🟢 The install-advice check probes the default address (src/gaia/cli.py:217). _lemonade_answers() builds a default LemonadeClient. Once GAIA's embedded server has stopped, that address falls back to 13305, so another Lemonade there makes the probe pass and print_server_error() gets skipped. The fallback is harmless (the user still sees the real error and exit 1), but you could reuse the address logic from lemonade_service._ask_the_daemon:
    def _lemonade_answers(base_url: str | None = None) -> bool:
        """Whether the Lemonade Server a command uses answers its health check now."""
        from gaia.llm.lemonade_client import LemonadeClient, running_embedded_lemonade_url
        from gaia.llm.lemonade_launcher import gaia_runs_lemonade
        from gaia.llm.lemonade_supervisor import _probe
    
        if gaia_runs_lemonade(base_url):
            base_url = running_embedded_lemonade_url()
            if not base_url:
                return False
        if base_url:
            client = LemonadeClient(base_url=base_url, keep_alive=True, verbose=False)
        else:
            client = LemonadeClient(keep_alive=True, verbose=False)
        return _probe(client)
    
  • 🟢 owned=True now covers servers the daemon claimed, not only ones it started (src/gaia/llm/lemonade_supervisor.py:283). The only consumer today is the supervised field in the /lemonade/start response, so this is fine. Anything that later uses owned to decide whether to stop a server will inherit the broader meaning, and the comment above it already documents that.

Strengths

  • Real root causes are fixed: the supervisor read started_pid, which the owner never had, which caused the bare 500. FakeOwner is now a subclass of the real owner, and a test fails if it exposes anything the real one lacks, so this kind of mock drift can't come back silently.
  • _ask_the_daemon no longer falls back to client.base_url when the daemon's answer has no base_url. It now raises an actionable error, in line with the fail-loudly rule.
  • The restart tests run the real owner, supervisor and FastAPI route, with a real HTTP "stranger" on the default port that must receive zero requests. That's the cold-state, contract-level coverage CLAUDE.md asks for.
  • The config key routing is narrowed to an explicit _LEMONADE_CHOICE_KEYS set. lemonade_api_key_stored is still refused, and unknown lemonade_* keys now hit the generic "Unknown config key" error.

…tand-in address

The install/start advice probed the default address, where another
Lemonade can answer once GAIA's own server has stopped. Probe GAIA's
recorded server instead, and drop the reimport pylint flagged.
@kovtcharov-amd

kovtcharov-amd commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Both points taken:

  • Install-advice probe: fixed in b1325b0. gaia llm now checks GAIA's recorded server, so a stopped GAIA server counts as down even when another Lemonade answers on 13305. Tests cover both the stopped and the running case.
  • owned=True for a claimed server: intended. The daemon stops GAIA's server at shutdown whoever started it (fix(lemonade): free GAIA's Lemonade when GAIA closes; keep its port #5118), so "this daemon will reap it" holds for a claimed server too. The one-line comment at that return says so.

@kovtcharov-amd
kovtcharov-amd merged commit 5d9181a into main Oct 16, 2026
71 of 72 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/restart-keeps-port-and-cli-errors branch October 16, 2026 05:56
kovtcharov-amd added a commit that referenced this pull request Oct 16, 2026
The restart port fallback, the `gaia config set lemonade_idle_timeout_minutes`
rejection and `gaia llm` hiding the memory refusal were fixed in #5166, so
their strict xfails would XPASS and fail against any release carrying it.
Drop the markers, the comment calling the CLI command broken, and the
"KNOWN BUG" evidence prefix.
kovtcharov-amd added a commit that referenced this pull request Oct 19, 2026
The restart port fallback, the `gaia config set lemonade_idle_timeout_minutes`
rejection and `gaia llm` hiding the memory refusal were fixed in #5166, so
their strict xfails would XPASS and fail against any release carrying it.
Drop the markers, the comment calling the CLI command broken, and the
"KNOWN BUG" evidence prefix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI changes daemon Daemon supervisor / sidecar control plane llm LLM backend changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant