startup: run.ps1 exits 1 instead of the debugger's exit code when taskkill reports an error for the -Translate watcher #2264

Closed
opened 2026-11-25 09:09:26 +00:00 by alvaroolt · 1 comment
alvaroolt commented 2026-11-25 09:09:26 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by alvaroolt on 2026-11-25T09:09:26Z.


Commit or build

main at 1a713de0 (tools/startup/run.ps1 line 79, added in 37aefadf / #2120)

Reproduction

run.ps1 sets $ErrorActionPreference = "Stop" and stops the -Translate watcher in a finally block:

if ($translator) { & taskkill.exe /T /F /PID $translator.Id 2>&1 | Out-Null }

Windows PowerShell 5.1 turns each stderr line of a native command redirected with 2>&1 into an error record, and Stop turns it into a terminating error. Whenever taskkill writes to stderr, the script therefore aborts. Before it aborts, it has printed neither the head of <LogDir>.out nor run exit $debuggerExit. A standalone script shows the mechanism:

# taskkill_stop.ps1 — run with: powershell -NoProfile -ExecutionPolicy Bypass -File taskkill_stop.ps1
$ErrorActionPreference = "Stop"
$p = Start-Process -FilePath cmd.exe -ArgumentList '/c','exit 0' -PassThru -NoNewWindow
$p.WaitForExit()
try {
    & taskkill.exe /T /F /PID $p.Id 2>&1 | Out-Null
    "reached the next statement"
} catch {
    "terminating error: $($_.FullyQualifiedErrorId)"
}
# prints: terminating error: NativeCommandError

Through run.ps1 itself, with the stub tree of tests/startup_run_ps1_check.py (no title files, no debugger): replace WATCH_STUB with a watcher that writes watch.json and exits at once, then call run_case(shell, script, code, tmp, translate=True) for debugger exit codes 0 and 7.

Expected behavior

run.ps1 -Render -Translate prints the first five lines of <LogDir>.out and exits with the debugger's exit code, as it does without -Translate (#1603). This should hold whether the watcher is still running or has already exited (crash, bad cache path or early return) when the debugger finishes. It should also hold when part of its process tree is already gone while taskkill /T walks it.

Observed behavior

With a watcher that has already exited, both cases fail the same way (run with the check from #2271, which reads the localized warning prefix):

stub debugger exited 0, run.ps1 exited 1
stub exit 0: printed ['ADVERTENCIA: Without -FakeUser, ...'], expected ['ADVERTENCIA: Without -FakeUser, ...', 'stub debugger line 1', ..., 'stub debugger line 5']
  (stderr: 'taskkill.exe : ERROR: ... NativeCommandError')
stub debugger exited 7, run.ps1 exited 1

The debugger's exit code is lost and the log head is not printed.

The same error also appeared once, intermittently, with the normal long-running watcher stub. That happened in the -Translate case of tests/startup_run_ps1_check.py during a full tools/run_checks_parallel.py run: run.ps1 exited 1, with stderr taskkill.exe : ERROR: el proceso con PID … (proceso secundario de PID …) (Spanish Windows) pointing at line 79. The check then passed in 8 of 8 serial runs and in 8 of 8 runs started at once, so this path is rare. A watcher that has already exited reproduces the failure every time.

A possible direction, for whoever picks this up: stop the tree without letting taskkill's stderr become a terminating error. For example, check $translator.HasExited first and run taskkill with a local $ErrorActionPreference = "Continue", or through Start-Process -Wait. Add a case to tests/startup_run_ps1_check.py with a watcher that exits early, which must still yield the debugger's exit code and the log head. The existing cleanup controls from #2222 still apply.

Environment

Windows 11 build 26300.9974 (UI language es-ES), Windows PowerShell 5.1.26100.9818, Python 3.12. pwsh 7 was not tested; its handling of native stderr under Stop differs from 5.1. No GPU involved.

Checklist

  • I reproduced this on a source-built input.
  • I did not include game files, dumps, distribution links or credentials.

This report was AI-assisted (Claude Code); I reviewed the reproduction and its output.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6601011878 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2272). Originally posted by [alvaroolt](https://github.com/alvaroolt) on 2026-11-25T09:09:26Z. --- ### Commit or build `main` at 1a713de0 (`tools/startup/run.ps1` line 79, added in 37aefadf / #2120) ### Reproduction `run.ps1` sets `$ErrorActionPreference = "Stop"` and stops the `-Translate` watcher in a `finally` block: ```powershell if ($translator) { & taskkill.exe /T /F /PID $translator.Id 2>&1 | Out-Null } ``` Windows PowerShell 5.1 turns each stderr line of a native command redirected with `2>&1` into an error record, and `Stop` turns it into a terminating error. Whenever `taskkill` writes to stderr, the script therefore aborts. Before it aborts, it has printed neither the head of `<LogDir>.out` nor run `exit $debuggerExit`. A standalone script shows the mechanism: ```powershell # taskkill_stop.ps1 — run with: powershell -NoProfile -ExecutionPolicy Bypass -File taskkill_stop.ps1 $ErrorActionPreference = "Stop" $p = Start-Process -FilePath cmd.exe -ArgumentList '/c','exit 0' -PassThru -NoNewWindow $p.WaitForExit() try { & taskkill.exe /T /F /PID $p.Id 2>&1 | Out-Null "reached the next statement" } catch { "terminating error: $($_.FullyQualifiedErrorId)" } # prints: terminating error: NativeCommandError ``` Through `run.ps1` itself, with the stub tree of `tests/startup_run_ps1_check.py` (no title files, no debugger): replace `WATCH_STUB` with a watcher that writes `watch.json` and exits at once, then call `run_case(shell, script, code, tmp, translate=True)` for debugger exit codes 0 and 7. ### Expected behavior `run.ps1 -Render -Translate` prints the first five lines of `<LogDir>.out` and exits with the debugger's exit code, as it does without `-Translate` (#1603). This should hold whether the watcher is still running or has already exited (crash, bad cache path or early return) when the debugger finishes. It should also hold when part of its process tree is already gone while `taskkill /T` walks it. ### Observed behavior With a watcher that has already exited, both cases fail the same way (run with the check from #2271, which reads the localized warning prefix): ``` stub debugger exited 0, run.ps1 exited 1 stub exit 0: printed ['ADVERTENCIA: Without -FakeUser, ...'], expected ['ADVERTENCIA: Without -FakeUser, ...', 'stub debugger line 1', ..., 'stub debugger line 5'] (stderr: 'taskkill.exe : ERROR: ... NativeCommandError') stub debugger exited 7, run.ps1 exited 1 ``` The debugger's exit code is lost and the log head is not printed. The same error also appeared once, intermittently, with the normal long-running watcher stub. That happened in the `-Translate` case of `tests/startup_run_ps1_check.py` during a full `tools/run_checks_parallel.py` run: `run.ps1 exited 1`, with stderr `taskkill.exe : ERROR: el proceso con PID … (proceso secundario de PID …)` (Spanish Windows) pointing at line 79. The check then passed in 8 of 8 serial runs and in 8 of 8 runs started at once, so this path is rare. A watcher that has already exited reproduces the failure every time. A possible direction, for whoever picks this up: stop the tree without letting `taskkill`'s stderr become a terminating error. For example, check `$translator.HasExited` first and run `taskkill` with a local `$ErrorActionPreference = "Continue"`, or through `Start-Process -Wait`. Add a case to `tests/startup_run_ps1_check.py` with a watcher that exits early, which must still yield the debugger's exit code and the log head. The existing cleanup controls from #2222 still apply. ### Environment Windows 11 build 26300.9974 (UI language es-ES), Windows PowerShell 5.1.26100.9818, Python 3.12. `pwsh` 7 was not tested; its handling of native stderr under `Stop` differs from 5.1. No GPU involved. ### Checklist - [x] I reproduced this on a source-built input. - [x] I did not include game files, dumps, distribution links or credentials. This report was AI-assisted (Claude Code); I reviewed the reproduction and its output.
RavenCurseBurg commented 2026-11-25 10:05:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T09:15:37Z.


I’ll take this using the existing synthetic launcher fixture on Windows PowerShell 5.1 and PowerShell 7. I’ll check the five-line output and debugger exit codes 0 and 7 after the watcher has actually exited, and retain the live parent/child cleanup controls from #2222. I’ll also check the stderr race independently of the early-exit case.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7158089706 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2272#issuecomment-7158089706). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T09:15:37Z. --- I’ll take this using the existing synthetic launcher fixture on Windows PowerShell 5.1 and PowerShell 7. I’ll check the five-line output and debugger exit codes 0 and 7 after the watcher has actually exited, and retain the live parent/child cleanup controls from #2222. I’ll also check the stderr race independently of the early-exit case.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#2264
No description provided.