Skip to content

fix: use FSEvent on macos to avoid Too many files#301

Merged
jdx merged 1 commit into
jdx:mainfrom
gaojunran:fix-fsevent
Mar 31, 2026
Merged

fix: use FSEvent on macos to avoid Too many files#301
jdx merged 1 commit into
jdx:mainfrom
gaojunran:fix-fsevent

Conversation

@gaojunran

Copy link
Copy Markdown
Contributor

PR #39 originally introduced macos_kqueue because FSEvents was believed to only report directory-level notifications, which would break pf watch and pf logs -t. However, in notify v8, the FSEvents implementation hardcodes the kFSEventStreamCreateFlagFileEvents flag, which enables file-level event reporting.

Fixes #298.

@greptile-apps

greptile-apps Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the macos_kqueue feature flag from the notify v8 dependency in Cargo.toml, allowing the default macos_fsevent (FSEvents) backend to be used on macOS instead of kqueue. This fixes the "Too many open files" (EMFILE) error that kqueue caused by opening a file descriptor for every watched path. The fix is safe because notify v8's FSEvents backend hardcodes kFSEventStreamCreateFlagFileEvents, which enables file-level event granularity — meaning pf watch and pf logs -t will continue to receive per-file change notifications rather than only directory-level ones.

  • Root cause addressed: macos_kqueue opened one fd per watched file; large projects exceeded the OS file descriptor limit.
  • No functional regression: notify v8 FSEvents reports file-level events via the hardcoded kFSEventStreamCreateFlagFileEvents flag, so all existing glob/pattern matching in watch_files.rs works unchanged.
  • Platform scope: The change only affects macOS; Linux (inotify) and Windows (ReadDirectoryChangesW) are unaffected.
  • Cargo.lock note: Only Cargo.toml was changed; Cargo.lock still references kqueue as a resolved package. Cargo does not store feature selections in the lockfile — features are resolved fresh per build from Cargo.toml — so regenerating the lockfile via cargo build or cargo update after merging will cleanly drop the now-unused kqueue and mio entries.

Confidence Score: 5/5

Safe to merge — single-line dependency feature removal with a well-understood correctness basis and no functional regression.

The change is minimal and surgical (one line in Cargo.toml). The technical claim is verifiable: notify v8's FSEvents backend hardcodes kFSEventStreamCreateFlagFileEvents, and the default feature for macOS in notify v8 is macos_fsevent. The file-watching logic in watch_files.rs uses RecommendedWatcher and only cares about EventKind::Modify/Create/Remove, all of which FSEvents reports at file granularity. No P1 issues were found.

No files require special attention.

Important Files Changed

Filename Overview
Cargo.toml Removes the macos_kqueue feature flag from the notify v8 dependency, letting the default macos_fsevent (FSEvents) backend be used on macOS — fixes "Too many open files" while preserving file-level event granularity via kFSEventStreamCreateFlagFileEvents.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[File Change on macOS] --> B{Before PR
macos_kqueue feature}
    B --> C[kqueue backend
opens 1 fd per watched file]
    C --> D[EMFILE: Too many open files]

    A --> E{After PR
default macos_fsevent feature}
    E --> F[FSEvents backend
kernel-level event stream]
    F --> G[kFSEventStreamCreateFlagFileEvents
hardcoded in notify v8]
    G --> H[File-level events reported
no fd per file]
    H --> I[WatchFiles / RecommendedWatcher
receives EventKind::Modify/Create/Remove]
    I --> J[path_matches_patterns checks glob patterns]
    J --> K[Daemon restarted if pattern matches]
Loading

Reviews (1): Last reviewed commit: "fix: use fsevent on macos to avoid `Too ..." | Re-trigger Greptile

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Cargo.toml file by removing the macos_kqueue feature from the notify dependency. I have no feedback to provide as there are no review comments to evaluate.

@jdx jdx merged commit 2d7f7b4 into jdx:main Mar 31, 2026
5 checks passed
@jdx jdx mentioned this pull request Mar 31, 2026
jdx added a commit that referenced this pull request Apr 9, 2026
## 🤖 New release

* `pitchfork-cli`: 2.3.0 -> 2.4.0

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

## [2.4.0](v2.3.0...v2.4.0) -
2026-04-09

### Added

- add mcp tools ([#311](#311))
- impl container mode
([#305](#305))

### Fixed

- use correct base dir for `.config/pitchfork.toml` case
([#307](#307))
- use FSEvent on macos to avoid `Too many files`
([#301](#301))

### Other

- *(deps)* lock file maintenance
([#310](#310))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Low risk release bookkeeping only: updates version metadata and the
changelog, without changing runtime code paths.
> 
> **Overview**
> Bumps `pitchfork-cli` from **2.3.0** to **2.4.0** in
`Cargo.toml`/`Cargo.lock` and adds the `2.4.0` entry to `CHANGELOG.md`
documenting the release contents (MCP tools, container mode, and a few
fixes).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
b7647a4. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
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.

2 participants