1 Commits
Author SHA1 Message Date
Beenu Arora 21fe39f543 feat(model): let users choose where the model runs (#1123)
* feat(model): let users choose where the model runs

make up is unchanged: the bundled model on CPU, no account and no GPU.
Alongside it, make up-gpu layers an NVIDIA device reservation onto the bundled
Ollama, and make up-host-llm uses an Ollama already running on the host --
the only way to reach a GPU on Apple Silicon, since Docker Desktop cannot pass
Metal into a Linux container. Hosted providers already worked and are now
reachable from the first-run wizard rather than only from Settings.

The reservation is an overlay and not a line in the base file. A host without
an NVIDIA GPU and the container toolkit cannot start a service that reserves
one -- the daemon answers 'could not select device driver nvidia' -- so putting
it in docker-compose.yml takes out make up for every Mac, every CPU-only Linux
box and every CI runner. A test asserts the base file reserves no devices, and
reintroducing the reservation fails it.

GET /api/v1/llm/runtime reports where the model actually is, because a
reservation is a request: a model can still land on the CPU for want of VRAM or
a usable driver. It asks Ollama rather than reading the compose file back.
Five states including 'not loaded right now', since Ollama unloads when idle
and answering CPU there would be a guess about the exact thing an operator is
deciding on. Verified against the pinned 0.6.7 image, which reports
size_vram: 0 in a container on Apple Silicon, and a native Ollama on the same
host, which reports size_vram == size because it reaches Metal.

POST /api/v1/llm/credentials/test places one real call. The existing routes
validate shape and never talk to the provider, so a revoked key surfaced as
triage quietly falling back. It deliberately does not use _guard_url, which
refuses every private address and would refuse the three local-* providers
migration 038 allows; it uses the agents SSRF guard with allow_private=True,
vendored and gated, which still rejects loopback and link-local so cloud
metadata stays unreachable.

Two fixes found on the way. make doctor told an operator with their own Ollama
to stop it -- on a Mac, the only one with a GPU. And the probe read
settings.AISOC_AIRGAPPED through a module-level reference that goes stale when
anything reloads app.core.config; its test passed alone and failed in the suite
for exactly that reason, so it now calls enforce_airgap_for_url, which reads
the flag at call time.

* fix(llm): route the credential probe through the contract helper

tests/test_llm_contract_no_bypass.py refused the first version: it made a raw
client.post to a completions endpoint. The prompt is a constant carrying no
untrusted input, so the contract has nothing to reject -- but the rule is that
every call to a completions endpoint goes through it, and a call site that
argues its way out is how the next one, with a real prompt, gets written the
same way.

safe_chat_completions_request calls raise_for_status, and the status code is
exactly what separates 'the key is wrong' from 'the model name is wrong' from
'you were rate-limited, so it works' -- so the ladder moved into a handler for
HTTPStatusError and reads the response the helper raised with. Verified by
driving a real 401 and a real 200 through the whole function rather than
trusting that the mocked client was still on the path.

* fix(llm): the test-connection route was mounted at a doubled path

The decorator repeated a prefix the router already carries, so the endpoint
published as /api/v1/llm/credentials/credentials/test and was reachable at no
URL anything calls.

Thirteen tests passed throughout, because every one of them called
probe_credential directly and none asked the app what it had mounted. Only
check_console_route_contract noticed, by comparing the console's fetch strings
against the real OpenAPI document -- which is the whole argument for a gate
that reads the published artefact rather than the source.

There are now three assertions that read app.openapi(): the path is where the
client asks for it, no segment is doubled, and the client string and the
server path are compared to each other directly.

* fix(llm): correct a comment path and give two stub bodies a docstring

check_comment_paths: the comment named tests/test_llm_contract_no_bypass.py,
which lives under services/agents/. A comment is an instruction to the next
contributor, and a path that does not resolve sends them looking.

CodeQL py/ineffectual-statement: the `...` bodies on two test stubs. A
docstring says the same thing and is not a no-op expression -- the pattern
the repository already uses for Protocol and abstract bodies.
2026-10-04 18:29:43 -07:00