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

address review (local): drop unused binaryPath field and guard the install exit listener

Adam Eivy9967d18c7601
diff --git a/server/services/llamaServerManager.js b/server/services/llamaServerManager.js
index 85d888e788..b833cf17b6 100644
--- a/server/services/llamaServerManager.js
+++ b/server/services/llamaServerManager.js
@@ -300,25 +300,32 @@ export async function installLlamaServer({ onProgress = () => {} } = {}) {
child.on('error', (err) => {
reject(new ServerError(`Failed to run brew: ${err.message}`, { status: 500 }));
});
+ // Async listener on a child-process event: it runs outside the Express
+ // lifecycle AND outside this Promise executor's own throw path, so an
+ // unguarded throw here would surface as an unhandled rejection while the
+ // install request hung forever. Route every failure to `reject`.
child.on('exit', async (code) => {
- let binaryPath = resolveLlamaServerBinary();
- let linkOutput = '';
-
- // `brew install` exits 0 without linking when the keg is already
- // installed but unlinked ("Warning: llama.cpp X is already installed,
- // it's just not linked."). Link it explicitly rather than leaving that
- // warning as a dead end for the caller.
- if (!binaryPath && code === 0) {
- onProgress({ event: 'progress', message: 'llama.cpp keg is installed but not linked — linking…' });
- const { linked, output } = await linkLlamaCpp(env);
- linkOutput = output;
- if (linked) binaryPath = resolveLlamaServerBinary();
- }
+ try {
+ let binaryPath = resolveLlamaServerBinary();
+ let linkOutput = '';
+
+ // `brew install` exits 0 without linking when the keg is already
+ // installed but unlinked ("Warning: llama.cpp X is already installed,
+ // it's just not linked."). Link it explicitly rather than leaving that
+ // warning as a dead end for the caller.
+ if (!binaryPath && code === 0) {
+ onProgress({ event: 'progress', message: 'llama.cpp keg is installed but not linked — linking…' });
+ const { linked, output } = await linkLlamaCpp(env);
+ linkOutput = output;
+ if (linked) binaryPath = resolveLlamaServerBinary();
+ }
+
+ if (binaryPath) {
+ onProgress({ event: 'complete', message: `llama.cpp installed successfully (${binaryPath})` });
+ resolve({ success: true, message: 'llama.cpp installed successfully' });
+ return;
+ }
- if (binaryPath) {
- onProgress({ event: 'complete', message: `llama.cpp installed successfully (${binaryPath})` });
- resolve({ success: true, message: 'llama.cpp installed successfully', binaryPath });
- } else {
// A `brew link` conflict can list every clashing file, so cap what
// rides along into the error message.
const hint = linkOutput
@@ -328,6 +335,8 @@ export async function installLlamaServer({ onProgress = () => {} } = {}) {
? `brew completed but llama-server was not found on PATH — ${hint}`
: `brew install llama.cpp failed (exit code ${code})`;
reject(new ServerError(msg, { status: 500 }));
+ } catch (err) {
+ reject(new ServerError(`Failed to verify the llama.cpp install: ${err.message}`, { status: 500 }));
}
});
});
diff --git a/server/services/llamaServerManager.test.js b/server/services/llamaServerManager.test.js
index 0a8085748e..58793fe968 100644
--- a/server/services/llamaServerManager.test.js
+++ b/server/services/llamaServerManager.test.js
@@ -198,6 +198,23 @@ describe('llamaServerManager', () => {
await expect(installLlamaServer()).rejects.toThrow(/Could not symlink bin\/llama-server/);
});
+ it('rejects instead of hanging when the link spawn throws synchronously', async () => {
+ // The exit listener is async and lives inside a Promise executor, so an
+ // unguarded throw would escape as an unhandled rejection while the install
+ // request never settled.
+ vi.spyOn(commandExistsModule, 'commandExists').mockImplementation(async (cmd) => cmd === 'brew');
+ vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue(null);
+
+ vi.spyOn(childProcess, 'spawn').mockImplementation((cmd, args) => {
+ if (args[0] === 'link') throw new Error('spawn EACCES');
+ const child = fakeSpawnProcess();
+ setTimeout(() => child.emit('exit', 0), 10);
+ return child;
+ });
+
+ await expect(installLlamaServer()).rejects.toThrow(/Failed to verify the llama\.cpp install: spawn EACCES/);
+ });
+
it('rejects with a `brew link` hint when linking does not resolve the binary', async () => {
vi.spyOn(commandExistsModule, 'commandExists').mockImplementation(async (cmd) => cmd === 'brew');
vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue(null);