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 (claude): keep log reset best effort

[._.]/ Adam Eivybd02ae82b71d
diff --git a/server/services/mtplxServerManager.js b/server/services/mtplxServerManager.js
index a31bffc592..5ac62bf0b4 100644
--- a/server/services/mtplxServerManager.js
+++ b/server/services/mtplxServerManager.js
@@ -130,9 +130,19 @@ const MTPLX_LOG_FILES = {
stderr: join(tmpdir(), 'portos-mtplx-error.log'),
};
-const resetMtplxLogs = () => Promise.all(
- Object.values(MTPLX_LOG_FILES).map((path) => writeFile(path, '')),
-);
+const resetMtplxLogs = async () => {
+ const results = await Promise.all(
+ Object.entries(MTPLX_LOG_FILES).map(([stream, path]) => (
+ writeFile(path, '')
+ .then(() => true)
+ .catch((error) => {
+ console.error(`❌ MTPLX: could not reset ${stream} startup log (${error?.code || 'unknown'}); bootstrap diagnosis disabled for this launch`);
+ return false;
+ })
+ )),
+ );
+ return results.every(Boolean);
+};
const isMtplxRuntimeBootstrapFailure = (output) => {
const text = String(output ?? '');
@@ -475,7 +485,7 @@ export async function startMtplxServer(options = {}) {
clearJlistCache();
console.log(`🚄 MTPLX starting on ${DEFAULT_HOST}:${port}${model ? ` (model ${model})` : ' (MTPLX default model)'}${tuningArgs.length ? ` with ${tuningArgs.join(' ')}` : ''}`);
- await resetMtplxLogs();
+ const logsReset = await resetMtplxLogs();
await execPm2([
'start', binaryPath,
'--name', MTPLX_APP,
@@ -503,10 +513,11 @@ export async function startMtplxServer(options = {}) {
if (currentProc && ['errored', 'stopped', 'not_found'].includes(currentProc.status)) {
const pm2Logs = await execPm2(['logs', MTPLX_APP, '--nostream', '--lines', '15']).catch(() => null);
const lines = `${pm2Logs?.stderr || pm2Logs?.stdout || ''}`.split('\n').map((l) => l.trimEnd()).filter(Boolean);
- for (const line of lines) appendLog(line);
- const tail = (lines.length ? lines : daemon.snapshotLogs()).slice(-4).join(' | ');
+ const currentLines = logsReset ? lines : [];
+ for (const line of currentLines) appendLog(line);
+ const tail = (currentLines.length ? currentLines : (logsReset ? daemon.snapshotLogs() : [])).slice(-4).join(' | ');
lastExitError = `PM2 status: ${currentProc.status}`;
- const message = isMtplxRuntimeBootstrapFailure(lines.join('\n'))
+ const message = logsReset && isMtplxRuntimeBootstrapFailure(currentLines.join('\n'))
? MTPLX_RUNTIME_BOOTSTRAP_ERROR
: `MTPLX exited immediately (${lastExitError}).${tail ? ` Last output: ${tail}` : ''}`;
diff --git a/server/services/mtplxServerManager.test.js b/server/services/mtplxServerManager.test.js
index ad1a70f114..7ab6552cba 100644
--- a/server/services/mtplxServerManager.test.js
+++ b/server/services/mtplxServerManager.test.js
@@ -1,3 +1,4 @@
+import { readFile, writeFile } from 'fs/promises';
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import {
getMtplxServerStatus,
@@ -254,6 +255,48 @@ describe('mtplxServerManager', () => {
expect(pm2State).toBeNull();
});
+ it('does not classify bootstrap text left by a previous launch', async () => {
+ await startMtplxServer();
+ const firstStart = execPm2Calls.find((args) => args[0] === 'start');
+ const outputPath = firstStart[firstStart.indexOf('--output') + 1];
+ const errorPath = firstStart[firstStart.indexOf('--error') + 1];
+ await stopMtplxServer();
+
+ const staleBootstrap = [
+ 'runtime is not installed',
+ 'Bootstrapping with pip',
+ 'python3.13 -m ensurepip --upgrade --default-pip',
+ "Command '['python3.13', '-m', 'ensurepip']' returned non-zero exit status 1",
+ ].join('\n');
+ await writeFile(outputPath, staleBootstrap);
+ await writeFile(errorPath, staleBootstrap);
+
+ execPm2Calls = [];
+ pm2Module.execPm2.mockImplementation(async (args) => {
+ execPm2Calls.push(args);
+ if (args[0] === 'start') {
+ pm2State = { name: MTPLX_APP, status: 'errored', pid: null, args: [] };
+ }
+ if (args[0] === 'delete') pm2State = null;
+ if (args[0] === 'logs') {
+ return {
+ stdout: await readFile(outputPath, 'utf8'),
+ stderr: await readFile(errorPath, 'utf8'),
+ };
+ }
+ return { stdout: '', stderr: '' };
+ });
+
+ const err = await startMtplxServer().catch((error) => error);
+
+ expect(err).toMatchObject({ code: 'MTPLX_EXITED' });
+ expect(err.message).toMatch(/MTPLX exited immediately/);
+ expect(err.message).not.toMatch(/Homebrew/);
+ expect(await readFile(outputPath, 'utf8')).toBe('');
+ expect(await readFile(errorPath, 'utf8')).toBe('');
+ 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.