Repository navigation
test(windows-native): wait for what the started bridge writes, not for its launcher's process, and say how PowerShell failed - #4021
Conversation
…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.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Merge passMerged head
Test-only: one file, 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 Low notes left as follow-ups:
|
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):
All three failures look the same:
windowsHost.start.powershell.exeexited non-zero.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'scmd.exelauncher throughInvoke-CimMethod Win32_Process Createand 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:That line was at
windows-native.test.ts:280on main.Leading hypothesis, from reading the code (not reproduced). The launched
cmd.exelives a very short time: it runs the stand-inovis-server.exe, which writes one file and one line and then exits. When that process is already gone by the timeWait-Processlooks up its id, this is what happens:Wait-Processwrites a non-terminating error. That isNoProcessFoundForGivenId, orProcessNotTerminatedif the process is still exiting (seeProcess.csin PowerShell's source).-ErrorAction SilentlyContinuehides the error, but$?stays$false.-Command/-EncodedCommand,powershell.exeexits with 1 when the last command's$?is false (about_PowerShell_exe).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.exeitself 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
start, the test watches its home folder with the file's existingwatchJsonhelper, the same way the desktop start test already does. The wait ends whenstarted.jsonis there and complete, and it has a 30 s bound.writeSync(1, ...); the launcher redirects stdout to the log.started.json.tmpand renames it tostarted.json(as in Flaky windows-native test: the desktop child's result file is parsed while still being written #2165). Oncestarted.jsoncan be read, the log line is already in the log.watchJsoncan 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.removeFixture, a bounded retry for up to 20 s (25 ms between tries) on EBUSY, ENOTEMPTY or EPERM, the codes Node'srmretries. 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.AggregateError.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 tagbun-v1.4.2(744846f8, the build CI's logs print), insrc/runtime/node/node_fs.rs,max_retriesandretry_delayappear only in the option parser (lines 3203-3284).fn rm(line 7500) callszig_delete_treeonce (line 7511) and returns its error.windowsPowerShell.$ProgressPreference = 'SilentlyContinue', asssh.tsalready does for the product, so stderr holds errors, not CLIXML progress.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
watchJsonresolves only whencompleteJsonparses the whole file. A missing, busy or half-written file reads as "not yet".startlaunches 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.start's own script cannot run early.started.jsoncannot run past its bound. At 30 s,watchJsonlooks one last time and then rejects with "...started.json was not written" and the bridge log. Thefinallycloses the watcher in every case.started.json. It does not bound the PowerShell call insidestart, which has no limit of its own; the case's 90 s budget bounds that call (60 s before this change).Not changed
The product's start path does not wait on the process:
remote-host.ts:425-426launches and checksReturnValue, andwindows-herdr-start.ts:126-127ends with an explicitexit $r.ReturnValue. So the product does not have this race.app/electron/windows/replace-old-setup.ps1:94,97uses the sameWait-Process ... -ErrorAction SilentlyContinueline. There, more statements follow it and the script ends with an explicitexit $failed, so the silenced error cannot reach the exit code.There is no changelog fragment.
changelog.d/README.mdasks for one only from "a PR that changes something users notice", and this PR changes only a test.Validation
bun run check fastran 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 #2165watchJsoncase.unit: 18268 pass, 1 fail, 61 skip in 986 files(732 s).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).unit: 18269 pass, 0 fail, 61 skip in 986 files; workflow syntax, generated types and themes, typecheck and build allok(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.
writeSync(1, ...)in the compiled stand-in.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.