Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

explain the llama.cpp model-id mismatch and offer a one-click fix

Adam Eivy2c19d2df426b
diff --git a/client/src/components/providers/ProviderCard.jsx b/client/src/components/providers/ProviderCard.jsx
index 56f85f0b64..38ad1e61be 100644
--- a/client/src/components/providers/ProviderCard.jsx
+++ b/client/src/components/providers/ProviderCard.jsx
@@ -91,6 +91,8 @@ export default function ProviderCard({
onInstallRuntime,
onAutoSetupRuntime,
onUseServedModel,
+ onServeWantedModel,
+ servingModel = false,
}) {
const style = CARD_STATE_STYLES[cardState.state];
return (
@@ -264,6 +266,8 @@ export default function ProviderCard({
readiness={daemonReadiness}
onAutoSetup={(setup) => onAutoSetupRuntime?.({ ...setup, providerId: provider.id })}
onUseServedModel={(modelId) => onUseServedModel?.(provider, modelId)}
+ onServeWantedModel={onServeWantedModel ? () => onServeWantedModel(provider) : undefined}
+ serving={servingModel}
/>
{provider.enabled && status?.available === false && (
diff --git a/client/src/components/providers/ProviderReadiness.jsx b/client/src/components/providers/ProviderReadiness.jsx
index 0a8ccaba79..4912ef8602 100644
--- a/client/src/components/providers/ProviderReadiness.jsx
+++ b/client/src/components/providers/ProviderReadiness.jsx
@@ -19,6 +19,13 @@
* running server answers under a different id, or an in-app Local LLM
* settings link. Vendor setup docs are never the way forward.
*
+ * A model mismatch is fixable from BOTH ends, and the banner offers both.
+ * llama.cpp serves one model per process and answers under the `--alias` on its
+ * launch line, so a provider pinned to `qwen3.8-27b-dflash2` against a server
+ * started as `dflash` is a naming mismatch, not a missing download — the user
+ * can move the provider onto the served id, or press "Serve as …" to relaunch
+ * the daemon on the weights it already has under the id they picked.
+ *
* That includes the case where the daemon is installed but has NO model weights
* cached: the server can't start, so `setup.action` is `pull-start` and the
* button downloads the runtime's own default checkpoint before starting it.
@@ -27,7 +34,7 @@
*/
import { Link } from 'react-router';
-import { CheckCircle2, Download, HelpCircle, Wand2, Wrench, XCircle } from 'lucide-react';
+import { CheckCircle2, Download, HelpCircle, RefreshCw, Wand2, Wrench, XCircle } from 'lucide-react';
import Banner from '../ui/Banner';
import Pill from '../ui/Pill';
@@ -60,7 +67,7 @@ function CodeText({ text }) {
);
}
-export default function ProviderReadiness({ readiness, onAutoSetup, onUseServedModel, className = '' }) {
+export default function ProviderReadiness({ readiness, onAutoSetup, onUseServedModel, onServeWantedModel, serving = false, className = '' }) {
if (!readiness || !Array.isArray(readiness.checks) || readiness.checks.length === 0) return null;
const { label, endpoint, ready, checks, manageUrl, setup } = readiness;
@@ -94,10 +101,10 @@ export default function ProviderReadiness({ readiness, onAutoSetup, onUseServedM
{check.fixHint && (
<span className="block text-port-warning/90"><CodeText text={check.fixHint} /></span>
)}
- {check.id === 'model' && check.ok === false && onUseServedModel
+ {check.id === 'model' && check.ok === false
&& Array.isArray(check.servedModels) && check.servedModels.length > 0 && (
<span className="flex flex-wrap gap-1.5 mt-1.5">
- {check.servedModels.slice(0, 3).map((id) => (
+ {onUseServedModel && check.servedModels.slice(0, 3).map((id) => (
<button
key={id}
type="button"
@@ -108,6 +115,23 @@ export default function ProviderReadiness({ readiness, onAutoSetup, onUseServedM
Use {id} as default
</button>
))}
+ {/* The other direction: move the SERVER onto the id this
+ provider sends. Offered only when the runtime names its
+ model with a launch-line label (`check.renameTo`), which
+ makes the fix a rename of the loaded weights rather than
+ a multi-gigabyte download. */}
+ {check.renameTo && onServeWantedModel && (
+ <button
+ type="button"
+ onClick={() => onServeWantedModel(check.renameTo)}
+ disabled={serving}
+ className={`${ACTION_CLASS} disabled:opacity-50 disabled:cursor-not-allowed`}
+ title={`Restart ${label} serving the model it already has loaded under the id ${check.renameTo}. No weights are downloaded.`}
+ >
+ <RefreshCw size={12} className={serving ? 'animate-spin' : ''} />
+ {serving ? 'Restarting…' : `Serve as ${check.renameTo}`}
+ </button>
+ )}
</span>
)}
</span>
diff --git a/client/src/components/providers/ProviderReadiness.test.jsx b/client/src/components/providers/ProviderReadiness.test.jsx
index 025c701956..e65d53ad3b 100644
--- a/client/src/components/providers/ProviderReadiness.test.jsx
+++ b/client/src/components/providers/ProviderReadiness.test.jsx
@@ -131,6 +131,90 @@ describe('ProviderReadiness', () => {
expect(screen.queryByText(/setup docs/i)).toBeNull();
});
+ // The mismatch is fixable from both ends. Moving the provider is one click;
+ // moving the SERVER — relaunching llama.cpp on the weights it already has,
+ // under the id the provider sends — is the other, and it is the one a user
+ // who picked that model id deliberately actually wants.
+ it('offers to relaunch the daemon under the id the provider sends', () => {
+ const onServeWantedModel = vi.fn();
+ const mismatch = readiness({
+ checks: [
+ {
+ id: 'model',
+ label: 'Model `qwen3.8-27b-dflash2` available',
+ ok: false,
+ detail: 'llama.cpp is serving `dflash`. llama.cpp serves one model per process.',
+ fixHint: 'Same server, two names for it — nothing needs downloading.',
+ servedModels: ['dflash'],
+ renameTo: 'qwen3.8-27b-dflash2',
+ },
+ ],
+ });
+ renderWithRouter(
+ <ProviderReadiness readiness={mismatch} onUseServedModel={vi.fn()} onServeWantedModel={onServeWantedModel} />,
+ );
+
+ const button = screen.getByRole('button', { name: /Serve as qwen3\.8-27b-dflash2/ });
+ // The reassurance that makes the click safe to make: the weights stay put.
+ expect(button.getAttribute('title')).toMatch(/No weights are downloaded/);
+ fireEvent.click(button);
+ expect(onServeWantedModel).toHaveBeenCalledWith('qwen3.8-27b-dflash2');
+ });
+
+ // A relaunch reloads a multi-gigabyte GGUF, so a second click while the first
+ // is still loading would stop the daemon mid-start.
+ it('disables the relaunch button while the daemon is coming back', () => {
+ const onServeWantedModel = vi.fn();
+ renderWithRouter(
+ <ProviderReadiness
+ readiness={readiness({
+ checks: [
+ {
+ id: 'model',
+ label: 'Model `dspark` available',
+ ok: false,
+ detail: 'llama.cpp is serving `dflash`.',
+ fixHint: 'Same server, two names for it.',
+ servedModels: ['dflash'],
+ renameTo: 'dspark',
+ },
+ ],
+ })}
+ onServeWantedModel={onServeWantedModel}
+ serving
+ />,
+ );
+ const button = screen.getByRole('button', { name: /Restarting/ });
+ expect(button.disabled).toBe(true);
+ fireEvent.click(button);
+ expect(onServeWantedModel).not.toHaveBeenCalled();
+ });
+
+ // A runtime that names its model after the weights it loaded has no label to
+ // change, so the server sends no `renameTo` and the banner must not guess one.
+ it('offers no relaunch button when the runtime has no model id to rename', () => {
+ renderWithRouter(
+ <ProviderReadiness
+ readiness={readiness({
+ checks: [
+ {
+ id: 'model',
+ label: 'Model `qwen3:8b` available',
+ ok: false,
+ detail: 'Ollama is serving `llama3:8b`.',
+ fixHint: 'Use the button below to match them.',
+ servedModels: ['llama3:8b'],
+ renameTo: null,
+ },
+ ],
+ })}
+ onUseServedModel={vi.fn()}
+ onServeWantedModel={vi.fn()}
+ />,
+ );
+ expect(screen.queryByRole('button', { name: /Serve as/ })).toBeNull();
+ });
+
it('does not invent a use-as-default button when nothing is loaded', () => {
renderWithRouter(
<ProviderReadiness
diff --git a/client/src/pages/AIProviders.jsx b/client/src/pages/AIProviders.jsx
index 688889b399..90c7adbaae 100644
--- a/client/src/pages/AIProviders.jsx
+++ b/client/src/pages/AIProviders.jsx
@@ -128,6 +128,10 @@ export default function AIProviders() {
// streams from a different endpoint and is keyed by the PROVIDER whose
// endpoint the daemon must come up on.
const [settingUpRuntime, setSettingUpRuntime] = useState(null);
+ // Provider ids whose local daemon is mid-relaunch onto the model id they send
+ // (the "Serve as …" fix). A relaunch reloads the weights, so the button has to
+ // stay disabled for the tens of seconds a large GGUF takes to come back.
+ const [servingModel, setServingModel] = useState({});
// Ollama / LM Studio install state (and the model lists the editor's pickers
// fold in) — fetched once here rather than inside ProviderForm so opening the
// editor doesn't re-request it.
@@ -292,6 +296,29 @@ export default function AIProviders() {
loadReadiness();
};
+ // The mirror of `handleUseServedModel`: instead of moving the provider onto
+ // whatever the daemon answers as, relaunch the daemon under the id the
+ // provider sends. llama.cpp serves one model per process under its `--alias`,
+ // so this keeps the loaded weights and only changes the name — no download.
+ const handleServeWantedModel = async (provider) => {
+ if (!provider?.id || servingModel[provider.id]) return;
+ setServingModel((prev) => ({ ...prev, [provider.id]: true }));
+ // `silent` so the 409 refusal (an externally-started daemon) reads as one
+ // toast naming the fix rather than the helper's generic error on top of it.
+ const result = await api.serveProviderModel(provider.id, { silent: true })
+ .catch((err) => ({ error: err?.message || 'The relaunch failed.' }));
+ setServingModel((prev) => ({ ...prev, [provider.id]: false }));
+ if (!result?.success) {
+ toast.error(result?.error || 'Could not relaunch the local server under that model id.');
+ loadReadiness();
+ return;
+ }
+ toast.success(result.relaunched
+ ? `Local server restarted — now serving ${result.model}`
+ : `Local server already serves ${result.model}`);
+ loadReadiness();
+ };
+
const handleRefreshModels = async (id) => {
setRefreshing(prev => ({ ...prev, [id]: true }));
try {
@@ -768,6 +795,8 @@ export default function AIProviders() {
onInstallRuntime={setInstallingRuntime}
onAutoSetupRuntime={setSettingUpRuntime}
onUseServedModel={handleUseServedModel}
+ onServeWantedModel={handleServeWantedModel}
+ servingModel={Boolean(servingModel[provider.id])}
/>
))}
</CollapsibleSection>
diff --git a/client/src/services/apiProviders.js b/client/src/services/apiProviders.js
index 0852067b62..f2a844aaf7 100644
--- a/client/src/services/apiProviders.js
+++ b/client/src/services/apiProviders.js
@@ -32,6 +32,15 @@ export const getProviderRuntimes = (options) => request('/providers/runtimes', o
// serving the model this provider asks for. Keyed by provider id; providers
// with no local dependency are absent from the map.
export const getProviderReadiness = (options) => request('/providers/readiness', options);
+// The model-mismatch fix that moves the SERVER rather than the provider:
+// llama.cpp serves one model per process under the `--alias` on its launch
+// line, so PortOS can relaunch the weights it already has under the id this
+// provider sends. The model id is re-derived server-side from the stored
+// record — this call names only the provider.
+export const serveProviderModel = (id, options) => request(
+ `/providers/readiness/serve-model?provider=${encodeURIComponent(id)}`,
+ { method: 'POST', ...options },
+);
// Provider status (usage limits, availability)
export const getProviderStatuses = () => request('/providers/status');
diff --git a/docs/API.md b/docs/API.md
index 8b4271f3ec..2df8fa4787 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -69,6 +69,7 @@ PortOS is designed for personal/developer use on trusted networks. It implements
| POST | `/providers/runtimes/install?runtime=<id>` | Install one runtime from the installer's fixed table, streaming installer output as SSE. Rejects any id not in the table. |
| GET | `/providers/readiness` | Requirements checklist per provider backed by a LOCAL daemon (llama.cpp / Ollama / LM Studio / MTPLX), keyed by provider id: is the daemon installed, is it answering at the endpoint THIS provider points at, and is it serving the provider's default model. Each entry also carries `setup` — what the one-click fix below can do about the unmet checks (`null` when nothing is auto-fixable here). Providers with no local dependency are absent from the map. Complements `/providers/runtimes` (which answers "can PortOS run this CLI?"). Booleans, labels, and the provider's own endpoint only — never a resolved binary path. Skips disabled providers; 15s endpoint-probe cache (one probe per distinct endpoint), 60s binary-PATH cache, both dropped by the llama-server start/stop/install routes. |
| POST | `/providers/readiness/setup?provider=<id>` | Install and/or start the LOCAL DAEMON that provider points at (llama.cpp / Ollama / LM Studio / MTPLX), streaming progress as SSE — the "do it for me" half of `/providers/readiness`, so an unmet requirement is fixed from the card instead of from a vendor setup doc. The request names a PROVIDER only: the runtime kind and endpoint are re-derived server-side from the stored record, so no query value reaches a spawn argument (an optional `runtime=` is cross-checked and 409s on a mismatch). Every command comes from a fixed per-runtime table. Never downloads model weights, never starts llama-server (it needs a checkpoint you choose), and never runs MTPLX's privileged fan-control helper. Single-flight. |
+| POST | `/providers/readiness/serve-model?provider=<id>` | Relaunch the local daemon so it answers under the model id THIS provider sends — the other half of the readiness model mismatch. `llama-server` serves one model per process under the `--alias` on its launch line, so the fix keeps the loaded weights and changes only the name; the whole launch line is carried forward and the previous one restored if the relaunch is rejected or never answers. The model id is re-derived server-side from the stored record. 400s for a runtime that has no such label (Ollama / LM Studio / MTPLX name a model after its weights), 409s when PortOS did not start the daemon. |
| GET | `/providers/opencode/installation` | **Legacy alias**, kept so a stale client bundle still renders: `{ installed, npmAvailable }` for the `opencode` runtime. New code uses `/providers/runtimes`. |
| POST | `/providers/opencode/install` | **Legacy alias** for `/providers/runtimes/install?runtime=opencode`. |
diff --git a/docs/features/dflash2.md b/docs/features/dflash2.md
index 7c9f64ddc4..2a2a8e9e50 100644
--- a/docs/features/dflash2.md
+++ b/docs/features/dflash2.md
@@ -214,6 +214,33 @@ Until all three pass, the card says what is missing and links to
**Models → LLMs**. The same failure previously surfaced only as
`Cannot connect to API: Unable to connect` inside the agent transcript.
+### "llama.cpp is serving `dflash`" — the model check is a NAME check
+
+`llama-server` serves **one model per process**, and the id it answers
+`GET /v1/models` with is whatever `--alias` was on its launch line — not the
+GGUF's filename. So the three aliases the provider ships with
+(`dflash`, `qwen3.8-27b-dflash2`, `Muse-Glimmer-30B-DFlash2`) are *names you may
+start the server under*, not three models sitting there ready to switch between.
+Pinning the provider to one the running server was not started under fails the
+model check even when the weights loaded are exactly the ones you wanted.
+
+Nothing is missing and nothing needs downloading. The checklist offers both
+fixes, and either is one click:
+
+- **Use `dflash` as default** — point the provider at the id the server answers
+ with.
+- **Serve as `qwen3.8-27b-dflash2`** — relaunch `llama-server` on the weights it
+ already has, under the id the provider sends
+ (`POST /api/providers/readiness/serve-model`). The whole launch line is
+ carried forward, tuning flags included; if the relaunch is rejected or never
+ answers, the previous line is put back so the provider is never left pointing
+ at a dead port.
+
+The second button only appears for `llama.cpp` — Ollama, LM Studio, and MTPLX
+name a model after the weights they loaded, so there is no label to change.
+It also refuses (naming the flag to add yourself) when `llama-server` was
+started outside PortOS: that process belongs to whoever ran it.
+
The GGUF weights are a separate download from the binary: `llama-server` will
not start without them, and PortOS refuses the start with the missing path named
rather than reporting a PID for a process that already exited. The Speculative
diff --git a/server/lib/localProviderRuntime.js b/server/lib/localProviderRuntime.js
index 26c4b702fe..92ec68d803 100644
--- a/server/lib/localProviderRuntime.js
+++ b/server/lib/localProviderRuntime.js
@@ -135,6 +135,18 @@ export const LOCAL_RUNTIMES = Object.freeze({
// weights are a separate download from the binary — the single most common
// reason a freshly-installed llama.cpp still cannot serve a request.
modelsHint: 'Pick a GGUF preset on that tab — PortOS downloads the weights and starts the server there.',
+ // One process, one model. Without this the readiness checklist read as
+ // "llama.cpp does not have the model you asked for" — which sent users off
+ // to download weights they already had.
+ servesOneModel: true,
+ // ...and the id it answers under is a LABEL on the launch line, not the
+ // GGUF's filename. That is the whole reason a provider can list three model
+ // names while the server accepts exactly one: the other two were never
+ // separate downloads, they were names nothing was ever started under. It
+ // also makes the mismatch a rename rather than a fetch, which is what lets
+ // `providerReadiness.js` offer to relaunch the same weights under the id the
+ // provider asks for.
+ aliasFlag: '--alias',
}),
ollama: Object.freeze({
id: 'ollama',
@@ -168,6 +180,9 @@ export const LOCAL_RUNTIMES = Object.freeze({
manageUrl: null,
docsUrl: 'https://github.com/atomantic/PortOS/blob/main/docs/features/qwen38-rtx3090.md',
modelsHint: 'Clone syv-ai/qwen38-27b-rtx3090 and run its prepare step once — PortOS never pulls the image or the ~20 GB of weights.',
+ // One container, one checkpoint — but its served id is baked into the
+ // compose project, so PortOS has no launch line of its own to rename.
+ servesOneModel: true,
}),
mtplx: Object.freeze({
id: 'mtplx',
@@ -181,6 +196,9 @@ export const LOCAL_RUNTIMES = Object.freeze({
manageUrl: null,
docsUrl: 'https://github.com/atomantic/PortOS/blob/main/docs/features/mtplx.md',
modelsHint: 'Point the server at the Qwen MTP checkpoint you want, or let the checklist fetch MTPLX\'s default one when nothing is cached.',
+ // One process, one checkpoint — MTPLX names it after the checkpoint it
+ // loaded, so there is no label for PortOS to change.
+ servesOneModel: true,
}),
});
diff --git a/server/routes/providers.js b/server/routes/providers.js
index cfe9189a04..99c290671b 100644
--- a/server/routes/providers.js
+++ b/server/routes/providers.js
@@ -15,7 +15,8 @@ import {
spawnRuntimeInstaller,
stopRuntimeInstaller,
} from '../services/providerRuntimeInstaller.js';
-import { getProviderReadinessMap, resetProviderReadinessCache } from '../services/providerReadiness.js';
+import { getProviderReadinessMap, resetProviderReadinessCache, servedModelId } from '../services/providerReadiness.js';
+import { relaunchLlamaServerWithAlias } from '../services/llamaServerManager.js';
import { getProviderPrerequisiteMap } from '../services/providerPrerequisites.js';
import { runLocalRuntimeSetup, SETUP_ACTIONS } from '../services/localRuntimeSetup.js';
import { localRuntimeForProvider } from '../lib/localProviderRuntime.js';
@@ -445,6 +446,57 @@ export function createPortOSProviderRoutes(aiToolkit) {
safeEnd();
}));
+ /**
+ * Relaunch the local daemon so it answers under the model id THIS provider
+ * sends — the other half of the readiness checklist's model mismatch.
+ *
+ * "Use `dflash` as default" already moved the provider onto whatever the
+ * server happens to answer as. This moves the server instead, which is what a
+ * user wants when they picked the model id deliberately: llama.cpp serves one
+ * model per process under the `--alias` on its launch line, so the mismatch is
+ * a label, not a missing download, and renaming it keeps the weights that are
+ * already loaded.
+ *
+ * Only runtimes that HAVE such a label (`aliasFlag`) qualify; the model id is
+ * re-derived server-side from the stored provider record, so nothing from the
+ * query reaches a launch argument.
+ */
+ router.post('/readiness/serve-model', asyncHandler(async (req, res) => {
+ const providerId = String(req.query.provider || '');
+ const data = await providerService.getAllProviders();
+ // RAW record — a sanitized copy redacts the secret env values a custom base
+ // URL can live in, which would resolve the wrong runtime.
+ const provider = (data.providers || []).find((row) => row.id === providerId);
+ if (!provider) {
+ throw new ServerError('Unknown provider', { status: 404, code: 'UNKNOWN_PROVIDER', context: { provider: providerId } });
+ }
+ const runtime = localRuntimeForProvider(provider);
+ if (!runtime?.aliasFlag) {
+ throw new ServerError(
+ 'This provider\'s runtime names its model after the weights it loaded, so PortOS cannot rename it — change the provider\'s default model instead.',
+ { status: 400, code: 'NO_MODEL_ALIAS' },
+ );
+ }
+ const wanted = servedModelId(provider, runtime.kind);
+ if (!wanted) {
+ throw new ServerError('This provider selects no specific model, so there is nothing to serve it as.', { status: 400, code: 'NO_DEFAULT_MODEL' });
+ }
+
+ const result = await relaunchLlamaServerWithAlias(wanted);
+ // The daemon's launch line just changed under the readiness caches, and the
+ // page polls them within seconds.
+ resetProviderReadinessCache();
+ if (result.applied === false) {
+ throw new ServerError(result.reason, { status: 409, code: 'SERVE_MODEL_FAILED', context: { model: wanted } });
+ }
+ res.json({
+ success: true,
+ model: wanted,
+ // `null` = it already answered under that id, so nothing was restarted.
+ relaunched: result.applied === true,
+ });
+ }));
+
// `runtime` rides in the query string because the shared RuntimeInstallModal
// already appends it there for every BYO-runtime installer.
router.post('/runtimes/install', asyncHandler(async (req, res) => {
diff --git a/server/services/llamaServerManager.js b/server/services/llamaServerManager.js
index 28db4f9936..74ce33bfa0 100644
--- a/server/services/llamaServerManager.js
+++ b/server/services/llamaServerManager.js
@@ -159,12 +159,9 @@ const endpointFor = (config) =>
* default.
*/
export async function getLlamaServerEndpoint() {
- if (!currentConfig) {
- const pm2Status = await getAppStatusStrict(LLAMA_APP);
- if (pm2Status?.status === 'online' && pm2Status.args) {
- currentConfig = parseConfigFromArgs(pm2Status.args);
- }
- }
+ // Reconstructs `currentConfig` from PM2's args as a side effect when PortOS
+ // restarted under a still-running daemon — see `readLlamaServerLaunch`.
+ if (!currentConfig) await readLlamaServerLaunch();
return endpointFor(currentConfig);
}
@@ -485,6 +482,133 @@ async function waitForEndpoint(endpoint) {
return false;
}
+/**
+ * Stop whatever is running and bring `next` up in its place, putting `previous`
+ * back when the new launch line is rejected or never answers.
+ *
+ * Shared by the two relaunch paths below — both are "same weights, one field
+ * changed", and this restore ceremony is the entire reason either of them is
+ * safe to offer from a button: this daemon fronts the `llama` provider for the
+ * whole install, so a relaunch that leaves it down breaks every later request,
+ * not just the one that was being tuned or renamed.
+ *
+ * @returns {Promise<{ok: boolean, rejected: string|null, config: object|null}>}
+ * `ok: false` with `rejected: null` means the process came up but never
+ * answered on its port.
+ */
+async function relaunchWithConfig(next, previous) {
+ // Both failure paths below land here: the port is free (or about to be), and
+ // the known-good launch line goes back on it. Resolves to `null` rather than
+ // throwing — a restore that fails is already the worst case, and replacing the
+ // caller's own reason with a second error would hide why the relaunch failed.
+ const restorePrevious = async () => {
+ await waitForPortRelease(previous.port ?? PORTS.LLAMA_SERVER);
+ const restored = await startLlamaServer(previous).catch((err) => {
+ console.error(`❌ llama-server: could not restore the previous configuration: ${err.message}`);
+ return null;
+ });
+ return restored?.config || null;
+ };
+
+ await stopLlamaServer();
+ await waitForPortRelease(next.port ?? PORTS.LLAMA_SERVER);
+
+ // A tuning sweep EXPECTS launch lines that don't work — `--flash-attn` on a
+ // build without it, a `--cache-type-k` this build lacks, a `-ub` past what the
+ // GPU can hold. llama-server exits immediately and `startLlamaServer` throws.
+ const started = await startLlamaServer(next).catch(async (err) => {
+ console.error(`❌ llama-server: relaunch failed (${err.message}) — restoring the previous configuration`);
+ return { failure: err.message, config: await restorePrevious() };
+ });
+ if (started.failure) return { ok: false, rejected: started.failure, config: started.config };
+
+ // PM2 reporting `online` is not the same as the server answering. But
+ // `startLlamaServer` only polls for four seconds, and a large GGUF routinely
+ // takes longer than that to load — so `online: false` is "not ready YET",
+ // not "wedged". Give it a real readiness budget before judging.
+ if (started.online || await waitForEndpoint(started.endpoint)) {
+ return { ok: true, rejected: null, config: started.config };
+ }
+
+ // Still silent. Treat it exactly like a rejected launch line: put the previous
+ // configuration back, so the install's llama provider is not left pointing at
+ // a process that never serves.
+ console.error('❌ llama-server: relaunched process never answered — restoring the previous configuration');
+ await stopLlamaServer().catch(() => {});
+ return { ok: false, rejected: null, config: await restorePrevious() };
+}
+
+/**
+ * The launch line PM2 is currently running llama-server on, without the log
+ * fetch and endpoint probe `getLlamaServerStatus` spends on a full status.
+ *
+ * `managed: false` covers both "nothing is running" and "something is listening
+ * that PortOS did not start" — neither is a launch line PortOS may change.
+ *
+ * @returns {Promise<{managed: boolean, config: object|null}>}
+ */
+export async function readLlamaServerLaunch() {
+ const pm2Status = await getAppStatusStrict(LLAMA_APP);
+ if (!pm2Status || pm2Status.status !== 'online') return { managed: false, config: null };
+ if (!currentConfig && pm2Status.args) currentConfig = parseConfigFromArgs(pm2Status.args);
+ return { managed: true, config: currentConfig };
+}
+
+/**
+ * Relaunch llama-server serving the SAME weights under a different model id.
+ *
+ * llama.cpp answers `GET /v1/models` with exactly one entry, and that entry is
+ * whatever `--alias` was on its launch line. So a provider pinned to
+ * `qwen3.8-27b-dflash2` against a server started as `dflash` fails every request
+ * even when the GGUF loaded IS Qwen3.8-27B + DFlash 2 — the ids simply never
+ * matched. Nothing is missing and nothing needs downloading; the fix is a label.
+ *
+ * Refuses (never throws) when PortOS did not start the process: an
+ * externally-launched llama-server belongs to whoever ran it, and stopping it to
+ * change a name PortOS invented would kill a server the user owns.
+ *
+ * @param {string} alias the model id the provider will send
+ * @returns {Promise<{applied: boolean|null, reason: string|null, config: object|null}>}
+ * `applied: null` means the daemon already answers under that id.
+ */
+export async function relaunchLlamaServerWithAlias(alias) {
+ const wanted = String(alias ?? '').trim();
+ if (!wanted) return { applied: false, reason: 'No model id was given to serve under.', config: null };
+
+ const { managed, config } = await readLlamaServerLaunch();
+ if (!managed || !config?.model) {
+ return {
+ applied: false,
+ reason: `llama-server is not running under PortOS, so its launch line is not PortOS's to change. Start it from Models → LLMs, or add \`--alias ${wanted}\` to your own launch line.`,
+ config: null,
+ };
+ }
+ if (config.alias === wanted) return { applied: null, reason: null, config };
+
+ // A rename carries the whole launch line forward, tuning flags included, so
+ // the baseline PortOS displaced when it tuned this daemon is still the line to
+ // put back later. `startLlamaServer` clears it on every fresh launch, so it is
+ // captured here and re-armed on success.
+ const baseline = preTuningConfig;
+ console.log(`🦙 llama-server: relaunching to answer as ${wanted} (was ${config.alias || 'unset'})`);
+ const outcome = await relaunchWithConfig({ ...config, alias: wanted }, config);
+ // Every outcome leaves the same weights and the same tuning flags on the port
+ // — the renamed line on success, the original one on either failure — so the
+ // displaced baseline is still the line to put back later, whichever it was.
+ preTuningConfig = baseline;
+ if (outcome.rejected) {
+ return { applied: false, reason: `llama-server rejected the relaunch: ${outcome.rejected}`, config: outcome.config };
+ }
+ if (!outcome.ok) {
+ return {
+ applied: false,
+ reason: 'llama-server relaunched but never answered on its port — the previous model id is back.',
+ config: outcome.config,
+ };
+ }
+ return { applied: true, reason: null, config: outcome.config };
+}
+
/**
* Relaunch llama-server with a different tuning, keeping the model/drafter it is
* already serving.
@@ -687,59 +811,27 @@ export async function relaunchLlamaServerWithTuning(tuning = {}, { reset = false
console.log(clearing
? '🦙 llama-server: relaunching without the tuning PortOS applied'
: `🦙 llama-server: relaunching to apply tuning (${knobs.length ? knobs.map(([k, v]) => `${k}=${v}`).join(', ') : 'backend defaults'})`);
- await stopLlamaServer();
- await waitForPortRelease(next.port ?? PORTS.LLAMA_SERVER);
-
- // A tuning sweep EXPECTS launch lines that don't work — `--flash-attn` on a
- // build without it, a `--cache-type-k` this build lacks, a `-ub` past what the
- // GPU can hold. llama-server exits immediately and `startLlamaServer` throws.
- // Leaving it down would be far worse than not applying the tuning: this daemon
- // fronts the `llama` provider for the whole install, so every later request
- // would fail too. Put the previous configuration back before reporting.
- const started = await startLlamaServer(next).catch(async (err) => {
- console.error(`❌ llama-server: tuning launch failed (${err.message}) — restoring the previous configuration`);
- await waitForPortRelease(previous.port ?? PORTS.LLAMA_SERVER);
- const restored = await startLlamaServer(previous).catch((restoreErr) => {
- console.error(`❌ llama-server: could not restore the previous configuration: ${restoreErr.message}`);
- return null;
- });
- return { failure: err.message, config: restored?.config || null };
- });
- if (started.failure) {
+ const outcome = await relaunchWithConfig(next, previous);
+ if (outcome.rejected) {
// `previous` is back on the port, so whatever tuning it carried is still in
// effect and still needs undoing later.
preTuningConfig = baseline;
return {
applied: false,
reason: clearing
- ? `llama-server rejected its pre-tuning launch line: ${started.failure}`
- : `llama-server rejected that tuning: ${started.failure}`,
- config: started.config,
+ ? `llama-server rejected its pre-tuning launch line: ${outcome.rejected}`
+ : `llama-server rejected that tuning: ${outcome.rejected}`,
+ config: outcome.config,
};
}
-
- // PM2 reporting `online` is not the same as the server answering. But
- // `startLlamaServer` only polls for four seconds, and a large GGUF routinely
- // takes longer than that to load — so `online: false` is "not ready YET",
- // not "wedged". Give it a real readiness budget before judging.
- const ready = started.online || await waitForEndpoint(started.endpoint);
- if (!ready) {
- // Still silent. Treat it exactly like a rejected launch line: put the
- // previous configuration back, so the install's llama provider is not left
- // pointing at a process that never serves. Without this the caller would go
- // on to measure a dead endpoint and record the timeouts as evidence.
- console.error('❌ llama-server: relaunched process never answered — restoring the previous configuration');
- await stopLlamaServer().catch(() => {});
- await waitForPortRelease(previous.port ?? PORTS.LLAMA_SERVER);
- const restored = await startLlamaServer(previous).catch((err) => {
- console.error(`❌ llama-server: could not restore the previous configuration: ${err.message}`);
- return null;
- });
+ if (!outcome.ok) {
+ // The relaunched process never answered. `previous` is back, so the caller
+ // measures a live endpoint rather than recording timeouts as evidence.
preTuningConfig = baseline;
return {
applied: false,
reason: 'llama-server relaunched but never answered on its port',
- config: restored?.config || null,
+ config: outcome.config,
};
}
// The daemon now serves `next`. Clearing leaves it untuned, so there is
@@ -748,7 +840,7 @@ export async function relaunchLlamaServerWithTuning(tuning = {}, { reset = false
preTuningConfig = clearing ? null : (baseline || previous);
// `null`, not `true`, for a clear: there was no tuning to apply, and the
// reading that follows describes backend defaults truthfully.
- return { applied: clearing ? null : true, reason: null, config: started.config };
+ return { applied: clearing ? null : true, reason: null, config: outcome.config };
}
/**
diff --git a/server/services/llamaServerManager.test.js b/server/services/llamaServerManager.test.js
index 068fe2bb3b..37e39cbc30 100644
--- a/server/services/llamaServerManager.test.js
+++ b/server/services/llamaServerManager.test.js
@@ -4,6 +4,7 @@ import {
startLlamaServer,
stopLlamaServer,
relaunchLlamaServerWithTuning,
+ relaunchLlamaServerWithAlias,
captureLlamaServerConfig,
restoreLlamaServerConfig,
installLlamaServer,
@@ -474,6 +475,67 @@ describe('llamaServerManager', () => {
// The sweep half of measured assessments: put new flags on the launch line
// between runs. Every failure mode here has to leave the daemon USABLE — it
// fronts the `llama` provider for the whole install.
+ describe('relaunchLlamaServerWithAlias', () => {
+ const startedAs = async (alias) => {
+ vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue('/usr/local/bin/llama-server');
+ vi.spyOn(openAiModelsProbe, 'probeOpenAiModels')
+ .mockImplementation(async () => ({ reachable: pm2State?.status === 'online' }));
+ await startLlamaServer({ model: modelPath, port: PORTS.LLAMA_SERVER, alias });
+ };
+ const lastStartArgs = () => {
+ const start = [...execPm2Calls].reverse().find((c) => c[0] === 'start') || [];
+ const dash = start.indexOf('--');
+ return dash === -1 ? [] : start.slice(dash + 1);
+ };
+
+ // The mismatch this whole feature exists for: llama.cpp answers under the
+ // `--alias` its launch line set, so pointing the daemon at the id the
+ // provider sends is a rename of the weights already loaded.
+ it('relaunches the SAME weights under the requested id', async () => {
+ await startedAs('dflash');
+ execPm2Calls = [];
+
+ const result = await relaunchLlamaServerWithAlias('qwen3.8-27b-dflash2');
+
+ expect(result.applied).toBe(true);
+ expect(result.reason).toBeNull();
+ const args = lastStartArgs();
+ expect(args[args.indexOf('--alias') + 1]).toBe('qwen3.8-27b-dflash2');
+ // The weights never move — that is what makes this cheap.
+ expect(args[args.indexOf('-m') + 1]).toBe(modelPath);
+ });
+
+ // `null`, not `true`: nothing was restarted, and a toast claiming a restart
+ // would have the user waiting for a reload that never happened.
+ it('does not bounce a daemon that already answers under that id', async () => {
+ await startedAs('dflash');
+ execPm2Calls = [];
+
+ const result = await relaunchLlamaServerWithAlias('dflash');
+
+ expect(result.applied).toBeNull();
+ expect(execPm2Calls.some((c) => c[0] === 'start' || c[0] === 'delete')).toBe(false);
+ });
+
+ // An externally-launched llama-server belongs to whoever ran it. Refuse with
+ // the flag they can add themselves rather than killing their process.
+ it('refuses — and names the flag — when PortOS did not start the daemon', async () => {
+ vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue('/usr/local/bin/llama-server');
+ const result = await relaunchLlamaServerWithAlias('qwen3.8-27b-dflash2');
+ expect(result.applied).toBe(false);
+ expect(result.reason).toMatch(/--alias qwen3\.8-27b-dflash2/);
+ expect(execPm2Calls.some((c) => c[0] === 'start' || c[0] === 'delete')).toBe(false);
+ });
+
+ it('refuses a blank model id without touching the daemon', async () => {
+ await startedAs('dflash');
+ execPm2Calls = [];
+ const result = await relaunchLlamaServerWithAlias(' ');
+ expect(result.applied).toBe(false);
+ expect(execPm2Calls).toEqual([]);
+ });
+ });
+
describe('relaunchLlamaServerWithTuning', () => {
// The default harness pins the endpoint unreachable so lifecycle tests don't
// collide with a developer's real llama-server. These tests need a FAITHFUL
diff --git a/server/services/providerReadiness.js b/server/services/providerReadiness.js
index e387c6e6e1..078d1b7f52 100644
--- a/server/services/providerReadiness.js
+++ b/server/services/providerReadiness.js
@@ -169,7 +169,7 @@ function findCommandCached(command) {
* OpenCode provider entry and never reaches the daemon's own model list.
* Returns null when the provider selects no specific model.
*/
-function servedModelId(provider, kind) {
+export function servedModelId(provider, kind) {
const model = provider?.defaultModel;
if (typeof model !== 'string' || model.trim() === '' || isConfiguredDefaultModel(model)) return null;
const trimmed = model.trim();
@@ -275,14 +275,29 @@ function modelCheck(runtime, wanted, served, probeError = null, { weights = 'unk
return { id: 'model', label, ok: true, detail: `${runtime.label} is serving \`${wanted}\`.`, fixHint: null };
}
const listed = served.slice(0, 3).map((id) => `\`${id}\``).join(', ');
+ // WHY only one id is listed, in the same line that lists it. A daemon that
+ // serves one model per process is not "missing" the others — nothing was ever
+ // started under those names — and without saying so the checklist reads as a
+ // missing multi-gigabyte download, which is the wrong fix and an expensive one
+ // to chase.
+ const oneModel = runtime.servesOneModel
+ ? ` ${runtime.label} serves one model per process${runtime.aliasFlag ? `, answering under the id its \`${runtime.aliasFlag}\` set rather than the weights' own name` : ''}.`
+ : '';
const detail = served.length === 0
? `${runtime.label} is running but has no model loaded.`
- : `${runtime.label} is serving ${listed}${served.length > 3 ? ` +${served.length - 3} more` : ''}.`;
+ : `${runtime.label} is serving ${listed}${served.length > 3 ? ` +${served.length - 3} more` : ''}.${oneModel}`;
+ // A runtime whose served id is a launch-line LABEL can be renamed onto the
+ // weights it is already running — no download, no model swap. That makes the
+ // mismatch fixable from EITHER end, so the hint names both rather than
+ // implying the provider is the only thing that may move.
+ const renameTo = served.length > 0 && runtime.aliasFlag ? wanted : null;
const fixHint = served.length === 0
? (runtime.manageUrl
? 'No model is loaded. Start a preset from Models → LLMs.'
: 'No model is loaded. Use the setup controls on this card to load one.')
- : `This provider will send \`${wanted}\`, but the running server only accepts ${listed}. Use the button below to match them${runtime.manageUrl ? ', or change the loaded weights on the Models → LLMs page' : ''}.`;
+ : renameTo
+ ? `Same server, two names for it — nothing needs downloading. Use the button below to point this provider at ${listed}, or “Serve as \`${wanted}\`” to relaunch ${runtime.label} on the weights it already has under that id.`
+ : `This provider will send \`${wanted}\`, but the running server only accepts ${listed}. Use the button below to match them${runtime.manageUrl ? ', or change the loaded weights on the Models → LLMs page' : ''}.`;
return {
id: 'model',
label,
@@ -290,6 +305,9 @@ function modelCheck(runtime, wanted, served, probeError = null, { weights = 'unk
detail,
fixHint,
servedModels: served,
+ // The id a one-click relaunch would put on the launch line, or null when
+ // this runtime has no label of its own to change.
+ renameTo,
};
}
diff --git a/server/services/providerReadiness.test.js b/server/services/providerReadiness.test.js
index e0eb66d1c2..ada438eaef 100644
--- a/server/services/providerReadiness.test.js
+++ b/server/services/providerReadiness.test.js
@@ -114,6 +114,45 @@ describe('getProviderReadiness', () => {
expect(readiness.docsUrl).toBeUndefined();
});
+ // The confusion this prose exists for: the provider lists three model names,
+ // the server accepts one, and the checklist read as "llama.cpp does not have
+ // the model you installed" — sending the user after a download they already
+ // had. llama.cpp serves ONE model per process, under the `--alias` its launch
+ // line set, so the other two names were never separate weights.
+ it('explains that a one-model-per-process runtime names its model with a launch flag', async () => {
+ const readiness = await getProviderReadiness(llamaProvider({ defaultModel: 'qwen3.8-27b-dflash2' }), {
+ findCommand: () => '/opt/homebrew/bin/llama-server',
+ probe: reachable(['dflash']),
+ });
+ const model = checkById(readiness, 'model');
+ expect(model.detail).toMatch(/serves one model per process/);
+ expect(model.detail).toMatch(/--alias/);
+ // Both directions are offered: move the provider, or move the server.
+ expect(model.renameTo).toBe('qwen3.8-27b-dflash2');
+ expect(model.fixHint).toMatch(/nothing needs downloading/);
+ expect(model.fixHint).toMatch(/Serve as/);
+ });
+
+ // A runtime whose served id comes from the weights it loaded has no label for
+ // PortOS to change — offering a rename button there would be a dead end.
+ it('offers no rename for a runtime that names its model after the weights', async () => {
+ const readiness = await getProviderReadiness(
+ {
+ id: 'ollama',
+ name: 'Ollama',
+ type: 'api',
+ endpoint: 'http://127.0.0.1:11434/v1',
+ defaultModel: 'qwen3:8b',
+ },
+ { findCommand: () => '/opt/homebrew/bin/ollama', probe: reachable(['llama3:8b']) },
+ );
+ const model = checkById(readiness, 'model');
+ expect(model.ok).toBe(false);
+ expect(model.renameTo).toBeNull();
+ expect(model.detail).not.toMatch(/serves one model per process/);
+ expect(model.fixHint).toMatch(/only accepts/);
+ });
+
it('calls out a running server with nothing loaded', async () => {
const readiness = await getProviderReadiness(llamaProvider(), {
findCommand: () => '/opt/homebrew/bin/llama-server',