Repository navigation
fix(sync): replace copy-mode copies with links when switching back to merge - #506
Conversation
… merge Switching a target from copy back to merge left every copy whose entry name did not change as a real folder. Merge sync treated it as the user's own folder, so status and doctor kept saying "run skillshare sync" while sync changed nothing, and only `sync --force` turned it into a link. Copy mode already replaces merge-mode links with copies on its own, so merge sync now replaces a folder the manifest records with a checksum (a copy-mode copy) with a link, without --force. Folders the manifest does not record, or records as a link, stay untouched. The pre-sync target backup is unchanged. The CLI and dashboard diffs name these entries as copies sync replaces instead of suggesting --force, and the sync-modes docs describe the switch.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e5bd1e924
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if force || manifest.IsCopyModeCopy(activeName) { | ||
| // Force, or a copy left by copy mode: replace it with a symlink | ||
| if dryRun { | ||
| if !quietDryRun { | ||
| fmt.Fprintf(DiagOutput, "[dry-run] Would replace local copy: %s\n", activeName) |
There was a problem hiding this comment.
Preserve modified copies before replacing them
When a user edits or replaces a previously copy-mode-managed directory and then switches the target to merge mode, the stale manifest entry still makes IsCopyModeCopy true, so a normal sync now executes os.RemoveAll without checking whether the target still matches the recorded copy. This can permanently discard those edits because global CLI sync --json skips pre-sync backups and project-mode dashboard sync explicitly excludes skill backups. Verify the existing directory is still the managed copy, require --force when it has diverged, or guarantee a recoverable backup before deleting it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 3e842a5. Verified: sync --json and project-mode dashboard sync take no pre-sync backup, and IsCopyModeCopy only read the manifest, so an edited copy was deleted. Merge sync now replaces a managed copy only while the folder still hashes to the recorded checksum (Manifest.OwnsCopy); an edited copy is kept and sync --force still replaces it. The CLI and dashboard diffs use the same check, so they keep suggesting --force for an edited copy. Known limit: a copy whose name: was rewritten by prefixed naming, or made with custom ignore patterns, no longer hashes to the source checksum and is kept too (the safe direction). Covered by TestSyncTargetMerge_KeepsEditedCopyModeCopy and TestSync_MergeMode_EditedCopyModeCopy_NeedsForce (both failed before the change).
The first version replaced any folder the manifest recorded as a copy-mode copy. The manifest checksum is only a record, so a copy edited since copy mode made it was deleted too, and `sync --json` and project-mode dashboard sync take no pre-sync backup to restore it from. Replace the folder only while it still hashes to the recorded checksum (Manifest.OwnsCopy). An edited copy is kept and `sync --force` still replaces it; diff keeps suggesting --force for it. A copy whose name: was rewritten by prefixed naming, or that was made with custom ignore patterns, no longer hashes to the source checksum and is kept the same way.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e842a5a4f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sum, err := DirChecksumWithIgnore(dir, DefaultFileIgnorePatterns()) | ||
| return err == nil && sum == recorded |
There was a problem hiding this comment.
Include file modes when identifying untouched copies
When a user changes only a copied file's permissions—for example, making a target-local script executable—and then switches the target from copy to merge mode, this checksum still matches because DirChecksumWithIgnore hashes only paths and contents. OwnsCopy therefore treats the directory as untouched, and merge sync removes it without --force, silently discarding the permission change. Track or compare file modes (and other meaningful filesystem metadata) before automatically replacing the copy.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this one. Copy mode records only a content checksum of the source, and it already replaces a managed copy whenever the source changes, so a permission-only edit on a managed copy is not something the manifest or any sync mode tracks today. Guarding it would need a new manifest field (modes of the written copy) plus a migration for existing manifests, and file modes have no meaning on Windows. A copy whose contents were edited is kept (3e842a5). A copy with only a changed mode bit is replaced, and the pre-sync target backup (plain sync) still holds it. Recorded as a known limit in the PR description.
The Sync page picks a row's text from the diff item's action alone. The copy-mode copy that merge sync now replaces comes from the server as an update, which the page worded as "Link is broken or points elsewhere. Will be relinked" even though no link exists yet. Match the server's reason and show "Copy made by copy mode. Will be replaced by a link" instead, in all eleven dashboard languages.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09502a77ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| skillshare sync | ||
| ``` | ||
|
|
||
| Copies that copy mode made are replaced with links on that sync, without `--force`. Folders you made yourself, which the manifest does not record, are kept; `--force` replaces those too. |
There was a problem hiding this comment.
Qualify which copy-mode copies are replaced
This promise is false when the managed copy has been edited: Manifest.OwnsCopy only permits replacement while the directory still hashes to the recorded checksum, so normal merge sync keeps an edited copy and still requires --force. It is also false for prefixed copies whose rewritten name: makes their target checksum differ. Document the checksum/unedited limitation rather than contrasting only with unrecorded user folders, and align the translated versions.
AGENTS.md reference: AGENTS.md:L13-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 290f947. Verified against Manifest.OwnsCopy: an edited copy, and a copy whose name: copy mode rewrote for prefixed naming, no longer hash to the recorded checksum and stay until sync --force. sync-modes.md now says only unedited copies are replaced and lists the cases that are kept (a folder you made yourself, an edited copy, a prefixed-rewritten copy). The diff reference's Modified and Local override rows are qualified the same way, and the ja, ko, zh-Hans and zh-Hant copies of both pages carry the same wording. Docs only, so no new test; make check and ai-context.py check pass.
…sync The sync-modes paragraph promised that copies copy mode made are replaced with links without --force. Merge sync keeps a copy that no longer hashes to the checksum copy mode recorded, so an edited copy, or one whose name: copy mode rewrote for prefixed naming, still needs --force. State the three cases in sync-modes and qualify the diff Modified and Local override labels, in English and the ja, ko, zh-Hans and zh-Hant copies.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 290f947df8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // It's a real directory | ||
| if force { | ||
| // Force: replace local copy with symlink | ||
| if force || manifest.OwnsCopy(activeName, targetSkillPath) { |
There was a problem hiding this comment.
Preserve the copy until the replacement link exists
When the checksum guard succeeds but createLink fails—such as on a Windows/network filesystem where neither a junction nor a permitted symlink can be created—the code has already removed the working copy with os.RemoveAll, so sync returns an error with the target skill now missing. Rename the copy aside and restore it on link-creation failure, or otherwise create/validate the replacement before permanently deleting the directory.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8f76bae. Verified: the old code ran os.RemoveAll and then createLink, so a failed link left the skill missing, and a plain sync now reaches that code. replaceWithLink now moves the folder to a hidden sibling, creates the link, and deletes the parked folder only after the link exists; if the link fails the folder is moved back. A parked folder left by a run that died mid-way is not deleted (it could be the only copy): the next sync stops and names the path. The manifest also drops the copy-mode Mtimes/Naming records of an entry that became a link. Covered by TestReplaceWithLink_KeepsFolderWhenLinkFails, TestReplaceWithLink_KeepsLeftoverParkedCopy and the extended TestSyncTargetMerge_ReplacesCopyModeCopy. make check passes.
There was a problem hiding this comment.
Correction: the reply above said make check passed on 8f76bae. It did not: TestRawWriteRatchet failed because replaceWithLink's new os calls were not registered in raw_writes.tsv. Fixed in 4f0670a (the four target-side calls are registered and the stale os.RemoveAll targetSkillPath allowance is removed). make check now exits 0 on this head.
Replacing a copy-mode copy removed the folder first and then created the link. If creating the link failed (no symlink or junction rights on a Windows or network filesystem), sync returned an error with the skill gone from the target. This path now also runs on a plain sync, not only on --force. Park the folder beside the entry, create the link, then delete the parked folder; on failure the folder is moved back. A parked folder left by a run that died mid-way may be the only copy, so the next sync stops with a message instead of deleting it. The manifest also forgets the copy-mode mtime and naming records of an entry that is now a link.
|
@codex review |
…rite ratchet The previous commit moved the merge-mode folder replacement into replaceWithLink, which the ratchet reports as new raw os calls and the old os.RemoveAll allowance as stale. All of them act on the sync target, not the skills source, like the neighbouring entries.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f76baefe0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| skillshare sync | ||
| ``` | ||
|
|
||
| Unedited copies that copy mode made are replaced with links on that sync, without `--force`. Everything else is kept until you run `sync --force`: a folder you made yourself (the manifest does not record it) and a copy you edited after copy mode made it. A copy whose `name:` copy mode rewrote for `prefixed` naming also counts as edited. |
There was a problem hiding this comment.
Preserve edited copies during simultaneous naming changes
When users change both mode: copy → merge and target_naming in one sync—for example, an edited flat copy group__alpha becomes standard name alpha—merge legacy detection accepts only links, so sync creates alpha and then the prune pass removes the manifest-recorded group__alpha directory without checking its checksum. Thus the edited copy is deleted despite this new promise that it is kept until --force. Fresh evidence beyond the earlier wording thread is this simultaneous mode-and-naming transition; either preserve/checksum-guard the legacy copy or explicitly warn about this exception.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing the code; documented in bbd905e. Verified: in merge mode the legacy-name detection only accepts links, and the prune pass removes a manifest-recorded directory whose name is no longer valid without looking at its content. That is how a copy-mode directory under an old name has always been treated (the issue's own simulation shows 7 pruned for the renamed entries), and it applies to any naming change, not to the copy → merge switch this PR fixes. Guarding it would change orphan pruning for every managed directory, which is a separate change. sync-modes (all five languages) now says that when the same sync also changes target_naming, the copy gets a new entry name and is removed as an orphan, edited or not; the backup of a plain sync holds it.
| // A leftover may be the only copy if an earlier run died before it could restore it. | ||
| if _, err := os.Lstat(parked); err == nil { | ||
| return fmt.Errorf("%s is left from an earlier replacement; move or delete it, then sync again", parked) |
There was a problem hiding this comment.
Recover parked copies before handling missing targets
If the process exits after os.Rename(path, parked) but before the link is created, the next sync sees the original path as missing and takes the ordinary create-link branch without ever calling this leftover check. The sync then succeeds while the hidden parked directory remains; after another copy-mode run, a later copy-to-merge transition fails permanently on this stale sibling until the user discovers and removes it. Detect and restore or reconcile the parked path before branching on whether the target exists.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this one. It needs the process to be killed in the microseconds between os.Rename(path, parked) and the symlink call. If that happens, the parked folder is the copy that would have been replaced anyway (it was either unedited or the user passed --force), the sync that follows creates the link, and a later copy → merge switch stops with a message that names the parked path, so nothing is lost silently. Reconciling it at the start of every entry would add a lookup per skill per sync for that window. Recorded as a known limit in the PR description.
| // replaceWithLink swaps the real folder at path for a link. The folder waits | ||
| // beside it until link has run, so a failed link leaves the folder as it was. | ||
| func replaceWithLink(path string, link func() error) error { | ||
| parked := filepath.Join(filepath.Dir(path), "."+filepath.Base(path)+".skillshare-replaced") |
There was a problem hiding this comment.
Use a bounded name for the parked copy
On filesystems with a 255-byte component limit, a valid existing flat target name longer than 234 bytes cannot be replaced because adding . and .skillshare-replaced makes the sibling basename exceed the limit, causing os.Rename to fail. Nested skills can readily produce such long flattened names even though the original copy was created successfully; use a short fixed or hashed temporary name instead of appending to the full basename.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bbd905e. Reproduced first: a 250-byte entry name failed with file name too long on the rename. The parked name is now .skillshare-replaced- plus the SHA-256 of the entry name, a fixed 85 bytes, and still starts with a dot so the target scanners skip it. Covered by TestReplaceWithLink_LongEntryName (failed before the change); make check exits 0.
…tion The folder parked while a link is created was named after the entry, so an entry near the 255-byte filename limit (a long flattened nested skill) could not be moved aside and its replacement failed. The parked name is now a fixed-length hash of the entry name. sync-modes also says what happens when `target_naming` changes in the same sync: the copy gets a new entry name and the prune pass removes it as an orphan whether or not it was edited, as it did before this change.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Main gained the kept-legacy diff rows (#504), the manifestSymlink constant and prefixed-naming warnings (#503), and the BOM-tolerant frontmatter reader (#505). The diff stream checks the kept legacy entry before the copy-mode copy, since sync leaves a folder on a name held for a kept legacy entry alone; the docs keep both new rows.
The generated entry listed every commit, including about thirty fixes to target_naming: prefixed made before it was ever released, a test commit and an internal helper. Group what users will notice: the prefixed naming feature, the shared-folder conflict notices, and the fixes to released behavior (#498, #505, #506, #508, combined --mode/--target-naming).
Type
proposals/only — see CONTRIBUTING.md)Linked Issue
Found by real-user simulation (copy → merge/flat return); no tracking issue.
Closes #
What changed
Switching a target from copy mode back to merge left every copy whose entry name did not change as a real folder. Merge sync treated it as the user's own folder, so
statusanddoctorkept saying "run skillshare sync" while sync changed nothing, and onlysync --forceturned it into a link.Copy mode already replaces merge-mode links with copies on its own. Merge sync now does the reverse: a folder the manifest records with a checksum (a copy-mode copy) is replaced with a link, without
--force. Folders the manifest does not record, or records as a link, stay untouched.SyncTargetMergeWithSkillsreplaces a manifest-recorded copy-mode copy that still hashes to its recorded checksum (Manifest.OwnsCopy)TestSyncTargetMerge_ReplacesCopyModeCopy,..._DryRun(internal/sync/merge_test.go)TestSyncTargetMerge_KeepsFolderRecordedAsLink,TestSyncTargetMerge_KeepsEditedCopyModeCopy,TestSync_MergeMode_EditedCopyModeCopy_NeedsForce, existingTestSyncTargetMerge_SkipsLocalCopydiffnames these entriesModified/ "copy mode copy (sync replaces with link)" instead of suggesting--forceTestDiff_MergeMode_CopyModeCopy_SyncReplacesWithoutForce(tests/integration/diff_test.go, also runs the realsync)TestComputeTargetDiff_MergeModeCopyModeCopyIsReplacedWithLink(internal/server)Mtimes/NamingTestReplaceWithLink_KeepsFolderWhenLinkFails,TestReplaceWithLink_KeepsLeftoverParkedCopy,TestReplaceWithLink_LongEntryName,TestSyncTargetMerge_ReplacesCopyModeCopysyncView.test.ts("says a copy-mode copy in a merge target is replaced by a link")sync-modes.md, plusdiff.mdModified and Local override rows, say only unedited copies are replaced; English plus ja/ko/zh-Hans/zh-Hantpython3 scripts/ai-context.py checkThe CLI and the Web API share one code path (
SyncSkillTarget→SyncTargetMergeWithSkills), so both get the fix. Symlink mode (the whole target is a link) is converted byensureRealTargetDirbefore this branch and is unaffected.Each new test failed before the fix (unit tests and the integration test against an
origin/mainbuild; the server test againstorigin/mainhandler_diff_stream.go).Checks
make checkin the devcontainer: passes (fmt, lint, unit, integration).python3 scripts/ai-context.py check: ok./simplifyonorigin/main: four angles (reuse, simplification, efficiency, altitude). Changed: the manifest check is nil-safe (the CLI diff ignores the manifest read error); the new unit tests lost an unused file write and a redundant two-skill case;CopyToLinkReasonmoved next toIsCopyModeCopyinmanifest.go. Skipped: a shared"symlink"constant and a shared "local copy" reason constant (both pre-existing literals, outside this change)./code-review(standards + spec axes) withorigin/mainas the fixed point: no hard violations. Added the dashboard diff test and thediff.mdModified-label update (English plus four locales). Left as is:reference/commands/sync.md--forcerow (still true:--forcereplaces any existing folder)./simplifypass on the follow-up merged the two integration tests' config helper and fixed a comment; its reuse/altitude notes about ignore patterns and prefixed names are the known limit above.difftext and--json,synctext /--json/--dry-run/--force,status, project mode (-p), server diff stream and sync, dashboard Sync page, UI locales, docs and i18n, built-in skill. Ran copy→merge end to end in the devcontainer for global and-p(plain,--dry-run,--json,--force, an edited copy, a user folder). Found and fixed the dashboard wording;status/doctorandskills/skillshareneeded no change. Full UI test run (86 files),tsc -band eslint pass./simplifypass: no change needed./simplifyon the follow-up: a stale parked folder now stops the sync instead of being deleted; moving the helper next toreformatLinkand generalizing it was skipped as a wider refactor. Full diff re-read before the next round./simplifyon the follow-up extractedparkedPathso the test shares the name formula.make checkexits 0 on the head.Notes and known limits
The diff wording change is small and goes beyond the sync fix, but without it
diffwould suggest--forcefor something plainsyncnow does. It does not touch feat(sync): make prefixed target naming misconfigurations visible #503 or fix(sync): close gaps found while simulating the prefixed naming switch #504 areas (their warnings, target pairing, skipped-skill listing, kept-legacy rows); the changed lines indiff.go/handler_diff_stream.gosit beside, not on, the kept-legacy code.A copy the user edited since copy mode made it is kept (Codex review): replacement needs the folder to still hash to the manifest checksum, because
sync --jsonand project-mode dashboard sync take no pre-sync backup.sync --forcestill replaces it.A copy whose
name:was rewritten byprefixednaming, or made with custom ignore patterns, no longer hashes to the source checksum, so it is kept and needs--force(safe direction; covering it would need a checksum of the written copy in the manifest and a migration for old manifests).Not forced, because they need unusual setups: a kept legacy-named entry can show a different diff row than sync's active name.
If the process is killed between parking the folder and creating the link, the parked folder stays hidden beside the entry; the next sync links the entry, and a later copy → merge switch stops with a message naming the parked path (declined in the Codex thread).
Changing
target_namingin the same sync as the copy → merge switch gives a copy a new entry name, and the existing prune pass removes it as an orphan whether or not it was edited (documented in sync-modes; the pre-sync backup holds it). Guarding orphan pruning would change every managed directory, so it is left for a separate change.statusanddoctorstill say "run skillshare sync" for a copy that sync keeps (edited, or a user folder). That wording belongs to feat(sync): make prefixed target naming misconfigurations visible #503, so it is not changed here.Other remove-then-create sites (
--forceon agents, copy mode's overwrite) are older and unchanged; only the merge-mode skill replacement this PR widens got the parked-folder protection.A copy whose only change is a file mode bit (for example
chmod +x) still hashes the same, so it is replaced; the pre-sync backup of a plainsyncholds it (declined in the Codex thread: copy mode tracks content only and replaces managed copies whenever the source changes).The dashboard matches the server's reason string for the new row text, like the existing
missing/(target naming)checks, instead of adding a reason code to the diff API for one case.Checklist
make check) — for code changes