startup: return the debugger's exit code from run.ps1 #1596

Merged
RenzoWit35 merged 1 commit from upstream-pr/1603 into main 2026-11-24 14:56:28 +00:00
RenzoWit35 commented 2026-11-24 14:47:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T14:47:59Z.


Change

tools/startup/run.ps1 never read $LASTEXITCODE, so it exited 0 whatever tools/startup/debug_launch.py returned. A caller or wrapper saw success when the debugger printed CreateProcess failed <error> and returned 2. Under PowerShell 7 the same held when the debugger ended with an uncaught Python exception.

  • run.ps1 now stores $LASTEXITCODE right after the debugger call, prints the first five lines of <LogDir>.out as before, and ends with exit $debuggerExit. Two added lines; parameters, environment switches and the debugger call itself are unchanged.
  • New tests/startup_run_ps1_check.py (ctest startup_run_ps1, registered next to startup_triage_run; also added as one line after tests/startup_triage_run_check.py \ in the single tools/run_checks_parallel.py command of the platform-independent Python job). On Windows it copies run.ps1 into a temporary tree whose debug_launch.py is a stub, with empty placeholder files for the eight stand-in DLLs and the executable, and runs it under every PowerShell found (powershell and pwsh). For stub exit codes 2, 0 and 7 it checks the script's exit code, that exactly the first five of the stub's seven lines are printed, that <LogDir>.out holds all seven, and that the debugger received <exe> <datadir> <logdir> --timeout 9 --memory-gib 3 --trace-files 1 --continue-asserts 4. On a host other than Windows, without a PowerShell, or with --text-only, it checks the text after the debugger call instead (a $LASTEXITCODE capture, the log head, a final exit of that variable). The call is found as the one statement that names debug_launch.py, however the interpreter is spelled. Three mutated copies of the script (no capture and no exit, a fixed exit 2, exit before the log head) must fail in whichever mode runs.
  • docs/startup-runtime.md gets one paragraph with the exit status and the check command.

Not changed: debug_launch.py. It returns 2 when the process cannot be created and 0 after a run it reported on, whatever the process did, so run.ps1 still exits 0 for such a run.

Verification

Environment: Windows 11, Windows PowerShell 5.1.26100.9818, PowerShell 7.7.0, Python 3.14.5, base a3ac47a9. The real debug_launch.py was never started; every run used a stub.

Before (unmodified run.ps1, stub import sys; print("stub: CreateProcess failed 193"); sys.exit(2), run from the scratch tree):

  • pwsh -NoProfile -File tools/startup/run.ps1 -Exe run/t.exe -DataDir data -LogDir lg7 -BuildDir bld: prints stub: CreateProcess failed 193, exit code 0.
  • powershell -NoProfile -ExecutionPolicy Bypass -File tools/startup/run.ps1 -Exe run/t.exe -DataDir data -LogDir lg5 -BuildDir bld: same line, exit code 0.

After (same commands): both print the same line and exit 2. Inside a session, pwsh -NoProfile -Command "& ./tools/startup/run.ps1 ...; 'after=' + $LASTEXITCODE" prints after=2 in both shells, so exit ends only the script; the same holds for .\tools\startup\run.ps1 ... and for a dot-sourced call. With -Command and the script as the last statement, the host exits 1 (0 before).

Checks after the change:

  • out/pe-env/Scripts/python.exe -B tests/startup_run_ps1_check.py: startup run.ps1 exit code: 0 failed (executed with powershell, pwsh), about 10 s.
  • out/pe-env/Scripts/python.exe -B tests/startup_run_ps1_check.py --text-only: startup run.ps1 exit code: 0 failed (text only: requested). With PATH reduced to the Python directory: 0 failed (text only: no PowerShell found).
  • cmake --preset dev -B out/build/dev -DINTAKE_PYTHON=<venv python>, then ctest --test-dir out/build/dev --no-tests=error -R "^startup_(run_ps1|triage_run)$": 2 of 2 passed (startup_run_ps1 11.24 s).
  • [System.Management.Automation.Language.Parser]::ParseFile on the edited run.ps1: 0 errors in both shells. The file keeps CRLF line endings, no byte order mark, ASCII only; git diff --stat shows 2 insertions.
  • tests/startup_triage_run_check.py: 0 failed. tests/dev_ps1_sccache_check.py: ok (executed with pwsh). tests/docs_links_check.py: 16 Markdown files, 347 links. tests/bidi_controls_check.py: 1260 files, no bidirectional controls.
  • ast.parse(source, feature_version=(3, 11)) accepts the new check.

