vercel/turborepo

`turbo watch` does not detect changes from IntelliJ IDEA

giovannipiller opened this issue · 3 comments

Verify canary release

  • I verified that the issue exists in the latest Turborepo canary release.

Link to code that reproduces this issue

No reproduction. I understand this makes it impossible to debug, but wanted to keep track of the issue and help users with similar issues until it can be reproduced in a public repo. More details below.

Which canary version will you have in your reproduction?

2.3.1-canary.0

Enviroment information

turbo 2.3.0

CLI:
   Version: 2.3.0
   Path to executable: /.../node_modules/turbo-darwin-arm64/bin/turbo
   Daemon status: Running
   Package manager: npm

Platform:
   Architecture: aarch64
   Operating system: macos
   WSL: false
   Available memory (MB): 33039
   Available CPU cores: 10

Environment:
   CI: None
   Terminal (TERM): xterm-256color
   Terminal program (TERM_PROGRAM): Apple_Terminal
   Terminal program version (TERM_PROGRAM_VERSION): 455
   Shell (SHELL): /bin/zsh
   stdin: false

-----

IntelliJ IDEA 2024.3

Expected behavior

When saving changes to a file (e.g. removing a single character) using IntelliJ, turbo watch reacts to the changes and restarts any affected package task.

Actual behavior

On IntelliJ Idea, sometimes, turbo watch doesn't detect changes after saving a file.

To Reproduce

Attempting to replicate the issue on an example repository has proven unsuccessful.
Since this is happening on a private mono-repo, with many thousands of files involved and ~100 of packages, I suspect it might be related to the amount of files that are being watched.

This used to work fine until turbo@2.1.3, but as far as I can tell it started breaking from turbo@2.2.0.
Further testing pinpointed the issue to turbo@2.1.4-canary.5.

That being said, I'm able to reproduce the issue only on IntelliJ Idea, since making the same changes on Visual Studio Code works fine.

Workaround and possible source cause

From what I gathered, it looks like the issue is reproducible on my repo only when the Back up files before saving option of IntelliJ Idea is turned on.
This option can be disabled from Preferences -> Appearance & Bahavior -> System Settings.

Back up files before saving
Before saving the file, create a backup. If the save operation is successful, IntelliJ IDEA deletes the backup. If not, it restores the contents of the original file from backup. This behavior is known as "safe write", and it prevents losing your file in case of a faulty save operation.

What this does in practice (e.g. when saving myfile.ts), is creating a temporary file called myfile.ts~backing up the original data until the save is successful .

Could this temporary file be messing with turbo's watcher?

Additional context

No persistent tasks are involved.
The watched tasks are straight up builds and rely turbo to watch for changes and restart.

Thank you for tracking down the version you noticed this behavior. This is probably related to #9228, but nothing is immediately jumping out at me.

What this does in practice (e.g. when saving myfile.ts), is creating a temporary file called myfile.ts~backing up the original data until the save is successful.

I know fsevents has requires some special casing for file renames (which I'm assuming is the final step: mv myfile.ts~backup myfile.ts), but I'm not sure why any of the changes in 2.1.4-canary.5 would make this matter.

If you would be able to get the logs from the logfile displayed by turbo daemon status that might be helpful to figure out what FS operations are getting reported.

Here are the logs whenever the change is not detected.
In this scenario I deleted a space within a string.

e.g. 'aa aa' -> 'aaaa'

2024-11-19T15:14:41.787127Z  WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx"), AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx~")}
2024-11-19T15:14:41.787150Z  WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Other("packages/mypackage"), path: AnchoredSystemPathBuf("packages/mypackage") }: FileChanged { file: AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx~") }}))
2024-11-19T15:14:41.887934Z  WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf(".idea/workspace.xml~")}
2024-11-19T15:14:41.887946Z  WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Root, path: AnchoredSystemPathBuf("") }: FileChanged { file: AnchoredSystemPathBuf(".idea/workspace.xml~") }}))

Side note: .idea/workspace.xml is a file containing IntelliJ's workspace information. This is often modified by the IDE, which is why it's present in these logs, but I don't think it should have any impact.


As a reference, these are the logs whenever a change to the same file is properly detected.

2024-11-19T15:25:20.087636Z  WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx~"), AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx")}
2024-11-19T15:25:20.087648Z  WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Other("packages/mypackage"), path: AnchoredSystemPathBuf("packages/mypackage") }: FileChanged { file: AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx") }}))
2024-11-19T15:25:20.187595Z  WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf(".idea/workspace.xml~"), AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx"), AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx~")}
2024-11-19T15:25:20.187607Z  WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Root, path: AnchoredSystemPathBuf("") }: FileChanged { file: AnchoredSystemPathBuf(".idea/workspace.xml~") }, WorkspacePackage { name: Other("packages/mypackage"), path: AnchoredSystemPathBuf("packages/mypackage") }: FileChanged { file: AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx~") }}))

And these are for the same interaction on turbo@2.1.4-canary.4, where changes are detected as expected.

2024-11-19T15:57:16.749751Z  WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx"), AnchoredSystemPathBuf("packages/mypackage/src/MyComponent/MyComponentMenuTeam.tsx~")}
2024-11-19T15:57:16.749769Z  WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Other("packages/mypackage"), path: AnchoredSystemPathBuf("packages/mypackage") }}))
2024-11-19T15:57:16.949665Z  WARN turborepo_lib::package_changes_watcher: changed_files: {AnchoredSystemPathBuf(".idea/workspace.xml~")}
2024-11-19T15:57:16.949674Z  WARN turborepo_lib::package_changes_watcher: changed_packages: Ok(Some({WorkspacePackage { name: Root, path: AnchoredSystemPathBuf("") }}))