Skip to content

test(windows-native): wait for what the started bridge writes, not for its launcher's process, and say how PowerShell failed - #4021

Merged
devswha merged 1 commit into
mainfrom
test/windows-native-start-wait
Nov 17, 2026
Merged

devswha merged 1 commit into
mainfrom
test/windows-native-start-wait

Conversation

@devswha

@devswha devswha commented Nov 17, 2026

Copy link
Copy Markdown
Owner

What

A test-only change to server/windows-native.test.ts. It removes a race in the test "writes the Windows bridge launcher and reads startup status with migration junction=false/true". That race fails the required "Native Windows install" check about once in 260 runs. The change also makes any future failure of the file's PowerShell helpers say what happened. Product code is unchanged.

Why

From 2026-11-11 (when the test came in with #3633) to 2026-11-17, the test failed 3 times in about 773 job attempts that ran it (about 0.4%, or 1 in 260):

Date (UTC) Job Branch
2026-11-12 10:38 131127172287 test/sidebar-filter-agent-order
2026-11-13 08:10 131770326914 ci/vm-runners
2026-11-17 06:18 133858976557 chore/import-boundary-check (#4015)

All three failures look the same:

  • The failing variant was junction=false.
  • The failure came from inside windowsHost.start.
  • The test's helper threw because powershell.exe exited non-zero.
  • stderr held nothing but three CLIXML "Preparing modules for first use." progress records, and no error record.

On main, 0 of 187 push runs failed. At this rate about 0.7 failures would be expected in 187 runs, so that does not show main is immune.

The cause

windowsHost.start (server/remote-host.ts:416-427) launches the bridge's cmd.exe launcher through Invoke-CimMethod Win32_Process Create and returns. It does not wait for the launcher.

The test's own PowerShell helper used to add one line to every script that contained Invoke-CimMethod:

; Wait-Process -Id $r.ProcessId -Timeout 15 -ErrorAction SilentlyContinue

That line was at windows-native.test.ts:280 on main.

Leading hypothesis, from reading the code (not reproduced). The launched cmd.exe lives a very short time: it runs the stand-in ovis-server.exe, which writes one file and one line and then exits. When that process is already gone by the time Wait-Process looks up its id, this is what happens:

  1. Wait-Process writes a non-terminating error. That is NoProcessFoundForGivenId, or ProcessNotTerminated if the process is still exiting (see Process.cs in PowerShell's source).
  2. -ErrorAction SilentlyContinue hides the error, but $? stays $false.
  3. With -Command/-EncodedCommand, powershell.exe exits with 1 when the last command's $? is false (about_PowerShell_exe).
  4. The helper threw new Error(stderr) (:285), and stderr held only the progress records.

By reading, no other line of the start script can exit non-zero without writing an error record, because it runs under $ErrorActionPreference = 'Stop'.

The old logs cannot confirm this. The helper dropped the exit code and stdout, so the logs show only that the exit was non-zero; the 1 is inferred from the rule above. A crash of powershell.exe itself would also exit non-zero with no error record, and those logs cannot rule it out. The new helper prints the exit code and stdout, so the next failure, if any, will show which it was.

What changes

  1. The test no longer waits on a process id. It waits for the state it asserts on.
    • Before calling start, the test watches its home folder with the file's existing watchJson helper, the same way the desktop start test already does. The wait ends when started.json is there and complete, and it has a 30 s bound.
    • The stand-in now writes its log line first, with a synchronous writeSync(1, ...); the launcher redirects stdout to the log.
    • The stand-in then writes started.json.tmp and renames it to started.json (as in Flaky windows-native test: the desktop child's result file is parsed while still being written #2165). Once started.json can be read, the log line is already in the log.
    • The case's budget goes from 60 s to 90 s, so it holds the worst case: the steps before and after the wait on a busy runner, the 30 s wait, and the 20 s removal. The file's own check that every Windows-only case has a budget of at least 30 s still holds.
    • If the wait fails, its error also carries the bridge log. The launcher sends the stand-in's stderr there too, so a stand-in that failed says why.
    • Both variants (junction=false and junction=true) get this change.
  2. watchJson can no longer fail on a missed event. It still waits on change events, with no polling. It now also looks once when its watch starts, and a last time when its deadline fires. A merged or missed event, or a look that found the file busy with no change after it, can no longer fail a wait whose file is complete. It still rejects if the file is not complete at that last look, and it never resolves on an incomplete file.
  3. Cleanup allows for a launcher that is still exiting. The old helper waited for the launcher's process; the new test does not. So the fixture is removed with removeFixture, a bounded retry for up to 20 s (25 ms between tries) on EBUSY, ENOTEMPTY or EPERM, the codes Node's rm retries. 20 s is no less than the 15 s the old test waited for the launcher. It is the same kind of loop as the desktop start test's cleanup, which retries only EBUSY for 5 s.
    • A cleanup error no longer replaces the test's own error. The two are collected the way the desktop start test does it: the test's error is thrown first, and a cleanup failure is attached in an AggregateError.
    • The rm(..., { maxRetries: 20, retryDelay: 100 }) it replaces never retried, because Bun 1.4.2 reads those options and never uses them. In the source at tag bun-v1.4.2 (744846f8, the build CI's logs print), in src/runtime/node/node_fs.rs, max_retries and retry_delay appear only in the option parser (lines 3203-3284). fn rm (line 7500) calls zig_delete_tree once (line 7511) and returns its error.
  4. The file's PowerShell helpers say how they failed.
    • The bridge test's helper and the bundle-install test's helper now share one function, windowsPowerShell.
    • It sets $ProgressPreference = 'SilentlyContinue', as ssh.ts already does for the product, so stderr holds errors, not CLIXML progress.
    • On a non-zero exit it throws powershell.exe exited with <code> with stdout and stderr.

What the tests assert about the product is unchanged.

Why the new wait cannot pass early or hang

  • watchJson resolves only when completeJson parses the whole file. A missing, busy or half-written file reads as "not yet".
  • The watcher is started before start launches anything, and it also looks once when it starts. If the change event for the rename is merged or missed, the look at the deadline still finds the complete file.
  • The file's name appears only by a rename, after its content and after the log line were written. So the later checks of the log line, the launcher text, and the status file removed by start's own script cannot run early.
  • The wait for started.json cannot run past its bound. At 30 s, watchJson looks one last time and then rejects with "...started.json was not written" and the bridge log. The finally closes the watcher in every case.
  • The 30 s bounds only the wait for started.json. It does not bound the PowerShell call inside start, which has no limit of its own; the case's 90 s budget bounds that call (60 s before this change).
  • The test does not need the launcher to have exited. The only place that touches what it may still hold is cleanup, and cleanup retries for up to 20 s.

Not changed

The product's start path does not wait on the process: remote-host.ts:425-426 launches and checks ReturnValue, and windows-herdr-start.ts:126-127 ends with an explicit exit $r.ReturnValue. So the product does not have this race.

app/electron/windows/replace-old-setup.ps1:94,97 uses the same Wait-Process ... -ErrorAction SilentlyContinue line. There, more statements follow it and the script ends with an explicit exit $failed, so the silenced error cannot reach the exit code.

There is no changelog fragment. changelog.d/README.md asks for one only from "a PR that changes something users notice", and this PR changes only a test.

Validation

bun run check fast ran twice on this head. In both runs this file's Windows cases were skipped on Linux, and its two cases that run everywhere passed, including the #2165 watchJson case.

  • Run 1: unit: 18268 pass, 1 fail, 61 skip in 986 files (732 s).
    • The one failure was in server/machine-core-choice.test.ts, a file this PR does not touch: "chooses the PC's own core server: runtime dir" hit its own 5 s reconnect deadline (the reconnect did not settle).
    • The PC was carrying three such runs at the time.
    • That file then passed alone on the same head (52 pass, 0 fail).
  • Run 2: unit: 18269 pass, 0 fail, 61 skip in 986 files; workflow syntax, generated types and themes, typecheck and build all ok (585 s).

The Windows test itself was not run locally. It runs only on Windows, and it was not run in the Windows VM either.

The real check is GitHub's "Native Windows install" job on this PR. It runs once with the PR, and is then rerun twice after it ends (N = 2), for three runs in all.

  • What three green runs show: that the new wait and the stand-in work on a Windows runner. The real unknown there is writeSync(1, ...) in the compiled stand-in.
  • What they do not show: that the old 1-in-260 failure is gone.
    • Assume independent runs at a fixed rate of 3 in about 773 (the figures do not establish that rate).
    • If the race were still there, three green runs would still be 99% likely.
    • To rule out the old rate with 95% confidence would take about 770 green runs.

The argument for this change is that the wait on a process id, where the race was read, is gone, and that any failure now prints its exit code and output.

…r its launcher's process, and say how PowerShell failed

The Windows bridge start test appended `Wait-Process -Id $r.ProcessId -Timeout 15
-ErrorAction SilentlyContinue` to windowsHost.start's script. The leading reading of
its failures: when the launcher's short-lived cmd.exe was gone before Wait-Process
looked it up, Wait-Process wrote a silenced non-terminating error, $? was false, and
powershell.exe -EncodedCommand exited non-zero with only CLIXML progress records on
stderr (the helper dropped the exit code and stdout). "Native Windows install"
failed so about once in 260 runs (3 of about 773, all junction=false).

The test now watches its home folder before the start (watchJson, as the desktop
start test does) until started.json is whole, within 30 s. The stand-in writes its
log line first and then renames started.json into place, so the assertions after
it cannot run early; a wait that fails carries the bridge log. watchJson also looks
once when its watch starts and once more at its deadline, so a merged or missed
change event cannot fail a wait whose file is whole. The fixture is removed with a
bounded retry of 20 s (no less than the 15 s the old test waited for the
launcher), as the launcher may still be exiting: Bun 1.4.2's rm never reads
maxRetries. A cleanup error comes after the test's own, never in its place, and
the case's budget (90 s) holds the steps, the 30 s wait and the 20 s removal.
Both PowerShell helpers of the file share windowsPowerShell, which turns progress
off as ssh.ts does and, on a non-zero exit, throws with the exit code, stdout and
stderr. The product is unchanged.
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Improved the reliability of Windows test checks for generated results, PowerShell commands, and temporary-file cleanup.
    • Test failures now include captured command output, and the bridge startup test reports errors from both verification and cleanup.

The Windows native tests now share PowerShell execution and fixture cleanup helpers. The bridge startup test waits for a complete JSON result written through a temporary file and rename.

Changes: Windows native test reliability

Layer / File(s) Summary
PowerShell execution and fixture cleanup
server/windows-native.test.ts
Shared helpers run encoded PowerShell scripts and retry fixture removal. The bridge and bundle-install tests use the PowerShell helper. The bridge test aggregates test and cleanup errors and uses a longer timeout.
Wait for complete bridge results
server/windows-native.test.ts
watchJson checks immediately, on changes, and at timeout. The bridge stand-in writes its result to a temporary file and renames it into place. Result-wait failures include the bridge log.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Suggested reviewers: yeongjo, islee23520

Merge Risk: Minimal · up to 437e7

This change only makes a Windows test more reliable and does not affect product behavior. Merge risk is minimal. The Windows CI check will confirm the new wait works on a runner.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the windows-native test now waits for the bridge's startup output rather than the launcher process, and PowerShell failures are reported. The raw summary and objective…
Description check Passed The description follows the template's Change and Validation sections. Change explains the problem (a race in the launcher-process wait), the resulting behavior, and why the product is unchanged. Vali…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the windows-native test now waits for the bridge's startup output rather than the launcher process, and PowerShell failures are reported. The raw summary and objectives confirm this matches the changeset, which is test-only and scoped to server/windows-native.test.ts.

Full details: Description check

Explanation

The description follows the template's Change and Validation sections. Change explains the problem (a race in the launcher-process wait), the resulting behavior, and why the product is unchanged. Validation lists the commands run (bun run check fast, twice, with results) and states that the Windows test was not run locally or in the Windows VM. The template's Change section asks for a linked issue for features only, and this is a test-only fix, so that is not required. The description is detailed and the template's headings are covered.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 116252f and 437e750.

Files selected for processing: 1

  • server/windows-native.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@devswha
devswha merged commit 0b4b6ff into main Nov 17, 2026
48 checks passed
@devswha

devswha commented Nov 17, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 437e7504497f as 0b4b6ffbda17 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Test-only: one file, server/windows-native.test.ts. Both reviews are clear at 437e7504; the four required checks are green there, and the Windows job ran three times on this head, all green.

What the reviews confirmed: every assertion of the two touched cases is still there (12 and 6); the only thing dropped is the silenced wait for the test's own launcher process, which was never a property of the product. The watch is installed before the launch in a fresh folder, and a broken bridge still fails the test.

What this does not show: the cause of the earlier failures (3 in about 773 attempts of Native Windows install) was read from the log, not reproduced. Three green runs do not prove a failure of that rate gone; about 780 clean runs would.

Low notes left as follow-ups:

  • The cleanup retry covers EBUSY, ENOTEMPTY and EPERM; Bun reports "access denied" as EACCES, which is not retried.
  • A cleanup error can replace the test's own error if closing the watcher fails after the test already failed.
  • Outside this change, in the same file's desktop test: a process id read from a file is signalled without checking whose it is (Windows-only path).

@devswha
devswha deleted the test/windows-native-start-wait branch November 17, 2026 08:03
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.

1 participant