Skip to content

Commit ebb02ca

Browse files
committed
fix(producer): reset distributed plan scratch state
1 parent d699cbf commit ebb02ca

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎packages/producer/src/services/distributed/plan.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,12 @@ export async function plan(
839839
}
840840

841841
const workDir = join(planDir, ".plan-work");
842-
if (!existsSync(workDir)) mkdirSync(workDir, { recursive: true });
842+
// `.plan-work` is planner-owned scratch space. A prior attempt can fail
843+
// before the end-of-plan cleanup and leave compiled assets behind; cpSync
844+
// and compileStage both overlay their outputs, so reusing that directory
845+
// would let stale bytes contaminate the new plan and its size check.
846+
rmSync(workDir, { recursive: true, force: true });
847+
mkdirSync(workDir, { recursive: true });
843848
const compiledDir = join(workDir, "compiled");
844849

845850
// Pre-seed the compiled directory with `projectDir`'s local assets

‎packages/producer/src/services/distributed/planSizeCap.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,31 @@ describe("plan() early size budget", () => {
320320
});
321321

322322
describe("plan() reused directory size check", () => {
323+
it("clears stale compiled scratch from a failed prior attempt", async () => {
324+
const projectDir = mkdtempSync(join(runRoot, "project-reused-work-dir-"));
325+
writeFileSync(join(projectDir, "index.html"), FIXTURE_HTML, "utf-8");
326+
const planDir = mkdtempSync(join(runRoot, "plandir-reused-work-dir-"));
327+
const staleCompiledDir = join(planDir, ".plan-work", "compiled");
328+
mkdirSync(staleCompiledDir, { recursive: true });
329+
writeFileSync(join(staleCompiledDir, "stale-large-asset.bin"), Buffer.alloc(100_000));
330+
331+
const result = await plan(
332+
projectDir,
333+
{
334+
fps: 30,
335+
width: 320,
336+
height: 240,
337+
format: "mp4",
338+
planDirSizeLimitBytes: 4_096,
339+
},
340+
planDir,
341+
);
342+
343+
expect(result.planHash).toMatch(/^[0-9a-f]{64}$/);
344+
expect(existsSync(join(planDir, "compiled", "stale-large-asset.bin"))).toBe(false);
345+
expect(measurePlanDirBytes(planDir)).toBeLessThan(4_096);
346+
}, 30_000);
347+
323348
it("ignores stale freeze-owned metadata that the new plan overwrites", async () => {
324349
const projectDir = mkdtempSync(join(runRoot, "project-reused-plan-dir-"));
325350
writeFileSync(join(projectDir, "index.html"), FIXTURE_HTML, "utf-8");

0 commit comments

Comments
 (0)