Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(mcp): keep an export record only when it matches its video

EtienneLescotd20552330685
diff --git a/electron/mcp/media-tools.test.ts b/electron/mcp/media-tools.test.ts
index 1ce39955f..2943f1b05 100644
--- a/electron/mcp/media-tools.test.ts
+++ b/electron/mcp/media-tools.test.ts
@@ -427,6 +427,35 @@ describe("getFrames on a project", () => {
expect(staleLabels[1]).toBe("6.00s on the ruler, 4.00s into the video");
});
+ it("keeps no record of an export the project changed during, or whose file was overwritten", async () => {
+ const first = await recordTake("First");
+ const out = path.join(dir, "demo.mp4");
+ runners.results.export = { success: true, outputPath: out };
+
+ runners.holdExport = true;
+ const exporting = call("exportVideo", { projectId: first.projectId, path: out });
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ await call("addTrim", { projectId: first.projectId, startSec: 2, endSec: 4 });
+ runners.releaseExport();
+ expect(textOf(await exporting)).toContain("changed while it exported");
+ expect(textOf(await call("getFrames", { projectId: first.projectId }))).toContain(
+ "no export yet",
+ );
+
+ runners.holdExport = false;
+ await call("exportVideo", { projectId: first.projectId, path: out });
+ expect(
+ (await call("getFrames", { projectId: first.projectId, atSec: [1] })).isError,
+ ).toBeFalsy();
+ // Another project's export to the same file replaces that video.
+ const second = await documents.createProject("Second");
+ await documents.addAsset(second.project.id, { path: videoPath });
+ await call("exportVideo", { projectId: second.project.id, path: out });
+ expect(textOf(await call("getFrames", { projectId: first.projectId }))).toContain(
+ "no export yet",
+ );
+ });
+
it("takes a project or a file, not both", async () => {
expect((await call("getFrames", {})).isError).toBe(true);
expect((await call("getFrames", { projectId: "p", path: "x.mp4" })).isError).toBe(true);
diff --git a/electron/mcp/media-tools.ts b/electron/mcp/media-tools.ts
index 53ef61306..f04901978 100644
--- a/electron/mcp/media-tools.ts
+++ b/electron/mcp/media-tools.ts
@@ -522,7 +522,21 @@ export function registerMediaTools(server: McpServer, deps: MediaToolDeps): void
if (!result.success) {
return text(`The export failed: ${result.error ?? "unknown error"}`, true);
}
- lastExports.set(args.projectId, { path: result.outputPath ?? outPath, at, rendered });
+ const written = result.outputPath ?? outPath;
+ // The file now holds this video: no other project's record may still point at it.
+ for (const [id, record] of lastExports) {
+ if (id !== args.projectId && record.path === written) lastExports.delete(id);
+ }
+ // The runner read the project file itself. Unless nothing was saved since `rendered`
+ // was read, it may have rendered another version, so this video gets no record.
+ const after = await deps.documents.getProject(args.projectId).catch(() => null);
+ if (after?.project.updatedAt !== rendered.project.updatedAt) {
+ lastExports.delete(args.projectId);
+ return text(
+ `${JSON.stringify({ path: result.outputPath, format: result.format, width: result.width, height: result.height })}\nThe project changed while it exported, so this video may not match it: export again before checking it with getFrames.`,
+ );
+ }
+ lastExports.set(args.projectId, { path: written, at, rendered });
return text(
JSON.stringify({
path: result.outputPath,