Skip to content

A local video studio for your coding agent. Describe a video in one sentence: your agent directs, your machine renders. Claude Code, Codex, Cursor, Devin and more. No API keys, no uploads.

Windows: write_json retries a replace another process holds (parallel audio mix runs into one folder)

Favio Vázquez4fefc9a2f853
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 57faaad..86aa6b7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,17 @@ All notable changes to showtime. Each entry says what changed and why, so this f
## 0.4.2 (2026-10-10)
+- **On Windows, `audio mix` runs writing into one folder at once no longer fail with "permission denied".**
+ Several `showtime audio mix` runs of one `mix.json` whose outputs go into one folder share its `mix.report.json`.
+ On Windows, replacing a file that another process is replacing or has open at that moment fails for a few
+ milliseconds with "Access is denied", so one mix could exit with `permission denied:
+ ...\.mix.report.json.<random>` (the end-to-end test of the 0.4.2 release PR on windows-2025). Every JSON file
+ showtime writes atomically (`write_json`) now retries that replace for up to 2 s, as run records already did, and
+ a "permission denied" on a rename names both paths and the Windows error code. `showtime render` was not affected:
+ each render mixes into its own folder. Test: `test_foundation.py`
+ (`test_write_json_retries_a_replace_another_process_holds`,
+ `test_permission_denied_names_both_sides_of_a_rename`); `test_audio.py` (`test_08_parallel_mixes_share_the_cache`)
+ is the end-to-end case.
- **Docs, second pass: stale `--workers` and splice help, the voice Essentials, "Whisper for transcripts", and a doctor pointer.**
Left over from the 0.4.2 audit: `render --help` still described the old one-browser-per-8-threads rule and a splice
"mixed again" audio it now reuses; the README repeated the old worker rule; `voice.md` listed the fit command without
diff --git a/skills/showtime/lib/st/cli.py b/skills/showtime/lib/st/cli.py
index b7af8a4..a984065 100644
--- a/skills/showtime/lib/st/cli.py
+++ b/skills/showtime/lib/st/cli.py
@@ -157,7 +157,12 @@ def explain(exc: BaseException) -> ShowtimeError:
return ShowtimeError("file not found: %s" % (exc.filename or exc),
hint="check the path (relative paths start from %s)" % os.getcwd())
if isinstance(exc, PermissionError):
- return ShowtimeError("permission denied: %s" % (exc.filename or exc),
+ what = exc.filename or exc
+ if exc.filename and getattr(exc, "filename2", None): # a rename: name both sides
+ what = "%s -> %s" % (exc.filename, exc.filename2)
+ if exc.filename and getattr(exc, "winerror", None): # str(exc) already carries it otherwise
+ what = "%s [WinError %d]" % (what, exc.winerror)
+ return ShowtimeError("permission denied: %s" % (what,),
hint="choose a folder you can write to, or fix the file's permissions")
if isinstance(exc, OSError) and exc.errno == _errno.ENOSPC:
return ShowtimeError("the disk is full", why=str(exc),
diff --git a/skills/showtime/lib/st/common.py b/skills/showtime/lib/st/common.py
index 9671f1e..4ade4ce 100644
--- a/skills/showtime/lib/st/common.py
+++ b/skills/showtime/lib/st/common.py
@@ -416,6 +416,23 @@ def _file_mode() -> int:
return 0o666 & ~old
+# Windows refuses to replace a file another process is replacing or has open, for a few milliseconds
+# (several `audio mix` runs writing into one folder share its mix.report.json): retry before giving up.
+REPLACE_RETRY_S = 2.0
+
+
+def _replace(src: str, dst: str) -> None:
+ t_end = time.time() + REPLACE_RETRY_S
+ while True:
+ try:
+ os.replace(src, dst)
+ return
+ except PermissionError:
+ if time.time() > t_end:
+ raise
+ time.sleep(0.05)
+
+
def write_json(path: PathLike, data: Any, indent: int = 2) -> Path:
"""Write JSON atomically (temp file + replace), UTF-8, trailing newline, normal file permissions."""
p = Path(path)
@@ -429,7 +446,7 @@ def write_json(path: PathLike, data: Any, indent: int = 2) -> Path:
os.chmod(tmp, _file_mode())
except OSError:
pass
- os.replace(tmp, str(p))
+ _replace(tmp, str(p))
except BaseException:
try:
os.unlink(tmp)
diff --git a/skills/showtime/tests/test_audio.py b/skills/showtime/tests/test_audio.py
index 03d5fbd..1cb13c2 100644
--- a/skills/showtime/tests/test_audio.py
+++ b/skills/showtime/tests/test_audio.py
@@ -531,7 +531,8 @@ print(json.dumps({"path": p.name, "names": sorted(x.name for x in d.iterdir()),
# ------------------------------------------------------------------ final pass: parallel renders, license
def test_08_parallel_mixes_share_the_cache(self):
- """Three renders of one project (16:9, 1:1, 9:16) mix at the same moment: synth hits, a typewriter and
+ """Three `audio mix` runs of one mix.json into one folder at the same moment (as three renders of one
+ project, 16:9, 1:1, 9:16, share the cache): synth hits, a typewriter and
a composed bed land in the shared cache without a collision (a per-process temp name + atomic
rename, a lock per entry), every mix succeeds and they are identical. No temp or lock file is left."""
import numpy as np
diff --git a/skills/showtime/tests/test_foundation.py b/skills/showtime/tests/test_foundation.py
index de7c73a..36984e8 100644
--- a/skills/showtime/tests/test_foundation.py
+++ b/skills/showtime/tests/test_foundation.py
@@ -225,6 +225,40 @@ class TestCommon(TempDirCase):
self.assertEqual(common.parse_time("1:02.5"), 62.5)
+ def test_write_json_retries_a_replace_another_process_holds(self):
+ # Windows: os.replace fails with PermissionError while another process replaces the same file
+ from unittest import mock
+ real, calls = os.replace, []
+
+ def flaky(src, dst):
+ calls.append(dst)
+ if len(calls) < 3:
+ raise PermissionError(13, "Access is denied", dst)
+ real(src, dst)
+ with mock.patch.object(common.os, "replace", flaky):
+ p = common.write_json(self.tmp / "r.json", {"ok": 1})
+ self.assertEqual(len(calls), 3)
+ self.assertEqual(common.read_json(p), {"ok": 1})
+ self.assertEqual([f.name for f in self.tmp.iterdir()], ["r.json"], "no temp file left behind")
+ with mock.patch.object(common, "REPLACE_RETRY_S", 0.1), \
+ mock.patch.object(common.os, "replace", mock.Mock(side_effect=PermissionError(13, "denied"))):
+ with self.assertRaises(PermissionError):
+ common.write_json(self.tmp / "s.json", {"ok": 2})
+ self.assertEqual(sorted(f.name for f in self.tmp.iterdir()), ["r.json"], "a failed write cleans up")
+
+ def test_permission_denied_names_both_sides_of_a_rename(self):
+ from st import cli
+ e = PermissionError(13, "Access is denied")
+ e.filename, e.filename2 = "a.tmp", "a.json"
+ self.assertIn("permission denied: a.tmp -> a.json", str(cli.explain(e)))
+ self.assertIn("permission denied: b.json", str(cli.explain(PermissionError(13, "denied", "b.json"))))
+ e.winerror = 5 # Windows sets it; settable by hand on every OS
+ self.assertIn("a.tmp -> a.json [WinError 5]", str(cli.explain(e)))
+ bare = PermissionError(13, "Access is denied")
+ bare.winerror = 5 # no file name: only Windows' str(exc) prints the code
+ self.assertEqual(str(cli.explain(bare)).count("WinError 5"), 1 if os.name == "nt" else 0)
+
+
class TestWindowsText(TempDirCase):
"""Text that Windows produces: UTF-8 files with a byte-order mark (Windows PowerShell 5.1's
Set-Content/Out-File -Encoding utf8, older Notepad) and ANSI-code-page pipes (cp1252)."""