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

Claude Code and agent skill by kjuhwa/skills-hub

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

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

Install

npx vskill@latest install kjuhwa/skills-hub/atomic-audio-save-temp-rename

SKILL.md

The same SKILL.md was published earlier as kjuhwa/skills-hub/atomic-audio-save-temp-rename.

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).

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/kjuhwa/skills-hub/atomic-audio-save-temp-rename/badge)](https://verified-skill.com/skills/kjuhwa/skills-hub/atomic-audio-save-temp-rename)

Something wrong with this skill or its page? Tell us.