Skip to content

fix(watch): skip ignored directories when watching#142

Open
andrewgazelka wants to merge 1 commit intomixedbread-ai:mainfrom
andrewgazelka:fix/watch-ignore-ignored-dirs
Open

fix(watch): skip ignored directories when watching#142
andrewgazelka wants to merge 1 commit intomixedbread-ai:mainfrom
andrewgazelka:fix/watch-ignore-ignored-dirs

Conversation

@andrewgazelka
Copy link
Copy Markdown

@andrewgazelka andrewgazelka commented Apr 2, 2026

Summary

  • replace recursive fs.watch with per-directory non-recursive watchers
  • skip ignored directories before allocating watchers, including .git/, hidden paths, and ignore-pattern matches
  • add subtree watcher cleanup when directories disappear and keep upload/delete handling intact

Testing

  • pnpm typecheck
  • pnpm build
  • pnpm exec biome lint src/commands/watch.ts
  • pnpm test (fails on existing unrelated test: Config maxFileCount via YAML)

Notes

  • pnpm lint currently fails in this repo because the script runs biome lint --check ., and this installed Biome version rejects --check for lint.
  • the watcher fix is isolated to src/commands/watch.ts; the failing dry-run config test exits before live watcher setup.

Note

Medium Risk
Moderate risk because it rewrites the file watching mechanism that drives incremental upload/delete behavior, and platform-specific fs.watch edge cases could cause missed events or orphaned watchers.

Overview
Replaces the single recursive fs.watch watcher with per-directory, non-recursive watchers that are created only for non-ignored paths, preventing inotify exhaustion on large repos (e.g., skipping .git/, node_modules/, and ignore-pattern matches).

Adds watcher lifecycle management: dynamically starts watching newly discovered directories, and closes watchers for deleted directories/subtrees while keeping existing upload-on-change and delete-on-missing behavior intact (now with safer stat/error handling and warning logs).

Written by Cursor Bugbot for commit 9ca0798. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

watchDirectory(path.join(dirPath, entry.name));
}
} catch (error) {
console.warn(`Warning: failed to read directory ${dirPath}:`, error);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New directories' existing files are never uploaded

Medium Severity

When handleFileEvent discovers a new directory, it calls watchDirectory which sets up watchers and recurses into subdirectories — but only for directory entries. The readdirSync loop filters with !entry.isDirectory() and skips all files. This means when a directory tree appears with files already inside (e.g., git checkout, git stash pop, mv, or archive extraction), those existing files are silently never uploaded. Only files created after the watcher is installed are detected. At initial startup this is fine because initialSync handles existing files, but for directories discovered mid-watch it's a gap.

Additional Locations (1)
Fix in Cursor Fix in Web

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