Skip to content

Undo local file rename when CLI fails to send rename to plugin#606

Open
huntercaron wants to merge 3 commits intomainfrom
huntercaron/undo-failed-rename
Open

Undo local file rename when CLI fails to send rename to plugin#606
huntercaron wants to merge 3 commits intomainfrom
huntercaron/undo-failed-rename

Conversation

@huntercaron
Copy link
Collaborator

@huntercaron huntercaron commented Mar 23, 2026

Description

When the code-link CLI detects a local file rename and fails to send it to the Framer plugin (no socket, send returns false, or throws), the local file stays renamed while the plugin still has the old name — causing a desync. This PR adds an undoLocalRename() helper that renames the file back on disk and sets up echo prevention so the watcher ignores the undo, keeping local and remote in sync.

Changelog

  • Renames will undo if they fail to sync

Testing

  • Rename fails due to no socket
    • Disconnect from the plugin
    • Rename a code component file locally
    • Verify the file is renamed back to its original name
  • Rename fails due to send failure
    • Simulate a send failure (e.g. plugin crashes mid-rename)
    • Verify the file is renamed back to its original name
  • Rename succeeds normally
    • Rename a file while connected
    • Verify it syncs to the plugin as before (no regression)

Copilot AI review requested due to automatic review settings March 23, 2026 13:21
@github-actions github-actions bot added the Auto submit to Marketplace on merge Submits the plugin to the marketplace after merging label Mar 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents local/remote desync when the CLI detects a local file rename but fails to notify the Framer plugin, by reverting the rename on disk and using hash-tracker “echo prevention” so the watcher ignores the undo.

Changes:

  • Add an undoLocalRename() path to revert the on-disk rename when no socket is available, sendMessage returns false, or sendMessage throws.
  • Add Vitest coverage for the undo behavior across the three failure modes above.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/code-link-cli/src/controller.ts Adds undoLocalRename() and invokes it on rename-send failures to keep disk state aligned with plugin state.
packages/code-link-cli/src/controller.rename.test.ts Adds tests ensuring the file is renamed back on failure and echo-prevention markers are set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Read fresh file content from disk before setting echo-prevention hash,
  since effect.content may be stale if the user edited the renamed file
- Clear echo-prevention markers in the catch block when fs.rename fails,
  preventing stale markers from poisoning tracker state
- Clean up hashTracker timers in tests to avoid dangling setTimeout
@niekert
Copy link
Member

niekert commented Mar 23, 2026

I'm missing some context, so pardon my ignorance, but was wondering if it would be possible to track renames in memory and try to sync when the link comes back online?

Also wonder if it could attempt to synchronize on the difference between the project & disk state when the link comes back online? (so that even if you'd edit a file without the CLI running it would synchronize when the connection comes back)

There may be reasons why this is not feasible, just curious

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

Labels

Auto submit to Marketplace on merge Submits the plugin to the marketplace after merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants