Skip to content

Drain AsyncStreamReader in GetStatus to fix flaky pwsh log-capture

Placeholder ppxd requested to merge fix/pwsh-getstatus-async-drain into main

Summary

Closes the deeper root cause behind the flaky WindowsPowerShellE2ETests that PR #317's RunToCompletion accumulator papered over. The race:

  1. Script writes a single line + exits within 50ms
  2. Test polls GetStatus → BuildStatus reads HasExited=true → returns Complete
  3. .NET's AsyncStreamReader hasn't yet dispatched the OutputDataReceived callback for the last line → log file on disk is still empty
  4. ReadLogsAndCursor returns empty list → test sees state=Complete + 0 lines

CompleteScript already drains via WaitForExit() (no-arg) at LocalScriptService.cs:594. GetStatus is the OTHER way state=Complete becomes observable — when the test polls before invoking CompleteScript. This PR adds the same drain to BuildStatus.

  • DrainAsyncReadersOnce(RunningScript) — gates on Interlocked.Exchange of a new DrainedAsyncReaders flag so concurrent polls don't double-call
  • Regression test — 5-iteration fast-exit script, first-Complete-poll asserts marker present
  • Affects every Windows-only PR; multiple flakes traced to this race across #317, #320

Test plan

  • Unit: 5212/5212 pass locally
  • Build: zero errors
  • Windows CI: WindowsPowerShellE2ETests + LocalScriptServiceTests stable across runs

🤖 Generated with Claude Code

Merge request reports

Loading