tooling: preserve the debugger exit code when the watcher stops early #2267
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2275"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T09:23:02Z.
Fixes #2272.
When the translation watcher has already exited, the launcher skips cleanup. For a live watcher it still runs
taskkill /T /Fto stop the worker tree. The native command runs with a locally scopedContinuepreference so a worker disappearing during cleanup cannot turn redirected stderr into a terminating error on Windows PowerShell 5.1.The regression uses the existing synthetic Python watcher and debugger. In the new cases the watcher publishes its PID atomically and exits without starting a child. The debugger waits until Windows no longer reports that PID before it prints seven lines and returns 0 or 7. The test checks all seven lines in the file, the first five on the console, and the launcher's exit code. The existing live parent/child cleanup tests run as before.
Verification
Windows 11 build 26100.9711, Windows PowerShell 5.1.26100.9711 and PowerShell 7.6.9, head
4a6669a3.python -B tests/startup_run_ps1_check.pyreported0 failed (executed with powershell, pwsh), including the missing-tree-stop and parent-only cleanup controls.python -B tests/startup_run_ps1_check.py --text-onlyreported 0 failures.git diff --checkpassed.07c1c20f, the early-exit fixture reproduced #2272 on 5.1 for both debugger codes. The launcher returned 1, printed none of the five summary lines, and reportedNativeCommandErrorbecause the PID was gone. PowerShell 7 preserved both original codes.HasExitedcheck from a scratch copy. Calling realtaskkill.exeon the already-exited fixture PID then preserved the five lines and both exit codes on both shells. RestoringStopinside that same copy reproduced the two failures on 5.1.The fixture builds on the repository's MIT-licensed test stubs. #2271 updates warning-prefix handling in the same test file. This change exercises watcher lifetime and uses the existing output comparison.
AI-assisted with Codex.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:28:03Z.
Review: COMMENTED
Review of head
4a6669a37747d47bdfb615cb4e05eba7cc82231a(2 files:tools/startup/run.ps1,tests/startup_run_ps1_check.py).Verdict: no P1, no P2. Two nits.
What I read: the
finallyblock inrun.ps1and the newearly_exitstub paths in the check.run.ps1: skippingtaskkillwhen$translator.HasExitedis true, and runningtaskkillunder a local$ErrorActionPreference = "Continue", keeps a dying watcher from turning redirected stderr into a terminating error.exit $debuggerExitis then reached. The preference change is scoped to the script block, so the rest of the script keepsStop. Correct.tasklistpoll, bounded by a 30 s monotonic deadline) before it exits, so the early-exit race is deterministic. The watcher record is written to a temp file and renamed, so the reader never sees a half-written file. Codes 0 and 7 are both checked.time.monotonic()is the right clock here.Nits:
run.ps1finally block: when the watcher has already exited,taskkill /Tis skipped, which is fine because/Tcannot walk the tree of a dead parent anyway. Real workers that outlive an early-exited watcher would be orphaned either way. A short comment saying so would help the next reader.tests/startup_run_ps1_check.py: the early-exit stub spawns no child, so the case checks the exit code only. It does not check that no worker is left running. That is acceptable for this fix, but say so in the docstring.CI on this head:
Build and test on Windows: pass.Run platform-independent Python checks on LinuxandAssemble and translate gfx1013 fixtures: fail withTypeError: 'NoneType' object is not an iteratorattools/mesh_entry_aot.py:882(run_group) and inmesh_dynamic_aot.py. This PR does not touch those files. The branch is 1 commit behindorigin/main(ed96f498); please rebase and re-run to confirm the red checks are not from this PR.Commands executed locally (Linux):
git diff --stat origin/main...HEAD: 2 files, +40/-14.python3 tests/startup_run_ps1_check.py:startup run.ps1 exit code: 0 failed (text only: not a Windows host). The real process cases need PowerShell, which is not installed here (nopwsh).python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 435 links.python3 tests/bidi_controls_check.py: self-test passed, 1566 files, no bidirectional controls.git diff --check origin/main...HEAD: clean.Not done: no mutation run of the new logic, and no Win2025 run. The behaviour needs PowerShell 5.1, so it can only be mutation-tested on Windows. The PR's Windows CI job passes.
Clean-room and title: neutral, no concerns.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:41:05Z.
Review: COMMENTED
Re-review at head
c9e67d03c572bd8d275c006a21c68469a066cf61(previous review was at4a6669a3). Diff vs main:tools/startup/run.ps1(+9/-2) andtests/startup_run_ps1_check.py(+31/-12). The head is a merge of main; the new part is the early-exit watcher handling.Verdict: no P1, no P2. Two nits.
What I checked
run.ps1:79-86:taskkill /Tnow runs only if the watcher has not exited. When the parent PID is gone,/Tcannot find the workers anyway, so skipping loses nothing. The taskkill call is wrapped in a scope with$ErrorActionPreference = "Continue". The script setsStopat line 33, so in Windows PowerShell 5.1 a redirected stderr from taskkill, when the watcher dies mid-call, can no longer abort the launcher beforeexit $debuggerExit. The scope is a child scope, soStopis restored afterwards. Looks correct.early_exitcases for exit codes 0 and 7. The debugger stub waits until the OS confirms the watcher PID is gone, so the "already exited" path is deterministic.watch.jsonis written via temp file plusreplace, so the stub cannot read a half-written file.time.monotonic()is used for the deadlines. Thepid is not Noneguard in the cleanup check is right for the childless case.Commands run locally
python3 tests/startup_run_ps1_check.py->startup run.ps1 exit code: 0 failed (text only: not a Windows host)(the behavioural cases only run on Windows)python3 tests/docs_links_check.py-> 18 files, 435 links okpython3 tests/bidi_controls_check.py-> 1566 files, no bidi controlsgit diff --check origin/main...HEAD-> cleandev,--py-checks tests/startup_run_ps1_check.py:ctest --preset dev -R '^startup_run_ps1$'1/1 passed (7.95s); the Windows Python check passed (7.4s). Release was skipped on purpose: only a PowerShell script and a Python test changed.-and -not $translator.HasExitedfromrun.ps1, then ran the Linux text-only check. It still passed, so the Linux job does not kill this mutant. Only the Windows run exercises the new logic. I did not run the mutant on Windows. I restored the file withgit checkout -- ..Nits
tests/startup_run_ps1_check.py(text_problems/mutants_of): the Linux text check has no rule for the new guard or theContinuescope, so a regression there only shows up on the Windows CI job. A small text rule plus a mutant (for example "taskkill outside the guard") would cover the Linux job too. It is optional, because the real test covers it on Windows.run.ps1:79:HasExitedis read once. A watcher that exits between that check and taskkill is handled by theContinuescope, but the case is not tested. The new tests cover "already gone", not "gone during taskkill". Acceptable because it is a race.CI at review time: Linux Python checks pass; Windows jobs pending. The PR is mergeable.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:56:10Z.
Review: COMMENTED
Re-review of head
852beb5960d37ed4c6197b19ef843f25a2a505ae(new since last review: onlytests/startup_run_ps1_check.py, +21 lines;tools/startup/run.ps1unchanged vs. the previously reviewed head).What changed
WATCH_CLEANUPregex in the text-only path: requiresif ($translator -and -not $translator.HasExited) { & { $ErrorActionPreference = 'Continue' & taskkill.exe ....HasExitedguard, drop the localContinue) must be flagged.Commands executed locally (Linux, no PowerShell host available)
python3 tests/startup_run_ps1_check.py->0 failed (text only: not a Windows host)python3 tests/docs_links_check.py-> pass (18 files, 435 links)python3 tests/bidi_controls_check.py-> passgit diff --check origin/main...HEAD-> clean-and -not $translator.HasExitedfrom run.ps1 ->FAIL text: taskkill lacks its live-watcher guard or local Continue scope(killed)$ErrorActionPreference = "Continue"with$x = 1-> same FAIL (killed)taskkill /T /Fto/F-> not detected in text-only mode (see nit)git checkout -- .Findings
/Tflag is not checked; the Windows-host path catches it via the "translator's child process still running" case. Linux CI therefore cannot see a dropped/T. Optional: add/T\s+/Fto theWATCH_CLEANUPregex.CI at review time: Linux Python checks pass; Windows jobs pending. PR is mergeable, title is neutral, scope is tooling only.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T09:25:59Z.
I reproduced the failing Linux mesh check on unmodified upstream
ed96f498withpython -B tests/mesh_dynamic_geometry_check.py. It reachesnext(steps)intools/mesh_entry_aot.pywithsteps = None. The failed Linux job reports the same failure in the mesh checks and the downstream PSO readiness assertion. #2276 and #2277 address that upstream regression. I'll pick up the merged fix and recheck this branch.Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T09:35:03Z.
Addressed both documentation comments in
bd2b5937. The launcher explains whytaskkill /Tneeds a live parent, and the test docstring identifies which case covers worker cleanup. The full native suite again reported zero failures on Windows PowerShell 5.1 and PowerShell 7.6.9. Text-only passed too.I merged upstream
f9f50048into the branch ate99d192aand the checks are rerunning. The mesh failure also reproduces on unmodified upstream; #2276 is the pending fix.Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T09:54:10Z.
Both follow-ups are covered in
852beb59. The portable text check now rejects a missing live-watcher guard or localContinuescope, with a mutation for each.On Windows the new fixture takes the live branch, stops its own watcher and child, and waits for the watcher to exit before the launcher's original
taskkillexecutes. That command sees a real missing PID. Windows PowerShell 5.1 and PowerShell 7.6.9 both printed the correct five lines and returned 7. In a separate 5.1 control, restoringStopin this same fixture producedNativeCommandErrorand returned 1 for debugger codes 0 and 7. The full native and text-only suites passed.Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T10:02:51Z.
Added the missing-
/Tmutation in3c213f75. Removing the tree flag now fails the text-only suite. The unmodified suite passed in both text-only mode and the native Windows PowerShell 5.1/PowerShell 7.6.9 runs.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:05:51Z.
Review: COMMENTED
Re-review of head
3c213f754fea2360fec436b6bc41a01396b03df4(new since my last pass at852beb59: the/Tcheck in the text-only test).Verdict: no P1, no P2.
What changed
tests/startup_run_ps1_check.py:WATCH_CLEANUPnow also requires/Ton the sametaskkill.exeline ([^|#\n]*\s/T\b), so a comment or a later line cannot satisfy it, and/TXor/Treedo not match. The failure message and the mutation list ('/T 'added) were updated to match.tools/startup/run.ps1is unchanged since the last pass: live-watcher guard plus a localContinuescope aroundtaskkill /T /F.Checks run locally (worktree at the exact head)
python3 tests/startup_run_ps1_check.py: exit 0 (text-only mode, not a Windows host).python3 tests/docs_links_check.py: self-test passed, 18 files, 435 links.python3 tests/bidi_controls_check.py: no bidirectional controls in 1566 files.git diff --check origin/main...HEAD: clean.Mutations of the new logic
taskkill.exe /T /F->taskkill.exe /F(flag dropped): killed, "tree cleanup lacks taskkill /T ...", exit 1.taskkill.exe /T /F->taskkill.exe /TX /F(look-alike flag): killed, exit 1./Tmoved after/PID $translator.Id(still a valid tree kill): correctly accepted.git checkout -- .after each mutation.Nits (non-blocking)
AI-assisted; commands listed were executed locally.