Skip to content

fix: stop the XCL child when Windows taskkill fails - #7069

Open
lucas-tafuri wants to merge 4 commits into
ItsNotRexed:mainfrom
lucas-tafuri:fix/xcl-watchdog-taskkill-fallback
Open

lucas-tafuri wants to merge 4 commits into
ItsNotRexed:mainfrom
lucas-tafuri:fix/xcl-watchdog-taskkill-fallback

Conversation

@lucas-tafuri

Copy link
Copy Markdown
Contributor

Claim: #6910 (comment)

In a restricted Windows process, taskkill /F /T returned 1 and left a synthetic child alive. The watchdog then waited for that child instead of restarting promptly. Keep the Windows tree-termination attempt. If it fails and the direct child is still alive, stop the direct child through its Popen handle. The fallback covers only that child.

Verification on Windows / Python 3.12, using upstream snapshot 8f208d09: the new mock-based regression failed with the original kill_tree(). With the change, python -I tests/test_xcl_compare.py passed all 13 tests, including the real synthetic restart cases. No game files or GPU used.

AI-assisted (OpenAI Codex).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 5465c64 merged with main 8575d36 on Linux/Python 3.12.16: pass

  • python -I tests/test_xcl_compare.py: 16 tests OK
  • Negative control: git checkout upstream/main -- tools/xcl_compare.py, same test: FAILED (failures=1). Restored with git checkout HEAD --.

Diff read: kill_tree on Windows now falls back to proc.kill() when taskkill /F /T returns non-zero and the process is still running; on other platforms it still kills only the process (guarded by proc.poll() is None). The new test runs on Linux, so the os.name == "nt" branch is exercised through mocks of os.name and subprocess.run, not with a real taskkill; I did not run it on Windows.

@duudiis

duudiis commented Nov 23, 2026

Copy link
Copy Markdown

Tested 5465c64 merged onto main 6b40d22 on Windows 11 Pro, Intel i7-14700KF, CPython 3.11.0 (venv: pytest 9.2.0, numpy 2.4.6, Pillow 13.0.0; numpy is below the 2.5.5 pin because 2.5 needs Python 3.12), CPU only: pass.

  • git merge --no-ff of the PR onto main: clean.
  • python -I tests/test_xcl_compare.py on the merge: 16 tests OK.
  • Same command on main 6b40d22: 15 tests OK (the new test is the only addition).
  • python -I -m compileall -q tools tests: clean.
  • Negative control: main's tools/xcl_compare.py with the PR's test file: test_taskkill_failure_stops_live_child fails with "Expected 'kill' to be called once. Called 0 times.", so the test catches the old behaviour.

Review notes:

  • tools/xcl_compare.py:131-138: kill_tree now falls back to proc.kill() when taskkill returns non-zero, and the only caller (tools/xcl_compare.py:187) follows with proc.wait(), so the watchdog no longer waits on a live child. Looks correct.
  • The new test mocks os.name and subprocess.run, so it covers the fallback logic rather than a real taskkill failure; that seems reasonable here.
  • As the PR body notes, when taskkill fails the fallback stops only the direct child, not grandchildren.
  • Minor: the PR body says 13 tests pass; on current main the file runs 15 before the PR and 16 with it.

AI-assisted (Claude Code).

@AsgerCode

Copy link
Copy Markdown

Tested 5465c64 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

The two earlier reviews ran the mock test. This one checks the fix with real Windows child processes and a real taskkill.exe failure.

What I ran:

taskkill result main PR
real, succeeds child gone child gone
mocked, returns 1 child still running after 10 s child gone
real taskkill.exe on a PID that does not exist, returns 128 child still running after 10 s child gone
mocked, returns 1; the child started a grandchild both still running child gone, grandchild still running
  • End to end: run_with_restarts with a real title that hangs in check b (time.sleep(30)), --timeout 2 s, and real taskkill.exe failing (128). main needed 30.1 s, because proc.wait() waited for the title's sleep to end. The PR needed 2.4 s, restarted with b skipped, and left no title process alive.
  • I could not make taskkill "not found" by changing PATH. With PATH set to only a scratch folder that has no taskkill, subprocess.run(["taskkill", "/?"]) still ran (rc 0), because CreateProcess searches System32 before PATH. So on Windows the realistic failure is a non-zero return code, which the PR handles.

Nits, none blocking:

  1. If subprocess.run raises OSError (I mocked FileNotFoundError), kill_tree raises before the fallback, and the child stays alive. main does the same, and the PATH result above shows that this is hard to reach. Catching OSError around the taskkill call would close it.
  2. The grandchild row confirms the PR body: when taskkill fails, only the direct child is stopped.

AI-assisted (Claude Code).

@lucas-tafuri

Copy link
Copy Markdown
Contributor Author

Thanks for the real Windows repro. I added the suggested launch-error fallback and a regression subcase in 6471905. The new subcase raises OSError on the prior head. With the fix, all 13 tests on the PR branch pass on Windows with Python 3.12. AI-assisted (OpenAI Codex).

@airp1ane

Copy link
Copy Markdown
Contributor

Tested 5465c64 on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass.

Ran the test files this PR adds or changes, from a clean checkout of the PR head: test_xcl_compare.py - all exit 0.

AI-assisted (Claude Code).

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.

5 participants