fix(skills_hub): use atomic writes for lock.json and taps.json#16440
Open
vominh1919 wants to merge 1 commit into
Open
fix(skills_hub): use atomic writes for lock.json and taps.json#16440vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
Use tempfile.mkstemp + os.replace pattern instead of write_text() so that a crash mid-write cannot corrupt lock.json or taps.json. The old approach would leave a truncated file if the process was killed after truncating but before the full write completes, losing all installed skill state. Pattern: 1. mkstemp in same parent dir (same filesystem for atomic rename) 2. write payload via os.write 3. os.replace(tmp, target) — atomic on POSIX 4. on any error, unlink the temp file and re-raise
This was referenced May 18, 2026
7 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
tools/skills_hub.pyhas twosave()methods that write JSON state files non-atomically usingwrite_text():skills/.hub/lock.json— tracks installed skills, trust levels, and hashestaps.json— tracks custom skill source tapsIf the process is killed mid-write (OOM, signal, power loss), the file is truncated/corrupted and all installed skill state is lost.
Fix
Replace
write_text()with the atomic write pattern used elsewhere in the codebase (e.g.memory_tool.py:441,mcp_oauth.py:161,skill_manager_tool.py:306):tempfile.mkstemp(dir=parent_dir)— create temp file in same directory (same filesystem for atomic rename)os.write(fd, payload.encode())— write full JSON payloados.replace(tmp, path)— atomic rename on POSIXexcept BaseException: os.unlink(tmp); raise— cleanup on failure