agentsclimarketplace

Atomic audio save temp rename

Skill kjuhwa/skills-hub/skills/python/atomic-audio-save-temp-rename

Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.

Install
npx -y skills add kjuhwa/skills-hub --skill atomic-audio-save-temp-rename

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Write audio (or any binary) atomically by staging to a sibling .tmp file and os.replace-ing it into place on success.

SKILL.md

2.4 KB, 447 tokens by cl100k_base, as published. Nobody here has run it

Atomic audio save (temp + rename)

When to use

Any process that writes user-visible output files (generated audio, rendered images, exported bundles) where a crash mid-write would leave a corrupt half-file that the app then tries to play / load on next startup.

Steps

  1. Accept the final path. Compute temp_path = f"{path}.tmp" in the same directory — same-volume guarantees os.replace is atomic.
  2. Path(path).parent.mkdir(parents=True, exist_ok=True) so downstream writes never fail on a missing data subdirectory.
  3. Write to temp_path. For soundfile.write, pass format='WAV' (or whatever container) explicitly because the .tmp extension does not match any recognized format and the default sniffer will raise.
  4. os.replace(temp_path, path). On POSIX and Win32 this is atomic — either old or new wins, never a truncated file.
  5. Wrap the whole thing in try/except. On exception, attempt to unlink the .tmp (best-effort try/except: pass) and re-raise as a clearly-labeled OSError("Failed to save audio to ...") with the original as __cause__.
  6. Return nothing / the final path. Never return from inside the try block before the os.replace.

Counter / Caveats

  • os.rename is NOT atomic on Windows if the destination exists; os.replace is. Always prefer os.replace.
  • The "same filesystem" requirement is the common pitfall — /tmp is frequently a separate volume. Keep the .tmp sibling.
  • If the caller is interrupted after the write but before the replace, you'll leave an orphan .tmp. A startup-time cleanup ("delete .tmp files older than N minutes in data dirs") is a reasonable sweep if you care.
  • For large files, consider fsync(temp_fd) before rename to guarantee durability — os.replace is atomic but the new content may still be in the page cache until fsync.

Source references: backend/utils/audio.py (save_audio).

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.