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.
annguyenNous
force-pushed
the
fix/skills-hub-atomic-writes
branch
from
May 29, 2026 01:51
b0886c6 to
ea7100f
Compare
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for addressing a real persistence-risk path. Current main still uses direct writes in HubLockFile.save() (tools/skills_hub.py:3406) and TapsManager.save() (tools/skills_hub.py:3481).
Problems
- The PR duplicates an atomic-write implementation. Calling
os.replace(tmp_path, self.path)directly does not preserve a target symlink or its existing permissions. The establishedatomic_json_write()path usesatomic_replace()for symlink preservation and restores existing ownership/mode (utils.py:91-136,utils.py:163-208). - The PR body promises index-cache protection, but the diff changes only the two save methods. The centralized cache remains a direct write at
tools/skills_hub.py:3848; the shared cache writers attools/skills_hub.py:1147andtools/skills_hub.py:3366are also direct writes. - No tests were added for the two save methods.
Suggested changes
- Replace both local tempfile blocks with the existing
atomic_json_write()helper. - Include the intended cache paths or narrow the PR claim to the two persistent files.
- Add focused wiring tests for both save methods.
Automated hermes-sweeper review.
|
|
||
| def save(self, data: dict) -> None: | ||
| import tempfile | ||
| self.path.parent.mkdir(parents=True, exist_ok=True) |
Contributor
There was a problem hiding this comment.
Please use utils.atomic_json_write() for both save methods instead of duplicating the tempfile flow. The shared helper preserves target symlinks through atomic_replace() and restores existing owner/mode; direct os.replace(tmp_path, self.path) does neither.
19 tasks
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.)