Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.
TypeScript agent-skillscodex-clideskop-appdubbingimage-generationlocalizationskillsttsvideo-editingvideo-generationvideo-transcriptionvideo-translation
fix(desktop): run stickman renderer in worker thread
wulien-centerb7130a13f3be
diff --git a/apps/daemon/src/creator/stickman/remotion-executor.ts b/apps/daemon/src/creator/stickman/remotion-executor.tsindex 04c93bb8..a12270c8 100644--- a/apps/daemon/src/creator/stickman/remotion-executor.ts+++ b/apps/daemon/src/creator/stickman/remotion-executor.ts@@ -2,9 +2,9 @@ import { readFile, rm, writeFile } from 'node:fs/promises';import { createRequire } from 'node:module';import { dirname, extname, join } from 'node:path';import { fileURLToPath, pathToFileURL } from 'node:url';+import { Worker } from 'node:worker_threads';import type { CreatorExecutor } from '../executor.js';import { CreatorExecutorError } from '../executor.js';-import { spawnCreatorProcess } from '../process-tree.js';import { validateMediaFile } from '../validators/media.js';import { readStickmanRemotionRuntime, type StickmanRemotionRuntime } from './remotion-runtime.js';@@ -114,25 +114,38 @@ function runWorker(signal: AbortSignal): Promise<void> {return new Promise((resolve, reject) => {- const workerArgs = extname(workerEntrypoint).toLowerCase() === '.ts'- ? [- '--import',- pathToFileURL(createRequire(import.meta.url).resolve('tsx')).href,- workerEntrypoint,- requestPath,- resultPath- ]- : [workerEntrypoint, requestPath, resultPath];- const child = spawnCreatorProcess(- process.execPath,- workerArgs,- { cwd: dirname(requestPath), stdio: ['ignore', 'ignore', 'pipe'] },- signal- );+ if (signal.aborted) {+ reject(new CreatorExecutorError('creator_stage_canceled', 'Creator stage was canceled'));+ return;+ }+ const isTypeScript = extname(workerEntrypoint).toLowerCase() === '.ts';+ const worker = new Worker(pathToFileURL(workerEntrypoint), {+ argv: [requestPath, resultPath],+ execArgv: isTypeScript+ ? ['--import', pathToFileURL(createRequire(import.meta.url).resolve('tsx')).href]+ : [],+ stderr: true+ });let stderr = '';- child.stderr?.on('data', chunk => { stderr += String(chunk); });- child.once('error', reject);- child.once('exit', code => {+ let settled = false;+ worker.stderr.on('data', chunk => { stderr += String(chunk); });+ const cleanup = () => signal.removeEventListener('abort', abort);+ const fail = (error: unknown) => {+ if (settled) return;+ settled = true;+ cleanup();+ reject(error);+ };+ const abort = () => { void worker.terminate(); };+ signal.addEventListener('abort', abort, { once: true });+ worker.once('error', error => fail(new CreatorExecutorError(+ 'stickman_remotion_worker_failed',+ error.message+ )));+ worker.once('exit', code => {+ if (settled) return;+ settled = true;+ cleanup();if (code === 0) resolve();else reject(new CreatorExecutorError('stickman_remotion_worker_failed',diff --git a/apps/daemon/test/unit/creator-stickman-remotion.test.ts b/apps/daemon/test/unit/creator-stickman-remotion.test.tsindex 2423d950..1f644c7e 100644--- a/apps/daemon/test/unit/creator-stickman-remotion.test.ts+++ b/apps/daemon/test/unit/creator-stickman-remotion.test.ts@@ -43,6 +43,38 @@ describe('stickman Remotion worker isolation', () => {});});+ it('runs the worker without spawning process.execPath as a Node executable', async () => {+ tempDir = mkdtempSync(join(tmpdir(), 'creator-stickman-remotion-success-'));+ const timelinePath = join(tempDir, 'timeline.json');+ writeFileSync(timelinePath, JSON.stringify({ fps: 30, width: 1280, height: 720, totalFrames: 30, shots: [] }));+ const successWorker = join(tempDir, 'success-worker.mjs');+ writeFileSync(successWorker, [+ "import { readFileSync, writeFileSync } from 'node:fs';",+ 'const request = JSON.parse(readFileSync(process.argv[2], \'utf8\'));',+ "writeFileSync(request.outputPath, 'fixture-video');",+ "writeFileSync(process.argv[3], JSON.stringify({ ok: true }));"+ ].join('\n'));+ const executor = createStickmanRemotionExecutor({+ ffprobePath: 'unused',+ runtimeRoot: tempDir,+ workerEntrypoint: successWorker,+ runtime: { root: tempDir, bundlePath: join(tempDir, 'bundle'), browserExecutable: join(tempDir, 'browser') },+ validateVideo: async () => ({ duration: 1, width: 1280, height: 720, hasVideo: true, hasAudio: true })+ });++ const result = await executor.run({+ stageRun: { id: 'stage-success', stageId: 'render-clean' },+ job: { id: 'job-success' },+ inputArtifacts: [{ id: 'timeline-1', kind: 'timeline_manifest', status: 'completed', path: timelinePath }],+ workdir: tempDir,+ reportProgress() {},+ signal: new AbortController().signal+ } as never);++ expect(result.outputs).toHaveLength(1);+ expect(existsSync(join(tempDir, 'landscape-clean.mp4'))).toBe(true);+ });+it('isolates worker crashes and cancellation without leaving a clean video', async () => {tempDir = mkdtempSync(join(tmpdir(), 'creator-stickman-remotion-'));const timelinePath = join(tempDir, 'timeline.json');