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 (agy): stop the Start button sending React's click event

Adam Eivye860f4f67a71
diff --git a/client/src/components/settings/RuntimeServersCard.jsx b/client/src/components/settings/RuntimeServersCard.jsx
index bab055c92a..a7d5432727 100644
--- a/client/src/components/settings/RuntimeServersCard.jsx
+++ b/client/src/components/settings/RuntimeServersCard.jsx
@@ -88,6 +88,12 @@ function pm2Row({ id, label, icon, status, platformReason, onStart, onStop, onIn
};
}
+/**
+ * Every action is invoked as `row.onX()`, never bound straight to `onClick` —
+ * React would hand the handler its SyntheticEvent as the first argument, and a
+ * handler that takes a launch config (MTPLX's start) would serialize the event
+ * into the request body instead of the config.
+ */
function ServerRow({ row, busy, actionInProgress, children }) {
const Icon = row.icon;
const meta = STATE_META[row.state] || STATE_META.missing;
@@ -116,7 +122,7 @@ function ServerRow({ row, busy, actionInProgress, children }) {
{children}
{row.onInstall && (
<button
- onClick={row.onInstall}
+ onClick={() => row.onInstall()}
disabled={busy}
className={accentBtn}
title={`Install ${row.label} on this machine`}
@@ -139,7 +145,7 @@ function ServerRow({ row, busy, actionInProgress, children }) {
)}
{row.onStart && (
<button
- onClick={row.onStart}
+ onClick={() => row.onStart()}
disabled={busy}
className={neutralBtn}
title={`Start the local ${row.label} server`}
@@ -153,7 +159,7 @@ function ServerRow({ row, busy, actionInProgress, children }) {
)}
{row.onStop && (
<button
- onClick={row.onStop}
+ onClick={() => row.onStop()}
disabled={busy}
className={neutralBtn}
title={`Stop the local ${row.label} server`}
diff --git a/client/src/components/settings/RuntimeServersCard.test.jsx b/client/src/components/settings/RuntimeServersCard.test.jsx
index 1da623a788..d768c2f549 100644
--- a/client/src/components/settings/RuntimeServersCard.test.jsx
+++ b/client/src/components/settings/RuntimeServersCard.test.jsx
@@ -25,7 +25,7 @@ const renderCard = (props = {}) => {
render(
<MemoryRouter>
<RuntimeServersCard
- status={{ ollama: {}, lmstudio: {} }}
+ status={{ ollama: { canAutoInstall: true }, lmstudio: {} }}
llamaStatus={null}
mtplxStatus={null}
loading={false}
@@ -91,6 +91,21 @@ describe('RuntimeServersCard', () => {
expect(handlers.onStartMtplx).toHaveBeenCalled();
});
+ it('invokes a row action with NO arguments — never React\'s click event', () => {
+ // MTPLX's start handler takes a launch config and the client JSON.stringify's
+ // it into the request body. Binding it straight to `onClick` handed it the
+ // SyntheticEvent instead, which throws on its circular DOM refs.
+ const handlers = renderCard({
+ mtplxStatus: { installed: true, running: false, supported: true, cachedModels: ['Example/Qwen-MTP'] },
+ });
+ const mtplx = row('MTPLX');
+ fireEvent.click(within(mtplx).getByRole('button', { name: /^Start/ }));
+ expect(handlers.onStartMtplx).toHaveBeenCalledWith();
+
+ fireEvent.click(within(row('Ollama')).getByRole('button', { name: /Install/ }));
+ expect(handlers.onInstallBackend).toHaveBeenCalledWith('ollama');
+ });
+
it('blocks the MTPLX Start with the pull command when its cache is empty', () => {
// PortOS never downloads MTPLX weights, and `mtplx serve` exits before it
// binds on an empty cache — so offering Start would only produce a failure.
diff --git a/server/lib/mediaValidation.js b/server/lib/mediaValidation.js
index 1b9d38af60..5a09dbcea1 100644
--- a/server/lib/mediaValidation.js
+++ b/server/lib/mediaValidation.js
@@ -173,7 +173,8 @@ export const localLlmLmStudioServiceSchema = z.object({ action: z.enum(['start',
// point at. `model` is a Hugging Face repo id, which lands in the launch argv.
export const localLlmMtplxStartSchema = z.object({
port: z.coerce.number().int().min(1).max(65535).optional(),
- host: z.string().trim().max(100).optional(),
+ // No `host`: MTPLX is a loopback daemon and the manager never puts one on the
+ // launch line, so accepting one would only record an endpoint it isn't bound to.
model: z.string().trim().max(200).regex(
/^$|^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/,
'model must be a Hugging Face repo id',
diff --git a/server/services/localRuntimeSetup.js b/server/services/localRuntimeSetup.js
index 59fee24693..81abfe014e 100644
--- a/server/services/localRuntimeSetup.js
+++ b/server/services/localRuntimeSetup.js
@@ -177,7 +177,8 @@ const SETUP_ROWS = Object.freeze({
}
if (cache.state === 'empty') return { success: false, error: MTPLX_NO_MODEL_ERROR };
if (cache.state === 'partial') return { success: false, error: mtplxPartialCacheError(cache.count) };
- if (cache.model) emit(`Serving the cached MTPLX model ${cache.model}.`);
+ // The manager emits "Serving the cached MTPLX model …" once it has the
+ // checkpoint, so don't announce it here too — both go to the same modal.
// The cache lookup is an awaited subprocess — the modal can close while it
// runs, and the caller's cancellation check happened BEFORE it. Without
// this, a cancelled setup still starts a server nobody asked to keep.
diff --git a/server/services/localRuntimeSetup.test.js b/server/services/localRuntimeSetup.test.js
index 119b2c0a12..792df7b27a 100644
--- a/server/services/localRuntimeSetup.test.js
+++ b/server/services/localRuntimeSetup.test.js
@@ -451,6 +451,28 @@ describe('runLocalRuntimeSetup', () => {
expect(result).toMatchObject({ success: false, error: expect.stringContaining('connection reset') });
});
+ it('announces the cached checkpoint once, not once per layer', async () => {
+ // The manager emits this line itself once it has the checkpoint, and both
+ // layers stream into the SAME setup modal.
+ pathLookup.findCommandOnPath.mockReturnValue('/opt/homebrew/bin/mtplx');
+ probe.probeOpenAiModels
+ .mockResolvedValueOnce(unreachable)
+ .mockResolvedValueOnce(unreachable)
+ .mockResolvedValueOnce(reachable(['mtplx']));
+ // Stand in for the real manager's own emit, so the count covers both layers.
+ mtplx.startMtplxServer.mockImplementation(async ({ model, onProgress }) => {
+ if (model) onProgress(`Serving the cached MTPLX model ${model}.`);
+ return { success: true, endpoint: 'http://127.0.0.1:8000/v1' };
+ });
+ const lines = [];
+ const restore = pinPlatform('darwin');
+
+ await runLocalRuntimeSetup('mtplx', { endpoint: 'http://127.0.0.1:8000/v1', emit: (l) => lines.push(l) });
+ restore();
+
+ expect(lines.filter((l) => /Serving the cached MTPLX model/.test(l))).toHaveLength(1);
+ });
+
it('exposes every action the route may accept', () => {
expect([...SETUP_ACTIONS].sort()).toEqual(['install', 'install-start', 'pull-start', 'start']);
});
diff --git a/server/services/mtplxServerManager.js b/server/services/mtplxServerManager.js
index e88adcadd3..ad34425c55 100644
--- a/server/services/mtplxServerManager.js
+++ b/server/services/mtplxServerManager.js
@@ -81,7 +81,7 @@ const probeEndpoint = async (endpoint) =>
(await probeOpenAiModels(endpoint, { timeoutMs: PROBE_TIMEOUT_MS })).reachable;
const endpointFor = (config) =>
- `http://${config?.host || DEFAULT_HOST}:${config?.port ?? DEFAULT_PORT}/v1`;
+ `http://${DEFAULT_HOST}:${config?.port ?? DEFAULT_PORT}/v1`;
/**
* Reconstructs the launch config from PM2 process args when PortOS restarted
@@ -94,7 +94,6 @@ function parseConfigFromArgs(args) {
if (!list.includes('serve')) return null;
const port = pm2ArgValue(list, '--port');
return {
- host: pm2ArgValue(list, '--host') || DEFAULT_HOST,
port: port ? Number(port) : DEFAULT_PORT,
// Absent means MTPLX was started on its OWN default checkpoint — don't
// invent a repo id the launch line never carried.
@@ -156,7 +155,7 @@ export async function getMtplxServerStatus() {
running: isManagedActive || reachable,
managed: isReadFailed ? null : isManagedActive,
pid: isManagedActive ? (pm2Status?.pid || null) : null,
- host: currentConfig?.host || DEFAULT_HOST,
+ host: DEFAULT_HOST,
port: currentConfig?.port ?? DEFAULT_PORT,
endpoint,
config: isManagedActive ? currentConfig : null,
@@ -231,10 +230,15 @@ async function resolveStartModel(requested, emit) {
* checklist passes its own longer budget, because that flow's contract is "the
* endpoint answers when this returns".
*
- * @param {{port?: number, host?: string, model?: string, waitMs?: number, onProgress?: (line: string) => void}} options
+ * There is deliberately no `host` option: MTPLX is a loopback daemon
+ * (`docs/features/mtplx.md`), every shipped provider preset points at
+ * 127.0.0.1, and accepting a host PortOS never puts on the launch line would
+ * report an endpoint the server is not bound to.
+ *
+ * @param {{port?: number, model?: string, waitMs?: number, onProgress?: (line: string) => void}} options
*/
export async function startMtplxServer(options = {}) {
- const { port = DEFAULT_PORT, host = DEFAULT_HOST, model: requestedModel = null, waitMs, onProgress = () => {} } = options;
+ const { port = DEFAULT_PORT, model: requestedModel = null, waitMs, onProgress = () => {} } = options;
const emit = (line) => { appendLog(line); onProgress(line); };
const binaryPath = resolveMtplxBinary();
@@ -250,13 +254,13 @@ export async function startMtplxServer(options = {}) {
throw new ServerError(`MTPLX is already running with PID ${pm2Status.pid}`, { status: 409 });
}
- const endpoint = `http://${host}:${port}/v1`;
+ const endpoint = `http://${DEFAULT_HOST}:${port}/v1`;
if (await probeEndpoint(endpoint)) {
throw new ServerError(`Port ${port} is already in use by an active server at ${endpoint}`, { status: 409 });
}
if (await isPortInUse(port)) {
throw new ServerError(
- `Port ${port} is already in use on ${host}. Point MTPLX at a different port before starting it.`,
+ `Port ${port} is already in use on ${DEFAULT_HOST}. Point MTPLX at a different port before starting it.`,
{ status: 409, code: 'MTPLX_PORT_IN_USE' }
);
}
@@ -274,14 +278,14 @@ export async function startMtplxServer(options = {}) {
// where the PROVIDER points — a user who moved MTPLX to 8010 would otherwise
// get a second server on 8000 that nothing talks to.
const args = ['serve', '--port', String(port), ...(model ? ['--model', model] : [])];
- currentConfig = { host, port, model };
+ currentConfig = { port, model };
appendLog(`Starting: mtplx ${args.join(' ')}`);
// Delete any stale PM2 entry so our own previous instance doesn't count as a collision.
await execPm2(['delete', MTPLX_APP]).catch(() => {});
clearJlistCache();
- console.log(`🚄 MTPLX starting on ${host}:${port}${model ? ` (model ${model})` : ' (MTPLX default model)'}`);
+ console.log(`🚄 MTPLX starting on ${DEFAULT_HOST}:${port}${model ? ` (model ${model})` : ' (MTPLX default model)'}`);
await execPm2([
'start', binaryPath,
'--name', MTPLX_APP,
diff --git a/server/services/mtplxServerManager.test.js b/server/services/mtplxServerManager.test.js
index 7670622cf6..d12ff78fcd 100644
--- a/server/services/mtplxServerManager.test.js
+++ b/server/services/mtplxServerManager.test.js
@@ -174,6 +174,17 @@ describe('mtplxServerManager', () => {
expect(pm2State).toBeNull();
});
+ it('reports the endpoint it actually bound, with no host it never passes', async () => {
+ // MTPLX is a loopback daemon and no `--host` ever reaches its launch line,
+ // so accepting a host would record an endpoint the server is not bound to.
+ const result = await startMtplxServer({ port: 8010, host: '0.0.0.0' });
+ expect(result.endpoint).toBe('http://127.0.0.1:8010/v1');
+ expect(result.config).not.toHaveProperty('host');
+ const launch = execPm2Calls.find((a) => a[0] === 'start');
+ expect(launch).not.toContain('--host');
+ expect((await getMtplxServerStatus()).host).toBe('127.0.0.1');
+ });
+
it('refuses when the binary is not installed', async () => {
vi.spyOn(processEnv, 'findCommandOnPath').mockReturnValue(null);
await expect(startMtplxServer()).rejects.toThrow(/not found on PATH/);