fix(skills-hub): use atomic writes for lock.json, taps.json, and index cache#29699
Open
annguyenNous wants to merge 1 commit into
Open
fix(skills-hub): use atomic writes for lock.json, taps.json, and index cache#29699annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
Collaborator
7 tasks
HubLockFile.save() and TapsFile.save() used Path.write_text() which can leave corrupt JSON if the process is interrupted mid-write (crash, disk full, SIGKILL). On next startup the JSON parse fails and the fallback returns empty data — effectively forgetting all hub-installed skills and configured taps. Use tempfile.mkstemp + fsync + os.replace for atomic writes, matching the pattern already used by skill_usage.py and utils.py:atomic_json_write. Fixes corruption risk for hub skill state and tap configuration.
b0886c6 to
ea7100f
Compare
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.
Problem
Three file write sites in
tools/skills_hub.pyuse directwrite_text()which truncates the file before writing new content. If the process is killed mid-write (SIGKILL, OOM, power loss), the file is left empty or partially written, corrupting the data.Affected files:
HubLockFile.save()(line 2775) — writeslock.jsonwhich coordinates concurrent skill installs across multiple processes. Corruption here can break all subsequent skill operations.HubTapsFile.save()(line 2842) — writestaps.json(skill registry sources). Corruption loses all configured taps.Fix
Replace all three
write_text(json.dumps(...))calls withatomic_json_write()fromutils.py, which already implements the correct pattern:tempfile.mkstemp()+fsync()+os.replace().Diff: +4 lines, -4 lines (1 file)
Before vs After
Testing
ast.parse()passesatomic_json_write()is already used extensively in the codebase (cron/jobs.py, agent/memory_manager.py, etc.)