Skip to content

fix(models): honor runtime-discovered cloud models in Local only and setup - #7002

Merged
kovtcharov-amd merged 7 commits into
amd:mainfrom
huong8373tt-beep:fix/6996-runtime-cloud-catalog
Nov 10, 2026
Merged

kovtcharov-amd merged 7 commits into
amd:mainfrom
huong8373tt-beep:fix/6996-runtime-cloud-catalog

Conversation

@huong8373tt-beep

@huong8373tt-beep huong8373tt-beep commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Turning on Local only kept a saved default that only Lemonade's model list identifies as a cloud model (for example an opencode.* model), so every later chat was refused. Setup also planned to download such a model, the vision default could mistake it for an NPU model, and agent startup tried to preload it on the PC. These paths now read Lemonade's model list whenever a saved or requested id could be a gateway model, including in a fresh CLI process, and treat it as cloud. Known cloud ids (amd.*, fireworks.*, Claude) still need no network call, and models GAIA knows are local, including user-added dotted ids, never trigger a lookup.

With Lemonade unreachable, nothing silently guesses: Local only clears the known cloud ids, keeps the one it couldn't check and warns that it wasn't checked; agent startup starts Lemonade without loading a model and asks again, failing with a clear error if it still can't tell; setup returns a plan error instead of a 500. Discovered cloud models also get the cloud output-token cap and context eviction at agent startup.

Fixes #6996.

Test plan

  • python -m pytest tests/unit/test_local_only_paths.py tests/unit/test_base_agent_lemonade_api_key.py tests/unit/test_default_vision_model.py tests/unit/chat/ui/test_setup_plan.py tests/unit/chat/ui/test_setup_chat_model.py
  • python -m pytest tests/unit/test_vision_off_on_npu.py tests/unit/test_vision_uses_downloaded_model.py tests/unit/test_agent_max_output_tokens.py tests/unit/test_lemonade_cloud_models.py tests/unit/installer/test_init_test_step.py
  • With a gateway provider connected and an opencode.* model saved as default_model, Lemonade stopped: gaia config set network_policy local_ai_only clears any amd.* default and warns that the opencode.* id wasn't checked; with Lemonade running it clears it.

No prompts, tool text or schemas change, so no eval category needs a re-run.

Disclosure and authorization

Slai Agent Runtime performed the investigation, implementation, and test execution.
The account owner authorized this contribution and is responsible for its content.

@github-actions github-actions Bot added llm LLM backend changes tests Test changes performance Performance-critical changes agents labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes

This PR makes Local only, setup, vision-model choice and agent startup recognise cloud models GAIA learned about from Lemonade's catalog, such as opencode.*. The checks are right, but they only see what the current process has already read from the catalog, and nothing on these paths reads it first. In a fresh process the catalog is empty, so the fix misses:

  • Turning on Local only from the CLI still keeps a saved opencode.* default. gaia config set network_policy … runs in a new process that never reads the catalog. That leaves the bug the issue calls the worst one in place: every later chat is refused.
  • A one-off run like gaia -p --model opencode.x still tries to load that model on the PC. Agent startup reads the catalog only after this check.
  • The new tests can't catch this. Each one loads the catalog by hand before calling the code, which is the warm-state masking CLAUDE.md warns about. To fix: on these paths, read the catalog once whenever a saved or requested id could be a cloud id. Add one test that starts with an empty catalog.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on static review alone. The PR itself says it ran no live cloud gateway or hardware check. I couldn't run the unit tests either, because pytest isn't installed in this review environment.

🔍 Technical details

🟡 New checks are cold-cache blind (src/gaia/llm/local_only.py:321, src/gaia/agents/base/agent.py:2979)
is_cloud_model() only checks the in-process _CLOUD_MODELS map, which record_cloud_models() fills when list_models() is called. Its docstring says: "a caller that must be correct on a cold cache should list models first."

  • clear_saved_cloud_models() is reached from cli.py:7369 (_handle_network_policy → apply_policy). That is a fresh process with no prior list_models(), so opencode.big-model returns False and is not cleared. The UI path (routers/system.py:1248) probably works only because the server has usually listed models by then.
  • In Agent.__init__, nothing has listed models before line 2979 in a CLI process, so a discovered gateway id falls into LemonadeManager.ensure_ready(model=…).
  • LemonadeClient._is_cloud_model() (lemonade_client.py:~7722) already does the right thing. It short-circuits local ids via may_be_cloud_model, warms the catalog once, raises with context if the catalog can't be read, and handles a registered provider whose model is absent. Agent init already builds a LemonadeClient, so it could build one before the branch and call probe_client._is_cloud_model(model_id). For clear_saved_cloud_models, warm the catalog once when any saved id passes may_be_cloud_model but not is_cloud_model. If the read fails, surface it as an apply_policy notice; don't silently keep the model. Silently keeping it would be the fallback CLAUDE.md prohibits.
  • Tests: every new test calls record_cloud_models({...}) up front. Add one that leaves the map empty and stubs LemonadeClient.list_models to return the opencode.* entry. Assert that the id is cleared or skipped and that list_models was called.

