Skip to content

fix(skills_hub): use atomic writes for lock.json and taps.json#16440

Open
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/skills-hub-atomic-write
Open

fix(skills_hub): use atomic writes for lock.json and taps.json#16440
vominh1919 wants to merge 1 commit into
NousResearch:mainfrom
vominh1919:fix/skills-hub-atomic-write

Conversation

@vominh1919

Copy link
Copy Markdown
Contributor

Problem

tools/skills_hub.py has two save() methods that write JSON state files non-atomically using write_text():

  1. HubLockFile.save() (line ~2565): writes skills/.hub/lock.json — tracks installed skills, trust levels, and hashes
  2. TapsManager.save() (line ~2632): writes taps.json — tracks custom skill source taps

If 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):

  1. tempfile.mkstemp(dir=parent_dir) — create temp file in same directory (same filesystem for atomic rename)
  2. os.write(fd, payload.encode()) — write full JSON payload
  3. os.replace(tmp, path) — atomic rename on POSIX
  4. except BaseException: os.unlink(tmp); raise — cleanup on failure

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
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/tools Tool registry, model_tools, toolsets tool/skills Skills system (list, view, manage) labels Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have tool/skills Skills system (list, view, manage) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants