Skip to content

VoiceStudio is the open-source, fully-local ElevenLabs alternative — voice cloning, voice design, video dubbing, dictation, transcription & audiobook creation in 646 languages.

feat(diagnostics): read machine and runtime facts in the main process

velixiocd62fc4455d6
diff --git a/electron/src/main/host-snapshot.test.ts b/electron/src/main/host-snapshot.test.ts
new file mode 100644
index 000000000..ba030267a
--- /dev/null
+++ b/electron/src/main/host-snapshot.test.ts
@@ -0,0 +1,60 @@
+import { mkdtemp, rm, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { expect, it } from 'vitest';
+import { collectHostSnapshot, pathRiskFlags } from './host-snapshot';
+
+it('flags launch-hostile Windows paths without exposing them', () => {
+ expect(pathRiskFlags('C:\\Users\\Ana\\OneDrive\\Masaüstü\\VoiceStudio', 'win32')).toEqual([
+ 'onedrive',
+ 'non-ascii',
+ ]);
+ expect(pathRiskFlags('C:\\Windows\\System32\\VoiceStudio', 'win32')).toContain('system32');
+ expect(pathRiskFlags('\\\\server\\share\\VoiceStudio', 'win32')).toContain('network-share');
+ expect(pathRiskFlags('C:\\Program Files\\VoiceStudio', 'win32')).toEqual([
+ 'spaces',
+ 'program-files',
+ ]);
+ expect(pathRiskFlags('/home/ana/voicestudio', 'linux')).toEqual([]);
+});
+
+it('reports machine facts and missing runtime files with no backend running', async () => {
+ const dir = await mkdtemp(join(tmpdir(), 'host-snapshot-'));
+ try {
+ const uv = join(dir, 'uv');
+ await writeFile(uv, '');
+ const snapshot = await collectHostSnapshot({
+ platform: 'linux',
+ runtimeProject: dir,
+ runtimePython: join(dir, '.venv', 'bin', 'python'),
+ uv,
+ gpu: async () => 'vendor 0x1002',
+ });
+ expect(snapshot.runtime).toEqual({ pythonPresent: false, uvPresent: true, pathFlags: [] });
+ expect(snapshot.gpu).toBe('vendor 0x1002');
+ expect(snapshot.ramGb).toBeGreaterThan(0);
+ expect(snapshot.diskFreeGb).toBeGreaterThan(0);
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
+
+it('survives a hung or throwing GPU probe', async () => {
+ const hung = await collectHostSnapshot({
+ runtimeProject: null,
+ runtimePython: null,
+ uv: null,
+ gpu: () => new Promise(() => {}),
+ });
+ const thrown = await collectHostSnapshot({
+ runtimeProject: null,
+ runtimePython: null,
+ uv: null,
+ gpu: async () => {
+ throw new Error('no gpu');
+ },
+ });
+ expect(hung.gpu).toBeNull();
+ expect(thrown.gpu).toBeNull();
+ expect(thrown.runtime.pythonPresent).toBeNull();
+});
diff --git a/electron/src/main/host-snapshot.ts b/electron/src/main/host-snapshot.ts
new file mode 100644
index 000000000..8a4cda69c
--- /dev/null
+++ b/electron/src/main/host-snapshot.ts
@@ -0,0 +1,107 @@
+import { arch, cpus, release, totalmem, version } from 'node:os';
+import { stat, statfs } from 'node:fs/promises';
+
+export interface HostSnapshot {
+ os: string;
+ arch: string;
+ cpu: string | null;
+ ramGb: number;
+ diskFreeGb: number | null;
+ gpu: string | null;
+ runtime: {
+ pythonPresent: boolean | null;
+ uvPresent: boolean | null;
+ pathFlags: string[];
+ };
+}
+
+export interface HostSnapshotInput {
+ platform?: NodeJS.Platform;
+ /** Runtime project directory (holds `.venv`); null when it cannot be resolved. */
+ runtimeProject: string | null;
+ runtimePython: string | null;
+ uv: string | null;
+ gpu?: () => Promise<string | null>;
+}
+
+/**
+ * Path traits that explain launch failures (`spawn UNKNOWN`, access
+ * violations, EPERM renames) without printing the path itself, which is
+ * private. Stable tokens so triage can grep them.
+ */
+export function pathRiskFlags(
+ path: string,
+ platform: NodeJS.Platform = process.platform,
+): string[] {
+ const flags: string[] = [];
+ if (/onedrive/i.test(path)) flags.push('onedrive');
+ if (/[^\x00-\x7f]/.test(path)) flags.push('non-ascii');
+ if (/\s/.test(path)) flags.push('spaces');
+ if (platform === 'win32') {
+ if (/^\\\\/.test(path)) flags.push('network-share');
+ if (/[\\/]windows[\\/]system32/i.test(path)) flags.push('system32');
+ else if (/[\\/]program files/i.test(path)) flags.push('program-files');
+ if (path.length > 180) flags.push('long-path');
+ }
+ return flags;
+}
+
+async function exists(path: string | null): Promise<boolean | null> {
+ if (!path) return null;
+ try {
+ return (await stat(path)).isFile();
+ } catch {
+ return false;
+ }
+}
+
+async function freeGb(path: string | null): Promise<number | null> {
+ if (!path) return null;
+ try {
+ const fs = await statfs(path);
+ return Math.round(((fs.bavail * fs.bsize) / 1024 ** 3) * 10) / 10;
+ } catch {
+ return null;
+ }
+}
+
+async function withTimeout<T>(task: Promise<T>, ms: number): Promise<T | null> {
+ let timer: NodeJS.Timeout | undefined;
+ try {
+ return await Promise.race([
+ task,
+ new Promise<null>((resolve) => {
+ timer = setTimeout(() => resolve(null), ms);
+ }),
+ ]);
+ } catch {
+ return null;
+ } finally {
+ clearTimeout(timer);
+ }
+}
+
+/** Machine and runtime facts read in the main process, so a bug report is
+ * useful even when the backend never started and `/system/info` is unreachable. */
+export async function collectHostSnapshot(input: HostSnapshotInput): Promise<HostSnapshot> {
+ const platform = input.platform ?? process.platform;
+ const [pythonPresent, uvPresent, diskFreeGb, gpu] = await Promise.all([
+ exists(input.runtimePython),
+ exists(input.uv),
+ freeGb(input.runtimeProject),
+ input.gpu ? withTimeout(input.gpu(), 1500) : Promise.resolve(null),
+ ]);
+ return {
+ os: `${platform} ${version()} (${release()})`,
+ arch: arch(),
+ cpu: cpus()[0]?.model?.trim() || null,
+ ramGb: Math.round((totalmem() / 1024 ** 3) * 10) / 10,
+ diskFreeGb,
+ gpu,
+ runtime: {
+ pythonPresent,
+ uvPresent,
+ pathFlags: input.runtimeProject ? pathRiskFlags(input.runtimeProject, platform) : [],
+ },
+ };
+}