Skip to content

fix: prevent data loss in skills sync on copy/update failure#563

Merged
teknium1 merged 1 commit intoNousResearch:mainfrom
0xbyt4:fix/skills-sync-error-handling
Mar 7, 2026
Merged

fix: prevent data loss in skills sync on copy/update failure#563
teknium1 merged 1 commit intoNousResearch:mainfrom
0xbyt4:fix/skills-sync-error-handling

Conversation

@0xbyt4
Copy link
Contributor

@0xbyt4 0xbyt4 commented Mar 7, 2026

Summary

Two bugs in sync_skills() that cause silent data loss when filesystem operations fail:

Bug 1: Failed copy poisons the manifest

When shutil.copytree fails (disk full, permission error, etc.), the skill is still recorded in the manifest. On the next sync, the skill appears as "in manifest but not on disk" — which is interpreted as "user deliberately deleted it." The skill is never retried.

Before: manifest[skill_name] = bundled_hash runs unconditionally after the try/except block.
After: Only written to manifest on successful copy or when the destination already exists.

Bug 2: Failed update destroys the user's copy

shutil.rmtree(dest) deletes the user's skill directory before shutil.copytree runs. If copytree then fails, the skill is gone with no way to recover.

Before: rmtree then copytree — no rollback on failure.
After: shutil.move to .bak backup, then copytree. If copytree fails, the backup is restored.

Test plan

Both bugs are proven by regression tests that fail on the old code and pass on the fix:

  • test_failed_copy_does_not_poison_manifest — patches copytree to raise OSError, verifies the skill is NOT in the manifest, then runs sync again and verifies it succeeds
  • test_failed_update_does_not_destroy_user_copy — patches copytree to fail during update, verifies the user's original skill directory still exists
uv run pytest tests/tools/test_skills_sync.py -v   # 29 passed

Two bugs in sync_skills():

1. Failed copytree poisons manifest: when shutil.copytree fails (disk
   full, permission error), the skill is still recorded in the manifest.
   On the next sync, the skill appears as "in manifest but not on disk"
   which is interpreted as "user deliberately deleted it" — the skill
   is never retried.  Fix: only write to manifest on successful copy.

2. Failed update destroys user copy: rmtree deletes the existing skill
   directory before copytree runs. If copytree then fails, the user's
   skill is gone with no way to recover.  Fix: move to .bak before
   copying, restore from backup if copytree fails.

Both bugs are proven by new regression tests that fail on the old code
and pass on the fix.
@teknium1 teknium1 merged commit 6cd3bc6 into NousResearch:main Mar 7, 2026
1 check passed
@teknium1
Copy link
Contributor

teknium1 commented Mar 7, 2026

Merged in 6cd3bc6. Thanks @0xbyt4 — both bugs were real and the fixes are clean. The backup+restore pattern for updates is exactly the right approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants