Repository navigation
Carry over five temp-scanner fixes that landed after #11217 merged - #11280
Conversation
…g as cover Two ways the previous version still reported a clean run over a hole. The deletion race can land INSIDE the retry window. The first read fails, Test-Path says the directory is there, and it is gone by the time the retry runs; the inner catch then recorded it as unread, and an unread directory under an unwatched root voids the measurement. That is the ordinary temp deletion this change exists to tolerate, so existence is rechecked in the inner catch too. A FileSystemWatcher that overflows its buffer raises Error and drops the creations it could not queue, and its handle stays in the list looking exactly like a working one. The coverage check therefore counted an overflowed watcher as covering its root and withheld the unread directories beneath it, so an artifact could be missing from the live stream AND from the listing at once, which is the only combination that turns a real compile into a pass. The Error event is now subscribed, drained in Stop-StudioTempWatch as FailedRoots, and those roots are excluded when $watchedRoots is built. Any Error at all condemns the root: the event carries the exception, not the list of creations it dropped, so a watcher that raised once cannot say what it missed.
Test-Path cannot tell a deleted directory from an unreadable one, so using it to
decide meant an ACL-denied directory was called deleted and dropped silently out
of the comparison. Pre-existing files under it then read as new in the other
snapshot, and where its root had no watcher the coverage guard was skipped
entirely, so an incomplete scan could report clean.
Measured under pwsh with $ErrorActionPreference = 'Stop':
missing directory -> ItemNotFoundException, Test-Path returns $false
denied directory -> Test-Path THROWS 'Access to the path ... is denied'
which is worse than it first looks: the probe could raise from inside the catch
that was meant to contain the failure.
Test-StudioPathIsGone walks the exception chain for ItemNotFoundException,
DirectoryNotFoundException and FileNotFoundException, and is used for the first
failure and the retry alike. It fails safe: anything not positively identified
as a missing path is reported as still present, so the directory is recorded as
unread. Over-reporting a gap costs a withheld path or a voided run;
under-reporting one drops a directory out of the comparison, which is the defect
this file exists to prevent.
Windows staging caught this and nothing else could: the two rows asserting the
void message did a plain substring match, and on Windows a throw reaches the
caller through PowerShell's error formatter, which wraps at terminal width,
interleaves ANSI colour codes and gutters each continuation line:
...so this run cannot
| say whether a compiler ran.
so the sentence is never contiguous. Linux pwsh does not wrap that way, which is
why both rows passed everywhere they could be run locally while failing on the
one platform this script actually executes on.
Colour codes, then the gutter, then whitespace collapsed. The gutter is the part
worth naming: stripping ANSI alone leaves a '|' in the middle of the sentence and
the match keeps failing for a new reason, which is what happened on the first
attempt at this fix.
…lure The void-the-run throw sat before the evidence write and before the captured action failure was rethrown. So an installer that genuinely died, on a run where the final sweep also hit an unreadable directory with nothing watching its root, was reported as a scanner problem and never produced the <name>-error.txt this function promises. The uncovered directories are collected into $uncovered now and raised at the very end: evidence first, then the action's own failure, then the incomplete scan. An incomplete sweep is worth failing on; it is not worth failing on INSTEAD of the thing being measured. $uncovered reaches the evidence either way through <name>-unread-dirs.txt. Ordering is the whole claim, so the tests assert offsets taken from the shipped function, and pin that the coverage loop collects rather than raises.
A skip reason claimed the Windows half of the denial question was "the ACL-based control below". There is no such control and there never was, so the file promised a guarantee it did not provide. Three rows here are POSIX-only and skip on Windows, and nothing replaces them: on a Windows runner the denial behaviour of this walk is not exercised. That is now stated, along with why an ACL control is not being guessed at from a Linux host - the failure worth catching is a control that denies nothing and passes, which is what happened when an ACL denial was first tried as a stand-in for the race. The eight platform-neutral rows do run on Windows and do drive the real PowerShell. The DirectorySeparatorChar bug is the class they catch, which is why they are written against Windows-shaped literals.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e804563074
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| $watchedRoots = New-Object 'System.Collections.Generic.HashSet[string]' ( | ||
| [string[]]@($watch | ForEach-Object { $_.Root }), [StringComparer]::OrdinalIgnoreCase) | ||
| if ($unread.Count -gt 0) { | ||
| foreach ($dir in $unread) { | ||
| # Withholding is only safe while the watcher is covering that root: it reports | ||
| # creations live, so a compile inside an unread directory still lands in | ||
| # $transient. With no watcher on the root the listing is the only evidence there | ||
| # is, and withholding part of it would report a hole as a clean result. That is | ||
| # the same call as the traversal cap in Get-StudioTempSubtree, for the same | ||
| # reason, so it is the same answer: declare the measurement void. | ||
| $covered = @($watchedRoots | Where-Object { Test-StudioPathUnder -Path $dir -Directory $_ }) | ||
| if ($covered.Count -eq 0) { | ||
| throw ("the temp sweep could not read $dir, and no file watcher is attached " + | ||
| "to the root containing it. The listing is the only evidence here and " + | ||
| "it is incomplete, so this run cannot say whether a compiler ran.") | ||
| [string[]]@( | ||
| $watch | ForEach-Object { $_.Root } | Where-Object { | ||
| $watchFailedRoots -notcontains $_ | ||
| } | ||
| } | ||
| ), [StringComparer]::OrdinalIgnoreCase) |
There was a problem hiding this comment.
Reject every measurement whose watcher overflowed
When a FileSystemWatcher raises Error, this change only removes its root from $watchedRoots; that affects the verdict only if $unread also contains a directory beneath the root. With otherwise successful before/after scans, $uncovered remains empty and the measurement is accepted even though the overflow may have dropped a transient CodeDom artifact that was deleted before the final scan—the exact case the live watcher exists to detect. Treat a nonempty $watchFailedRoots as an incomplete measurement (after preserving/rethrowing any action failure), rather than merely excluding those roots from unread-directory coverage.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it is the right severity. Fixed in 5a0607570.
The exclusion I added only changes the verdict when $unread also holds something beneath the same root, which is backwards for this half of the detector. The watcher exists for artifacts that never reach the listing at all: CodeDom deletes its intermediate directory once the assembly is loaded, so a compile can be invisible to the before/after diff and present only as live events. That is the case the file's own header describes, with the csc.exe ... @"...\Temp\vpmyd5eq\vpmyd5eq.cmdline" observation. An overflow drops exactly those events, so two clean sweeps plus a failed watcher is the shape of a missed compile, and nothing is unreadable for the coverage check to notice.
A non-empty $watchFailedRoots is now an incomplete measurement in its own right, independent of $unread.
Both reasons are collected into $incomplete and raised in a single throw rather than racing each other, so a run with both problems reports both. Otherwise fixing the first would surface the second as a fresh failure later, which is the same "one reason at a time" trap as the earlier ordering bug. It still raises after the action's own failure is rethrown, and the failed roots reach the evidence as <name>-watch-failures.txt whatever the verdict.
Sabotage, each against the restored file, and in both directions so the guard cannot pass by voiding everything:
revert to exclusion-only (this bug) -> overflowed_watcher_voids_the_measurement_on_its_own FAILED
both_incompleteness_reasons_are_reported_together FAILED
void unconditionally -> unreadable_root_with_a_watcher_on_it_does_not_void FAILED
healthy_watcher_and_a_readable_sweep_still_pass FAILED
report only the first reason -> both_incompleteness_reasons_are_reported_together FAILED
restored -> 23 passed, 11 skipped
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Excluding a failed watcher's root from $watchedRoots changes the verdict only when $unread also holds something beneath that root. With two otherwise clean sweeps, $uncovered is empty and the run is accepted. That is the wrong way round for this detector. The live half exists for artifacts that never reach the listing at all: CodeDom deletes its intermediate directory once the assembly is loaded, so a compile can be invisible to the before/after diff and present only as events. An overflow drops those silently, so two clean scans plus a failed watcher is the exact shape of a missed compile, with nothing unreadable for the coverage check to catch. A non-empty $watchFailedRoots is now an incomplete measurement in its own right. Both reasons are collected into $incomplete and raised in one throw, so the caller is told everything wrong with the sweep at once rather than fixing one and meeting the other. Still after the action's own failure is rethrown, and recorded as <name>-watch-failures.txt either way.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…1285) tests/studio/test_pwsh_calls_use_the_shared_runner.py is red on main. Two changes that landed today added pwsh calls through subprocess.run: the stale-copy sweep and helper tests in #11248, and the temp-scanner tests carried over in #11280. Both share one $XDG_CACHE_HOME/powershell startup cache with every other xdist worker, which is the failure mode that test exists to prevent, and which reads as a Windows-installer regression when it hits. run_pwsh takes the argv the call site already built, so each is a one-word change and no invocation flags move.
…i#11303) tests/studio/test_pwsh_calls_use_the_shared_runner.py is red on main. Seven call sites in two files start PowerShell with subprocess.run instead of run_pwsh, so they share one $XDG_CACHE_HOME/powershell startup cache with every other xdist worker and can die at startup with `Stack overflow.` or `System.IO.FileLoadException`. Three of them are mine, from unslothai#11280. The guard predates that PR and I added the file without reading it. run_pwsh takes the argv the call site already built and only redirects pwsh's own startup cache, so each of the seven is a one-word change with no invocation flags moved. The launcher case in test_studio_install_workspace_guard.py keeps its explicit `env`, which run_pwsh extends rather than replaces. tests/studio/test_pwsh_calls_use_the_shared_runner.py: 6 passed. The two converted files: 120 passed, 1 skipped.
…merged (unslothai#11280) * Recheck existence inside the retry, and stop a failed watcher counting as cover Two ways the previous version still reported a clean run over a hole. The deletion race can land INSIDE the retry window. The first read fails, Test-Path says the directory is there, and it is gone by the time the retry runs; the inner catch then recorded it as unread, and an unread directory under an unwatched root voids the measurement. That is the ordinary temp deletion this change exists to tolerate, so existence is rechecked in the inner catch too. A FileSystemWatcher that overflows its buffer raises Error and drops the creations it could not queue, and its handle stays in the list looking exactly like a working one. The coverage check therefore counted an overflowed watcher as covering its root and withheld the unread directories beneath it, so an artifact could be missing from the live stream AND from the listing at once, which is the only combination that turns a real compile into a pass. The Error event is now subscribed, drained in Stop-StudioTempWatch as FailedRoots, and those roots are excluded when $watchedRoots is built. Any Error at all condemns the root: the event carries the exception, not the list of creations it dropped, so a watcher that raised once cannot say what it missed. * Classify the enumeration error instead of probing the path Test-Path cannot tell a deleted directory from an unreadable one, so using it to decide meant an ACL-denied directory was called deleted and dropped silently out of the comparison. Pre-existing files under it then read as new in the other snapshot, and where its root had no watcher the coverage guard was skipped entirely, so an incomplete scan could report clean. Measured under pwsh with $ErrorActionPreference = 'Stop': missing directory -> ItemNotFoundException, Test-Path returns $false denied directory -> Test-Path THROWS 'Access to the path ... is denied' which is worse than it first looks: the probe could raise from inside the catch that was meant to contain the failure. Test-StudioPathIsGone walks the exception chain for ItemNotFoundException, DirectoryNotFoundException and FileNotFoundException, and is used for the first failure and the retry alike. It fails safe: anything not positively identified as a missing path is reported as still present, so the directory is recorded as unread. Over-reporting a gap costs a withheld path or a voided run; under-reporting one drops a directory out of the comparison, which is the defect this file exists to prevent. * Match the raised message however PowerShell chose to wrap it Windows staging caught this and nothing else could: the two rows asserting the void message did a plain substring match, and on Windows a throw reaches the caller through PowerShell's error formatter, which wraps at terminal width, interleaves ANSI colour codes and gutters each continuation line: ...so this run cannot | say whether a compiler ran. so the sentence is never contiguous. Linux pwsh does not wrap that way, which is why both rows passed everywhere they could be run locally while failing on the one platform this script actually executes on. Colour codes, then the gutter, then whitespace collapsed. The gutter is the part worth naming: stripping ANSI alone leaves a '|' in the middle of the sentence and the match keeps failing for a new reason, which is what happened on the first attempt at this fix. * Raise the incomplete-scan verdict last, not over the action's own failure The void-the-run throw sat before the evidence write and before the captured action failure was rethrown. So an installer that genuinely died, on a run where the final sweep also hit an unreadable directory with nothing watching its root, was reported as a scanner problem and never produced the <name>-error.txt this function promises. The uncovered directories are collected into $uncovered now and raised at the very end: evidence first, then the action's own failure, then the incomplete scan. An incomplete sweep is worth failing on; it is not worth failing on INSTEAD of the thing being measured. $uncovered reaches the evidence either way through <name>-unread-dirs.txt. Ordering is the whole claim, so the tests assert offsets taken from the shipped function, and pin that the coverage loop collects rather than raises. * Say what Windows actually covers in the temp-scan tests A skip reason claimed the Windows half of the denial question was "the ACL-based control below". There is no such control and there never was, so the file promised a guarantee it did not provide. Three rows here are POSIX-only and skip on Windows, and nothing replaces them: on a Windows runner the denial behaviour of this walk is not exercised. That is now stated, along with why an ACL control is not being guessed at from a Linux host - the failure worth catching is a control that denies nothing and passes, which is what happened when an ACL denial was first tried as a stand-in for the race. The eight platform-neutral rows do run on Windows and do drive the real PowerShell. The DirectorySeparatorChar bug is the class they catch, which is why they are written against Windows-shaped literals. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Void the measurement when a watcher raised, not only its coverage Excluding a failed watcher's root from $watchedRoots changes the verdict only when $unread also holds something beneath that root. With two otherwise clean sweeps, $uncovered is empty and the run is accepted. That is the wrong way round for this detector. The live half exists for artifacts that never reach the listing at all: CodeDom deletes its intermediate directory once the assembly is loaded, so a compile can be invisible to the before/after diff and present only as events. An overflow drops those silently, so two clean scans plus a failed watcher is the exact shape of a missed compile, with nothing unreadable for the coverage check to catch. A non-empty $watchFailedRoots is now an incomplete measurement in its own right. Both reasons are collected into $incomplete and raised in one throw, so the caller is told everything wrong with the sweep at once rather than fixing one and meeting the other. Still after the action's own failure is rethrown, and recorded as <name>-watch-failures.txt either way. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…slothai#11285) tests/studio/test_pwsh_calls_use_the_shared_runner.py is red on main. Two changes that landed today added pwsh calls through subprocess.run: the stale-copy sweep and helper tests in unslothai#11248, and the temp-scanner tests carried over in unslothai#11280. Both share one $XDG_CACHE_HOME/powershell startup cache with every other xdist worker, which is the failure mode that test exists to prevent, and which reads as a Windows-installer regression when it hits. run_pwsh takes the argv the call site already built, so each is a one-word change and no invocation flags move.
…i#11303) tests/studio/test_pwsh_calls_use_the_shared_runner.py is red on main. Seven call sites in two files start PowerShell with subprocess.run instead of run_pwsh, so they share one $XDG_CACHE_HOME/powershell startup cache with every other xdist worker and can die at startup with `Stack overflow.` or `System.IO.FileLoadException`. Three of them are mine, from unslothai#11280. The guard predates that PR and I added the file without reading it. run_pwsh takes the argv the call site already built and only redirects pwsh's own startup cache, so each of the seven is a one-word change with no invocation flags moved. The launcher case in test_studio_install_workspace_guard.py keeps its explicit `env`, which run_pwsh extends rather than replaces. tests/studio/test_pwsh_calls_use_the_shared_runner.py: 6 passed. The two converted files: 120 passed, 1 skipped.
Summary
Five fixes to the temp scanner that #11217 introduced. They were reviewed and written against that PR but landed on its branch after it had already been squash-merged, so none of them reached
main. This carries them over unchanged.Four came from review rounds on #11217 after the merge; one came from a Windows CI run, and could not have come from anywhere else.
What
mainhas wrong today1.
Test-Pathcannot tell a deleted directory from an unreadable one. The walk currently decides with a probe, and the probe cannot answer the question. Measured under pwsh:Being precise about how reachable this is on
maintoday, because I could not make it fire with a static permission change and do not want to overstate it. A directory that is merely unreadable, with a readable parent, is handled correctly:mainrecords it as unread. Verified againstca59c723f:Two conditions do break it, neither of which a Linux run reproduces on demand:
Test-Paththrows when the PARENT is denied, and the walk only reaches such a path if the parent was readable when it was enqueued and denied by the time the retry runs, i.e. a permission change mid-walk. It then raises from inside the catch that was meant to contain the enumeration failure.$falsefor a directory that exists. This needs an ACL that denies metadata as well as enumeration, which is a Windows shape; on Linux the same situation throws instead. There the directory is called deleted and dropped silently out of the comparison, so pre-existing files under it read as new on the other side, or a real artifact is hidden.main's own tests pass on Linux (11 passed), so this is latent rather than visible.Test-StudioPathIsGoneremoves the question by classifying the error instead of probing: it walks the exception chain forItemNotFoundException,DirectoryNotFoundExceptionandFileNotFoundException, and fails safe, so anything not positively identified as missing is recorded as unread.2. The deletion race can land inside the retry window. The first read fails,
Test-Pathsays the directory is there, and it is gone by the time the retry runs. It was then recorded as unread, and an unread directory under an unwatched root voids the run, which fails the job for exactly the ordinary temp deletion this scanner exists to tolerate.3. An overflowed watcher still counts as coverage.
FileSystemWatcherraisesErroron buffer overflow and drops the creations it could not queue, and nothing subscribes to that event, so the handle stays in the list indistinguishable from a healthy one. The coverage check then withholds the unread directories beneath that root, and an artifact can be missing from the live stream and from the listing at once. That is the only combination here that turns a real compile into a clean pass rather than a false alarm.Erroris now subscribed, drained asFailedRoots, and those roots are excluded when$watchedRootsis built.4. The incomplete-scan verdict fires over the action's own failure. The void throw sits before the evidence write and before the captured
$failureis rethrown, so an installer that genuinely died on a run that also hit an unreadable directory is reported as a scanner problem, and the<name>-error.txtthe function promises is never written. The uncovered directories are collected now and raised last: evidence, then the action's failure, then the incomplete scan.5. The void message is asserted with a plain substring match, which fails on Windows. A
throwreaches the caller through PowerShell's error formatter, which on Windows wraps at terminal width, interleaves ANSI colour codes and gutters each continuation line, so the sentence is never contiguous:Linux pwsh does not wrap that way, so the rows pass everywhere they can be run locally and fail on the one platform this script actually executes on. Found by a Windows staging run, not by review. Colour codes, then the gutter, then whitespace collapsed.
Also included: a comment correction. A skip reason claimed the Windows half of the denial question was "the ACL-based control below". There is no such control and there never was, so the file promised a guarantee it did not provide. Three rows here are POSIX-only and skip on Windows with nothing replacing them; that is now stated, along with why an
icaclscontrol is not being guessed at from a Linux host.Verification
Each guard was sabotage-proved on #11217 against the restored file, and the classifier in both directions so that neither "always gone" nor "never gone" can pass:
The
Watch-ForCompiler.ps1content here is byte-identical to the reviewed branch; the test file differs from it only bymain's own formatter output.