Skip to content

fix(editor): prevent file-watch freezes and bound LSP exit waits - #419

Merged
fcoury merged 1 commit into
mainfrom
fcoury/nonblocking-file-watch
Oct 23, 2026
Merged

fcoury merged 1 commit into
mainfrom
fcoury/nonblocking-file-watch

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Opening the file tree or file picker in a large project could freeze the editor for seconds while macOS registered native file watches. Session restoration could hit the same blocking API when starting an LSP workspace watcher. Exiting could then wait another five seconds for a language server that had already acknowledged shutdown.

Move open-buffer and LSP workspace watcher registration onto dedicated threads. Open-buffer updates coalesce to the latest requested set, native teardown stays off the editor thread, and existing polling fallbacks continue to detect changes while registration is pending or unavailable. Limit the post-exit process grace period to 500 ms on non-Windows platforms; preserve Windows' 100 ms grace and the separate shutdown-response timeout.

Opt-in performance tracing now includes correlated span IDs, monotonic timestamps, thread IDs, and input/background/watcher/LSP-start timings. It remains disabled by default (RED_PERF=trace enables detailed tracing).

How to Test

  1. Build with cargo build --bin red. Launch that binary from a large repository with several restored buffers, including a file that starts an LSP server. Press Ctrl+E and Ctrl+P: both should open promptly while native watches register in the background. With RED_PERF=trace, watcher-registration spans should run on worker threads rather than the editor thread.
  2. Modify an open, clean file externally: its buffer should reload. Modify a dirty file externally: existing conflict handling should remain intact. Close buffers and repeat to exercise changing watch sets.
  3. Quit with a language server that acknowledges shutdown but remains alive after exit: Red should terminate and reap it after the 500 ms grace period on macOS/Linux, rather than waiting five seconds.
  4. Run cargo test --lib editor::file_watch, cargo test --lib lsp::workspace_watch, and cargo test --lib shutdown. The blocked-registration tests cover responsive input, polling, teardown, and coalescing; the shutdown tests cover protocol ordering and concurrent client shutdown.

Validation

  • User testing confirmed immediate Ctrl+E/Ctrl+P response and improved exit latency in the affected large project.
  • Local checks passed: 11 editor file-watch tests, 152 LSP unit tests, 11 shutdown-filtered tests (overlapping coverage), formatting, self-check, and all-targets/all-features Clippy with warnings denied.
  • Compilation, tests, and Clippy used an isolated compatibility dependency copy because the configured registry lacks locked zip 9.0.4. Repository manifests and lockfile are unchanged; exact-lock Clippy remains blocked locally and needs CI validation. Linux and Windows behavior was not manually tested.

Register open-buffer and LSP workspace watches on dedicated workers while retaining polling fallbacks. Coalesce pending open-buffer changes and keep native teardown off the editor thread.

Add correlated trace spans and blocked-registration regression tests. Bound the non-Windows language-server exit grace period to 500ms.
@fcoury
fcoury merged commit 4b3a16f into main Oct 23, 2026
22 of 24 checks passed
@fcoury
fcoury deleted the fcoury/nonblocking-file-watch branch October 23, 2026 03:51
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