Skip to content

fix(sync): prune only links skillshare created - #315

Merged
runkids merged 1 commit into
runkids:mainfrom
star-nebula:fix/prune-link-provenance
Oct 1, 2026
Merged

runkids merged 1 commit into
runkids:mainfrom
star-nebula:fix/prune-link-provenance

Conversation

@star-nebula

Copy link
Copy Markdown
Contributor

What

merge-mode prune stops deleting links it never created.

PruneOrphanLinksWithSkills removed any target entry that was a symlink/junction resolving
under the skills source and was not in the current filter resolution, without asking whether
skillshare had created it. Provenance is already recorded — SyncTargetMergeWithSkills writes
manifest.Managed[name] = "symlink" for every link it creates — and the directory branch of
this same function, and all of copy-mode pruning, already consult the manifest. This applies
the same rule to links:

case before after
link into source, target gone removed removed (unchanged)
link into source, in manifest (e.g. now filtered out) removed removed (unchanged)
link into source, not in manifest removed kept, counted as local
same with --force removed removed (escape hatch kept)

A kept link is appended to PruneResult.LocalDirs, which sync_parallel.go already folds into
the merged (N linked, M local, …) line, so no output plumbing changes.

Reproduction

Reported in #314 with a full transcript. Short version, released 0.22.0 binary on Windows,
isolated config, one source skill handmade outside the target's include, linked in by hand
with mklink /J:

$ skillshare sync -g
  mypool: merged (1 linked, 0 local, 0 updated, 1 pruned)   # ← a link skillshare never made

Reproduced on a real 12-target / 663-link pool where one unqualified sync removed 140
hand-made links; content survived in the source, the wiring did not, and it was not in trash.

Tests

internal/sync/merge_test.go adds TestPruneOrphanLinks_KeepsUnmanagedLiveLinkToSource, which
fails on unpatched main (bcb8c6c7) at four assertions — link kept, 0 removed, 1 local, and
the follow-up force prune finding nothing left to remove — and passes with the change. The same
test then prunes with force and expects handmade to go, so the escape hatch is pinned too.

No existing test needed editing — in particular TestPruneOrphanLinks_RemovesOrphans (broken
link into source) and TestPruneOrphanLinks_RemovesExcluded (manifest-tracked live link, now
filtered out) still pass unchanged, which is the guard that this narrows the rule rather than
disabling it.

Verified in a Linux environment (WSL2 Ubuntu, Go 1.25.6, devcontainer not used), on a tree reset
to current main bcb8c6c781d86c656f1fb7fdc95ca73ebbaecb7c:

  • git apply --check clean; gofmt -l clean on both changed Go files; go vet ./internal/sync/ clean
  • go test -run TestPruneOrphanLinks -v ./internal/sync/ → 12 PASS, incl. the new one
  • go test ./internal/... → 27 packages ok, 0 failures
  • go test -run 'Sync|Prune' ./cmd/skillshare/ → ok, identically with and without the change

One gap in my local evidence: the full ./cmd/skillshare package does not run to completion in
my WSL environment — I watched it exceed both its own -timeout 90s and a 150 s wall clock on
unpatched main, so it is an environment limit rather than a consequence of this change, but
it does mean I cannot claim a clean sweep for that one package. The devcontainer is the authority
there; I will fix anything CI surfaces.

Docs

Two English lines that were ambiguous about who created the link, updated to match:

  • website/docs/reference/targets/configuration.md — the "Existing target entries when filters
    change" table now distinguishes a link skillshare created from a live link it never tracked.
    The ja translation of this row already reads "Source-managed symlinks/junctions", which is
    the behaviour implemented here.
  • website/docs/reference/commands/sync.md — same distinction in "What gets removed when
    filters change".

The same table exists under website/i18n/{ja,ko,zh-Hans,zh-Hant}. Say the word and I will
update those four in this PR, or leave them to your normal translation flow — I did not want to
guess at wording I am not qualified to write.

Deliberately out of scope

Two more prunes share the root cause and are not touched here:
PruneOrphanAgentLinks (internal/sync/agent_sync.go, removes any unexpected .md link with
neither a source-prefix nor a provenance test) and PruneExtraTarget → pruneExtraOrphans
(internal/sync/extras.go, empty managed set + merge mode deletes target symlinks). Worth a
follow-up once the skills-side rule is agreed; I kept this to one concern.

Closes #314

Merge-mode prune removed any target entry that was a symlink or junction
resolving under the skills source, without checking whether skillshare had
created it. Links made by hand or by another tool were therefore deleted by
name, silently and outside trash, so they were not recoverable through
restore.

Ask the manifest, which the directory branch of this same function and all
of copy-mode pruning already treat as the ownership record: a live link into
the source is pruned when it is tracked there or when --force is set, and is
kept and reported as a local entry otherwise. Broken links into the source
and the force escape hatch behave exactly as before.
@runkids

runkids commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Thanks for the thorough report and the tight fix — the provenance check matches how the directory branch and copy-mode pruning already decide ownership.

Verified locally in the devcontainer on 4b9fbed5 (base is current main):

  • go vet ./internal/sync/ and go test ./internal/... pass
  • make test-int passes, including TestSyncProject_MovedDefaultPath_*, so the leftover cleanup in legacy_project.go still removes the links skillshare created in the old project paths

Two small follow-ups I'll handle on our side, so no changes needed here:

  • The ManagedOnly comment in internal/sync/legacy_project.go still says a link is ours if it "points into the source or is in the manifest"; after this change a live link needs the manifest entry.
  • Links created before the manifest existed (pre-v0.15.0) that are now filtered out are no longer pruned automatically; --force reclaims them. I'll note that in the changelog.

The agent and extras cases you listed are worth their own issue. Merging now.

@runkids runkids left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified locally; approving.

@runkids
runkids merged commit 5f3e79f into runkids:main Oct 1, 2026
7 checks passed
runkids added a commit that referenced this pull request Oct 1, 2026
Since #315, a live link into the source is pruned only when the manifest
tracks it. The ManagedOnly comments still said any link into the source
counted as skillshare's, which no longer matches what the leftover-dir
cleanup removes.
runkids added a commit that referenced this pull request Oct 1, 2026
Merge-mode pruning for agents and extras removed any link whose name was
not expected, so links a user made to agent or extra files outside the
source were deleted on the next sync or `extras --remove-target --prune`.

Agents and extras do not record their links in a manifest, so the #315
provenance check cannot be reused. Prune now removes a link only when it
is broken or resolves inside the source. Relative links are resolved from
the real parent directory, matching how createLink writes them, so
orphans under a symlinked target directory are still found.
runkids added a commit that referenced this pull request Oct 1, 2026
wuhaoyujerry reported the per-target CLI (#307) and Codex plugin update (#309) requests, and star-nebula fixed sync deleting user-made links (#315).
@star-nebula
star-nebula deleted the fix/prune-link-provenance branch October 2, 2026 08:29
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.

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

2 participants