Skip to content

fix: watch directories instead of files on Linux - #2155

Merged
backnotprop merged 1 commit into
backnotprop:mainfrom
utpalsinghdev:fix/1439-bounded-directory-watches
Oct 25, 2026
Merged

backnotprop merged 1 commit into
backnotprop:mainfrom
utpalsinghdev:fix/1439-bounded-directory-watches

Conversation

@utpalsinghdev

Copy link
Copy Markdown
Contributor

Summary

Linux folder-browser subscriptions currently use chokidar to watch individual files, even though the UI only needs a notification to refresh the folder listing. On large repositories, this can consume the user's inotify allowance and affect other applications.

This changes Linux directory subscriptions to use one fs.watch per directory instead of per file.

  • Discover new nested directories and replace or remove watches when directories are recreated, moved, or deleted.
  • Exclude .jj/ alongside .git/.
  • Limit directory watches to 512 per registry and release the affected subscription's watches when the limit is reached or watching fails.
  • Keep exact-file subscriptions and native recursive watching on macOS and Windows unchanged.

When a subscription stops watching, Plannotator logs the reason and sends a final refresh notification. Automatic file refresh stops for that subscription; other subscriptions remain active. Exact-file and Git metadata watches are outside the directory-watch budget.

Closes #1439.

Verification

On a Linux fixture containing 100 files in two subdirectories, owned inotify watches dropped from 103 to 3. Increasing the fixture to 500 files still used 3 watches.

Passed:

  • bun run typecheck
  • bun run build:pi
  • Focused shared/Bun/Pi watcher suites: 29 tests.
  • File-browser DOM tests: 6 tests.
  • Post-build asset checks: 37 tests.

Runtime checks covered nested file creation, edits and deletion; directory recreation and moves; real permission denial; injected watch-capacity failure; and cleanup during startup. The capacity check confirmed that the affected subscription released its watches after reaching the limit.

Limitations and feedback

There's a limit of 512 directory watches shared across subscriptions in each registry. If a subscription reaches that limit, it releases its watches and stops refreshing automatically, while other subscriptions keep working. This protects resources, but large repositories may hit the limit. Feedback on the limit and this behavior would be helpful.

The full test suite did not pass in the container. Two Git authentication-helper tests failed on both unchanged main and this patch with the container's older Git, and both passed with the host's newer Git. Other tests needed PowerShell or network access that the container didn't have. The run also ended without a final test summary.

Code review raised one possible timing problem: two overlapping folder scans might interfere with each other. Eight small create, rename, and recreate trials still picked up later file edits, so we haven't reproduced that problem or ruled it out. No change was added based only on that possibility.

@backnotprop
backnotprop merged commit 168cee5 into backnotprop:main Oct 25, 2026
25 checks passed
backnotprop added a commit that referenced this pull request Oct 25, 2026
…owup

fix: Linux folder watches keep working past the cap and unreadable folders (follow-up to #2155)
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.

Bug: a dirPath subscription registers one inotify watch per file, exhausting fs.inotify.max_user_watches on large repos

2 participants