Skip to content

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

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
RenzoWit35:startup/run-ps1-exit-code
Nov 24, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
RenzoWit35:startup/run-ps1-exit-code

Conversation

@RenzoWit35

Copy link
Copy Markdown
Contributor

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).

  • startup: run the debugger with the repository Python #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 startup: run the debugger with the repository Python #1535's own run.ps1, without this change, the check fails the same way as on origin/main.
  • startup: map a console package drive letter to a real folder #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 ci: run the full Windows suites with CTest in parallel #1173 and Textures: build and verify a standalone Rust DDS batch exporter #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.

tools/startup/run.ps1 never read $LASTEXITCODE, so it exited 0 whatever
tools/startup/debug_launch.py returned. A caller saw success when the
debugger printed "CreateProcess failed" and returned 2.

The script now stores $LASTEXITCODE right after the debugger call, prints
the first five lines of <LogDir>.out as before and exits with the stored
code. The debugger still returns 0 for a run it reported on, whatever the
process did; that is not changed.

tests/startup_run_ps1_check.py (ctest startup_run_ps1) runs a copy of the
script on a stub debug_launch.py under Windows PowerShell 5.1 and pwsh,
for stub exit codes 2, 0 and 7, and checks the exit code, the printed log
head, <LogDir>.out and the arguments the debugger received. On a host
other than Windows, or without a PowerShell, it checks the text after the
debugger call instead. Three mutated copies of the script must fail in
either mode.

Refs R0Y00#1149
@R0Y00
R0Y00 merged commit e92566a into R0Y00:main Nov 24, 2026
5 checks passed
denn0x added a commit to denn0x/Xbox2Windows that referenced this pull request Nov 25, 2026
Conflicts resolved keeping both sides:
- d3d12_draw.inl: mip comment line, upstream's wording (R0Y00#1630).
- d3d12_xs_device.cpp: Pass keeps local compute root state and upstream viewport/scissor flags (R0Y00#1657);
  local ExecuteIndirect trace (slot 61) and upstream list_root_cbv (slot 42, R0Y00#1654) both kept.
- xcrdapi.cpp: local failure tally, RDS5 shift/slice and stream cache kept next to upstream's BCPack
  census (R0Y00#1622); queue worker is upstream's CreateThread worker (R0Y00#1410), the local
  tally_failure("exception") moved into fail_entry.
- run.ps1: upstream venv python and exit code (R0Y00#1535/R0Y00#1603) with local --fast-exit/--log-repeats.
- gfx2hlsl.py image(): local 1D lowering (load, sample, sample_l, a16) kept over upstream's
  sample-only 1D guard; startup_image_sample_l_check keeps the local 1D SampleLevel expectation,
  startup_image_3d_check keeps the local 1D assertions plus upstream's cube-dimension refusal.

Tests adjusted for local behaviour: startup_run_ps1_check expects the two local debugger
arguments, startup_translator_check's StubPipeline has ps_entry_reads, and the coverage check's
hand-built Pipeline sets packed_position_vgpr (new in R0Y00#1634).
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.

2 participants