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: clean partial launch-video artifacts after failed delivery (#8649)
[._.]/ Adam Eivyf5ab03106faf
diff --git a/server/services/htmlComposition/index.js b/server/services/htmlComposition/index.jsindex 10b673fb2a..b437759165 100644--- a/server/services/htmlComposition/index.js+++ b/server/services/htmlComposition/index.js@@ -1,6 +1,7 @@import { join, resolve } from 'node:path';-import { copyFile, writeFile, realpath } from 'node:fs/promises';-import { constants } from 'node:fs';+import { open, realpath } from 'node:fs/promises';+import { createReadStream } from 'node:fs';+import { pipeline } from 'node:stream/promises';import { PATHS, ensureDir, unlinkGuarded } from '../../lib/fileUtils.js';import { htmlCompositionContractSchema, htmlCompositionRenderSchema, validateRequest } from '../../lib/validation.js';import { generateThumbnail } from '../../lib/ffmpeg.js';@@ -31,6 +32,12 @@ export async function renderComposition({ jobId, ...input }) {let result;let failure;const deliveredPaths = [];+ const deliver = async (target, write) => {+ const handle = await open(target, 'wx');+ // Record ownership after exclusive creation, before any fallible I/O.+ deliveredPaths.push(target);+ try { await write(handle); } finally { await handle.close(); }+ };try {const { directory, musicTrack, launchVideo } = validateRequest(htmlCompositionRenderSchema, input);const musicPath = musicTrack ? await resolveMusicTrackPath(musicTrack) : null;@@ -79,13 +86,11 @@ export async function renderComposition({ jobId, ...input }) {// validated snapshot, never re-read source prose after rendering.for (const name of ['plan.md', 'storyboard.json', 'caption.txt']) {const target = join(deliveryRoot, name);- await writeFile(target, launchAssets.get(`/${name}`), { flag: 'wx' });- deliveredPaths.push(target);+ await deliver(target, handle => handle.writeFile(launchAssets.get(`/${name}`)));}for (const [source, name] of [[outputPath, 'video.mp4'], [join(PATHS.videoThumbnails, thumbnail), 'poster.jpg']]) {const target = join(deliveryRoot, name);- await copyFile(source, target, constants.COPYFILE_EXCL);- deliveredPaths.push(target);+ await deliver(target, handle => pipeline(createReadStream(source), handle.createWriteStream()));}launchMetadata = { appId: launchVideo.appId, runId: launchVideo.runId,caption: launchAssets.get('/caption.txt').toString('utf8').trim(), posterSec: launchPlan.posterSec };diff --git a/server/services/htmlComposition/index.test.js b/server/services/htmlComposition/index.test.jsindex 4a835303f3..f98838da4f 100644--- a/server/services/htmlComposition/index.test.js+++ b/server/services/htmlComposition/index.test.js@@ -123,6 +123,12 @@ describe.skipIf(!chrome || !ffmpeg)('HTML composition with real Chrome and ffmpe'-vf', 'scale=1:1', '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-']);expect(pixel[0]).toBeGreaterThan(220);expect(pixel[2]).toBeLessThan(30);+ // Exclusive delivery cannot replace an earlier successful run on retry.+ const retryId = randomUUID();+ await expect(renderComposition({ ...input, jobId: retryId, launchVideo: { targetDurationSec: 15, appId: 'example', runId } })).rejects.toThrow(/EEXIST/);+ expect(await readFile(join(runRoot, 'video.mp4'))).toEqual(await readFile(join(PATHS.videos, result.filename)));+ expect((await readdir(PATHS.videos)).some(name => name.includes(retryId))).toBe(false);+ expect(await loadHistory()).not.toContainEqual(expect.objectContaining({ id: retryId }));}, 60000);it('refuses a remote request by its full URL and removes partial artifacts', async () => {