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: treat noisy non-zero brew install exit as success when package is on disk

Ilya Eivy61ea37d83b21
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index e6ed45eb0b..7b6b72d34f 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -22,6 +22,7 @@
- **[issue-1539] Recommended models that pull from Ollama's own registry by bare name now get the RAM-aware quant picker too.** Previously only Hugging Face-backed recommended cards offered a **Quant** menu; cards for Ollama registry models (Llama 3.2, Qwen2.5, GPT-OSS, Llama 3.3, …) showed a single hard-coded build. PortOS now discovers each of those models' available quantizations from the Ollama registry and presents them in the same picker, with per-quant fit hints and the highest-fidelity build that fits your memory selected by default — so every recommended card adapts to your hardware, regardless of which registry the model comes from. When a model can't be reached on the registry, its card keeps its single curated build as before.
- **Hugging Face search results now rank by downloads and recency more strongly.** A model's download count and how recently it was updated now dominate the result ordering (recency is graduated — a model updated this week outranks an equivalent one from months or years ago, and stale models are demoted), so popular, actively-maintained models surface first instead of being outweighed by publisher/format bonuses.
- **[issue-1488] Pinning a small-context local model to a heavy analysis stage no longer overflows its window.** The reverse-outline, continuity-bible, comic-script verification, alternate-POV rewrite, and per-issue editorial-analysis stages used to size the manuscript they send to a fixed 48–60K-character floor regardless of the model — fine on a big-context provider, but on a genuinely small-window local model (e.g. an 8K-context model) that floor plus the prompt could exceed the window. These stages now scale the manuscript to the model's actual window, trimming it to fit a small one (never down to empty — a usable minimum is always kept) while still feeding the whole manuscript to a large-context model exactly as before.
+- **Installing Ollama (or LM Studio) via Homebrew no longer reports a false "install failed."** `brew install` routinely exits non-zero *after* a successful pour — a failed `brew cleanup`, a dependency's post-install caveats, or env-hint noise (notably Ollama's new `mlx`/`mlx-c` dependencies) all bubble up as exit 1 even though the formula/cask is fully installed on disk. PortOS treated that exit code as a hard failure and told you the install didn't work, when in fact it did. The install path now verifies presence-on-disk via `brew list` after a non-zero exit and treats the package being installed as the source of truth — so a successful-but-noisy Homebrew install is reported as success and proceeds to start the backend, instead of surfacing a misleading error. (`server/services/localLlm.js`)
## Comic pages
diff --git a/server/services/localLlm.js b/server/services/localLlm.js
index df8fb13fb6..191bd99ee8 100644
--- a/server/services/localLlm.js
+++ b/server/services/localLlm.js
@@ -195,6 +195,18 @@ async function commandExists(cmd, args) {
return execFileAsync(cmd, args, { timeout: 5_000 }).then(() => true).catch(() => false)
}
+// Whether Homebrew already has the backend's formula/cask installed. Used to
+// recover from a non-zero `brew install` exit that nonetheless left the package
+// on disk (post-install cleanup/hint failures exit 1 after a successful pour).
+// `brew list` exits 0 only when the package is present, so its success IS the
+// presence check — no output parsing needed.
+async function brewPackageInstalled(backend) {
+ const args = backend === 'ollama'
+ ? ['list', '--versions', 'ollama']
+ : ['list', '--cask', '--versions', 'lm-studio']
+ return commandExists('brew', args)
+}
+
const manager = (backend) => (backend === 'ollama' ? ollamaManager : lmStudioManager)
/**
@@ -294,8 +306,21 @@ export async function installBackend(backend, onProgress = () => {}) {
const args = backend === 'ollama' ? ['install', 'ollama'] : ['install', '--cask', 'lm-studio']
emit(`Installing ${label} via Homebrew (this can take a few minutes)…`)
const r = await runStreaming('brew', args, emit, BACKEND_INSTALL_TIMEOUT_MS)
- if (!r.success) return { success: false, error: `Homebrew install failed: ${r.error}` }
- console.log(`🍺 Installed ${label} via Homebrew`)
+ if (!r.success) {
+ // `brew install` routinely exits non-zero AFTER a successful pour — a
+ // failed `brew cleanup`, a dependency's post-install hint, or env-hint
+ // noise (e.g. Ollama's new mlx/mlx-c deps) all bubble up as exit 1 even
+ // though the formula/cask is fully installed. Treat presence-on-disk as
+ // the source of truth: if `brew list` now sees it, the install worked.
+ if (await brewPackageInstalled(backend)) {
+ console.log(`🍺 ${label} already present after non-zero brew exit — treating as installed (${r.error})`)
+ emit(`${label} is installed (Homebrew reported a non-fatal warning).`)
+ } else {
+ return { success: false, error: `Homebrew install failed: ${r.error}` }
+ }
+ } else {
+ console.log(`🍺 Installed ${label} via Homebrew`)
+ }
if (backend === 'ollama') {
emit('Starting Ollama as a Homebrew service…')
const service = await ollamaManager.startPersistentService().catch((err) => ({ success: false, error: err.message }))
diff --git a/server/services/localLlm.test.js b/server/services/localLlm.test.js
index 151731fd49..b960174888 100644
--- a/server/services/localLlm.test.js
+++ b/server/services/localLlm.test.js
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import os from 'os';
import path from 'path';
import fs from 'fs';
+import { EventEmitter } from 'events';
// vi.mock factories are hoisted above the module body, so the mutable holder
// and the mock objects must come from vi.hoisted (which runs first). The
@@ -52,11 +53,49 @@ vi.mock('./ollamaManager.js', () => mocks.ollama);
vi.mock('./lmStudioManager.js', () => mocks.lmstudio);
vi.mock('./providers.js', () => mocks.providers);
+// child_process is mocked so the install/upgrade paths (spawn-based streaming +
+// execFile-based presence checks) are drivable. Defaults are benign for the rest
+// of the suite: spawn closes clean, execFile rejects (→ commandExists() false).
+const cp = vi.hoisted(() => ({
+ defaults: {
+ spawn: () => {
+ const child = new EventEmitter();
+ child.stdout = new EventEmitter();
+ child.stderr = new EventEmitter();
+ child.kill = () => {};
+ setImmediate(() => child.emit('close', 0));
+ return child;
+ },
+ execFile: (_cmd, _args, _opts, cb) => cb(new Error('ENOENT')),
+ },
+ spawn: null,
+ execFile: null,
+}));
+vi.mock('child_process', () => ({
+ spawn: (...a) => cp.spawn(...a),
+ execFile: (cmd, args, opts, cb) => cp.execFile(cmd, args, opts, cb),
+}));
+
+// Build a fake `brew` child that streams `lines`, then closes with `code`.
+const fakeChild = ({ code = 0, lines = [] } = {}) => {
+ const child = new EventEmitter();
+ child.stdout = new EventEmitter();
+ child.stderr = new EventEmitter();
+ child.kill = () => {};
+ setImmediate(() => {
+ for (const l of lines) child.stdout.emit('data', Buffer.from(`${l}\n`));
+ child.emit('close', code);
+ });
+ return child;
+};
+
const writeEnv = (content) => fs.writeFileSync(path.join(state.root, '.env'), content);
let svc;
beforeEach(async () => {
vi.clearAllMocks(); // clears calls, keeps the default impls defined above
+ cp.spawn = cp.defaults.spawn; // reset child_process drivers to benign defaults
+ cp.execFile = cp.defaults.execFile;
delete process.env.LLM_BACKEND;
state.root = fs.mkdtempSync(path.join(os.tmpdir(), 'portos-llm-svc-'));
vi.resetModules();
@@ -301,6 +340,40 @@ describe('localLlm', () => {
Object.defineProperty(process, 'platform', orig);
}
});
+
+ it('treats a non-zero `brew install` exit as success when the package is actually on disk', async () => {
+ // Repro of the real Ollama install failure: `brew install ollama` poured
+ // the formula but exited 1 (mlx dep + cleanup/env-hint noise), so PortOS
+ // wrongly reported failure for a successful install.
+ const orig = Object.getOwnPropertyDescriptor(process, 'platform');
+ Object.defineProperty(process, 'platform', { value: 'darwin', configurable: true });
+ cp.spawn = () => fakeChild({ code: 1, lines: ['Pouring ollama…', '🍺 ollama installed', 'brew cleanup hint'] });
+ // `brew --version` (gate) and `brew list --versions ollama` (presence) succeed.
+ cp.execFile = (_cmd, _args, _opts, cb) => cb(null, { stdout: 'ollama 0.30.10', stderr: '' });
+ try {
+ const r = await svc.installBackend('ollama');
+ expect(r.success).toBe(true);
+ expect(r.backend).toBe('ollama');
+ } finally {
+ Object.defineProperty(process, 'platform', orig);
+ }
+ });
+
+ it('still reports failure when `brew install` exits non-zero AND the package is absent', async () => {
+ const orig = Object.getOwnPropertyDescriptor(process, 'platform');
+ Object.defineProperty(process, 'platform', { value: 'darwin', configurable: true });
+ cp.spawn = () => fakeChild({ code: 1, lines: ['Error: download failed'] });
+ // brew --version succeeds (gate passes); brew list rejects (not installed).
+ cp.execFile = (_cmd, args, _opts, cb) =>
+ args.includes('--version') ? cb(null, { stdout: 'Homebrew 4', stderr: '' }) : cb(new Error('not installed'));
+ try {
+ const r = await svc.installBackend('ollama');
+ expect(r.success).toBe(false);
+ expect(r.error).toMatch(/Homebrew install failed/);
+ } finally {
+ Object.defineProperty(process, 'platform', orig);
+ }
+ });
});
describe('listVisionModels', () => {