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

resolve llama.cpp's endpoint without paying for a status probe

Adam Eivya40cdf4c9733
diff --git a/server/services/llamaServerManager.js b/server/services/llamaServerManager.js
index c270d94e6f..77daa0880d 100644
--- a/server/services/llamaServerManager.js
+++ b/server/services/llamaServerManager.js
@@ -121,6 +121,35 @@ function parseConfigFromArgs(args) {
};
}
+// The endpoint the current (or last-known) configuration serves on. Split out so
+// the two callers below can't drift on how host/port are defaulted.
+const endpointFor = (config) =>
+ `http://${config?.host || '127.0.0.1'}:${config?.port ?? PORTS.LLAMA_SERVER}/v1`;
+
+/**
+ * Just the base URL llama-server is serving on — no endpoint probe, no PM2 log
+ * fetch.
+ *
+ * `getLlamaServerStatus` answers a much bigger question and pays for it with a
+ * network probe AND an `execPm2 logs` subprocess. A caller that only needs
+ * "which port is it on?" (the assessments read path, which runs on every
+ * Performance page load) must not spawn a process to find out and then discard
+ * the logs it paid for.
+ *
+ * Reads the same recovered-config path as the status call, so a PortOS restart
+ * that left the PM2 process online still resolves the real port rather than the
+ * default.
+ */
+export async function getLlamaServerEndpoint() {
+ if (!currentConfig) {
+ const pm2Status = await getAppStatusStrict(LLAMA_APP);
+ if (pm2Status?.status === 'online' && pm2Status.args) {
+ currentConfig = parseConfigFromArgs(pm2Status.args);
+ }
+ }
+ return endpointFor(currentConfig);
+}
+
/**
* Returns current status of llama-server (binary availability, running state, config, logs).
*/
@@ -138,7 +167,7 @@ export async function getLlamaServerStatus() {
const host = currentConfig?.host || '127.0.0.1';
const port = currentConfig?.port ?? PORTS.LLAMA_SERVER;
- const endpoint = `http://${host}:${port}/v1`;
+ const endpoint = endpointFor(currentConfig);
const reachable = await probeEndpoint(endpoint);
diff --git a/server/services/localModelAssessments.js b/server/services/localModelAssessments.js
index 92de2bcf3b..960505a486 100644
--- a/server/services/localModelAssessments.js
+++ b/server/services/localModelAssessments.js
@@ -74,7 +74,7 @@ import {
} from '../lib/localModelTuning.js';
import { probeOpenAiModels } from '../lib/openAiModelsProbe.js';
import { runEndpointLlmTest, runLocalLlmTest } from './localLlmPlayground.js';
-import { getLlamaServerStatus, relaunchLlamaServerWithTuning } from './llamaServerManager.js';
+import { getLlamaServerEndpoint, relaunchLlamaServerWithTuning } from './llamaServerManager.js';
import { listModels } from './localLlm.js';
import {
getLoadedModels as getLoadedOllamaModels,
@@ -147,8 +147,11 @@ export function buildSamplePrompt(contextTokens) {
*/
export async function runtimeEndpoint(runtime) {
if (runtime === 'llama') {
- const status = await getLlamaServerStatus().catch(() => null);
- if (status?.endpoint) return status.endpoint;
+ // The endpoint-only accessor, NOT `getLlamaServerStatus` — that one pays for
+ // a network probe and an `execPm2 logs` subprocess, and this path runs on
+ // every Performance page load only to learn a port number.
+ const endpoint = await getLlamaServerEndpoint().catch(() => null);
+ if (endpoint) return endpoint;
}
return LOCAL_RUNTIMES[runtime]?.defaultBaseUrl || null;
}
diff --git a/server/services/localModelAssessments.test.js b/server/services/localModelAssessments.test.js
index 9c75d22c02..5511e256a7 100644
--- a/server/services/localModelAssessments.test.js
+++ b/server/services/localModelAssessments.test.js
@@ -31,10 +31,10 @@ vi.mock('./localLlmPlayground.js', () => ({
const probeOpenAiModels = vi.fn();
vi.mock('../lib/openAiModelsProbe.js', () => ({ probeOpenAiModels: (...args) => probeOpenAiModels(...args) }));
-const getLlamaServerStatus = vi.fn();
+const getLlamaServerEndpoint = vi.fn();
const relaunchLlamaServerWithTuning = vi.fn();
vi.mock('./llamaServerManager.js', () => ({
- getLlamaServerStatus: (...args) => getLlamaServerStatus(...args),
+ getLlamaServerEndpoint: (...args) => getLlamaServerEndpoint(...args),
relaunchLlamaServerWithTuning: (...args) => relaunchLlamaServerWithTuning(...args),
}));
@@ -81,7 +81,7 @@ beforeEach(() => {
getLmStudioListError.mockReset().mockReturnValue(null);
runEndpointLlmTest.mockReset();
probeOpenAiModels.mockReset().mockResolvedValue({ reachable: true, models: [], error: null });
- getLlamaServerStatus.mockReset().mockResolvedValue({ running: true, managed: true, endpoint: 'http://127.0.0.1:5568/v1', config: { model: '/models/base.gguf' } });
+ getLlamaServerEndpoint.mockReset().mockResolvedValue('http://127.0.0.1:5568/v1');
relaunchLlamaServerWithTuning.mockReset().mockResolvedValue({ applied: true, reason: null, config: null });
});
@@ -565,15 +565,23 @@ describe('endpoint runtimes', () => {
});
it('reads llama.cpp\'s endpoint from the running server, not from the default port', async () => {
- getLlamaServerStatus.mockResolvedValue({ endpoint: 'http://127.0.0.1:9999/v1' });
+ getLlamaServerEndpoint.mockResolvedValue('http://127.0.0.1:9999/v1');
expect(await svc.runtimeEndpoint('llama')).toBe('http://127.0.0.1:9999/v1');
});
- it('falls back to the canonical base URL when llama-server status is unavailable', async () => {
- getLlamaServerStatus.mockRejectedValue(new Error('pm2 is not installed'));
+ it('falls back to the canonical base URL when llama-server cannot be reached', async () => {
+ getLlamaServerEndpoint.mockRejectedValue(new Error('pm2 is not installed'));
expect(await svc.runtimeEndpoint('llama')).toMatch(/^http:\/\/127\.0\.0\.1:\d+\/v1$/);
});
+ // The read path runs on every Performance page load. `getLlamaServerStatus`
+ // costs a network probe plus an `execPm2 logs` subprocess whose output this
+ // caller would throw away.
+ it('resolves the endpoint without paying for a status probe', async () => {
+ await svc.getAssessmentReport();
+ expect(getLlamaServerEndpoint).toHaveBeenCalled();
+ });
+
it('measures an endpoint runtime directly instead of through the provider path', async () => {
probeOpenAiModels.mockResolvedValue({ reachable: true, models: ['dflash'], error: null });
runEndpointLlmTest.mockResolvedValue(okRun());