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
address review (codex): verify muscriptor import, not just the venv binary
[._.]/ Adam Eivyb591b26caca0
diff --git a/server/lib/pythonSetup.js b/server/lib/pythonSetup.jsindex b60b1f8bd3..80d67cdae4 100644--- a/server/lib/pythonSetup.js+++ b/server/lib/pythonSetup.js@@ -332,8 +332,32 @@ export function resolveMuscriptorPython() {return null;}+// A killed-mid-install run (e.g. the user cancels the in-app installer during+// pip) leaves the venv's python binary but no `muscriptor` package.+// resolveMuscriptorPython() only existsSync's the binary, so it would report+// that broken state as ready — the transcription then fails deep in the sidecar+// and, because the binary IS present, no 503 fires to re-open the installer.+// Probe the actual import the sidecar needs (mirrors isByovRuntimeReady / the+// Flux2 health check) so a partial venv is treated as not-ready: the 503 gate+// re-opens the installer and the install short-circuit runs the repair instead+// of claiming "already installed". Only the positive result is cached (the+// probe spawns a process); a not-ready venv re-probes each call so an+// out-of-band repair reflects without a restart. Bust via invalidateMuscriptorPython().+let cachedMuscriptorReady = false;+export async function isMuscriptorRuntimeReady() {+ if (cachedMuscriptorReady) return true;+ const py = resolveMuscriptorPython();+ if (!py) return false;+ const ok = await execFileAsync(py, ['-c', 'from muscriptor import TranscriptionModel'], { env: safeChildProcessEnv(), timeout: 30_000 })+ .then(() => true)+ .catch(() => false);+ cachedMuscriptorReady = ok;+ return ok;+}+export function invalidateMuscriptorPython() {cachedMuscriptorPython = null;+ cachedMuscriptorReady = false;}// Used by /api/image-gen/setup/* routes to validate user-supplied pythonPathdiff --git a/server/routes/midiRuntime.js b/server/routes/midiRuntime.jsindex 5d2b491df1..c9cdad4656 100644--- a/server/routes/midiRuntime.js+++ b/server/routes/midiRuntime.js@@ -24,6 +24,7 @@ import { safeChildProcessEnv } from '../lib/processEnv.js';import { openSseStream } from '../lib/sseDownload.js';import {resolveMuscriptorPython,+ isMuscriptorRuntimeReady,invalidateMuscriptorPython,MUSCRIPTOR_VENV_DEFAULT,} from '../lib/pythonSetup.js';@@ -49,12 +50,13 @@ router.get('/install', asyncHandler(async (req, res) => {// The venv may already exist (another surface installed it) — short-circuit// rather than re-running the multi-GB setup. Drop the cached resolve first so- // this reflects on-disk truth, not a stale null from before a prior install.+ // this reflects on-disk truth, not a stale value from before a prior install.+ // Gate on the import, not just the binary: a partial venv (cancelled mid-pip)+ // must NOT short-circuit as "already installed" — it needs the repair run.invalidateMuscriptorPython();- const existing = resolveMuscriptorPython();- if (existing) {+ if (await isMuscriptorRuntimeReady()) {installInFlight = null;- send({ type: 'log', message: `MuScriptor already installed at ${existing}` });+ send({ type: 'log', message: `MuScriptor already installed at ${resolveMuscriptorPython()}` });send({ type: 'complete', message: 'Already installed — nothing to do.' });return safeEnd();}@@ -92,19 +94,19 @@ router.get('/install', asyncHandler(async (req, res) => {send({ type: 'error', message: `Installer failed to spawn: ${err.message}` });safeEnd();});- child.on('close', (code) => {+ child.on('close', async (code) => {finished = true;installInFlight = null;- // Drop the cached resolve so this probe (and the next transcription) sees- // the freshly-created venv, then re-probe rather than trusting the exit- // code alone — the setup script import-verifies MuScriptor and exits- // non-zero on failure, but a partial venv shouldn't be reported "ready".+ // Drop the cached resolve/ready so this probe (and the next transcription)+ // sees the freshly-created venv, then verify the import rather than trusting+ // the exit code alone — the setup script import-verifies MuScriptor and+ // exits non-zero on failure, but a partial venv shouldn't be reported "ready".invalidateMuscriptorPython();- const py = resolveMuscriptorPython();- if (code === 0 && py) {- send({ type: 'complete', message: `MuScriptor ready: ${py}` });+ const ready = await isMuscriptorRuntimeReady();+ if (code === 0 && ready) {+ send({ type: 'complete', message: `MuScriptor ready: ${resolveMuscriptorPython()}` });} else if (code === 0) {- send({ type: 'error', message: `Installer exited 0 but ${MUSCRIPTOR_VENV_DEFAULT} is still missing. Re-run from a terminal to see what happened.` });+ send({ type: 'error', message: `Installer exited 0 but MuScriptor can't be imported from ${MUSCRIPTOR_VENV_DEFAULT}. Re-run from a terminal to see what happened.` });} else {send({ type: 'error', message: `Installer exited with code ${code}.` });}diff --git a/server/routes/midiRuntime.test.js b/server/routes/midiRuntime.test.jsindex f333d93e0f..3219d7d365 100644--- a/server/routes/midiRuntime.test.js+++ b/server/routes/midiRuntime.test.js@@ -9,6 +9,9 @@ import { request } from '../lib/testHelper.js';const py = vi.hoisted(() => ({ installed: true }));vi.mock('../lib/pythonSetup.js', () => ({resolveMuscriptorPython: () => (py.installed ? '/home/x/.portos/venv-muscriptor/bin/python3' : null),+ // Ready = binary present AND `muscriptor` importable. The route now gates the+ // short-circuit on this (not bare binary presence) so a partial venv repairs.+ isMuscriptorRuntimeReady: async () => py.installed,invalidateMuscriptorPython: vi.fn(),MUSCRIPTOR_VENV_DEFAULT: '/home/x/.portos/venv-muscriptor/bin/python3',}));diff --git a/server/services/audioMidiTranscription.js b/server/services/audioMidiTranscription.jsindex a772e6d506..10af809b38 100644--- a/server/services/audioMidiTranscription.js+++ b/server/services/audioMidiTranscription.js@@ -31,7 +31,7 @@ import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay } from 'import { killWithEscalation } from '../lib/killWithEscalation.js';import { safeChildProcessEnv } from '../lib/processEnv.js';import { hfTokenEnv } from '../lib/hfToken.js';-import { resolveMuscriptorPython, MUSCRIPTOR_VENV_DEFAULT } from '../lib/pythonSetup.js';+import { resolveMuscriptorPython, isMuscriptorRuntimeReady, MUSCRIPTOR_VENV_DEFAULT } from '../lib/pythonSetup.js';import { runSidecarProcess, parseSidecarResult } from '../lib/sidecarProcess.js';import { ServerError } from '../lib/errorHandler.js';@@ -109,10 +109,13 @@ export function cancelMidiTranscription(jobId) {* audio (the peer-sync asset manifest only ships known directories).*/export async function startMidiTranscription({ audioPath, outputName = 'transcription', model, onComplete, destDir = PATHS.uploads }) {- const pythonPath = resolveMuscriptorPython();- if (!pythonPath) {+ // Gate on the actual import, not just the binary — a partial venv (binary+ // present, `muscriptor` not importable) must still 503 so the in-app+ // installer re-opens to repair it instead of failing later in the sidecar.+ if (!(await isMuscriptorRuntimeReady())) {throw new ServerError(MUSCRIPTOR_INSTALL_HINT, { status: 503, code: 'MIDI_RUNTIME_MISSING' });}+ const pythonPath = resolveMuscriptorPython();if (!existsSync(audioPath)) {throw new ServerError('Audio file not found', { status: 404, code: 'NOT_FOUND' });}