fix: prune stale install_meta skill/plugin rows whose files were deleted#78
Open
SherlockSalvatore wants to merge 1 commit into
Open
Conversation
sync_extensions and sync_extensions_for_agent exempted every install_meta row from stale cleanup, so a skill or plugin whose files the user deleted (e.g. rm -rf ~/.claude) lingered forever as a ghost row in the Extensions list. Narrow the exemption via a shared stale_row_should_prune predicate used by both sync paths: CLI binaries (flaky detection) stay exempt, and file-backed rows with install_meta are kept only while their source_path still exists on disk β a genuine delete is pruned, a transient scan gap is not. Scanned MCP/hook entries carry no install_meta and were already pruned by the existing path, so this concretely targets skill (SKILL.md) and plugin (dir) rows. Add regression tests: decision matrix, plus ghost pruning through both the global and per-agent sync paths.
24a1d39 to
ebe4664
Compare
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
Fixes #77. A skill or plugin whose files were deleted from disk (e.g.
rm -rf ~/.claude) lingered forever as a ghost row in the Extensions list, still attributed to the agent it was installed under.Root cause
sync_extensionsandsync_extensions_for_agentexempted every row carryinginstall_metafrom stale cleanup. That exemption is meant for CLI binaries, whose detection can transiently fail on startup (a CLI is resolved viaPATH, which a GUI app may not fully inherit), so "missing from one scan" isn't proof it was removed. But the rule didn't look at the extension kind, so file-backed kinds (skill, plugin) were kept too β and a skill is a concrete file on disk, so "missing from scan" does mean the file is gone.(Scanned MCP/hook entries carry no
install_metaβ they're entries in a shared config file β so they never hit this exemption and were already pruned by the normal path. This bug only affected skill/plugin.)Fix
Narrow the exemption via a shared
stale_row_should_prunepredicate used by both sync paths:install_metaβ kept (flaky binary detection);install_metarows β kept only while theirsource_pathstill exists on disk; pruned once the file is gone.This removes ghosts after a real delete while still tolerating a transient scan gap (if the file is still on disk, the row is kept). Only the DB row is deleted β no on-disk files are touched. No schema change.
Test plan
cargo test -p hk-coreβ 492 passing, incl. three new tests:test_stale_row_should_prune_decisionβ the keep/prune decision matrixtest_sync_prunes_ghost_skill_when_files_deletedβ global path: ghost pruned, live skill kept, CLI kepttest_sync_for_agent_prunes_ghost_skill_with_install_metaβ same through the per-agent pathcargo clippy -p hk-coreclean (no new warnings)Before / After
Before (ghost row still listed under the agent):
After (ghost row gone after rescan):