Skip to content

fix(server): chokidar fallback watches subfolders (#760) (#2904)#812

Merged
inkeep-oss-sync[bot] merged 1 commit into
mainfrom
copybara/sync
Jul 24, 2026
Merged

fix(server): chokidar fallback watches subfolders (#760) (#2904)#812
inkeep-oss-sync[bot] merged 1 commit into
mainfrom
copybara/sync

Conversation

@inkeep-oss-sync

Copy link
Copy Markdown
Contributor

Copybara-translated 1 Inkeep OSS change. Rebase-merge this PR so the prepared commit lands directly on public main.

* fix(server): chokidar fallback watches subfolders (#760)

The file watcher prefers @parcel/watcher and falls back to chokidar
whenever that native module can't load (every packaged desktop build
today). The fallback's `ignored` predicate misclassified any
subdirectory chokidar probed WITHOUT file stats — routing it through
the file-only `isExcluded`, which default-excludes any non-`.md`/
non-asset name — so chokidar pruned every content subfolder and
silently stopped watching it. External edits to docs in subfolders
never reached the server; the graph, backlinks, and dead-link views
stayed stale until a restart re-read from disk.

Extract the predicate as `isChokidarPathIgnored` and lstat a stats-less
path to resolve dir-vs-file before deciding (lstat matches
followSymlinks:false); a path that can't be stat'd is admitted, not
pruned, so a mid-scan delete still propagates. Add a `forceBackend`
test seam to `startWatcher` (mirrors head-watcher) and cover the
regression: a subfolder edit, a doc created in a brand-new subfolder
after watch start, node_modules staying pruned, plus a predicate
stats matrix.

* fix(server): await chokidar `ready` so the watcher is live before startWatcher resolves

The chokidar backend's live-subfolder tests were flaky on Linux CI —
even the root-level control edit was missed. `chokidar.watch()` returns
before its initial scan + per-directory inotify registration finish, so
an edit made immediately after `startWatcher` resolved landed in the
setup window and never fired (macOS FSEvents arms fast enough to hide
it locally). Await chokidar's `ready` event before returning, bounded by
a 10s cap so a pathological scan can't wedge boot. Also space the
new-subfolder test's mkdir and write so the create isn't lost to the
inotify addDir→subwatch race.

* test(server): sentinel-anchor the node_modules-pruned negative assertion

Address PR review: the excluded-subtree test replaced its fixed 600ms
sleep with a sentinel edit to a watched file. Waiting for the sentinel
to dispatch proves the watcher was live through the window, so the
absent node_modules event is a real negative rather than a vacuous pass
if the watcher never started.

* test(server): anchor the new-subfolder sub-watch on the folder-create event

The fixed 200ms sleep guessed at how long chokidar takes to arm a sub-watch
on a freshly created directory — too short under load, wasted wall time when
not. Waiting for the folder-create DiskEvent is the deterministic signal that
the addDir was processed.

---------

GitOrigin-RevId: 8b6d1d9bc0fbc9f84ca93d82192ee1dd421dcb73
@inkeep-oss-sync
inkeep-oss-sync Bot merged commit ad5bb04 into main Jul 24, 2026
@inkeep-oss-sync
inkeep-oss-sync Bot deleted the copybara/sync branch July 24, 2026 20:59
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.

1 participant