Skip to content

bug: File watcher stops triggering after first save in VS Code and other IDEs #432

Open

Description

@PranjaliBhardwaj

Description: While testing the microcks import --watch command, I noticed that file changes are only detected on the first save when editing specs in editors like VS Code or IntelliJ. After the initial save, subsequent saves are ignored and the watcher no longer triggers imports.

Expected Behavior : The watcher should continue monitoring the file and trigger imports on every save.

Actual behavior : The watch appears to be lost after the first save, so later modifications are ignored silently.

Possible cause: It looks related to how some editors perform atomic saves by writing to a temporary file and renaming it over the original file. In that case, fsnotify emits Rename/Remove events instead of only Write, and the existing watch may get dropped without being re-registered.

Activity

  1. yada commented on Oct 14, 2026

    @yada
    Member

    Reproduced on master (f9550f5) against a real Microcks server, using microcks import <file>:true --watch and comparing in-place writes with atomic saves (write a temp file, then mv it over the original).

    Platform Atomic save Later in-place edits
    Linux (inotify, alpine container) 0 re-imports 0 re-imports, the watcher is dead
    macOS (kqueue) 0 re-imports, so the saved edit is lost still trigger (1 each)

    In-place writes (the control) trigger a re-import on both platforms (1 on macOS, 2 on Linux, see #297).

    Cause: RunContext in pkg/watcher/watchManager.go only handles fsnotify.Write events. A rename-over (what atomic saves do) emits Rename/Remove/Create, which are ignored, and the watch on the replaced inode is never re-added.

    Suggested fix: also handle Create, Rename and Remove events, and re-add the watch (or watch the parent directory and filter by name). This shares a code area with #297, so one PR could cover both.

  2. yada commented on Oct 17, 2026

    @yada
    Member

    Update: PR #586 ("File watcher stops triggering after first save") looks like it addresses this. I built its head and ran import --watch against a real server on macOS, compared with master:

    • Plain write, atomic save (temp file plus mv), write after the atomic save, second atomic save: 4 re-imports with the PR, versus 2 on master (both atomic saves lost).
    • A burst of 20 appends: 1 re-import with the PR, versus 12 on master.

    Not tested: Linux (inotify), where the watcher died after an atomic save on master. That should be checked before merging.

    Disclosure: this comment was drafted with AI assistance, and the results were run locally.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions