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

fix(local-llm): auto-replace Ollama.app on 412, prominent upgrade banner

[._.]/ Adam Eivydac25feb0973
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 588d7760c2..2fb97395a9 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -11,7 +11,7 @@ TBD
- **Unified Story Builder** (`/story-builder`): a new guided page that walks a story from idea → universe aesthetic → plot arc → reader map → characters → issues → production as one linear flow. Each step is LLM-assisted with an AI-refinement affordance and ends with an explicit lock before the next unlocks; going back to revise an earlier step soft-flags the downstream locked steps as "stale" (integrity gate) so nothing silently drifts — without destroying their content. The builder is a thin conductor over the existing Universe / Series / Issue records (no data duplication); heavy per-issue production hands off to the existing Pipeline issue page. Reachable from the sidebar (Create → Story Builder), ⌘K, and voice. The intro screen supports two intake modes: **start from a seed idea**, or **import a finished work** (comic script / screenplay / novel / short story) — the importer reverse-engineers it into a universe, arc, characters, and issues, then drops you into the wizard to review and lock each stage. An **AI provider/model picker** at the top of the builder (and the import tab) drives every operation — idea expand, aesthetic, arc, reader map, character refine, and the import analysis — persisted on the session so one selection applies throughout. The **characters step generates a styled preview image per character** (world style fused with the character descriptor, via the same render path as the Universe Builder) and shows it alongside each character so you can eyeball that the world and character styles read correctly together.
- **Base style image (style probe)** on a universe: generate a canonical image from the raw style guide alone — style notes + the embrace/avoid influences as the positive/negative prompt, with no character or subject — to preview the world's base visual emphasis. Triggerable from both the Universe Builder (under the style/influences editor) and the Story Builder's Universe Aesthetic step; the result persists on the universe (`styleImageRefs`) so both surfaces share it.
- **Reader Map** on a series arc (`series.arc.readerMap`): a distinct audience-experience roadmap — hooks, payoffs, emotional beats, and cliffhangers across the arc — built on top of the Vonnegut story shape, separate from the protagonist arc. Generated and refined via the new Story Builder reader-map step (also preserved by arc regeneration).
-- Local LLMs: when an Ollama model pull fails with `412: requires a newer version of Ollama`, PortOS now offers an inline "Upgrade Ollama & Retry" prompt instead of surfacing the raw error. It detects how Ollama was installed and picks the right upgrade path — Homebrew formula, Homebrew cask (`ollama-app`), or the official self-updating `.app` (in which case the UI tells you exactly how to update from the app's menu bar instead of running `brew` against a package it doesn't own and reporting a useless `exited with code 1`). For Homebrew installs it restarts the Ollama service after upgrade so the new binary is actually serving requests, then automatically retries the original model download. Failed `brew` runs now surface the actual stderr (e.g. `Error: ollama not installed`) instead of just an exit code.
+- Local LLMs: when an Ollama model pull fails with `412: requires a newer version of Ollama`, PortOS now auto-upgrades Ollama in place and retries the install — no confirm click. On macOS with `/Applications/Ollama.app` present, this downloads the latest `Ollama-darwin.zip` directly from GitHub releases, force-kills the running Ollama, replaces the `.app` bundle, strips quarantine, relaunches, and polls `/api/version` until the new binary is serving. (The old brew-only path silently left the old binary running, because `/usr/local/bin/ollama` symlinks into the `.app` bundle — even a successful `brew upgrade` doesn't change which binary is on disk inside the `.app`.) On Linux it still re-runs the official Ollama install script; for headless macOS installs (brew formula only, no `.app`), it still runs `brew upgrade ollama`. The UI now shows a prominent yellow warning banner with live step-by-step progress for the whole upgrade flow, instead of a quiet inline confirm row. Failed `brew` runs now also surface the actual stderr (e.g. `Error: ollama not installed`) instead of just an exit code.
## Changed
diff --git a/client/src/components/settings/LocalLlmTab.jsx b/client/src/components/settings/LocalLlmTab.jsx
index 4cb8d29d7d..46c0866943 100644
--- a/client/src/components/settings/LocalLlmTab.jsx
+++ b/client/src/components/settings/LocalLlmTab.jsx
@@ -1,5 +1,5 @@
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
-import { Cpu, Box, ArrowRightLeft, Download, Trash2, RefreshCw, Search, Plus, ExternalLink, Star, Link2, Copy, Play, Square, Power, PowerOff, Eye, Wrench, Brain, Code2, MessageSquare, Boxes } from 'lucide-react';
+import { Cpu, Box, ArrowRightLeft, Download, Trash2, RefreshCw, Search, Plus, ExternalLink, Star, Link2, Copy, Play, Square, Power, PowerOff, Eye, Wrench, Brain, Code2, MessageSquare, Boxes, AlertTriangle } from 'lucide-react';
import toast from '../ui/Toast';
import BrailleSpinner from '../BrailleSpinner';
import { formatBytes, timeAgo } from '../../utils/formatters';
@@ -361,10 +361,15 @@ export function LocalLlmTab() {
.filter((group) => group.models.length > 0);
}, [activeCategory, catalog, catalogCategories, catalogSource]);
+ // Active auto-upgrade flow (Ollama outdated → 412 on pull). Stays set while we
+ // download / install / relaunch so the warning banner can show live status.
+ // `{ modelId, phase: 'upgrading' | 'retrying' | 'failed', error? }`.
+ const [upgradeFlow, setUpgradeFlow] = useState(null);
+
// LM Studio's REST fallback returns { pending: true } — the download was only
// queued, not finished — so don't claim "installed" in that case. Install is
- // silent so an OLLAMA_OUTDATED failure replaces the default toast with an
- // inline confirm row offering to auto-upgrade Ollama and retry.
+ // silent so an OLLAMA_OUTDATED failure can take over the UI with the upgrade
+ // banner instead of stacking a useless toast with the auto-upgrade flow.
const install = (modelId) => runAction(
`install-${modelId}`,
() => installLocalLlmModel(selected, modelId, { silent: true }),
@@ -372,12 +377,10 @@ export function LocalLlmTab() {
{
onError: (err) => {
if (err?.code === 'OLLAMA_OUTDATED' && selected === 'ollama') {
- setConfirmAction({
- type: 'upgrade-ollama',
- modelId,
- label: 'Ollama is out of date for this model.',
- detail: `${modelId} needs a newer Ollama than the one installed. PortOS can upgrade Ollama in place (Homebrew on macOS, the official Ollama installer on Linux), restart the service, and retry the download.`
- });
+ // Don't wait for a click — just upgrade. The user already said "install
+ // this model"; needing a newer Ollama to do it is an implementation
+ // detail, not a separate decision.
+ upgradeOllamaAndRetry(modelId);
} else {
// Any other failure: restore the default toast we suppressed.
toast.error(err?.message || 'Install failed');
@@ -388,17 +391,30 @@ export function LocalLlmTab() {
);
const remove = (modelId) => runAction(`delete-${modelId}`, () => deleteLocalLlmModel(selected, modelId), `${modelId} deleted`);
+ // Upgrade Ollama in place (direct .app download on macOS; brew elsewhere) and
+ // retry the original model install once Ollama is back online. `upgradeFlow`
+ // drives the prominent warning banner so the user sees what's happening; the
+ // socket-driven `progressMsg` provides per-step detail inside the same banner.
const upgradeOllamaAndRetry = (modelId) => {
setConfirmAction(null);
- // runAction resolves with the server result on success and undefined when
- // its internal catch consumed the error — gate the retry on a truthy
- // result so a failed upgrade doesn't loop straight back into the same 412.
+ setUpgradeFlow({ modelId, phase: 'upgrading' });
runAction(
'upgrade-ollama',
() => upgradeLocalLlmBackend('ollama'),
(r) => r?.note ? `Ollama upgraded — ${r.note}` : 'Ollama upgraded'
).then((r) => {
- if (r?.success && modelId) install(modelId);
+ if (r?.success && modelId) {
+ setUpgradeFlow({ modelId, phase: 'retrying' });
+ install(modelId);
+ // install() either succeeds (its own success toast + status reload covers
+ // it) or re-enters the OLLAMA_OUTDATED branch above and resets the flow.
+ // Clear after a beat so the banner doesn't linger past the retry kickoff.
+ setTimeout(() => setUpgradeFlow((cur) => (cur?.phase === 'retrying' ? null : cur)), 1500);
+ } else if (!r?.success) {
+ setUpgradeFlow({ modelId, phase: 'failed', error: r?.error });
+ }
+ }).catch((err) => {
+ setUpgradeFlow({ modelId, phase: 'failed', error: err?.message });
});
};
@@ -430,7 +446,40 @@ export function LocalLlmTab() {
))}
</div>
- {progressMsg && (
+ {upgradeFlow && (
+ <div className="bg-port-warning/10 border-2 border-port-warning/60 rounded-lg p-4 space-y-2" role="alert">
+ <div className="flex items-start gap-3">
+ <AlertTriangle size={20} className="text-port-warning mt-0.5 shrink-0" />
+ <div className="flex-1 min-w-0 space-y-1">
+ <p className="text-sm font-semibold text-port-warning">
+ {upgradeFlow.phase === 'failed' ? 'Ollama upgrade failed' : 'Upgrading Ollama'}
+ </p>
+ <p className="text-xs text-gray-300">
+ {upgradeFlow.phase === 'upgrading' && `${upgradeFlow.modelId} needs a newer Ollama than the one installed. Downloading the latest Ollama and replacing the installed app — this can take a minute.`}
+ {upgradeFlow.phase === 'retrying' && `Ollama is up to date — retrying the ${upgradeFlow.modelId} download now.`}
+ {upgradeFlow.phase === 'failed' && (upgradeFlow.error || 'See the server logs for details.')}
+ </p>
+ {progressMsg && upgradeFlow.phase !== 'failed' && (
+ <p className="text-xs text-port-warning/90 flex items-center gap-2 pt-1">
+ <BrailleSpinner /> {progressMsg}
+ </p>
+ )}
+ {upgradeFlow.phase === 'failed' && (
+ <p className="text-xs text-gray-400 pt-1">
+ You can also upgrade manually from <a href="https://ollama.com/download" target="_blank" rel="noopener noreferrer" className="text-port-accent hover:underline inline-flex items-center gap-1">ollama.com/download <ExternalLink size={10} /></a>.
+ </p>
+ )}
+ </div>
+ {upgradeFlow.phase === 'failed' && (
+ <button onClick={() => setUpgradeFlow(null)} className="text-xs text-gray-400 hover:text-white transition-colors" aria-label="Dismiss">
+ Dismiss
+ </button>
+ )}
+ </div>
+ </div>
+ )}
+
+ {progressMsg && !upgradeFlow && (
<div className="flex items-center gap-2 text-sm text-port-accent bg-port-accent/10 border border-port-accent/20 rounded-lg px-3 py-2">
<BrailleSpinner />
{progressMsg}
@@ -442,38 +491,24 @@ export function LocalLlmTab() {
<p className="text-sm text-white">{confirmAction.label}</p>
{confirmAction.detail && <p className="text-xs text-gray-400">{confirmAction.detail}</p>}
<div className="flex items-center gap-2 flex-wrap">
- {confirmAction.type === 'upgrade-ollama' ? (
- <button
- onClick={() => upgradeOllamaAndRetry(confirmAction.modelId)}
- disabled={busy}
- className="flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors disabled:opacity-50 bg-port-accent/20 hover:bg-port-accent/30 text-port-accent"
- title="Run brew upgrade ollama (macOS) or the official Ollama install script (Linux), then retry the model download"
- >
- {actionInProgress === 'upgrade-ollama' ? <BrailleSpinner /> : <Download size={14} />}
- Upgrade Ollama & Retry
- </button>
- ) : (
- <>
- <button
- onClick={() => runAction(`migrate-${confirmAction.to}-link`, () => migrateLocalLlmBackend(confirmAction.to, 'link'), summarizeMigrate)}
- disabled={busy}
- className="flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors disabled:opacity-50 bg-port-accent/20 hover:bg-port-accent/30 text-port-accent"
- title="Hardlink each GGUF so both backends share one file on disk (no extra space; falls back to a copy across filesystems)"
- >
- {actionInProgress === `migrate-${confirmAction.to}-link` ? <BrailleSpinner /> : <Link2 size={14} />}
- Link (share disk)
- </button>
- <button
- onClick={() => runAction(`migrate-${confirmAction.to}-copy`, () => migrateLocalLlmBackend(confirmAction.to, 'copy'), summarizeMigrate)}
- disabled={busy}
- className="flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors disabled:opacity-50 bg-port-border hover:bg-port-border/70 text-white"
- title="Make an independent duplicate on the target (uses extra disk; survives deleting the source backend's copy)"
- >
- {actionInProgress === `migrate-${confirmAction.to}-copy` ? <BrailleSpinner /> : <Copy size={14} />}
- Copy (independent)
- </button>
- </>
- )}
+ <button
+ onClick={() => runAction(`migrate-${confirmAction.to}-link`, () => migrateLocalLlmBackend(confirmAction.to, 'link'), summarizeMigrate)}
+ disabled={busy}
+ className="flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors disabled:opacity-50 bg-port-accent/20 hover:bg-port-accent/30 text-port-accent"
+ title="Hardlink each GGUF so both backends share one file on disk (no extra space; falls back to a copy across filesystems)"
+ >
+ {actionInProgress === `migrate-${confirmAction.to}-link` ? <BrailleSpinner /> : <Link2 size={14} />}
+ Link (share disk)
+ </button>
+ <button
+ onClick={() => runAction(`migrate-${confirmAction.to}-copy`, () => migrateLocalLlmBackend(confirmAction.to, 'copy'), summarizeMigrate)}
+ disabled={busy}
+ className="flex items-center gap-2 px-3 py-1.5 text-sm font-medium rounded-lg transition-colors disabled:opacity-50 bg-port-border hover:bg-port-border/70 text-white"
+ title="Make an independent duplicate on the target (uses extra disk; survives deleting the source backend's copy)"
+ >
+ {actionInProgress === `migrate-${confirmAction.to}-copy` ? <BrailleSpinner /> : <Copy size={14} />}
+ Copy (independent)
+ </button>
<button onClick={() => setConfirmAction(null)} className="px-3 py-1.5 text-sm text-gray-400 hover:text-white transition-colors">
Cancel
</button>
diff --git a/server/services/localLlm.js b/server/services/localLlm.js
index eec9d4a614..692a325991 100644
--- a/server/services/localLlm.js
+++ b/server/services/localLlm.js
@@ -22,9 +22,12 @@
import { execFile, spawn } from 'child_process'
import { promisify } from 'util'
-import { readFileSync, writeFileSync } from 'fs'
-import { stat } from 'fs/promises'
+import { readFileSync, writeFileSync, createWriteStream } from 'fs'
+import { stat, mkdir, rm } from 'fs/promises'
import { join } from 'path'
+import { tmpdir } from 'os'
+import { pipeline } from 'stream/promises'
+import { Readable } from 'stream'
import { PATHS } from '../lib/fileUtils.js'
import { isBackend, mapModelToBackend } from '../lib/localLlmCatalog.js'
import { sanitizeOllamaName } from '../lib/localLlmDisk.js'
@@ -308,22 +311,144 @@ export async function installBackend(backend, onProgress = () => {}) {
}
}
+/**
+ * Pre-upgrade Ollama version (best-effort — returns null if Ollama isn't running
+ * or isn't responding). Used to verify an upgrade actually moved the version.
+ */
+async function readOllamaVersion() {
+ const status = await ollamaManager.getStatus(true).catch(() => null)
+ return status?.version || null
+}
+
+/**
+ * Poll Ollama's /api/version until it responds (after a (re)start). Returns the
+ * version string when reachable, null on timeout.
+ */
+async function waitForOllamaVersion(timeoutMs = 30_000) {
+ const deadline = Date.now() + timeoutMs
+ while (Date.now() < deadline) {
+ const v = await readOllamaVersion()
+ if (v) return v
+ await new Promise((resolve) => setTimeout(resolve, 500))
+ }
+ return null
+}
+
+/**
+ * Download + install the latest Ollama macOS .app in place. This is the only
+ * reliable path on macOS — `brew upgrade ollama` either has a behind-by-weeks
+ * formula, OR the running server is the .app binary (because `/usr/local/bin/
+ * ollama` symlinks into the bundle) so even a successful brew upgrade leaves
+ * the wrong binary serving. Pulls the latest `Ollama-darwin.zip` from the
+ * official GitHub releases, replaces `/Applications/Ollama.app` on disk, strips
+ * quarantine, and relaunches.
+ *
+ * The .app keeps its own user prefs / model store (`~/.ollama`) so this is
+ * non-destructive; only the bundle itself gets swapped.
+ */
+async function upgradeOllamaMacApp(emit) {
+ const appPath = '/Applications/Ollama.app'
+
+ emit('Looking up the latest Ollama release on GitHub…')
+ const release = await fetch('https://api.github.com/repos/ollama/ollama/releases/latest', {
+ headers: { 'User-Agent': 'PortOS', Accept: 'application/vnd.github+json' }
+ }).then((r) => (r.ok ? r.json() : null)).catch(() => null)
+ if (!release) return { success: false, error: 'Could not reach GitHub to look up the latest Ollama release.' }
+
+ const asset = (release.assets || []).find((a) => a.name === 'Ollama-darwin.zip')
+ if (!asset?.browser_download_url) {
+ return { success: false, error: `Latest Ollama release ${release.tag_name} has no Ollama-darwin.zip asset — try downloading from ${DOWNLOAD_URL.ollama}.` }
+ }
+
+ const before = await readOllamaVersion()
+ const tagClean = String(release.tag_name || '').replace(/^v/, '')
+ if (before && tagClean && before === tagClean) {
+ return { success: true, backend: 'ollama', note: `Ollama is already at ${before} (latest).`, alreadyLatest: true }
+ }
+
+ const tmpDir = join(tmpdir(), `portos-ollama-upgrade-${Date.now()}`)
+ const zipPath = join(tmpDir, 'Ollama-darwin.zip')
+ await mkdir(tmpDir, { recursive: true })
+
+ emit(`Downloading Ollama ${release.tag_name} (${Math.round(asset.size / 1024 / 1024)} MB)…`)
+ const dl = await fetch(asset.browser_download_url).catch((err) => ({ _err: err.message }))
+ if (dl._err || !dl?.ok || !dl.body) {
+ await rm(tmpDir, { recursive: true, force: true }).catch(() => {})
+ return { success: false, error: `Download failed: ${dl?._err || dl?.statusText || 'no response body'}` }
+ }
+ await pipeline(Readable.fromWeb(dl.body), createWriteStream(zipPath))
+ .catch(async (err) => {
+ await rm(tmpDir, { recursive: true, force: true }).catch(() => {})
+ throw err
+ })
+
+ emit('Stopping running Ollama…')
+ await ollamaManager.stopServer().catch(() => null)
+ // Force-kill stragglers — the menu-bar .app launches `ollama serve` as a child
+ // that doesn't always exit cleanly via the service stop above.
+ await runStreaming('pkill', ['-x', 'Ollama'], () => {}, 10_000).catch(() => null)
+ await runStreaming('pkill', ['-x', 'ollama'], () => {}, 10_000).catch(() => null)
+ // Brief settle so the OS releases the bundle before we replace it.
+ await new Promise((resolve) => setTimeout(resolve, 1500))
+
+ emit('Extracting…')
+ const unzip = await runStreaming('unzip', ['-q', '-o', zipPath, '-d', tmpDir], emit, 5 * 60 * 1000)
+ if (!unzip.success) {
+ await rm(tmpDir, { recursive: true, force: true }).catch(() => {})
+ return { success: false, error: `Extract failed: ${unzip.error}` }
+ }
+ const extractedApp = join(tmpDir, 'Ollama.app')
+ if (!(await pathExists(extractedApp))) {
+ await rm(tmpDir, { recursive: true, force: true }).catch(() => {})
+ return { success: false, error: 'Extracted archive did not contain Ollama.app — release layout may have changed.' }
+ }
+
+ emit('Installing /Applications/Ollama.app…')
+ // rm the old bundle first — `mv` can't merge with an existing directory on macOS.
+ await rm(appPath, { recursive: true, force: true }).catch(() => {})
+ const move = await runStreaming('mv', [extractedApp, appPath], emit, 60_000)
+ if (!move.success) {
+ await rm(tmpDir, { recursive: true, force: true }).catch(() => {})
+ return { success: false, error: `Could not install ${appPath}: ${move.error}. PortOS may not have permission to write to /Applications — try running the official installer manually.` }
+ }
+ // Strip quarantine so Gatekeeper doesn't refuse to launch the freshly-downloaded bundle.
+ await runStreaming('xattr', ['-dr', 'com.apple.quarantine', appPath], () => {}, 30_000).catch(() => null)
+ await rm(tmpDir, { recursive: true, force: true }).catch(() => {})
+
+ emit('Starting Ollama…')
+ const launch = await runStreaming('open', ['-g', '-a', appPath], () => {}, 30_000)
+ if (!launch.success) {
+ return {
+ success: true,
+ backend: 'ollama',
+ note: `Upgraded to ${release.tag_name}, but couldn't auto-launch Ollama (${launch.error}). Open Ollama.app manually.`
+ }
+ }
+ const after = await waitForOllamaVersion(30_000)
+ if (!after) {
+ return {
+ success: true,
+ backend: 'ollama',
+ note: `Upgraded to ${release.tag_name}, but Ollama did not come back online within 30s. Open Ollama.app if it isn't already running.`
+ }
+ }
+ console.log(`⬆️ Upgraded Ollama: ${before || 'unknown'} → ${after} (${release.tag_name})`)
+ return { success: true, backend: 'ollama', note: `Ollama ${before ? `${before} → ` : ''}${after}. The new binary is now serving requests.` }
+}
+
/**
* Upgrade an already-installed backend in place. Used when a model pull returns
- * Ollama's 412 "requires a newer version of Ollama" error — instead of telling
- * the user to download a new binary, we run the same package manager that put
- * it there. The right path depends on how the install actually got there:
+ * Ollama's 412 "requires a newer version of Ollama" error.
*
- * • brew formula (`ollama`) → `brew upgrade ollama`
- * • brew cask (`ollama-app`, `lm-studio`) → `brew upgrade --cask <name>`
- * • direct .app download → the app's own auto-updater handles it; we can't
- * drive it from here, so we report a `manualUpdateRequired` result with
- * instructions instead of running brew against a package it doesn't own
- * (which exits 1 with "Error: ollama not installed").
- * • Linux Ollama → re-run the official install script (idempotent upgrade).
+ * macOS Ollama is special: even when Homebrew has a recent enough formula, the
+ * .app binary is what `ollama serve` actually runs (via the symlink at
+ * `/usr/local/bin/ollama` → `/Applications/Ollama.app/Contents/Resources/ollama`),
+ * so a brew-only upgrade leaves the OLD binary serving. So we prefer a direct
+ * download + .app replacement on macOS whenever the .app is present. Other paths:
*
- * The route layer turns `manualUpdateRequired` into a 502 with the same error
- * shape, so the existing UI confirm row keeps working.
+ * • macOS LM Studio cask → `brew upgrade --cask lm-studio`
+ * • macOS Ollama brew formula (no .app) → `brew upgrade ollama`
+ * • Linux Ollama → re-run the official install script (idempotent upgrade)
*
* @param {string} backend - 'ollama' | 'lmstudio'
* @param {(p: { event: string, message: string }) => void} [onProgress]
@@ -334,8 +459,7 @@ export async function upgradeBackend(backend, onProgress = () => {}) {
const label = backend === 'ollama' ? 'Ollama' : 'LM Studio'
const downloadHint = `Download the latest version from ${DOWNLOAD_URL[backend]}.`
- // Linux Ollama: the official install script is also the upgrade path
- // (idempotent — it replaces the binary in place).
+ // Linux Ollama: the official install script is also the upgrade path.
if (process.platform === 'linux' && backend === 'ollama') {
emit('Upgrading Ollama via the official install script…')
const r = await runStreaming('bash', ['-c', 'curl -fsSL https://ollama.com/install.sh | sh'], emit, BACKEND_INSTALL_TIMEOUT_MS)
@@ -351,29 +475,25 @@ export async function upgradeBackend(backend, onProgress = () => {}) {
return { success: false, error: `Automatic upgrade isn't supported on this platform. ${downloadHint}` }
}
- // macOS: pick the upgrade path based on how this install actually landed.
- const source = await detectInstallSource(backend)
+ // macOS Ollama with a .app present — direct download is the only path that
+ // actually replaces the binary that's serving requests.
+ if (backend === 'ollama' && await pathExists(macAppPath('ollama'))) {
+ return upgradeOllamaMacApp(emit)
+ }
+ // Everything else: route through Homebrew.
+ const source = await detectInstallSource(backend)
if (source.source === 'mac-app') {
- // The .app has its own updater; brew doesn't know about it. Tell the user
- // exactly what to do — vague "try downloading" is what we're trying to fix.
- const note = backend === 'ollama'
- ? 'Open Ollama from the menu bar → "Check for updates", or quit and download the latest .dmg.'
- : 'Open LM Studio → Settings → "Check for updates", or download the latest .dmg.'
- console.warn(`⚠️ ${label} was installed from the official .app — Homebrew can't upgrade it; user must update the app.`)
+ // LM Studio .app — Sparkle handles updates; brew doesn't know about it.
return {
success: false,
manualUpdateRequired: true,
- error: `${label} was installed from the official .app, which has its own updater — PortOS can't drive it from here. ${note} ${downloadHint}`
+ error: `LM Studio was installed from the official .app, which has its own updater — PortOS can't drive it from here. Open LM Studio → Settings → "Check for updates", or ${downloadHint.toLowerCase()}`
}
}
-
if (source.source === 'unknown') {
- // No brew install AND no .app — likely a hand-placed binary; we have
- // nothing safe to run automatically.
return { success: false, error: `Couldn't identify how ${label} was installed. ${downloadHint}` }
}
-
if (!(await commandExists('brew', ['--version']))) {
return { success: false, error: `Homebrew not found — install it from https://brew.sh first, or ${downloadHint.toLowerCase()}` }
}
@@ -385,9 +505,6 @@ export async function upgradeBackend(backend, onProgress = () => {}) {
}
console.log(`🍺 Upgraded ${label} via Homebrew (${source.source})`)
if (backend === 'ollama') {
- // Restart the service so the new binary is actually running — `brew upgrade`
- // doesn't bounce running services. Best-effort; report it in `note` either
- // way so the user knows whether to restart Ollama themselves.
const stop = await ollamaManager.stopPersistentService().catch((err) => ({ success: false, error: err.message }))
const restart = await ollamaManager.startPersistentService().catch((err) => ({ success: false, error: err.message }))
const note = restart.success