Skip to content

merge-mode prune deletes live links into the source that skillshare never created #314

Closed

Description

@star-nebula

Summary

In merge mode, skillshare sync removes any entry in a target directory that (a) is a
symlink/junction, (b) resolves to a path under the skills source, and (c) is not in the
target's current include/exclude resolution. Provenance is never checked, so links created
by the user or by another tool are deleted even though skillshare never managed them.

The manifest already records every link skillshare creates, and the sibling branches of this
same function already use it as the ownership test. The link branch is the one place that
does not.

Reproduction

Released binary (skillshare version → 0.22.0), isolated APPDATA, nothing else on the
machine involved. Paths abbreviated as <root>.

<root>/src/alpha/SKILL.md          (name: alpha)
<root>/src/handmade/SKILL.md       (name: handmade)
<root>/tgt/                        (empty pool)

config:

sources:
  skills: <root>/src
mode: merge
targets:
  mypool:
    skills:
      path: <root>/tgt
      include:
        - alpha

Create the second entry by hand, as a Windows junction (no privileges needed) pointing at a
live source skill — i.e. exactly the shape skillshare itself produces:

mklink /J <root>\tgt\handmade <root>\src\handmade

Preview, then sync:

$ skillshare sync --dry-run -g
[dry-run] Would remove orphan symlink to source: <root>\tgt\handmade
  mypool: merged (1 linked, 0 local, 0 updated, 1 pruned)

$ skillshare sync -g
  mypool: merged (1 linked, 0 local, 0 updated, 1 pruned)

$ ls <root>/tgt
alpha@            # handmade is gone; it was never in the manifest and skillshare never made it

skillshare trash list is empty afterwards — the link is not recoverable through restore.

Impact in a real multi-tool setup

I run one source (241 skill directories) against 12 tool pools, ~663 per-skill links, of
which a substantial share are links I created by hand before adopting skillshare as the
writer. One unqualified sync removed 140 of them. The skill content itself was not lost
(the links point at the source), but the wiring that made each tool see those skills was,
silently and per-name, and it is not covered by backup/restore/trash.

Root cause

internal/sync/sync.go, PruneOrphanLinksWithSkills:

			if utils.PathHasPrefix(absLink, absSource+string(filepath.Separator)) {
				if !targetExists {
					shouldRemove = true
					reason = "broken symlink to source"
				} else {
					shouldRemove = true
					reason = "orphan symlink to source"      // <- no provenance test
				}
			}

targetExists is only used to pick the reason string; a live link and a dangling one are
treated identically. Note the asymmetry inside this same function a few lines further down —
the directory branch does ask the manifest:

			} else if info.IsDir() {
				if _, inManifest := manifest.Managed[name]; inManifest {
					shouldRemove = true
					reason = "orphan skillshare-managed directory (manifest)"
				}

and copy-mode pruning is manifest-driven by construction (internal/sync/copy.go,
PruneOrphanCopiesWithSkills iterates for entryName := range manifest.Managed). Merge-mode
links are the only case that deletes on a path heuristic.

Skillshare has the information needed to be right here: SyncTargetMergeWithSkills writes
manifest.Managed[name] = "symlink" for every link it creates (internal/sync/sync.go,
manifest write block at the end of the merge routine).

Why I read this as a bug rather than an intended rule

website/docs/reference/targets/configuration.md ("Existing target entries when filters
change") lists four rows: source-linked entries now filtered out → removed; managed copies →
removed; local non-symlink directory → preserved; unrelated local content → preserved.
A link the user made themselves and skillshare never tracked is the fourth row, but the
implementation sorts it into the first, because "source-linked" is evaluated as "resolves
under the source" instead of "linked by skillshare". The same wording in
website/docs/reference/commands/sync.md ("What gets removed when filters change") carries
the ambiguity.

Same class, two more places (not proposed for this fix, for scoping)

  • internal/sync/agent_sync.go, PruneOrphanAgentLinks: removes any .md link whose name is
    not expected, with neither a source-prefix nor a provenance test.
  • internal/sync/extras.go, PruneExtraTarget → pruneExtraOrphans(targetPath, map[string]bool{}, mode):
    with an empty managed set, merge-mode pruning deletes symlinks under the target on the same
    "it is a link" basis.

Proposed change

Narrow the link branch to provenance, keeping every documented row true for links skillshare
owns:

  • broken link into source → still removed (nothing of the user's is involved);
  • live link into source that is in manifest.Managed, or force is set → still removed
    (today's documented behaviour, incl. the include/exclude change case);
  • live link into source that skillshare never created → kept, reported as a local entry
    like the directory branch does, so sync output shows it under the existing N local
    counter;
  • --force stays the documented escape hatch for reclaiming a name.

I have this working as a 4-file change (53 insertions / 5 deletions): the link branch, one
regression test that fails on unpatched main at three assertions and passes with the change,
and the two English doc lines that carry the ambiguity. All 12 TestPruneOrphanLinks* tests pass
and none of the existing ones needed editing; ./internal/... is green (27 packages, 0 failures)
under Go 1.25.6 on Linux, re-checked against current main today. Happy to open it as a PR if you
want the shape on the table rather than in prose, or to hold it until the rule is agreed here.

Environment: released 0.22.0 binary on Windows 11 for the reproduction (the hand-made link is an
mklink /J junction, which needs no privileges); main @ bcb8c6c781d86c656f1fb7fdc95ca73ebbaecb7c
for the code reading and the regression test.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions