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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([ref-watch-phosphene-strip-malloc-subprocess-env]): strip Malloc* env vars before spawning Python subprocesses
[._.]/ Adam Eivy81f69659e5d5
diff --git a/server/lib/README.md b/server/lib/README.mdindex a45ebcfd09..e939f95946 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -106,6 +106,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `execGit.js` | `execGit` utility imported by `git.js` + worktree manager. || `ffmpeg.js` | Shared ffmpeg helpers (videoGen + videoTimeline). || `gitRemote.js` | `getOriginInfo`, `parseGitRemoteUrl`, `UPSTREAM_OWNER`/`UPSTREAM_REPO` — classifies the local `origin` remote vs the upstream atomantic/PortOS repo. Used by the update flow to detect forks. |+| `processEnv.js` | `stripDebugMallocEnv(env)` — drop macOS `Malloc*` debug env vars before spawning a child. Pinokio-launched PortOS exports `MallocStackLogging`/`MallocScribble`/etc. that flood Python subprocess stderr with `can't turn off malloc stack logging` lines; route every Node→Python spawn through this. No-op on Linux/Windows. || `pythonSetup.js` | Python venv / runner setup helpers. |## Networkingdiff --git a/server/lib/hfDownload.js b/server/lib/hfDownload.jsindex 5359033a32..b32b6fd6a1 100644--- a/server/lib/hfDownload.js+++ b/server/lib/hfDownload.js@@ -23,6 +23,7 @@ import { join } from 'node:path';import { resolveFlux2Python, isFlux2VenvHealthy } from './pythonSetup.js';import { PATHS } from './fileUtils.js';import { getHfTokenInfo } from './hfToken.js';+import { stripDebugMallocEnv } from './processEnv.js';import { getSettings } from '../services/settings.js';const HELPER_SCRIPT = join(PATHS.root, 'scripts', 'hf_download_repo.py');@@ -70,7 +71,7 @@ export function downloadHfRepo({ repo, revision = null, onEvent }) {}const { token } = await getHfTokenInfo();if (killed) return { ok: false, errorKind: 'cancelled', errorMessage: 'Cancelled' };- const env = { ...process.env };+ const env = stripDebugMallocEnv(process.env);// The Python helper looks up the token by env-var name so we don't have// to pass secrets on argv. Strip any stale value when the user has// explicitly cleared their stored token.diff --git a/server/lib/index.js b/server/lib/index.jsindex 86195c5f89..399f8d56da 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -91,6 +91,7 @@ export * from './commandSecurity.js';export * from './execGit.js';export * from './ffmpeg.js';export * from './gitRemote.js';+export * from './processEnv.js';export * from './pythonSetup.js';// === Networking ===diff --git a/server/lib/processEnv.js b/server/lib/processEnv.jsnew file mode 100644index 0000000000..1a07534011--- /dev/null+++ b/server/lib/processEnv.js@@ -0,0 +1,17 @@+// Strip macOS `Malloc*` debug env vars before spawning a child process.+//+// When PortOS is launched from Pinokio (or any tool that exports an empty or+// zero `MallocStackLogging` / `MallocScribble` / similar var), every Python+// subprocess prints+// `MallocStackLogging: can't turn off malloc stack logging because it was not enabled`+// once per child exit. The image-gen and video-gen helpers fan out into+// download/probe subprocesses, so a single render can flood stderr with+// dozens of these lines and bury real progress.+//+// The Malloc* family is documented in libmalloc(3) and only affects macOS;+// stripping the prefix is a no-op on Linux/Windows.+export function stripDebugMallocEnv(env) {+ return Object.fromEntries(+ Object.entries(env).filter(([k]) => !k.startsWith('Malloc'))+ );+}diff --git a/server/lib/processEnv.test.js b/server/lib/processEnv.test.jsnew file mode 100644index 0000000000..089b3e3cf9--- /dev/null+++ b/server/lib/processEnv.test.js@@ -0,0 +1,31 @@+import { describe, it, expect } from 'vitest';+import { stripDebugMallocEnv } from './processEnv.js';++describe('stripDebugMallocEnv', () => {+ it('drops every key that starts with "Malloc"', () => {+ const out = stripDebugMallocEnv({+ PATH: '/usr/bin',+ HOME: '/Users/x',+ MallocStackLogging: '1',+ MallocScribble: '1',+ MallocCheckHeapEach: '100',+ MallocNanoZone: '0',+ });+ expect(out).toEqual({ PATH: '/usr/bin', HOME: '/Users/x' });+ });++ it('preserves keys that contain but do not start with "Malloc"', () => {+ const out = stripDebugMallocEnv({ MY_MallocFlag: 'keep', MallocFlag: 'drop' });+ expect(out).toEqual({ MY_MallocFlag: 'keep' });+ });++ it('returns an empty object for an empty env', () => {+ expect(stripDebugMallocEnv({})).toEqual({});+ });++ it('does not mutate the input', () => {+ const input = { PATH: '/x', MallocStackLogging: '1' };+ stripDebugMallocEnv(input);+ expect(input).toEqual({ PATH: '/x', MallocStackLogging: '1' });+ });+});diff --git a/server/lib/pythonSetup.js b/server/lib/pythonSetup.jsindex 6c4bf82052..5d9f995770 100644--- a/server/lib/pythonSetup.js+++ b/server/lib/pythonSetup.js@@ -4,6 +4,7 @@ import { arch, homedir, platform } from 'node:os';import { join } from 'node:path';import { promisify } from 'node:util';import { PATHS } from './fileUtils.js';+import { stripDebugMallocEnv } from './processEnv.js';const execFileAsync = promisify(execFile);const IS_WIN = platform() === 'win32';@@ -259,7 +260,7 @@ export async function checkPackages(pythonPath) {// live child handle so the caller's outer closure can track it for SIGTERM.function streamSpawn(bin, args, onLog, onProc) {return new Promise((resolve) => {- const proc = spawn(bin, args, { stdio: ['ignore', 'pipe', 'pipe'] });+ const proc = spawn(bin, args, { env: stripDebugMallocEnv(process.env), stdio: ['ignore', 'pipe', 'pipe'] });onProc(proc);const onChunk = (chunk) => {for (const line of chunk.toString().split(/[\r\n]+/)) {diff --git a/server/routes/videoGen.js b/server/routes/videoGen.jsindex 8b1ad774e1..4fc70c8ee3 100644--- a/server/routes/videoGen.js+++ b/server/routes/videoGen.js@@ -20,6 +20,7 @@ import { PATHS, ensureDir, resolveGalleryImage } from '../lib/fileUtils.js';import { safeUnder } from '../lib/ffmpeg.js';import { getSettings } from '../services/settings.js';import { checkPackages, isAllowedPython } from '../lib/pythonSetup.js';+import { stripDebugMallocEnv } from '../lib/processEnv.js';import {listVideoModels,defaultVideoModelId,@@ -275,7 +276,7 @@ router.get('/setup/runtime-install', asyncHandler(async (req, res) => {// orphaned to init — the user sees the modal close but the bandwidth keeps// burning until the network drops or the snapshot completes.const child = spawn('bash', [scriptPath], {- env: { ...process.env, [info.installEnvVar]: '1' },+ env: { ...stripDebugMallocEnv(process.env), [info.installEnvVar]: '1' },stdio: ['ignore', 'pipe', 'pipe'],detached: true,});diff --git a/server/services/imageGen/local.js b/server/services/imageGen/local.jsindex 13dc596715..fbe7fcab40 100644--- a/server/services/imageGen/local.js+++ b/server/services/imageGen/local.js@@ -25,6 +25,7 @@ import { imageGenEvents } from '../imageGenEvents.js';import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay, PYTHON_NOISE_RE } from '../../lib/sseUtils.js';import { resolveFlux2Python, FLUX2_VENV_DEFAULT } from '../../lib/pythonSetup.js';import { hfTokenEnv } from '../../lib/hfToken.js';+import { stripDebugMallocEnv } from '../../lib/processEnv.js';import { IMAGE_GEN_MODE } from './modes.js';const IS_WIN = process.platform === 'win32';@@ -357,7 +358,7 @@ export async function generateImage({ pythonPath, prompt, negativePrompt = '', mimageGenEvents.emit('started', { generationId: jobId, totalSteps: actualSteps });activeJob = { ...meta, generationId: jobId, totalSteps: actualSteps, step: 0, progress: 0, currentImage: null, mode: IMAGE_GEN_MODE.LOCAL };- const proc = spawn(bin, args, { env: { ...process.env, ...(await hfTokenEnv()) }, stdio: ['ignore', 'pipe', 'pipe'] });+ const proc = spawn(bin, args, { env: { ...stripDebugMallocEnv(process.env), ...(await hfTokenEnv()) }, stdio: ['ignore', 'pipe', 'pipe'] });activeProcess = proc;// Spawn ENOENT (missing/non-executable pythonPath) fires BOTH 'error' and// 'close' on Node — without this guard, a typo'd pythonPath emits twodiff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.jsindex 0a4e3049f4..406cc7d7eb 100644--- a/server/services/videoGen/local.js+++ b/server/services/videoGen/local.js@@ -24,6 +24,7 @@ import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay, PYTHON_import { getVideoModels, getDefaultVideoModelId, getTextEncoderRepo } from '../../lib/mediaModels.js';import { findFfmpeg, safeUnder, generateThumbnail, optimizeForStreaming, upscaleVideo2x, extractEvaluationFrames } from '../../lib/ffmpeg.js';import { hfTokenEnv } from '../../lib/hfToken.js';+import { stripDebugMallocEnv } from '../../lib/processEnv.js';// Path to the dgrauet/ltx-2-mlx venv populated by `INSTALL_LTX2=1// scripts/setup-image-video.sh`. Used when a model entry has@@ -136,6 +137,7 @@ export async function isByovRuntimeReady(runtimeId) {if (readyCache.get(runtimeId) === true) return true;const probeOk = await new Promise((resolve) => {const child = spawn(info.venvPython, ['-c', info.importProbe], {+ env: stripDebugMallocEnv(process.env),stdio: ['ignore', 'ignore', 'ignore'],});const timer = setTimeout(() => { if (!child.killed) child.kill('SIGKILL'); resolve(false); }, 30000);@@ -705,7 +707,7 @@ export async function generateVideo({ pythonPath, prompt, negativePrompt = '', m// python helpers can authenticate snapshot_download() against gated repos// (mirrors the imageGen child-spawn pattern). LTX-2 doesn't currently use// a gated repo, but the merge is harmless when no token is configured.- const childEnv = { ...process.env, ...(await hfTokenEnv()) };+ const childEnv = { ...stripDebugMallocEnv(process.env), ...(await hfTokenEnv()) };delete childEnv.PYTHONPATH;// Force unbuffered Python I/O so tqdm + loguru + our own STAGE: prints flush// immediately. Without this, child stdio is line-buffered against a pipe and