🟡 Follow-up: same __init__, same blind spot (src/gaia/agents/base/agent.py:3110, :3139)
Context eviction (cloud=cloud_model_provider(model_id) is not None) and the output cap (CLOUD_MAX_OUTPUT_TOKENS vs LOCAL_MAX_OUTPUT_TOKENS) still use the built-in-providers-only check. A discovered gateway model therefore gets local eviction and the local output cap. The issue didn't list these lines, but they sit a few lines below the preload branch this PR fixes. Fix them here, or file "Discovered cloud models get local eviction and output-token cap in Agent init".

🟢 Repeated three-way check
startswith("claude-") or cloud_model_provider(m) or is_cloud_model(m) now appears in four files. _ui_cloud_provider in ui/_chat_helpers.py:1318 already wraps the catalog-aware form. A shared helper in lemonade_client.py would stop the next caller from forgetting the third clause, which is how #6996 happened.

Strengths

  • Dotted local ids stay local (test_dotted_local_model_survives_cloud_cleanup), so the fix doesn't over-correct into "has a dot = cloud".
  • The tests assert behaviour, not just calls. The vision test fails if the NPU probe runs, and the setup test fails if _device_for runs for a cloud model.
  • Each test resets the shared catalog in finally, so no state leaks into other tests.

@huong8373tt-beep

Copy link
Copy Markdown
Contributor Author

Addressed the cold-catalog review blocker in 72dc5d4ed.

  • Fresh CLI Local only: when a saved ID could be a gateway model, read the Lemonade catalog before clearing saved defaults; if unavailable, return an explicit saved_models_not_checked warning instead of silently treating the ID as local.
  • Fresh gaia -p --model / Agent startup: resolve ambiguous model IDs from Lemonade before any local preload. On catalog failure, propagate a contextual error; never call LemonadeManager.ensure_ready for an unclassified gateway candidate.
  • Agent defaults: use that same cloud classification for context eviction and output-token caps.
  • Shared classification: expose is_cloud_model_with_catalog() and use it in setup planning, vision selection, and setup failure messaging rather than relying on a warm in-process catalog.
  • Cold/warm regressions: exercise real empty-cache paths in Local only, Agent startup, setup planning/failure messaging, and vision choice; retain tests protecting dotted local model IDs.

Local verification: 373 passed, 1 skipped across nine focused unit test modules; Black check (10 changed files), isort check, compileall, and git diff --check passed. No live cloud gateway or physical-device run was performed; remote CI/rereview is pending.

Disclosure and authorization: Slai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Thanks — this fixes #6996 and every local default still stays local with no network call. Two regressions against main need fixing before merge:

  • Turning on Local only with Lemonade down can leave a cloud default saved. If any saved model id is ambiguous and the catalog can't be read, clear_saved_cloud_models raises before clearing anything, including amd.* / fireworks.* / claude* ids main clears without a network call. Please clear the definitely-cloud ids first, then read the catalog only for the ambiguous ones and report a failure for those alone.
  • An agent on a user-added dotted local model fails to start when Lemonade is stopped. The new catalog probe in Agent.__init__ runs before LemonadeManager.ensure_ready, the step that starts Lemonade (e.g. user.Llama-3.2-3B-GGUF raises LemonadeClientError, where main starts). Start Lemonade first, or classify after ensure_ready for ids that aren't known cloud.
  • PR body: it still describes the first commit; please cover the cold-catalog reads and the raise-on-failure behaviour, since it becomes the commit message.
🔍 Technical details
  • /api/setup/model-need only translates GaiaConfigError, so with Lemonade down it now returns a generic 500; RAGConfig.vlm_model's default now hits the network on construction; init_vlm swallows the error, so vision tools can quietly disappear.
  • agent.py and local_only.py repeat the three-way check inline instead of calling is_cloud_model_with_catalog; setup_runner._test_agent still uses the cache-only check.
  • The helper answers "is this cloud?" (unlisted counts as local), so it must never be used as the privacy gate — that's _runs_on_this_pc / recipes_confirm_local, which require a model to be confirmed local.

@huong8373tt-beep

Copy link
Copy Markdown
Contributor Author

Addressed the maintainer-requested regressions in 7565deb5c.

  • Local-only cleanup now removes definitely-cloud saved ids first, persists that cleanup even when Lemonade is unavailable, and reports catalog failure only for ambiguous ids.
  • Agent startup keeps known gateway ids off the local preload path, while a registered dotted local model can still reach the normal LemonadeManager.ensure_ready startup path when catalog probing fails.
  • Added a cold-catalog regression covering the dotted local startup case.
  • Updated validation: 213 focused tests passed, 1 skipped; Black, isort, compileall, and git diff --check passed.

The PR description still reflects the first implementation and should be updated separately to describe the cold-catalog behavior and failure handling accurately.

Disclosure and authorization: Slai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes

The cold-catalog fixes from my last review are in: Local only and agent startup now read the catalog, and context eviction and the output cap use the same check. One regression the maintainer flagged is still unfixed:

🟡 With Lemonade stopped, setup and vision now error for a user-added dotted model. Take a saved chat model added from a Hugging Face link, such as user.Llama-3.2-3B-GGUF. The new shared check asks the catalog about it, and when Lemonade is down that request raises. On main nothing raised here. Now:

  • The setup "does this job need a model" call returns a 500 where it used to answer "not needed".
  • In the flagship, the vision tools are quietly dropped.

The fix: treat a registered local model as local before asking the catalog. Agent startup already does this.

🔍 Technical details
  • is_cloud_model_with_catalog (src/gaia/llm/lemonade_client.py:3375) only short-circuits on may_be_cloud_model, which checks MODELS alone. Custom user.* ids, and dotted Lemonade ids missing from MODELS, fall through to _is_cloud_model, and that raises LemonadeClientError when the server is unreachable.
  • setup_plan.model_need catches only GaiaConfigError around _job_model. Its docstring says "with no server reachable nothing can be said, so nothing is asked", so GET /api/setup/needs/{chat,vision} now 500s.
  • resolve_default_vision_model is the RAGConfig.vlm_model default factory, so RAGConfig() raises. It is also called inside ChatAgent's init_vlm try/except Exception, which logs at debug and skips the tools.
  • Suggested fix, matching agent.py:3005:
    if not may_be_cloud_model(model_id) or find_model_requirement(model_id) is not None:
        return False

Add a cold-cache test with list_models raising and a custom user.* id saved.

  • The PR body still has a ## Summary heading and no line about raise-on-failure for unregistered dotted ids. The maintainer asked for that line, since the body becomes the commit message.

@huong8373tt-beep

Copy link
Copy Markdown
Contributor Author

Addressed the latest bot finding in 600512b97.

Registered local models (including user-added dotted ids) are now treated as local before catalog probing in the shared classifier. Setup planning and default vision selection therefore keep the normal local path when Lemonade is stopped; unregistered ambiguous dotted ids still read the catalog and fail loudly if it cannot be checked.

Added cold setup and vision regressions proving the catalog is not queried for a registered local id.

Validation: 165 focused tests passed, 1 skipped; Black, compileall, and git diff --check passed.

The PR body already describes the cold-catalog behavior and raise-on-failure handling. No live gateway or hardware result is claimed.

…stopped

Turning on Local only with Lemonade down now still clears known cloud
defaults and names the one id it couldn't check. Agent startup on a dotted
model GAIA doesn't know starts Lemonade without loading anything, then asks
the catalog again instead of failing. Setup reports a plan error rather than
a 500, and the vision default only reads the catalog for an -FLM id, so
RAGConfig() no longer needs a running server. Registered local models never
trigger a catalog read on any of these paths.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Thanks @huong8373tt-beep, this is a solid fix and the cold-catalog tests are exactly what was needed. I merged main in and closed the remaining gaps from the review: with Lemonade stopped, Local only now still clears known cloud defaults and names only the id it couldn't check, agent startup on an unlisted dotted local model starts Lemonade before asking the catalog again, setup returns a plan error instead of a 500, and the vision default no longer needs a running server. Tests for each are in, and the PR body and CLI reference now match.

@github-actions github-actions Bot added documentation Documentation changes cli CLI changes labels Nov 10, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 10, 2026
Merged via the queue into amd:main with commit 9d082f2 Nov 10, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents cli CLI changes 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.

Runtime-discovered cloud models still count as local in Local only, setup and preload (5 places)

2 participants