From 845bd638a7784d0859df047e16c61b8790b9a8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Wed, 4 Nov 2026 15:46:32 +0000 Subject: [PATCH] fix(producer): a drive that refuses frame links gets a copy, whatever code it refuses with (#7163) * fix(producer): a drive that refuses frame links gets a copy, whatever code it refuses with * fix(producer): an entry already where the frames go still gets cleared and relinked * test(producer): the relinked frame dir is read through its new link --- .../producer/src/services/render/shared.ts | 27 ++++----- .../src/services/windowsFrameStaging.test.ts | 58 +++++++++++++++++++ 2 files changed, 69 insertions(+), 16 deletions(-) diff --git a/packages/producer/src/services/render/shared.ts b/packages/producer/src/services/render/shared.ts index 1b7e64d60d..73b29c6e70 100644 --- a/packages/producer/src/services/render/shared.ts +++ b/packages/producer/src/services/render/shared.ts @@ -581,6 +581,11 @@ export function createMemorySampler(intervalMs: number = 250): MemorySampler { // One-time guard for the symlink→copy fallback notice below. let warnedSymlinkFallback = false; +const copyCannotFix = (error: unknown): boolean => + ["ENOSPC", "EDQUOT", "EEXIST", "ENOENT"].includes( + (error as NodeJS.ErrnoException | undefined)?.code ?? "", + ); + // Junctions avoid Windows symlink privileges. POSIX keeps its copy fallback. function tryWindowsFrameJunction( fileSystem: MaterializeFileSystem, @@ -592,30 +597,20 @@ function tryWindowsFrameJunction( fileSystem.symlinkSync(src, dest, "junction"); return true; } catch (error) { - const code = - error instanceof Error && "code" in error && typeof error.code === "string" - ? error.code - : undefined; - if ( - ["EPERM", "EACCES", "UNKNOWN", "EINVAL", "ENOSYS", "EOPNOTSUPP", "ENOTSUP"].includes( - code ?? "", - ) - ) { - return false; - } - throw error; + if (copyCannotFix(error)) throw error; + return false; } } -// Create the symlink, degrading to a copy on Windows' no-symlink-privilege -// errors (EPERM/EACCES, plus UNKNOWN), trying a Windows junction first. -// Other symlink errors and non-capability junction errors propagate. +// Create the symlink; a drive that refuses it, with any code, gets a Windows junction, then a copy. +// A full disk, a missing source or an entry already at dest (stageExtractedFrameDir clears a stale one) +// propagate: copying would not fix them. function linkOrCopyFrameDir(fileSystem: MaterializeFileSystem, src: string, dest: string): void { try { fileSystem.symlinkSync(src, dest, "dir"); } catch (err) { + if (copyCannotFix(err)) throw err; const code = (err as NodeJS.ErrnoException | undefined)?.code; - if (code !== "EPERM" && code !== "EACCES" && code !== "UNKNOWN") throw err; if (tryWindowsFrameJunction(fileSystem, src, dest)) return; // Copying is measurably slower than symlinking, so surface the degrade once // — it explains a render that suddenly got heavier and saves a support diff --git a/packages/producer/src/services/windowsFrameStaging.test.ts b/packages/producer/src/services/windowsFrameStaging.test.ts index 81913794d2..7a7b44b002 100644 --- a/packages/producer/src/services/windowsFrameStaging.test.ts +++ b/packages/producer/src/services/windowsFrameStaging.test.ts @@ -127,6 +127,19 @@ it("distributed materialization stays physically self-contained after cache remo expect(readFileSync(extracted.framePaths.get(0)!, "utf8")).toBe("frame bytes"); }); +it.skipIf(process.platform === "win32")( + "relinks over a dangling frame link left where the frames go", + () => { + const { root, compiled, extracted } = fixture(); + const dest = join(compiled, "__hyperframes_video_frames", "clip"); + mkdirSync(join(compiled, "__hyperframes_video_frames"), { recursive: true }); + symlinkSync(join(root, "collected-cache"), dest, "dir"); + materializeExtractedFramesForCompiledDir([extracted], compiled); + expect(lstatSync(dest).isSymbolicLink()).toBe(true); + expect(readFileSync(join(dest, "frame_000001.jpg"), "utf8")).toBe("frame bytes"); + }, +); + describe("Windows link fallbacks", () => { const platform = Object.getOwnPropertyDescriptor(process, "platform")!; beforeEach(() => Object.defineProperty(process, "platform", { value: "win32" })); @@ -157,6 +170,51 @@ describe("Windows link fallbacks", () => { }, ); + it.each(["EISDIR", "EIO", "EINVAL"])( + "copies after the drive refuses the symlink with %s and the junction too", + (code) => { + const { compiled, extracted } = fixture(); + const attempts: Array = []; + materializeExtractedFramesForCompiledDir([extracted], compiled, { + fileSystem: { + existsSync, + mkdirSync, + cpSync, + rmSync, + symlinkSync: (_target, _path, type) => { + attempts.push(type); + throw Object.assign(new Error("link refused"), { code }); + }, + }, + }); + expect(attempts).toEqual(["dir", "junction"]); + expect(lstatSync(extracted.outputDir).isSymbolicLink()).toBe(false); + expect(readFileSync(extracted.framePaths.get(0)!, "utf8")).toBe("frame bytes"); + }, + ); + + it("does not copy onto a disk the symlink found full", () => { + const { compiled, extracted } = fixture(); + const copy = vi.fn(); + const attempts: Array = []; + expect(() => + materializeExtractedFramesForCompiledDir([extracted], compiled, { + fileSystem: { + existsSync, + mkdirSync, + rmSync, + cpSync: copy, + symlinkSync: (_target, _path, type) => { + attempts.push(type); + throw Object.assign(new Error("disk full"), { code: "ENOSPC" }); + }, + }, + }), + ).toThrow("disk full"); + expect(attempts).toEqual(["dir"]); + expect(copy).not.toHaveBeenCalled(); + }); + it("does not hide a disk failure from the junction attempt", () => { const { compiled, extracted } = fixture(); const copy = vi.fn();