Skip to content

fix(init): pull built-in NPU/FLM model by name, not recipe (#1655) - #1658

Merged
kovtcharov-amd merged 3 commits into
mainfrom
fix/npu-init-builtin-flm-model-1655
Jun 15, 2026
Merged

kovtcharov-amd merged 3 commits into
mainfrom
fix/npu-init-builtin-flm-model-1655

Conversation

@kovtcharov-amd

@kovtcharov-amd kovtcharov-amd commented Jun 13, 2026 •

Copy link
Copy Markdown
Collaborator

Why this matters

gaia init --profile npu was dead on arrival: it failed at the model-download step with HTTP 400 before any NPU user could get set up (#1655). The init flow pulled gemma4-it-e2b-FLM with recipe=flm, but Lemonade only allows a recipe/checkpoint on /pull when registering a new user model (which must carry a user. prefix). gemma4-it-e2b-FLM is a built-in Lemonade model, so it must be pulled by name only. After this fix the NPU profile downloads, verifies, and runs inference on the NPU.

Root cause was a wrong assumption added in #1252 that FLM models need their recipe at pull time. They don't — the recipe is baked into the built-in model and applied at load time. The fix routes the download through ensure_model_downloaded (pull by name, with an already-downloaded pre-check), same as every other profile.

This PR also adds a CLAUDE.md testing rule so the class of bug can't recur silently: #1655 passed every test only because they ran against a warm model cache and a mocked client, so the fresh-pull 400 never surfaced. The rule requires (1) testing setup/download paths from a cold state — runtime-verified ≠ setup-verified — and (2) asserting external-API call shape rather than trusting a mocked 200.

Test plan

Validated on real XDNA2 hardware (AMD Ryzen AI MAX+ PRO 395, FLM npu backend v0.9.39, Lemonade 10.4.0):

  • Reproduced the bug: POST /pull {"model_name":"gemma4-it-e2b-FLM","recipe":"flm"} → 400 ... must include the user. prefix; without recipe → 200 {"status":"success"}.
  • CLI cold path: gaia init --profile npu --yes --force-models — model is deleted then re-pulled successfully (no 400) and passes inference verification (gemma4-it-e2b-FLM - OK (ctx: 4096)).
  • Agent UI / NPU inference: chat completion on gemma4-it-e2b-FLM returns correctly with the model loaded on device: npu, recipe: flm; the UI device resolver maps npu → gemma4-it-e2b-FLM (ctx 4096).
  • Unit test added (test_npu_profile_pulls_builtin_model_without_recipe) — regression guard that the npu profile pulls by name and never calls pull_model(recipe=...). Full TestDownloadModels suite green.

Fixes #1655

gaia init --profile npu failed at the download step with HTTP 400:
Lemonade rejects a /pull call that carries a recipe unless the model name
uses the user. prefix — that rule is for registering new user models. But
gemma4-it-e2b-FLM is a built-in Lemonade model, so passing recipe=flm was
wrong; it should be pulled by name. Switch the download path to
ensure_model_downloaded (pull by name), which also pre-checks for an
already-downloaded model. The recipe is baked into the built-in model and
applied at load time, so NPU inference is unaffected.
@github-actions

Copy link
Copy Markdown
Contributor

Summary

This is a tight, correct fix for a broken setup path: gaia init --profile npu was 400ing at model download because it passed recipe=flm to Lemonade's /pull, which Lemonade only accepts when registering a new user.-prefixed model — not for a built-in like gemma4-it-e2b-FLM. Routing the download through ensure_model_downloaded() (pull by name, same as every other profile) is the right call, and the diff is appropriately small. The single most important thing: the change is verified on real XDNA2 hardware and guarded by a regression test, which is exactly what a fix like this needs. No security, breaking-change, or architecture concerns.

Issues Found

🟢 Minor — display label still advertises recipe=flm (init_command.py:1499)

The recipe variable is now used only to format the download label (f"{model_id} (recipe={recipe})"), even though the recipe is no longer sent to pull. Showing recipe=flm next to a by-name pull is slightly misleading now that the recipe plays no part in the download. Not blocking — the recipe genuinely does apply at load time, so it's arguably still informative — but if you want the label to reflect what actually happens, dropping it is cleaner:

                label = model_id

(If you'd rather keep it as an at-a-glance hint of how the model loads, leaving it is fine too — just flagging the mismatch.)

Strengths

  • Verified where it counts. The fix was reproduced and validated end-to-end on real NPU hardware (XDNA2, FLM v0.9.39), not just unit-mocked — the failure mode here was a live HTTP contract, so on-hardware proof is the right bar.
  • Regression guard matches the bug. test_npu_profile_pulls_builtin_model_without_recipe asserts both the positive (ensure_model_downloaded("gemma4-it-e2b-FLM")) and the negative (pull_model.assert_not_called()), so a future "let's pass the recipe again" regression fails loudly.
  • Correct mock target. Patching gaia.llm.lemonade_client.LemonadeClient lines up with the deferred import inside _download_models() — the common footgun (patching where it's imported, not where it's defined) is avoided.
  • Comment explains the why, not the what. The new comment names the Lemonade contract and the issue number — exactly the kind of non-obvious constraint worth a code comment.

Verdict

Approve. No blocking issues. The lone minor note (the recipe= label) is optional and safe to merge with or without.

…aths

#1655 shipped because every test ran against a warm model cache and mocked
the Lemonade client, so the fresh-pull 400 never surfaced. Add a Testing
Philosophy rule covering the two failure modes — test setup/download paths
from a cold state (runtime-verified != setup-verified), and assert external
API call shape rather than trusting a mocked 200 — with #1655 as the
canonical example.
@github-actions github-actions Bot added the devops DevOps/infrastructure changes label Jun 13, 2026
The cold-state and call-validity rules apply to any change, not just
setup/download paths. Reframe around the two underlying failure modes —
hidden-state masking (empty cache/DB/session, first run, expired token,
zero results) and mocks asserting invocation rather than validity (any
HTTP/subprocess/SQL/IPC/file boundary) — with #1655 kept as the canonical
example of both.
@github-actions

Copy link
Copy Markdown
Contributor

🟡 init_command.py:1495-1499 — recipe is now a dead variable that still generates a misleading user-facing label.

After the fix, recipe is read from the profile config but never passed to any download call. However, line 1499 still constructs the label as f"{model_id} (recipe={recipe})", so NPU users see:

Downloading: gemma4-it-e2b-FLM (recipe=flm)

…which implies the recipe is being applied during the pull — the exact bug this PR just fixed. The dead read + misleading display should be removed together:

            success = True
            for model_id in model_ids:
                self._print("")
                self.agent_console.print(
                    f"   [bold cyan]Downloading:[/bold cyan] {model_id}"
                )

(Drop the recipe = profile_config.get("recipe") line at 1495 too — nothing uses it anymore.)

@itomek

itomek commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Real-world verification on NPU hardware ✅

Reproduced the bug and confirmed the fix end-to-end on AMD Ryzen AI MAX+ 395 (Strix Halo), Ubuntu 24.04, XDNA NPU (/dev/accel/accel0, amdxdna loaded), Lemonade on FastFlowLM flm:npu. Both runs used --force-models to force the cold pull the bug needs (the model was warm-cached otherwise — exactly the masking this PR's new CLAUDE.md rule calls out).

1. Root cause at the API layer

# recipe=flm  →  rejected
POST /api/v1/pull {"model_name":"gemma4-it-e2b-FLM","recipe":"flm"}
{"error":"When providing 'checkpoint' or 'recipe', the model name must include the `user.` prefix ... Received: gemma4-it-e2b-FLM"}
HTTP=400

# by name only  →  accepted
POST /api/v1/pull {"model_name":"gemma4-it-e2b-FLM"}
{"model_name":"gemma4-it-e2b-FLM","status":"success"}
HTTP=200

2. Pre-fix init flow (6d03b4b8, before the fix) — gaia init --profile npu --force-models reproduces the failure:

Step 5/7: Downloading models for 'npu' profile...
   Downloading: gemma4-it-e2b-FLM (recipe=flm)
   ❌ Failed to download gemma4-it-e2b-FLM: ... status 400: ... must include the `user.` prefix ...
=== EXIT CODE: 1 ===

3. Post-fix init flow (this PR, 8f3e0868) — same command succeeds:

Step 5/7: Downloading models for 'npu' profile...
   Downloading: gemma4-it-e2b-FLM (recipe=flm)
   ✓ Downloaded gemma4-it-e2b-FLM
Step 7/7: Verifying setup...
   ✓  gemma4-it-e2b-FLM - OK (ctx: 4096)
   ✓ All 2 model(s) verified
=== EXIT CODE: 0 ===

4. NPU inference confirmed (not a CPU/llama.cpp fallback): chat completion returns correctly via the FastFlowLM backend ("id":"fastflowlm-chat-completion", "model":"gemma4-it:e2b"), with flm serve gemma4-it:e2b --ctx-len 4096 running and the model registered "recipe":"flm", "downloaded":true.

Note: post-fix still prints the cosmetic (recipe=flm) label, but the download now goes through ensure_model_downloaded() (pull by name) — confirmed in source; the recipe is only used for the display string.

One unrelated observation: the Agent UI frontend build failed during init because the test box has Node.js 18 (Vite needs 20+). Pre-existing environment limitation, independent of this fix — init still completed (exit 0).

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Jun 15, 2026
Merged via the queue into main with commit a3e86b0 Jun 15, 2026
33 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/npu-init-builtin-flm-model-1655 branch June 15, 2026 15:29
@github-actions github-actions Bot mentioned this pull request Jun 15, 2026
6 of 7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops DevOps/infrastructure changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gaia init --profile npu fails with status 400 (missing user. prefix for model name)

2 participants