kjuhwa/skills-hub/atomic-audio-save-temp-rename
Claude Code and agent skill by kjuhwa/skills-hub
Trust tier 2
- community
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-renameSKILL.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
- Accept the final
path. Computetemp_path = f"{path}.tmp"in the same directory — same-volume guaranteesos.replaceis atomic. Path(path).parent.mkdir(parents=True, exist_ok=True)so downstream writes never fail on a missing data subdirectory.- Write to
temp_path. Forsoundfile.write, passformat='WAV'(or whatever container) explicitly because the.tmpextension does not match any recognized format and the default sniffer will raise. os.replace(temp_path, path). On POSIX and Win32 this is atomic — either old or new wins, never a truncated file.- Wrap the whole thing in try/except. On exception, attempt to unlink the
.tmp(best-efforttry/except: pass) and re-raise as a clearly-labeledOSError("Failed to save audio to ...")with the original as__cause__. - Return nothing / the final path. Never return from inside the try block before the
os.replace.
Counter / Caveats
os.renameis NOT atomic on Windows if the destination exists;os.replaceis. Always preferos.replace.- The "same filesystem" requirement is the common pitfall —
/tmpis frequently a separate volume. Keep the.tmpsibling. - 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.replaceis 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
- SKILL.md in the repositoryCheckingskills/python/atomic-audio-save-temp-rename/SKILL.md
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
[](https://verified-skill.com/skills/kjuhwa/skills-hub/atomic-audio-save-temp-rename)