fix: prevent data loss in skills sync on copy/update failure#563
Merged
teknium1 merged 1 commit intoNousResearch:mainfrom Mar 7, 2026
Merged
Conversation
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.
Contributor
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.
Summary
Two bugs in
sync_skills()that cause silent data loss when filesystem operations fail:Bug 1: Failed copy poisons the manifest
When
shutil.copytreefails (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_hashruns 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 beforeshutil.copytreeruns. Ifcopytreethen fails, the skill is gone with no way to recover.Before:
rmtreethencopytree— no rollback on failure.After:
shutil.moveto.bakbackup, thencopytree. Ifcopytreefails, 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— patchescopytreeto raiseOSError, verifies the skill is NOT in the manifest, then runs sync again and verifies it succeedstest_failed_update_does_not_destroy_user_copy— patchescopytreeto fail during update, verifies the user's original skill directory still exists