Skip to content

feat: choose and verify local models for Gateway hardware - #138464

Merged
steipete merged 2 commits into
mainfrom
codex/local-model-smart-setup
Sep 4, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/local-model-smart-setup

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #138426

What Problem This Solves

Managed local model setup previously selected one fixed model regardless of the Gateway's hardware and verified only a text reply. Operators had to work out whether the model and runtime would fit and whether the result could actually use OpenClaw tools.

Why This Change Was Made

The existing llama.cpp plugin now owns hardware detection, curated model selection, verified runtime installation, and a host/model/download confirmation. Core activation reuses one inference-verification flow and adds a real file-read tool challenge for managed models before changing the default. Each candidate uses an isolated preset and port so failed verification preserves the previous selection and server preset.

The recipes pin Hugging Face revisions and SHA-256 identities. Recommendations account for current RAM/container limits, one GPU's usable memory, a 64K context, embeddings, and disk capacity. Separate disks get separate budgets; shared or uncertain storage pools retain a combined reserve. Verified cached artifacts are reused on retries. Managed streams now use the existing llama-server payload adapter, fixing the thinking-off setting that otherwise prevented one new recipe from returning a final answer during activation.

User Impact

The existing Run a model locally → llama.cpp → Set up model flow recommends:

Hardware floor Preferred recipe
8 GiB RAM Qwen3.5 4B Q4_K_M
16 GiB RAM Qwen3.5 9B Q4_K_M
24 GiB RAM with acceleration Gemma 4 12B IT Q4_K_M
32 GiB RAM with acceleration Qwen3.8 27B UD-Q4_K_M when its budget fits; Muse Glimmer 30B Q4_K_M for the smaller GPU-memory budget

These are selection floors, not guaranteed speed or comparative benchmark rankings. CPU recommendations stop at 9B. Existing Gemma recipes remain available for existing and cached routes. The pinned runtime supports Apple Metal, CPU platforms, and Windows CUDA 12.4 with the matching verified runtime DLL archive. Linux NVIDIA hosts receive an explicit CPU confirmation or can connect an externally managed server.

No public configuration key, environment variable, SQLite schema, or dependency is added. The docs describe the Gateway-host boundary, resource budgets, runtime choices, verification, and retry behavior.

Evidence

  • All five new recipes passed real OpenClaw activation on Apple silicon: connection, actual file-read tool execution, exact content returned, and default persisted only after success. Verification times were 14.5s (4B), 18.6s (9B), 15.4s (12B), 30.2s (Muse), and 45.8s (27B). Earlier E2B and 26B Gemma live paths also passed.
  • 389 focused tests (216 provider + 173 core/wizard), plus 5 doctor contract checks, cover selection, pressure/container budgets, cached downloads, separate/shared storage, integrity, CUDA packaging/device validation, cancellation, and tool-verification failure preservation. New thinking and disk-accounting regressions were observed failing before their fixes.
  • Desktop/mobile model-setup browser E2E passed. The images below contain synthetic fixture data.
  • Runtime/application/plugin/Control UI build passed in 2m42s. Built-plugin Qwen 9B activation passed with a real tool roundtrip (28.9s verification, 40.6s total). Core/plugin and test typechecks, core/plugin lint, formatting, dead-export, boundary, manifest, and dependency guards passed. The full changed-file check found one unused test import; after its removal the final plugin type/lint rerun passed. Runtime builds omit declaration emission; separate typechecks cover the changed programs. Exact-head hosted CI passed for 65fb014c70f6a122b7d475955ab4b14d397f5208, including openclaw/ci-gate.
  • Live platform proof is macOS Metal. Windows CUDA and Linux paths have source/fixture coverage; no physical Windows GPU run is claimed. Resource budgets are derived estimates, not measured peak VRAM.

Setup flow

Before starting setup:

Local-model setup offer

Hardware-specific confirmation:

Qwen 9B recommendation for a 16 GiB Gateway

After verified activation, mobile:

Verified local model on mobile

Follow-ups and scope

The real-router investigation reproduced a pre-existing issue when switching between multiple configured managed models: #138452. Fresh single-model activation is covered here; the full configured-inventory lifecycle repair belongs in that follow-up. Another pre-existing custom-source concern is concurrent resolutions of a mutable Hugging Face ref joining the same destination with different resolved digests; the new immutable recipes do not take that differing-artifact path.

Production growth supplies hardware/catalog selection, verified GPU installation, cached integrity reuse, and real tool verification. The previous duplicated inference probe is extracted into one shared owner, not retained as a parallel implementation.

Diff accounting: metadata +2/−2 (net +0), docs +95/−22 (net +73), tests +1263/−88 (net +1175), production +1401/−394 (net +1007).

@steipete steipete self-assigned this Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime extensions: llama-cpp size: XL maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 18:10
Recommend pinned Qwen, Gemma, and Muse recipes from available host resources. Install a verified runtime and require a real tool roundtrip before activation while preserving the prior configuration on failure.

Closes #138426
@steipete
steipete force-pushed the codex/local-model-smart-setup branch from 3018bc8 to 65fb014 Compare September 4, 2026 18:33
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

The first CI run exposed a host-dependent setup test: it mocked total RAM but still consumed the runner's real cgroup/memory/disk probes. The test now supplies a complete hardware fixture at the detector boundary, preserving its assertion that local embeddings do not suppress chat setup. The focused suite, typecheck, lint, and fresh independent P0–P2 review pass.

The other failure was the inherited Control UI startup budget overrun (350,366 bytes versus 350,141 allowed). This PR changes no production UI source or build configuration. Rebased once to include the existing lazy provider-settings catalog repair from #137342; the budget is unchanged. git range-diff confirms both task commits are patch-identical after rebase. CI is rerunning on the new head.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 2:41 PM ET / 18:41 UTC.

ClawSweeper review

What this changes

Adds hardware-aware managed llama.cpp model selection, verified runtime/model installation, and tool-use verification before a new local model becomes the Gateway default.

Merge readiness

⛔ Blocked before merge - 2 items remain

No introduced blocker found. This active maintainer-owned PR keeps managed local-model policy in the llama.cpp plugin, verifies an isolated candidate with a restricted real tool roundtrip before persistence, and preserves existing managed and external-server paths.

Priority: P2
Reviewed head: 65fb014c70f6a122b7d475955ab4b14d397f5208

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A well-scoped owner-boundary implementation with strong supplied behavior evidence; cross-platform physical validation and exact-head CI remain useful confidence builders.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-owned PR; supplied evidence describes managed Apple Metal activation with a read-tool nonce roundtrip before configuration persistence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-owned PR; supplied evidence describes managed Apple Metal activation with a read-tool nonce roundtrip before configuration persistence.
Evidence reviewed 5 items Plugin-owned setup path: Setup detects host resources, prepares the candidate with isolation enabled, and returns a staged result rather than writing the active configuration directly.
Candidate verification boundary: The generic verifier requires both an observed read-tool result and a nonce-bearing final response, restricts the probe to the read tool, and closes the prepared admission during cleanup.
Conservative recommendation logic: Selection reserves host headroom, does not aggregate GPU memory, and rejects models that do not fit the relevant cache/runtime disk budgets.
Findings None None.
Security None None.

How this fits together

The managed llama.cpp plugin supplies local model setup to Gateway onboarding and Model Setup. It detects the Gateway host, prepares a verified local server and model, then hands a candidate route to shared inference verification before persisting the default.

flowchart LR
A[Gateway onboarding] --> B[Managed llama.cpp setup]
B --> C[Host hardware detection]
C --> D[Model and runtime selection]
D --> E[Verified download and isolated server]
E --> F[Inference and tool verification]
F --> G[Persisted default model]
Loading

Before merge

  • Resolve merge risk (P1) - The new recommendation is exercised with supplied Apple Metal evidence; Windows CUDA and Linux hardware remain source- and fixture-covered, so exact-head CI and the documented manual-server path should remain part of landing review.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +1007, Tests +1175, Docs +73, Other 0. Total +2255 across 30 files.

View PR surface stats
Area Files Added Removed Net
Source 17 1402 395 +1007
Tests 10 1263 88 +1175
Docs 2 95 22 +73
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 30 2761 506 +2255

Review metrics

Metric Value Why it matters
Production versus test LOC production +1,401/-394; tests +1,263/-88; docs +95/-22; metadata +2/-2 The feature adds plugin-owned resource selection, artifact handling, and verification, with substantial focused regression coverage.
Managed setup default 1 managed selection flow changed; 0 public config keys added or removed New local setup chooses a hardware-fitting recipe while existing custom GGUF and external-server configuration shapes remain supported.

Stored data model

Persistent data-model change detected: serialized state: extensions/llama-cpp/src/embedding-provider.ts, serialized state: extensions/llama-cpp/src/hardware.ts, unknown-data-model-change: extensions/llama-cpp/src/hardware.ts, unknown-data-model-change: src/system-agent/setup-inference-persist.ts, vector/embedding metadata: extensions/llama-cpp/src/embedding-provider.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138426
Summary: This PR is the candidate implementation for the maintainer issue requesting hardware-aware managed local-model setup and verification.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land after exact-head CI is green while retaining plugin-owned hardware/runtime policy and generic inference verification; keep the separate live multi-model router-inventory defect in Managed llama.cpp model switching leaves preset and live router inventory inconsistent #138452 scoped independently.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land after exact-head CI is green while retaining plugin-owned hardware/runtime policy and generic inference verification; keep the separate live multi-model router-inventory defect in #138452 scoped independently.

