Skip to content

fix(daemon): a file written right after its new folder is seen on Linux - #604

Merged
7schmiede merged 1 commit into
mainfrom
fix/587-watch-new-dir-race
Nov 20, 2026
Merged

7schmiede merged 1 commit into
mainfrom
fix/587-watch-new-dir-race

Conversation

@7schmiede

Copy link
Copy Markdown
Member

What and why

On Linux a file written right after its new folder was missed now and then (edits_become_candidates failed twice on 2026-11-18): no build, no candidate, until the next edit.

Cause notify's inotify backend calls the handler of an event batch first and adds the watch for a new directory after it (notify 8.2, inotify.rs: handle_event at the end of the read loop, add_watch after it). The watcher listed the new directory inside that handler, so before the watch: a file written in between was in neither the listing nor an event
Bug class race-on-start
Fix the new directory is listed once more 200 ms after its event was handled, on one thread per watcher (feed); what it finds is delivered like any change (a candidate or restart waits for its debounce anyway)
Proof a_file_written_right_after_its_new_folder_is_reported, real inotify through feed (the production path), a handler that takes 30 ms as the daemon's does: red on Linux with all five files missed (never reported: ["src0/v2.txt", …]), green with the fix, three repeats green, all 21 watcher tests green, clippy clean (run in a rust:1-bookworm container; the test is Linux-only)
Siblings the lane sync watcher (remote.rs, watch_worktree) only sets a flag; its sync lists the whole worktree up to 2 s later and in full every 30 s, after the watch is in place: left as it is. macOS (FSEvents) and Windows report a new directory's files themselves
Safeguard the test drives the same feed the daemon uses, with the real OS watch

Closes #587

🤖 Generated with Claude Code

notify's inotify backend watches a new directory only after the handler
of its event batch returned (notify 8.2, `inotify.rs`: handlers first,
`add_watch` after). The watcher listed the new directory inside that
handler, before the watch: a file written in between was in neither the
listing nor any event, and its change made no candidate until the next
edit. This is how `edits_become_candidates` failed now and then on Linux.

A new directory is listed once more 200 ms after its event was handled,
on one thread per watcher (`feed`), and what it finds is delivered as any
change. The handling of events moved into `feed`, which the new test
drives with real inotify.

Closes #587

Bug-Class: race-on-start
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@7schmiede
7schmiede force-pushed the fix/587-watch-new-dir-race branch from 006a359 to 5cd314c Compare November 20, 2026 16:19
@7schmiede
7schmiede merged commit c61a1ff into main Nov 20, 2026
14 checks passed
@7schmiede
7schmiede deleted the fix/587-watch-new-dir-race branch November 20, 2026 16: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.

Watcher (Linux): a file written right after its new folder is missed now and then

1 participant