Skip to content

fix(llm): size model downloads from Lemonade's catalog and model cache - #4297

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:claude/lemonade-predownload-checks
Sep 25, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:claude/lemonade-predownload-checks

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Before auto-downloading a model, GAIA guessed its size from the name and checked free space on whatever disk the command ran from. Gemma-4-E4B was estimated at 2.5 GB against a real 5.56 GB, so a nearly full drive could pass and run out mid-download, while a remote server with room could be refused. Now the check uses the catalog's real size and Lemonade's own model-cache free space, and fails loudly if the server doesn't report it. The first-run "Downloading model… several minutes" banner can now actually appear, and gaia init stops unloading models that were only downloaded, never loaded.

Overlaps textually with #3669, which touches the old except in check_model_loaded. This PR replaces that body, so whichever lands second needs a small rebase.

Test plan

  • python -m pytest tests/unit/test_lemonade_predownload_checks.py -q: 12 pass. On origin/main, 10 fail and 2 pass (the 2 passing are control cases).
  • LEMONADE_BASE_URL=<live server> python -m pytest tests/integration/test_lemonade_predownload_checks.py -v: 3 pass against a live Lemonade 11.8.1. All 3 fail on origin/main.
  • Neighbouring suites (test_lemonade_ctx_ceiling, test_lemonade_model_loading, test_lemonade_manager_preload, test_llamacpp_backend, test_init_command, tests/unit/installer, test_hardware_advisor_agent, …): 682 pass. The 2 test_uninstall_command failures also fail on origin/main.
  • tests/test_lemonade_client.py -k Mock: the same 11 tests fail before and after this change (pre-existing on this machine).
  • black, isort, and pylint (repo rcfile) clean.

Fixes #4214

Before auto-downloading a model, GAIA now checks free space in Lemonade's own
model cache against the catalog's real download size, instead of a name-based
guess against whatever disk the command ran from. Gemma-4-E4B was estimated at
2.5 GB against a real 5.56 GB, so a nearly full drive could pass the check and
run out mid-download, while a roomy remote server could be refused.

- get_model_info queries /models?show_all=true (undownloaded models are absent
  otherwise) and reads the `size` field; catalog errors now raise.
- The disk check reads /system-info model_storage.free_bytes and raises when
  the server doesn't report it, instead of warning and continuing.
- The first-run "Downloading model" banner uses show_all, so it can fire.
- check_model_loaded asks /health, so a model that is only downloaded (or a
  substring of a loaded one) no longer counts as loaded.

Fixes amd#4214
@github-actions github-actions Bot added documentation Documentation changes llm LLM backend changes tests Test changes performance Performance-critical changes labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This replaces two guesses with facts: the download size now comes from Lemonade's own catalog instead of a name-based estimate, and free space is checked on the server's model cache instead of whatever disk the command happened to run from. "Is this model loaded?" also stops meaning "is it on disk", which is what made gaia init unload models it had only downloaded. The direction is right and the tests are real.

Two things worth attention before merge:

  • The new live-server test can fail for the wrong reason. On a machine that has a locally registered (user.-prefixed) model loaded, the last check compares two spellings of the same model name and reports a false failure. Normalize the names the same way the client does before comparing.
  • The same "downloaded ≠ loaded" bug is still in the C++ client, which documents itself as mirroring the Python one. Nothing here breaks, but the two now disagree and the comment is no longer true — worth a follow-up issue if you'd rather not widen this PR.

Also note this makes auto-download hard-fail against any Lemonade that doesn't report its model-cache free space. That's the right call under the fail-loudly rule, but the error should name the version a user needs.

Real-world evidence

No evidence-bundle.md was produced for this run (the automated evidence stage didn't write one), so the surface evidence is what the PR description carries: unit results with a stated before/after against origin/main, and 3 integration tests passing against a live Lemonade 11.8.1 — that does exercise the real /models, /system-info and /health shapes this change depends on, which is the part most at risk of being wrong. I could not re-run anything here (no pytest in this environment), so my verdict rests on static review plus your reported runs.

What's not shown is the user-facing surface: the first-run 📥 Downloading model… banner and the new out-of-space message only appear in a real gaia init / cold model pull. A short terminal transcript of a cold download on a fresh cache would close that gap — nudge, not a blocker.

🔍 Technical details

Issues

🟡 Integration test compares un-normalized model names (tests/integration/test_lemonade_predownload_checks.py:53)

/v1/models strips the user. namespace while /health reports the registered name — that asymmetry is exactly why _model_ids_match exists. So on a server with user.foo loaded, downloaded contains foo, loaded contains user.foo, the set difference keeps foo, and check_model_loaded("foo") correctly returns True — failing the assert. The test only runs against a live server, so this surfaces as a confusing red on someone's machine.

    for model_id in downloaded:
        if any(_model_ids_match(model_id, loaded_id) for loaded_id in loaded):
            continue
        assert client.check_model_loaded(model_id) is False

(needs _model_ids_match added to the import from gaia.llm.lemonade_client.)

🟡 C++ client still equates "downloaded" with "loaded" (cpp/src/lemonade_client.cpp:195, header comment at cpp/include/gaia/lemonade_client.h:142)

checkModelLoaded() iterates listModels() and returns true on a name match — the pre-fix Python behaviour — while its header says "Mirrors Python check_model_loaded()". After this PR that's inaccurate, and any C++ caller doing the gaia init-style "unload if loaded" dance hits the same bug. Fine as a follow-up; flagging so it isn't lost.

🟢 Name the required Lemonade version in the model_storage error (src/gaia/llm/lemonade_client.py:1660)

Update Lemonade Server (run gaia init) tells the user to act but not what "new enough" means; gaia.version.LEMONADE_VERSION is already the pinned floor and is imported elsewhere in this file (line 4931). Interpolating it turns a retry-and-hope into a checkable condition — especially for anyone pointing LEMONADE_BASE_URL at a server they don't control.

🟢 Hardware-advisor loop now refetches the whole catalog once per model (examples/hardware_advisor_agent.py:188, mirrored in docs/playbooks/hardware-advisor/index.mdx:651)

get_model_info() now issues list_models(show_all=True), and that loop already holds the full show_all response — so enumerating N models means N full-catalog round-trips to read a field that's already in hand. The pre-existing N+1 got heavier, not new, but the fix is a one-liner:

                    size_gb = model.get("size") or 0

Strengths

  • check_model_loaded now reads /health.all_models_loaded, which is the source of truth the rest of the file already settled on (see the [Bug]: 1.4MB file indexed no response to queries in the UI #1030 rationale in get_status, lemonade_client.py:4518). The substring match is gone too, so Qwen3.5-4B no longer reports as loaded because Qwen3.5-4B-GGUF is.
  • Both get_model_info and the disk check drop their swallow-and-guess handlers for actionable errors naming the path and the fix — the Fail-Loudly rule applied to code that predates it.
  • Test pairing is the right shape: mocked unit tests pin the 11.8.1 wire shapes (including show_all being required to see undownloaded models), and a live-server test proves the real thing sends them — exactly the "mocks prove we called it, not that the call is valid" guard in CLAUDE.md.
  • The test_lemonade_ctx_ceiling assertion was tightened rather than deleted: it now pins one show_all call to the banner probe instead of asserting none, so a ceiling check reaching for the catalog still fails.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 25, 2026
Merged via the queue into amd:main with commit b064163 Sep 25, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes llm LLM backend changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(llm): pre-download size and disk-space checks read the wrong data

2 participants