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): isolate MTPLX startup logs

[._.]/ Adam Eivy3edfb371e73f
diff --git a/server/services/mtplxServerManager.js b/server/services/mtplxServerManager.js
index a319f71683..a31bffc592 100644
--- a/server/services/mtplxServerManager.js
+++ b/server/services/mtplxServerManager.js
@@ -23,6 +23,9 @@
*/
import { commandExists } from '../lib/commandExists.js';
+import { writeFile } from 'fs/promises';
+import { tmpdir } from 'os';
+import { join } from 'path';
import { sleep } from '../lib/fileUtils.js';
import { ServerError } from '../lib/errorHandler.js';
import { launchArgs, normalizeTuning, tuningSpecsFor } from '../lib/localModelTuning.js';
@@ -117,18 +120,25 @@ const MTPLX_NO_MODEL_ERROR = 'MTPLX has no model weights cached, so its server e
const MTPLX_RUNTIME_BOOTSTRAP_ERROR = 'MTPLX\'s own Python runtime failed to bootstrap because Homebrew\'s Python does not provide a working `ensurepip`. Try `brew reinstall [email protected]` (or `brew reinstall --build-from-source youssofal/mtplx/mtplx` to force a rebuild against a working interpreter), then start MTPLX again.';
-const MTPLX_LOG_DATE_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSS';
-const PM2_LOG_TIMESTAMP_PATTERN = /(?:^|\s)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3})(?::|\s)/;
+/**
+ * Keep MTPLX startup logs raw while scoping each diagnosis to the current
+ * launch. PM2 appends to its configured files across process deletion, so
+ * stable, app-specific paths are truncated before every start.
+ */
+const MTPLX_LOG_FILES = {
+ stdout: join(tmpdir(), 'portos-mtplx-out.log'),
+ stderr: join(tmpdir(), 'portos-mtplx-error.log'),
+};
-const currentMtplxLogLines = (lines, launchStartedAt) => lines.filter((line) => {
- const timestamp = line.match(PM2_LOG_TIMESTAMP_PATTERN)?.[1];
- const loggedAt = timestamp ? Date.parse(timestamp) : NaN;
- return Number.isFinite(loggedAt) && loggedAt >= launchStartedAt;
-});
+const resetMtplxLogs = () => Promise.all(
+ Object.values(MTPLX_LOG_FILES).map((path) => writeFile(path, '')),
+);
const isMtplxRuntimeBootstrapFailure = (output) => {
const text = String(output ?? '');
- return /runtime is not installed|bootstrapping with pip/i.test(text) && /ensurepip/i.test(text);
+ return /runtime is not installed|bootstrapping with pip/i.test(text)
+ && /ensurepip/i.test(text)
+ && /returned non-zero exit status|no module named ensurepip|ensurepip is not available|failed to bootstrap/i.test(text);
};
let currentConfig = null;
@@ -465,13 +475,14 @@ 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(' ')}` : ''}`);
- const launchStartedAt = Date.now();
+ await resetMtplxLogs();
await execPm2([
'start', binaryPath,
'--name', MTPLX_APP,
'--interpreter', 'none',
'--no-autorestart',
- '--log-date-format', MTPLX_LOG_DATE_FORMAT,
+ '--output', MTPLX_LOG_FILES.stdout,
+ '--error', MTPLX_LOG_FILES.stderr,
'--',
...args,
]);
@@ -495,7 +506,7 @@ export async function startMtplxServer(options = {}) {
for (const line of lines) appendLog(line);
const tail = (lines.length ? lines : daemon.snapshotLogs()).slice(-4).join(' | ');
lastExitError = `PM2 status: ${currentProc.status}`;
- const message = isMtplxRuntimeBootstrapFailure(currentMtplxLogLines(lines, launchStartedAt).join('\n'))
+ const message = isMtplxRuntimeBootstrapFailure(lines.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 f09b8edc9f..ad1a70f114 100644
--- a/server/services/mtplxServerManager.test.js
+++ b/server/services/mtplxServerManager.test.js
@@ -206,10 +206,10 @@ describe('mtplxServerManager', () => {
return {
stdout: '',
stderr: [
- '2000-01-01T00:00:00.000: runtime is not installed',
- '2000-01-01T00:00:00.000: Bootstrapping with pip',
- '2000-01-01T00:00:00.000: python3.13 -m ensurepip --upgrade --default-pip',
- `${new Date().toISOString().slice(0, -1)}: error: model is not available locally`,
+ 'runtime is not installed',
+ 'Bootstrapping with pip',
+ 'python3.13 -m ensurepip --upgrade --default-pip',
+ 'error: model is not available locally',
].join('\n'),
};
}
@@ -228,16 +228,13 @@ describe('mtplxServerManager', () => {
}
if (args[0] === 'delete') pm2State = null;
if (args[0] === 'logs') {
- const timestamp = new Date().toISOString().slice(0, -1);
return {
stdout: '',
stderr: [
- ...[
- '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",
- ].map((line) => timestamp + ': ' + line),
+ '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'),
};
}
@@ -250,6 +247,9 @@ describe('mtplxServerManager', () => {
expect(err.message).toContain('Homebrew\'s Python does not provide a working `ensurepip`');
expect(err.message).toContain('brew reinstall [email protected]');
expect(err.message).toContain('brew reinstall --build-from-source youssofal/mtplx/mtplx');
+ const start = execPm2Calls.find((args) => args[0] === 'start');
+ expect(start[start.indexOf('--output') + 1]).toMatch(/portos-mtplx-out\.log$/);
+ expect(start[start.indexOf('--error') + 1]).toMatch(/portos-mtplx-error\.log$/);
expect(err.message).not.toContain('returned non-zero exit status 1');
expect(pm2State).toBeNull();
});