fix: handle cross-device rename in atomic_json_write#51
Open
on22s wants to merge 1 commit into
Open
Conversation
os.replace() raises OSError(EXDEV) when the source and destination are on different filesystems (Linux bind mounts, NAS shares, tmpfs-backed temp dirs). The retry loop only caught Windows file-locking errors (errno 5 / "Access is denied"), so EXDEV was re-raised immediately and every write to an affected path silently failed — chunks.json, voice_config.json, and LoRA manifests all go through this path. Add an EXDEV case that falls back to shutil.move(), which copies then deletes when os.rename() is unavailable across device boundaries. The fallback is not atomic, but avoids a hard failure in environments where the project directory is on a different filesystem than /tmp. errno.EXDEV is defined on all platforms Python supports (value 18; maps to ERROR_NOT_SAME_DEVICE on Windows). shutil.move() is likewise cross-platform. No behaviour change on same-device paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
atomic_json_write()inutils.pyusesos.replace()to rename a temp file over the target. On Linux,os.replace()raisesOSError(EXDEV, 'Invalid cross-device link')when the source and destination are on different filesystems — this affects bind-mounted project directories, NAS shares, and any setup where/tmpis on a different device than the project root.The existing retry loop only caught Windows file-locking errors (
errno 5/"Access is denied"), soEXDEVwas re-raised on the first attempt and the write failed permanently. Sincechunks.json,voice_config.json, and LoRA manifests all go throughatomic_json_write, this silently broke chunk saves and voice config saves on affected systems.Fix: Add an
EXDEVbranch that falls back toshutil.move(), which performs a copy-then-delete whenos.rename()is unavailable across device boundaries.Details
errno.EXDEVis defined on all platforms Python supports (value 18; maps toERROR_NOT_SAME_DEVICEon Windows)shutil.move()is cross-platformTest plan
python test_api.py— 55 passed, 0 failed, 13 skipped🤖 Generated with Claude Code