Do we have a high-confidence way to reproduce the issue?

Not applicable as an issue reproduction: the PR supplies after-fix managed Apple Metal activation evidence, while source tests cover insufficient resources and failed verification without persisting a candidate.

Is this the best way to solve the issue?

Yes. Provider-specific hardware, artifact, and runtime policy remains in the llama.cpp plugin, while the shared verifier owns only the generic model/tool capability check.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0062f2b127bb.

Labels

Label changes:

  • add P2: This is a substantial local-model onboarding improvement without a demonstrated release-blocking regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-owned PR; supplied evidence describes managed Apple Metal activation with a read-tool nonce roundtrip before configuration persistence.

Label justifications:

  • P2: This is a substantial local-model onboarding improvement without a demonstrated release-blocking regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-owned PR; supplied evidence describes managed Apple Metal activation with a read-tool nonce roundtrip before configuration persistence.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • sunlit-deng: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Complete exact-head CI.
  • Record a non-Metal hardware activation before relying on the recommendation as cross-platform evidence.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Addressing the review's compatibility and rank-up items:

The stored-data detector matched transient state, not a schema change. In embedding-provider.ts, the changed JSON.stringify key belongs to the process-local preparedEmbeddingServers Map; it now includes the existing localService configuration so switching runtimes does not reuse stale preparation. resolveIndexIdentity, cacheKeyData, persisted vector metadata, and the model/cache identity constants are unchanged. hardware.ts only reads probes and returns an in-memory setup snapshot. setup-inference-persist.ts moves the probe into its own module; the persistence/rollback implementation and stored configuration shapes are unchanged. There is no SQLite DDL, version change, migration, or new public config field in this diff.

Compatibility proof is included in the passing suites: old and managed embedding cache paths retain their index identity; embedding-only inventory stays empty; existing custom GGUF identities stay literal; configured direct-model and router services retain their commands/arguments/environment/cwd; external routes are preserved; and failed/cancelled activation retains the prior configuration. Real source and built activation also exercised the normal configuration write/read flow. No data migration is required for these unchanged formats.

Rank-up disposition: exact-head CI is required and is finishing. Non-Metal physical activation remains deferred because the proof host is Apple silicon; the PR explicitly limits live evidence to Metal and preserves the documented externally managed server path. Windows CUDA/Linux claims remain bounded to direct upstream source and fixture validation, including CUDA archive/device checks. The separate pre-existing multi-model lifecycle defect stays in #138452. These are the recorded mitigations for the review's platform risk; no test or performance gate is waived.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Ready to land: exact-head CI33906548543 completed successfully for 65fb014c70f6a122b7d475955ab4b14d397f5208, including openclaw/ci-gate. Independent P0–P2 review is clean, including the follow-up test-fixture repair. Local proof covers 389 focused tests plus 5 doctor checks, desktop/mobile browser E2E, the runtime/plugin/UI build, and core/plugin/test types and lint.

All five new model recipes completed real OpenClaw activation on macOS Metal, including an actual read-tool roundtrip; the final built plugin also passed with Qwen3.5 9B. Failed verification preserves the previous default, and candidate presets are isolated. Windows CUDA/Linux selection and packaging have source/fixture proof; physical Windows GPU behavior and measured peak VRAM are not claimed.

The first CI run's host-dependent test is fixed at its hardware-detector fixture. The inherited UI startup overrun is resolved by rebasing onto the existing lazy-settings fix from #137342, with no size-limit change. The two task commits remained patch-identical through that rebase. Pre-existing multiple-model router switching is tracked separately in #138452.

Production delta is +1,401/−394 (net +1,007); tests +1,263/−88 (net +1,175). Growth supplies the requested resource selection, verified runtime/artifact handling, and real tool-use activation; the old duplicate inference probe was removed. The plugin manifest remains refreshable local discovery, so uninstalled recipe choices are not advertised as usable models in the global catalog.

Latest ClawSweeper findings: none. Its compatibility/platform review items are addressed in the recorded disposition; exact-head CI rank-up is complete, and physical non-Metal activation remains an explicitly documented follow-up.

@steipete
steipete merged commit 9b95e87 into main Sep 4, 2026
196 checks passed
@steipete
steipete deleted the codex/local-model-smart-setup branch September 4, 2026 18:53
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…38464)

* feat: choose and verify local models for Gateway hardware

Recommend pinned Qwen, Gemma, and Muse recipes from available host resources. Install a verified runtime and require a real tool roundtrip before activation while preserving the prior configuration on failure.

Closes openclaw#138426

* test: isolate local setup from runner hardware capacity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation extensions: llama-cpp gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Managed local model setup should choose and verify a model for the Gateway hardware

1 participant