Skip to content

fix(skills): handle read-only files when cleaning up skill sync backups#35182

Closed
TKwave wants to merge 1 commit into
NousResearch:mainfrom
TKwave:fix/skill-sync-readonly-cleanup
Closed

fix(skills): handle read-only files when cleaning up skill sync backups#35182
TKwave wants to merge 1 commit into
NousResearch:mainfrom
TKwave:fix/skill-sync-readonly-cleanup

Conversation

@TKwave

@TKwave TKwave commented May 30, 2026

Copy link
Copy Markdown

Summary

Bundled skill sync leaves .bak directories when backup files are read-only (e.g. Nix store). The cleanup fails silently because shutil.rmtree(backup, ignore_errors=True) ignores errors.

Fix

Added _rmtree_readonly() helper that uses onerror handler to chmod read-only files before removal. Replaced the silent shutil.rmtree call.

Changes

  • tools/skills_sync.py: +13 lines (helper function + replacement call)

Fixes #34860

sync_skills() uses shutil.rmtree(backup, ignore_errors=True) to clean up
backup directories after a successful update. When files are read-only
(e.g. read from a Nix store or mounted read-only filesystem), the removal
fails silently and leaves .bak directories behind. These stale backups
interfere with subsequent sync runs.

Add a _rmtree_readonly() helper that catches PermissionError/readonly
errors, flips the file writable with os.chmod, and retries the removal.
Replace the silent-ignore rmtree call with this helper so backup cleanup
succeeds even on read-only file trees.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have tool/skills Skills system (list, view, manage) area/nix Nix flake, NixOS module, container packaging labels May 30, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competes with #35131 which fixes the same #34860 issue (read-only .bak cleanup) plus additionally fixes #34972 (transaction ordering in reset_bundled_skill). This PR is a strict subset of #35131's scope.

@teknium1

Copy link
Copy Markdown
Contributor

Superseded by #35251 (merged), which fixes the same read-only-rmtree class plus the underlying transaction-ordering bug in reset_bundled_skill (#34972). Your backup-cleanup fix in sync_skills was a correct subset — that path now uses the same writable rmtree helper. Thanks for the contribution!

@teknium1 teknium1 closed this May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/nix Nix flake, NixOS module, container packaging 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.

[Bug]: bundled skill sync can leave stale .bak directories

4 participants