Repository navigation
Conversation
Summary: `test_baseline_prune_ignores_diagnostics_below_threshold` fails intermittently on the Windows GitHub CI job (e.g. https://github.com/facebook/pyrefly/actions/runs/38726642921/job/116394023723). The server computes the prune, then logs `while writing baseline to ...: failed to persist temporary file: Access is denied. (os error 5)`, and the test times out waiting for the rewrite. `write_baseline_file` renames a temporary file over the baseline with `NamedTempFile::persist`, which on Windows calls `MoveFileExW(MOVEFILE_REPLACE_EXISTING)`. That fails with `ERROR_ACCESS_DENIED` whenever another handle has the baseline open at that moment, such as the server's own read of the baseline while it computes diagnostics, or the test polling the file. Windows users can lose a prune the same way. The baseline is now replaced with `std::fs::rename`. When `MoveFileExW` fails with `ERROR_ACCESS_DENIED`, the standard library retries the rename with `FILE_RENAME_FLAG_POSIX_SEMANTICS`, which replaces a file that others have open as long as their handles allow deletion; every handle the standard library opens does. Linux and macOS are unaffected, since a rename there never depends on open handles. On Windows, `NamedTempFile::new_in` marks the file it creates as temporary and only `persist` clears the mark, so the temporary file is created with `File::create_new` through `tempfile::Builder::make_in`, which keeps the cleanup on failure. On Unix that file is no longer private to its owner, so a new baseline gets the usual mode for a new file (the umask) instead of a fixed `0o644`. A rewrite still copies the permissions of the file it replaces. Differential Revision: D125499135
Contributor
|
@stroxler has exported this pull request. If you are a Meta employee, you can view the originating Diff in D125499135. |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
rchen152
approved these changes
Oct 16, 2026
rchen152
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
test_baseline_prune_ignores_diagnostics_below_thresholdfails intermittently on the Windows GitHub CI job (e.g. https://github.com/facebook/pyrefly/actions/runs/38726642921/job/116394023723). The server computes the prune, then logswhile writing baseline to ...: failed to persist temporary file: Access is denied. (os error 5), and the test times out waiting for the rewrite.write_baseline_filerenames a temporary file over the baseline withNamedTempFile::persist, which on Windows callsMoveFileExW(MOVEFILE_REPLACE_EXISTING). That fails withERROR_ACCESS_DENIEDwhenever another handle has the baseline open at that moment, such as the server's own read of the baseline while it computes diagnostics, or the test polling the file. Windows users can lose a prune the same way.The baseline is now replaced with
std::fs::rename. WhenMoveFileExWfails withERROR_ACCESS_DENIED, the standard library retries the rename withFILE_RENAME_FLAG_POSIX_SEMANTICS, which replaces a file that others have open as long as their handles allow deletion; every handle the standard library opens does. Linux and macOS are unaffected, since a rename there never depends on open handles.On Windows,
NamedTempFile::new_inmarks the file it creates as temporary and onlypersistclears the mark, so the temporary file is created withFile::create_newthroughtempfile::Builder::make_in, which keeps the cleanup on failure. On Unix that file is no longer private to its owner, so a new baseline gets the usual mode for a new file (the umask) instead of a fixed0o644. A rewrite still copies the permissions of the file it replaces.Differential Revision: D125499135