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.

fix(report-bug): address review findings on host snapshot

debpalash3b17f611a840
diff --git a/electron/src/main/backend.ts b/electron/src/main/backend.ts
index 28f1cade1..76d1f0cc9 100644
--- a/electron/src/main/backend.ts
+++ b/electron/src/main/backend.ts
@@ -698,11 +698,15 @@ export class BackendSupervisor extends EventEmitter<{
/** Machine and runtime facts for bug reports; works while the backend is down. */
async hostSnapshot(): Promise<HostSnapshot> {
- const project = this.runtimeProject ?? join(storedRuntimeRoot() ?? defaultRuntimeRoot(), 'project');
+ // Same location resolveSpawnPlan() launches from.
+ const project = app.isPackaged
+ ? (this.runtimeProject ?? join(storedRuntimeRoot() ?? defaultRuntimeRoot(), 'project'))
+ : backendRoot();
return collectHostSnapshot({
runtimeProject: project,
runtimePython: runtimePython(project),
uv: findUv(),
+ uvSearched: true,
gpu: async () => {
const info = (await app.getGPUInfo('basic')) as {
gpuDevice?: { vendorId?: number; deviceId?: number; active?: boolean; driverVersion?: string }[];
diff --git a/electron/src/main/host-snapshot.test.ts b/electron/src/main/host-snapshot.test.ts
index ba030267a..7ee800b75 100644
--- a/electron/src/main/host-snapshot.test.ts
+++ b/electron/src/main/host-snapshot.test.ts
@@ -1,3 +1,4 @@
+import { readFileSync } from 'node:fs';
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
@@ -58,3 +59,40 @@ it('survives a hung or throwing GPU probe', async () => {
expect(thrown.gpu).toBeNull();
expect(thrown.runtime.pythonPresent).toBeNull();
});
+
+it('reads free disk from the nearest existing ancestor on first run', async () => {
+ const dir = await mkdtemp(join(tmpdir(), 'host-snapshot-'));
+ try {
+ const snapshot = await collectHostSnapshot({
+ platform: 'linux',
+ runtimeProject: join(dir, 'not', 'created', 'yet'),
+ runtimePython: null,
+ uv: null,
+ });
+ expect(snapshot.diskFreeGb).toBeGreaterThan(0);
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
+
+it('reports uv missing only when the search completed with no result', async () => {
+ const searched = await collectHostSnapshot({
+ runtimeProject: null,
+ runtimePython: null,
+ uv: null,
+ uvSearched: true,
+ });
+ const unchecked = await collectHostSnapshot({
+ runtimeProject: null,
+ runtimePython: null,
+ uv: null,
+ });
+ expect(searched.runtime.uvPresent).toBe(false);
+ expect(unchecked.runtime.uvPresent).toBeNull();
+});
+
+it('validates the caller before the host snapshot IPC reads anything', () => {
+ const source = readFileSync(join(__dirname, 'ipc.ts'), 'utf8');
+ const handler = source.split('CHANNELS.backendHostSnapshot,')[1]?.split('ipcMain.handle')[0] ?? '';
+ expect(handler).toContain('assertTrustedMainFrame(event, ');
+});
diff --git a/electron/src/main/host-snapshot.ts b/electron/src/main/host-snapshot.ts
index 8a4cda69c..8001aa2b4 100644
--- a/electron/src/main/host-snapshot.ts
+++ b/electron/src/main/host-snapshot.ts
@@ -1,5 +1,6 @@
import { arch, cpus, release, totalmem, version } from 'node:os';
import { stat, statfs } from 'node:fs/promises';
+import { dirname } from 'node:path';
export interface HostSnapshot {
os: string;
@@ -21,6 +22,8 @@ export interface HostSnapshotInput {
runtimeProject: string | null;
runtimePython: string | null;
uv: string | null;
+ /** True when the uv search completed, so a null `uv` means "not installed". */
+ uvSearched?: boolean;
gpu?: () => Promise<string | null>;
}
@@ -57,11 +60,17 @@ async function exists(path: string | null): Promise<boolean | null> {
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;
+ // First run: the project dir does not exist yet, but its drive does.
+ let probe = path;
+ for (;;) {
+ try {
+ const fs = await statfs(probe);
+ return Math.round(((fs.bavail * fs.bsize) / 1024 ** 3) * 10) / 10;
+ } catch {
+ const parent = dirname(probe);
+ if (parent === probe) return null;
+ probe = parent;
+ }
}
}
@@ -86,9 +95,9 @@ async function withTimeout<T>(task: Promise<T>, ms: number): Promise<T | null> {
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),
+ withTimeout(exists(input.runtimePython), 1500),
+ input.uv ? exists(input.uv) : Promise.resolve(input.uvSearched ? false : null),
+ withTimeout(freeGb(input.runtimeProject), 1500),
input.gpu ? withTimeout(input.gpu(), 1500) : Promise.resolve(null),
]);
return {
diff --git a/electron/src/main/ipc.ts b/electron/src/main/ipc.ts
index bd7e609a2..2865ea3c0 100644
--- a/electron/src/main/ipc.ts
+++ b/electron/src/main/ipc.ts
@@ -355,7 +355,11 @@ export function registerIpc(
return supervisor.acknowledgeLastCrash();
});
ipcMain.handle(CHANNELS.backendGetConnection, () => supervisor.connection);
- ipcMain.handle(CHANNELS.backendHostSnapshot, () => supervisor.hostSnapshot());
+ ipcMain.handle(CHANNELS.backendHostSnapshot, (event) => {
+ const owner = getMainWindow();
+ assertTrustedMainFrame(event, owner);
+ return supervisor.hostSnapshot();
+ });
ipcMain.handle(CHANNELS.backendTestRemote, async (event, raw: unknown) => {
const owner = getMainWindow();
assertTrustedMainFrame(event, owner);
diff --git a/electron/src/renderer/src/components/report-bug.tsx b/electron/src/renderer/src/components/report-bug.tsx
index 4d0631987..db51a0824 100644
--- a/electron/src/renderer/src/components/report-bug.tsx
+++ b/electron/src/renderer/src/components/report-bug.tsx
@@ -5,7 +5,7 @@ import { formatBreadcrumbs } from '@shared/utils/breadcrumbs';
import { contactAge, lastBackendContact } from '@shared/utils/backendContact';
import { clampCrashTail } from '@shared/utils/crashReport';
import { scrubText } from '@shared/utils/scrub';
-import { formatHostSnapshot } from '@shared/utils/hostSnapshot';
+import { formatHostSnapshot, withDeadline } from '@shared/utils/hostSnapshot';
import { describeExitCode, isNativeFaultExit } from '@shared/utils/nativeExit';
import {
_adaptLastRunCrash,
@@ -110,7 +110,8 @@ export function ReportBug({ error }: { error?: Error | string }) {
error
? apiJson<{ lines?: unknown[] }>('/system/logs?tail=120', { signal })
: Promise.resolve(null),
- bridge?.backend?.getHostSnapshot?.() ?? Promise.resolve(null),
+ // A stalled network drive must not hold the report hostage.
+ withDeadline(bridge?.backend?.getHostSnapshot?.() ?? Promise.resolve(null), 3000),
]);
const backend =
nativeStatus.status === 'fulfilled' && nativeStatus.value
diff --git a/electron/src/shared/utils/hostSnapshot.test.ts b/electron/src/shared/utils/hostSnapshot.test.ts
index feaba1496..443dfb19f 100644
--- a/electron/src/shared/utils/hostSnapshot.test.ts
+++ b/electron/src/shared/utils/hostSnapshot.test.ts
@@ -1,5 +1,11 @@
import { expect, it } from 'vitest';
-import { formatHostSnapshot } from './hostSnapshot';
+import { formatHostSnapshot, withDeadline } from './hostSnapshot';
+
+it('gives up on a stalled snapshot after the deadline', async () => {
+ expect(await withDeadline(new Promise(() => {}), 20)).toBeNull();
+ expect(await withDeadline(Promise.resolve(5), 20)).toBe(5);
+ expect(await withDeadline(Promise.reject(new Error('x')), 20)).toBeNull();
+});
const snapshot = {
os: 'win32 Windows 11 Pro (10.0.26100)',
diff --git a/electron/src/shared/utils/hostSnapshot.ts b/electron/src/shared/utils/hostSnapshot.ts
index 51ee12acf..672b6b04f 100644
--- a/electron/src/shared/utils/hostSnapshot.ts
+++ b/electron/src/shared/utils/hostSnapshot.ts
@@ -12,7 +12,24 @@ export interface HostSnapshotLike {
};
}
-const present = (value: boolean | null | undefined) =>
+/** Resolve with the task's value, or null if it rejects or outlasts `ms`. */
+export async function withDeadline<T>(task: Promise<T>, ms: number): Promise<T | null> {
+ let timer: ReturnType<typeof setTimeout> | undefined;
+ try {
+ return await Promise.race([
+ task,
+ new Promise<null>((resolve) => {
+ timer = setTimeout(() => resolve(null), ms);
+ }),
+ ]);
+ } catch {
+ return null;
+ } finally {
+ clearTimeout(timer);
+ }
+}
+
+const present =(value: boolean | null | undefined) =>
value == null ? 'unknown' : value ? 'present' : 'MISSING';
/**