Fix flaky test_notebook_publish_diagnostics by preventing unnecessary RecheckFinished events
Summary: The test_notebook_publish_diagnostics test was flaky due to a race condition during LSP initialization. When a client responded to the WorkspaceConfiguration request during initialization, workspace_configuration_response() would trigger invalidate_config_and_validate_in_memory(), which always queued a RecheckFinished event. This RecheckFinished event calls validate_in_memory_and_commit_if_possible(), publishing diagnostics for all currently open files.
The race occurred because:
- If didOpen was processed BEFORE RecheckFinished: The notebook was already in open_files, so RecheckFinished published diagnostics for it → 2 publishDiagnostics (test passed)
- If didOpen was processed AFTER RecheckFinished: No files were open yet, so RecheckFinished published nothing → 1 publishDiagnostics (test failed)
The fix prevents RecheckFinished from being queued when there are no open files to revalidate. This makes the server behavior deterministic and eliminates the race condition. As a side benefit, this also improves performance by avoiding unnecessary revalidation work during initialization.
Differential Revision: D88116232
@kinto0 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D88116232.
This pull request has been merged in facebook/pyrefly@a63fbd8b22b97093d28972f1efddb47daf88ab58.