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: close MTPLX TUI lifecycle gaps

[._.]/ Adam Eivyeb18120c543f
diff --git a/client/src/components/settings/LocalLlmTab.jsx b/client/src/components/settings/LocalLlmTab.jsx
index f112bfd330..2e15e77681 100644
--- a/client/src/components/settings/LocalLlmTab.jsx
+++ b/client/src/components/settings/LocalLlmTab.jsx
@@ -505,9 +505,9 @@ export function LocalLlmTab() {
() => installMtplx(),
'MTPLX installed'
).then(loadMtplxStatus);
- const runtimeStartMtplx = () => runAction(
+ const runtimeStartMtplx = (launch = {}) => runAction(
'runtime-start-mtplx',
- () => startMtplxServer(),
+ () => startMtplxServer(launch),
(r) => r?.online ? 'MTPLX is running' : 'MTPLX is loading its checkpoint'
).then(loadMtplxStatus);
// The card can start MTPLX explicitly from its cached checkpoint, and the
@@ -943,6 +943,7 @@ export function LocalLlmTab() {
onConfigureLlama={() => scrollTo(llamaSectionRef)}
onConfigureMtplx={() => scrollTo(mtplxSectionRef)}
onInstallMtplx={runtimeInstallMtplx}
+ onStartMtplx={runtimeStartMtplx}
onStopMtplx={runtimeStopMtplx}
onSaveStartup={saveRuntimeStartup}
onSaveIdleWindow={saveIdleWindow}
diff --git a/client/src/components/settings/LocalLlmTab.test.jsx b/client/src/components/settings/LocalLlmTab.test.jsx
index 681493068a..f53c359c79 100644
--- a/client/src/components/settings/LocalLlmTab.test.jsx
+++ b/client/src/components/settings/LocalLlmTab.test.jsx
@@ -134,20 +134,21 @@ describe('LocalLlmTab runtime servers', () => {
}
});
- // MTPLX starts on demand — the first request routed to it brings it up — so
- // this surface offers Install and Configure, never Start.
- it('offers no MTPLX Start on that surface', async () => {
- const { getMtplxServerStatus } = await import('../../services/api');
+ // MTPLX starts on demand — the first request routed to it brings it up — and
+ // also offers an explicit start when its checkpoint is already cached.
+ it('offers MTPLX Start on the unified runtime surface', async () => {
+ const { getMtplxServerStatus, startMtplxServer } = await import('../../services/api');
getMtplxServerStatus.mockResolvedValue({
installed: true, running: false, supported: true, cachedModels: ['Example/Qwen-MTP'], endpoint: 'http://127.0.0.1:8000/v1',
});
+ startMtplxServer.mockResolvedValue({ online: true });
await renderTab();
const card = screen.getByRole('heading', { name: 'Local Runtime Servers' }).closest('div.bg-port-card');
const mtplxRow = within(card).getByText('MTPLX').closest('div.flex.flex-col');
- expect(within(mtplxRow).queryByRole('button', { name: /^Start/ })).toBeNull();
- expect(within(mtplxRow).getByText(/Starts on demand/)).toBeInTheDocument();
+ fireEvent.click(within(mtplxRow).getByRole('button', { name: /^Start/ }));
+ await waitFor(() => expect(startMtplxServer).toHaveBeenCalledWith({}));
});
it('saves an idle window through the settings slice for that runtime', async () => {
diff --git a/client/src/components/settings/MtplxServerCard.jsx b/client/src/components/settings/MtplxServerCard.jsx
index decb708d2e..8569cde2b8 100644
--- a/client/src/components/settings/MtplxServerCard.jsx
+++ b/client/src/components/settings/MtplxServerCard.jsx
@@ -163,7 +163,7 @@ export default function MtplxServerCard({
</p>
{!emptyCache && onStart && (
<button
- onClick={() => onStart?.()}
+ onClick={() => onStart({ model: model || null, ...(port ? { port: Number(port) } : {}) })}
disabled={busy}
className={`${btnClass} bg-port-success/20 hover:bg-port-success/30 text-port-success`}
title="Start MTPLX with the cached checkpoint; no weights are downloaded"
diff --git a/client/src/components/settings/MtplxServerCard.test.jsx b/client/src/components/settings/MtplxServerCard.test.jsx
index 43bf910f42..3ebf3201a5 100644
--- a/client/src/components/settings/MtplxServerCard.test.jsx
+++ b/client/src/components/settings/MtplxServerCard.test.jsx
@@ -149,7 +149,7 @@ describe('MtplxServerCard', () => {
const handlers = await renderCard({ installed: true, running: false, supported: true, cachedModels: ['Example/Qwen-MTP'] });
expect(screen.getByText(/starts on demand/i)).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /^Start MTPLX/ }));
- expect(handlers.onStart).toHaveBeenCalledWith();
+ expect(handlers.onStart).toHaveBeenCalledWith({ model: null });
});
it('will not offer to stop a server started outside PortOS', async () => {
diff --git a/server/services/promptRunner.js b/server/services/promptRunner.js
index cb93c968ca..5d77e5e163 100644
--- a/server/services/promptRunner.js
+++ b/server/services/promptRunner.js
@@ -26,7 +26,7 @@
* stay honest about what the runner actually executed.
*/
-import { createRun, executeApiRun, executeCliRun, extractBakedModel, hasModelFlag, stopRun, patchRunMetadata } from './runner.js';
+import { createRun, executeApiRun, executeCliRun, extractBakedModel, hasModelFlag, stopRun, patchRunMetadata, finalizeRunRecord } from './runner.js';
import { getActiveProvider, getProviderById, getAllProviders } from './providers.js';
import { executeTuiRun } from './tuiPromptRunner.js';
import { ServerError } from '../lib/errorHandler.js';
@@ -84,7 +84,9 @@ export function buildRequestCapabilities({ prompt, screenshots, outputReserveTok
// regardless — and, if the backend is configured for parallelism
// (OLLAMA_NUM_PARALLEL > 1), it loads N model contexts at once and can spike
// VRAM into an OOM/thrash. Cloud HTTP and CLI/TUI providers have no such
-// constraint. So we cap concurrent IN-FLIGHT calls per LOCAL endpoint and queue
+// constraint. Local TUI providers still share this gate because their readiness
+// hook can start the same daemon before the PTY is spawned. So we cap concurrent
+// IN-FLIGHT calls per LOCAL endpoint and queue
// the rest (FIFO). Default 1 (serialize); a beefy box can lift it with
// LOCAL_LLM_MAX_CONCURRENCY. Keyed by endpoint so two distinct local servers
// still run in parallel with each other.
@@ -120,11 +122,13 @@ function releaseLocalSlot(endpoint) {
else gate.active = Math.max(0, gate.active - 1);
}
-// Run `fn` under the local-endpoint gate when `provider` is a local API backend;
-// otherwise run it immediately (cloud / CLI / TUI are unconstrained).
+// Run `fn` under the local-endpoint gate when `provider` is a local API or TUI
+// backend; otherwise run it immediately (cloud / non-local CLI/TUI are
+// unconstrained).
export async function withLocalConcurrencyGate(provider, fn) {
const endpoint = provider?.endpoint;
- if (!(provider?.type === PROVIDER_TYPES.API && isLocalEndpoint(endpoint))) return fn();
+ const isLocalProvider = provider?.type === PROVIDER_TYPES.API || provider?.type === PROVIDER_TYPES.TUI;
+ if (!(isLocalProvider && isLocalEndpoint(endpoint))) return fn();
await acquireLocalSlot(endpoint);
try {
return await fn();
@@ -1254,7 +1258,16 @@ async function executeProviderRunOnce({
error: err.message,
}));
if (!ready.success) {
- const error = new Error(ready.error || 'Provider readiness check failed');
+ const message = ready.error || 'Provider readiness check failed';
+ await finalizeRunRecord({
+ runId,
+ output: '',
+ exitCode: 1,
+ success: false,
+ error: message,
+ startTime: Date.now(),
+ });
+ const error = new Error(message);
error.effectiveProvider = effectiveProvider;
error.effectiveModel = effectiveModel;
throw error;
diff --git a/server/services/stageRunner.test.js b/server/services/stageRunner.test.js
index 3e7735c752..fdb346a531 100644
--- a/server/services/stageRunner.test.js
+++ b/server/services/stageRunner.test.js
@@ -724,6 +724,13 @@ describe('withLocalConcurrencyGate', () => {
expect(state.peak).toBeGreaterThan(1);
});
+ it('serializes concurrent TUI calls to a LOCAL endpoint', async () => {
+ const provider = { type: 'tui', endpoint: 'http://127.0.0.1:8000/v1' };
+ const { state, fn } = makeTracker();
+ await Promise.all(Array.from({ length: 4 }, () => withLocalConcurrencyGate(provider, fn)));
+ expect(state.peak).toBeLessThanOrEqual(LOCAL_LLM_MAX_CONCURRENCY);
+ });
+
it('releases the slot even when the gated fn throws (no deadlock)', async () => {
const provider = { type: 'api', endpoint: 'http://127.0.0.1:1234' };
await expect(withLocalConcurrencyGate(provider, () => Promise.reject(new Error('boom')))).rejects.toThrow('boom');