Negative control 1, the new check on run.ps1 from origin/main:

FAIL powershell: stub debugger exited 2, run.ps1 exited 0
FAIL powershell: stub debugger exited 7, run.ps1 exited 0
FAIL pwsh: stub debugger exited 2, run.ps1 exited 0
FAIL pwsh: stub debugger exited 7, run.ps1 exited 0
startup run.ps1 exit code: 4 failed (executed with powershell, pwsh)

With --text-only: FAIL text: the statement after the debugger call does not store $LASTEXITCODE, exit code 1. Only the exit code fails there: the log head, <LogDir>.out and the argument list already pass on the old script.

Negative control 2, edited scratch copies of the fixed script:

  • exit line removed, or exit 0: the same four exited 0 failures; text mode: the script does not end with 'exit $debuggerExit'.
  • exit 2: stub debugger exited 0, run.ps1 exited 2 and stub debugger exited 7, run.ps1 exited 2 in both shells.
  • exit moved before Get-Content: printed [] instead of the first 5 debugger lines for all three codes in both shells.
  • -TotalCount 3: printed ['stub debugger line 1', 'stub debugger line 2', 'stub debugger line 3'] instead of the first 5 debugger lines.

Rebased onto origin/main at a3ac47a9 before opening this pull request and re-run there: tests/startup_run_ps1_check.py 0 failed (executed with powershell, pwsh); tests/docs_links_check.py (16 Markdown files, 347 links) and tests/bidi_controls_check.py (1260 files) pass; tools/run_checks_parallel.py tests/startup_triage_run_check.py tests/startup_run_ps1_check.py tests/run_checks_parallel_check.py all 3 checks passed; the check on run.ps1 from origin/main fails with 4 failures (exited 0 for stub exit codes 2 and 7 in both shells); on a trial merge with #1535 the check reports 0 failed in both modes.

Not run: the real debug_launch.py (it starts a process under a debugger); a CMake build and the full test suite; the check on a real Linux or macOS host (the text mode was only run on Windows, on the CRLF file and on an LF-only copy of its text); Python 3.11 and 3.12 (syntax only, see above).

Evidence and follow-up

