commit 3218b23231a6105773feeed9fa09525c017ca1bb
parent f083298e8958a03ee3a99a1acacb3f6b2bd5a8e5
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 23:27:39 -0500
umtool: the intro-play flake -- a take's play manifest written twice at once no longer loses a rename
intro-play's last step (Play on v1, its intro back on) failed in multi-spec runs (L8a, L4) with "the intro did
not compose: ENOENT ... rename '.take-v1.play.json.<pid>.tmp' -> '.take-v1.play.json'" (L4's trace). Opening
a take, Play asks the chrome preview and the intro for its pages together, and both routes call
writePlayManifest in the one server process -- with the tmp named `<file>.<pid>.tmp`, so the first rename took
the second's tmp. The race was the shared scratch file, not the take file or a cache: each write now has its
own tmp (`<file>.<pid>.<n>.tmp`) and the last rename wins (both write the take as it is). No sleep.
Test: takeManifest.test.mjs writes one take's play manifest twelve times at once -- every call lands, one
document is on disk, no tmp is left; it fails on the old name.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/umtool/lib/report/takeManifest.mjs b/umtool/lib/report/takeManifest.mjs
@@ -206,10 +206,17 @@ export async function cachedTakeManifest(projectDir, id) {
return value;
}
-/** Write a take's play manifest (tmp + rename); returns its path. */
+// Each write's own tmp name. Play asks for a take's pages twice at once when it opens one -- the chrome preview
+// (POST /api/report/chrome/preview) and the intro (POST /api/report/chrome/intro) both write this file, in one
+// server process -- and with `<file>.<pid>.tmp` the two shared the tmp: the first rename took it, the second
+// failed ENOENT, and Play said "the intro did not compose" (the intro-play flake, L8a/L4, 9 Nov). The last
+// rename wins; both write the same take as it is.
+let playManifestSeq = 0;
+
+/** Write a take's play manifest (tmp + rename); returns its path. Safe to call concurrently. */
export async function writePlayManifest(projectDir, id, manifest) {
const file = playManifestPath(projectDir, id);
- const tmp = `${file}.${process.pid}.tmp`;
+ const tmp = `${file}.${process.pid}.${++playManifestSeq}.tmp`;
await writeFile(tmp, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
await rename(tmp, file);
return file;
diff --git a/umtool/lib/report/takeManifest.test.mjs b/umtool/lib/report/takeManifest.test.mjs
@@ -123,3 +123,19 @@ test("the play manifest is written beside the project's; the cache follows the f
await rm(dir, { recursive: true, force: true });
}
});
+
+test("two writes of one take's play manifest at once both land (Play's preview and intro ask together)", async () => {
+ const dir = await project();
+ try {
+ // Before, both used `<file>.<pid>.tmp`: one rename took the other's tmp and the second threw ENOENT.
+ const docs = Array.from({ length: 12 }, (_, i) => ({ timeline: [], n: i }));
+ const files = await Promise.all(docs.map((d) => writePlayManifest(dir, "short", d)));
+ assert.ok(files.every((f) => f === playManifestPath(dir, "short")));
+ const n = JSON.parse(await readFile(playManifestPath(dir, "short"), "utf8")).n;
+ assert.ok(Number.isInteger(n) && n >= 0 && n < docs.length);
+ const { readdir } = await import("node:fs/promises");
+ assert.deepEqual((await readdir(dir)).filter((f) => f.endsWith(".tmp")), []);
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});