Refs #1149 (a specific untested launcher behavior with a device-free control: the stub debugger).

  • #1535 edits the same file (it starts the debugger through & $python, the repository environment's interpreter when present) and docs/startup-runtime.md; it does not touch the exit status. A trial merge of its head 48a04876 with this branch (git merge-tree --write-tree, on a3ac47a9) is textually clean. On the merged run.ps1 the check passes in both modes (0 failed (executed with powershell, pwsh) and 0 failed (text only: requested)), and each of the three mutants is still reported by the text mode and by both shells. On #1535's own run.ps1, without this change, the check fails the same way as on origin/main.
  • #1251 edits the same debugger call in run.ps1 (it adds arguments) and does not touch the exit status. A trial merge of its head ad94c950 with this branch conflicts in run.ps1 and in CMakeLists.txt (the test registration; docs/startup-runtime.md and .github/workflows/windows.yml merge automatically): the two lines added here sit directly after the line it changes, so whichever lands second resolves a small conflict in each file. On a scratch copy of its run.ps1 with these two lines added by hand, the check passes in both modes and the three mutants are reported; without -MapDrive the debugger still receives exactly the argument list the check expects, under both shells.
  • .github/workflows/windows.yml: the open pull requests #1173 and #836 also edit it; trial merges of their heads (97a524a6, 4b253aca) with this branch are textually clean. CMakeLists.txt and docs/startup-runtime.md are edited by many open PRs; the hunks here are 2 and 6 lines.
  • startup_triage_run is not in the pr test preset, so startup_run_ps1 is not either. On pull requests only the text mode in the Linux job runs; the executing mode runs with the full Windows suite. Adding it to the pr filter needs no build target; the test took about 10 s on this PC.
  • Observed, not changed here: under Windows PowerShell 5.1, $ErrorActionPreference = "Stop" with *> turns the debugger's first stderr line into a terminating NativeCommandError. With a stub that prints one line and raises, Windows PowerShell 5.1 exits 1 without printing the log head, before and after this change (4 of 4 runs each). PowerShell 7 prints the log head and exited 0 before, 1 after.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6584471499 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1603). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T14:47:59Z. --- ## Change `tools/startup/run.ps1` never read `$LASTEXITCODE`, so it exited 0 whatever `tools/startup/debug_launch.py` returned. A caller or wrapper saw success when the debugger printed `CreateProcess failed <error>` and returned 2. Under PowerShell 7 the same held when the debugger ended with an uncaught Python exception. - `run.ps1` now stores `$LASTEXITCODE` right after the debugger call, prints the first five lines of `<LogDir>.out` as before, and ends with `exit $debuggerExit`. Two added lines; parameters, environment switches and the debugger call itself are unchanged. - New `tests/startup_run_ps1_check.py` (ctest `startup_run_ps1`, registered next to `startup_triage_run`; also added as one line after `tests/startup_triage_run_check.py \` in the single `tools/run_checks_parallel.py` command of the platform-independent Python job). On Windows it copies `run.ps1` into a temporary tree whose `debug_launch.py` is a stub, with empty placeholder files for the eight stand-in DLLs and the executable, and runs it under every PowerShell found (`powershell` and `pwsh`). For stub exit codes 2, 0 and 7 it checks the script's exit code, that exactly the first five of the stub's seven lines are printed, that `<LogDir>.out` holds all seven, and that the debugger received `<exe> <datadir> <logdir> --timeout 9 --memory-gib 3 --trace-files 1 --continue-asserts 4`. On a host other than Windows, without a PowerShell, or with `--text-only`, it checks the text after the debugger call instead (a `$LASTEXITCODE` capture, the log head, a final `exit` of that variable). The call is found as the one statement that names `debug_launch.py`, however the interpreter is spelled. Three mutated copies of the script (no capture and no exit, a fixed `exit 2`, exit before the log head) must fail in whichever mode runs. - `docs/startup-runtime.md` gets one paragraph with the exit status and the check command. Not changed: `debug_launch.py`. It returns 2 when the process cannot be created and 0 after a run it reported on, whatever the process did, so `run.ps1` still exits 0 for such a run. ## Verification Environment: Windows 11, Windows PowerShell 5.1.26100.9818, PowerShell 7.7.0, Python 3.14.5, base `a3ac47a9`. The real `debug_launch.py` was never started; every run used a stub. Before (unmodified `run.ps1`, stub `import sys; print("stub: CreateProcess failed 193"); sys.exit(2)`, run from the scratch tree): - `pwsh -NoProfile -File tools/startup/run.ps1 -Exe run/t.exe -DataDir data -LogDir lg7 -BuildDir bld`: prints `stub: CreateProcess failed 193`, exit code 0. - `powershell -NoProfile -ExecutionPolicy Bypass -File tools/startup/run.ps1 -Exe run/t.exe -DataDir data -LogDir lg5 -BuildDir bld`: same line, exit code 0. After (same commands): both print the same line and exit 2. Inside a session, `pwsh -NoProfile -Command "& ./tools/startup/run.ps1 ...; 'after=' + $LASTEXITCODE"` prints `after=2` in both shells, so `exit` ends only the script; the same holds for `.\tools\startup\run.ps1 ...` and for a dot-sourced call. With `-Command` and the script as the last statement, the host exits 1 (0 before). Checks after the change: - `out/pe-env/Scripts/python.exe -B tests/startup_run_ps1_check.py`: `startup run.ps1 exit code: 0 failed (executed with powershell, pwsh)`, about 10 s. - `out/pe-env/Scripts/python.exe -B tests/startup_run_ps1_check.py --text-only`: `startup run.ps1 exit code: 0 failed (text only: requested)`. With `PATH` reduced to the Python directory: `0 failed (text only: no PowerShell found)`. - `cmake --preset dev -B out/build/dev -DINTAKE_PYTHON=<venv python>`, then `ctest --test-dir out/build/dev --no-tests=error -R "^startup_(run_ps1|triage_run)$"`: 2 of 2 passed (`startup_run_ps1` 11.24 s). - `[System.Management.Automation.Language.Parser]::ParseFile` on the edited `run.ps1`: 0 errors in both shells. The file keeps CRLF line endings, no byte order mark, ASCII only; `git diff --stat` shows 2 insertions. - `tests/startup_triage_run_check.py`: `0 failed`. `tests/dev_ps1_sccache_check.py`: `ok (executed with pwsh)`. `tests/docs_links_check.py`: 16 Markdown files, 347 links. `tests/bidi_controls_check.py`: 1260 files, no bidirectional controls. - `ast.parse(source, feature_version=(3, 11))` accepts the new check. Negative control 1, the new check on `run.ps1` from `origin/main`: ``` FAIL powershell: stub debugger exited 2, run.ps1 exited 0 FAIL powershell: stub debugger exited 7, run.ps1 exited 0 FAIL pwsh: stub debugger exited 2, run.ps1 exited 0 FAIL pwsh: stub debugger exited 7, run.ps1 exited 0 startup run.ps1 exit code: 4 failed (executed with powershell, pwsh) ``` With `--text-only`: `FAIL text: the statement after the debugger call does not store $LASTEXITCODE`, exit code 1. Only the exit code fails there: the log head, `<LogDir>.out` and the argument list already pass on the old script. Negative control 2, edited scratch copies of the fixed script: - `exit` line removed, or `exit 0`: the same four `exited 0` failures; text mode: `the script does not end with 'exit $debuggerExit'`. - `exit 2`: `stub debugger exited 0, run.ps1 exited 2` and `stub debugger exited 7, run.ps1 exited 2` in both shells. - `exit` moved before `Get-Content`: `printed [] instead of the first 5 debugger lines` for all three codes in both shells. - `-TotalCount 3`: `printed ['stub debugger line 1', 'stub debugger line 2', 'stub debugger line 3'] instead of the first 5 debugger lines`. Rebased onto `origin/main` at `a3ac47a9` before opening this pull request and re-run there: `tests/startup_run_ps1_check.py` `0 failed (executed with powershell, pwsh)`; `tests/docs_links_check.py` (16 Markdown files, 347 links) and `tests/bidi_controls_check.py` (1260 files) pass; `tools/run_checks_parallel.py tests/startup_triage_run_check.py tests/startup_run_ps1_check.py tests/run_checks_parallel_check.py` `all 3 checks passed`; the check on `run.ps1` from `origin/main` fails with 4 failures (`exited 0` for stub exit codes 2 and 7 in both shells); on a trial merge with #1535 the check reports `0 failed` in both modes. Not run: the real `debug_launch.py` (it starts a process under a debugger); a CMake build and the full test suite; the check on a real Linux or macOS host (the text mode was only run on Windows, on the CRLF file and on an LF-only copy of its text); Python 3.11 and 3.12 (syntax only, see above). ## Evidence and follow-up Refs #1149 (a specific untested launcher behavior with a device-free control: the stub debugger). - #1535 edits the same file (it starts the debugger through `& $python`, the repository environment's interpreter when present) and `docs/startup-runtime.md`; it does not touch the exit status. A trial merge of its head `48a04876` with this branch (`git merge-tree --write-tree`, on `a3ac47a9`) is textually clean. On the merged `run.ps1` the check passes in both modes (`0 failed (executed with powershell, pwsh)` and `0 failed (text only: requested)`), and each of the three mutants is still reported by the text mode and by both shells. On #1535's own `run.ps1`, without this change, the check fails the same way as on `origin/main`. - #1251 edits the same debugger call in `run.ps1` (it adds arguments) and does not touch the exit status. A trial merge of its head `ad94c950` with this branch conflicts in `run.ps1` and in `CMakeLists.txt` (the test registration; `docs/startup-runtime.md` and `.github/workflows/windows.yml` merge automatically): the two lines added here sit directly after the line it changes, so whichever lands second resolves a small conflict in each file. On a scratch copy of its `run.ps1` with these two lines added by hand, the check passes in both modes and the three mutants are reported; without `-MapDrive` the debugger still receives exactly the argument list the check expects, under both shells. - `.github/workflows/windows.yml`: the open pull requests #1173 and #836 also edit it; trial merges of their heads (`97a524a6`, `4b253aca`) with this branch are textually clean. `CMakeLists.txt` and `docs/startup-runtime.md` are edited by many open PRs; the hunks here are 2 and 6 lines. - `startup_triage_run` is not in the `pr` test preset, so `startup_run_ps1` is not either. On pull requests only the text mode in the Linux job runs; the executing mode runs with the full Windows suite. Adding it to the `pr` filter needs no build target; the test took about 10 s on this PC. - Observed, not changed here: under Windows PowerShell 5.1, `$ErrorActionPreference = "Stop"` with `*>` turns the debugger's first stderr line into a terminating `NativeCommandError`. With a stub that prints one line and raises, Windows PowerShell 5.1 exits 1 without printing the log head, before and after this change (4 of 4 runs each). PowerShell 7 prints the log head and exited 0 before, 1 after. AI-assisted.
upstream-sync closed this pull request 2026-11-24 15:02:18 +00:00
Sign in to join this conversation.
No reviewers
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!1596
No description provided.