Skip to content

xcl run: the end of a run ends the process past XCL's own exit hook - #2698

Open
Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:arch/end-title-watchdog
Open

Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:arch/end-title-watchdog

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

The end of a run (XCL_RUN_SECONDS, real::end_title) no longer hangs when a suspended thread holds the process heap. end_title suspends the title's threads, signals the fences and drains the GPU; its 15 s watchdog is the last resort when that drain cannot finish ("a suspended thread may hold a lock the drain needs"). The watchdog ended the process with TerminateProcess, that is through XCL's own NtTerminateProcess hook (eh.rs), which formats the stack and a log line, and so allocates, before the real call. In half the runs on one Linux machine of ours the watchdog waited there as well, and the process did not end. It now calls the real NtTerminateProcess. The drain itself can still wait for the held heap; such a run now ends at the watchdog's 15 s instead of never.

Under Wine this shows as a run that does not exit: err:sync:RtlpWaitForCriticalSection section … "dlls/ntdll/heap.c: main process heap section" wait timed out in thread …. In 6 runs on Linux (RTX 4070, Wine with vkd3d-proton) of main b49be18 with #684 (alone, with #1599 or with #1790; 2 runs each), every run logged that wait in the thread that ran end_title. 3 were ended at 15 s by the watchdog, through the hook (process ends (thread …), that thread's only line). The other 3 logged a second wait, in a thread that had logged nothing, and had not exited a minute later, when the harness killed them. We take that thread to be the watchdog: after the suspension it is the only other thread still running.

What is in it

  • crates/xcl/src/eh.rs: end_process_now, which ends the process through the real NtTerminateProcess. xcl run: end the process when the title's crash filter has not ended it in 30 s #967 adds the same function under the same name, for its crash watchdog. The two merge without a conflict but do not build together, so whichever goes in second drops its copy (and if that is this one, makes xcl run: end the process when the title's crash filter has not ended it in 30 s #967's pub(crate)).
  • crates/xcl/src/hle/d3d12x/real.rs: end_title's watchdog calls it. An ending after a drain that finishes still goes through the hook. With D3D12.X: batch used-pipelines.txt writes off the bind lock #2635 in, used-pipelines.txt is still flushed before end_title (shutdown_used() in host.rs); the watchdog's ending skips only the hook's bounded second flush.
  • A test, the_process_ends_while_another_thread_holds_the_heap: a child process with the crash handler installed, a thread holding the process heap (HeapLock), then the watchdog's ending; the parent waits 20 s for its exit code. The child first checks that the hook is installed and that HeapLock succeeded, then ends with status 7, so a child that returns normally, or that never held the heap, cannot pass. In the hook a non-zero status takes the dump_threads branch, where end_title's 0 takes the process ends line; both allocate.

Tested

  • Native Windows: NVIDIA GeForce RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, rustc 1.100.0; tests in debug, the smoke runs from release builds. Head 88f29d1 on main b49be18.
  • The new test with the watchdog's old ending (TerminateProcess through the hook): failed, the child had not ended after 20 s (the process did not end while another thread held the heap). On this branch it passes, with the other six eh:: tests. cargo test --workspace --no-fail-fast -- --test-threads=4: 1,436 passed, 0 failed, 47 ignored. 29 SKIPPED lines: 21 no wave64, 3 wave32 per-lane forms refused, 3 no D3D12 debug layer, 1 no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record (the driver cache cannot be turned off without Windows Developer Mode).
  • Linux (RTX 4070 12 GB, Wine with vkd3d-proton), main b49be18 with XG: fix CopyFromSubresource 7-argument ABI and guard destination span #684 and DirectStorage: a queue made with AutoSubmitDisabled waits for Submit #1599 merged in, 120 s a run, 4 runs each way, alternating; the first-run screens were completed once, no story progress. Without this change, all 4 runs logged the wait for the heap in the thread that ran end_title: 3 had not exited a minute after the end of the run and were killed, and 1 ended at the watchdog, through the hook. With it, 3 of 4 logged the same wait and ended 15 s after the end of the run, at the watchdog; the fourth, which met D3D12.X: title texture reads outside the coherent window use the safe copy #751's read fault in msvcrt.dll at 33.0 s, logged no wait and ended 10 s after, through the hook as before. Commits 543756d and 0108f24 (the same with this change: 0108f24 has it as at 95fc91c; 88f29d1 changes only the test).

Regression run

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 691 (PresentX 691)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14716 MB

PR:

xcl-smoke v1
commit: 88f29d183684c61f09b432e2c2650e2285b7cc8f
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1462 (PresentX 1462)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13886 MB

Not tested

  • The new test under Wine.
  • Which code holds the heap: Wine names the holding thread (blocked by …), but in 12 of the 13 runs here that logged the wait, it had logged nothing.
  • AMD GPUs.

AI use

  • Claude Code (Claude Opus 5.5) read the runs and the code, wrote the change, the test and this text, and ran the tests and the smoke runs on the Windows machine and the Linux runs, through scripts.

@luckyteagirl luckyteagirl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The child regression can report exit 7 without exercising the heap-held hook path. install_crash_handler() logs a hook-install failure but returns normally, and the child ignores HeapLock's BOOL before setting HELD. If the hook did not install, end_process_now sees ORIG_NT_TERMINATE == 0 and its TerminateProcess fallback can exit 7 through the normal unhooked path; if the heap lock failed, the old watchdog path would also lack the intended blocked-heap condition. The parent only checks exit 7, so either missing prerequisite can yield a green test.

Could the child assert that ORIG_NT_TERMINATE is nonzero after installation and that HeapLock succeeds before it signals HELD? That would make the test fail visibly when the environment cannot exercise the regression. This is an exact-head source review of 95fc91c3c9d46c06b15952ac4bd641db1cc83cf7; I did not inject either failure or rerun the test. AI-assisted review with Codex.

`end_title` suspends the title's threads, drains the GPU and ends the
process, with a watchdog that ends it within 15 s if the drain hangs:
"a suspended thread may hold a lock the drain needs". The watchdog
ended the process through `TerminateProcess`, so through XCL's
`NtTerminateProcess` hook, which formats the stack and a log line
first. When a suspended thread holds the process heap, the drain and
then the watchdog both wait for it, and the process does not end. On
Linux (Wine) the runs of today's trees log the drain's wait and, in
about half of them, the watchdog's ("main process heap section wait
timed out in thread …"), and then never exit.

The watchdog now calls the real `NtTerminateProcess`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh marked this pull request as ready for review November 26, 2026 07:13
@Royalflamejlh
Royalflamejlh force-pushed the arch/end-title-watchdog branch from 95fc91c to 88f29d1 Compare November 26, 2026 07:32
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@luckyteagirl yes: both could pass unseen. A hook that failed to install is only logged (install_crash_handler), and end_process_now then falls back to a plain TerminateProcess. A HeapLock that failed left nothing held. Either way the child still exited 7. In 88f29d1 the child asserts, before it ends, that NtTerminateProcess is hooked and that HeapLock succeeded, so a missing prerequisite makes the child panic and exit 101, and the parent's check for 7 fails.

  • On an RTX 2070 SUPER (debug, 1 run each), with the test's ending put back to TerminateProcess through the hook, the test failed after 20.0 s (the process did not end while another thread held the heap). The child, run with --nocapture, printed no failed assertion, so it got past both checks and then did not end. On 88f29d1 it passed, with the other six eh:: tests.
  • The description's suite (1,436 passed, 0 failed, 47 ignored) and smoke block are now those of 88f29d1.

AI use: Claude Code (Claude Opus 5.5) made the change, ran the tests and the smoke run, and wrote this reply.

Posted without review by a person: the account owner was away and reads replies later.

@sage-sage

Copy link
Copy Markdown

Test report: passes on NVIDIA. Exact head 88f29d18 (its base is current main b49be18, so head = merged).

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build
  • cargo test --workspace -- --test-threads=4: 1436 passed, 0 failed, 47 ignored; the_process_ends_while_another_thread_holds_the_heap passes
  • SKIPPED: 29 lines, the same as on main on this machine (wave64, debug layer, Developer Mode, heap windows)
  • With end_process_now reduced to the old TerminateProcess call (local only): the new test fails after its 20 s (the process did not end while another thread held the heap), so it covers the fix.

Not tested

  • No game, so not the end of a real run (XCL_RUN_SECONDS / the end watchdog).

Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@Decodere

Copy link
Copy Markdown
Contributor

Independent RTX 4060 (8 GB) / Windows 11 verification of PR #2698 at 88f29d183684c61f09b432e2c2650e2285b7cc8f (exact parent origin/main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7). Measurements and targeted test results only; not a full source review.

Setup

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6 cores / 12 threads), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200
  • Toolchain / caches: rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)
  • Workload: Retail workload title: 29640639 via scripts/smoke.ps1 -Seconds 60 (XCL_NETWORK=0 XCL_ACTIVITY=1, default flags, no input)

Targeted RTX 4060 release unit tests (88f29d18)

  • cargo test --release -p xcl --lib eh::tests::the_process_ends_while_another_thread_holds_the_heap -- --nocapture: 1 passed, 0 failed, 0 ignored (0.05 s, exit 0). The spawned child process passed both release-build assert_ne!(ORIG_NT_TERMINATE, 0) and HeapLock(GetProcessHeap()) != 0 preconditions and terminated promptly with exit code 7 via eh::end_process_now(7) while the background thread held the process heap lock.
  • cargo test --release -p xcl --lib eh::tests:: -- --test-threads=4: 7 passed, 0 failed, 0 ignored (0.07 s, exit 0).
  • cargo test --release -p xcl --lib hle::d3d12x::real:: -- --test-threads=4: 60 passed, 0 failed, 0 ignored (0.65 s, 0 skipped, exit 0).

Observations

  • Verified specifically in a release build (--release) on native Windows 11 26200: the 88f29d18 child-process regression test passes with NtTerminateProcess hook verified installed (ORIG_NT_TERMINATE != 0) and HeapLock held across threads, completing in 0.05 s (well inside its 20 s watchdog bound).
  • Quiet 60 s retail smoke ran and exited cleanly (exit: 0x0, 1574 frames shown, 60 60 60 steady-state presents per 2 s, 0 device removals, 0 crashes, 13987 MB peak commit vs parent b49be183's 14018 MB / 1518 frames).

Paired 60 s RTX 4060 smoke (b49be183 vs 88f29d18)

Parent origin/main (b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1518 (PresentX 1518)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14018 MB

PR #2698 head (88f29d18):

xcl-smoke v1
commit: 88f29d183684c61f09b432e2c2650e2285b7cc8f
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1574 (PresentX 1574)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13987 MB

Limits of coverage

  • Native Windows 11 (26200) only; Wine/Linux NtTerminateProcess hook behavior was not tested on this host.
  • The quiet 60 s retail smoke exited cleanly through the normal end_title drain rather than hitting the 15 s hung-drain watchdog timeout; the heap-locked end_process_now termination path is exercised by the child-process release test (eh::tests::the_process_ends_while_another_thread_holds_the_heap).
  • Full workspace test suite was not re-run on 88f29d18 (only targeted eh::tests:: and hle::d3d12x::real:: release tests plus paired quiet 60 s smoke).

AI use

Ran the targeted release unit tests and paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts and smoke blocks were taken directly from cargo test and scripts/smoke.ps1 outputs.

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) verification of exact PR head 88f29d183684c61f09b432e2c2650e2285b7cc8f on Windows 11 Pro 26300 (AMD Radeon RX 9060 XT 16 GB, driver 32.0.31044.16, Ryzen 5 5600, Rust 1.100.0 MSVC, DXC 1.9.2602.17).

Tested

  • cargo build --workspace (debug): passed (0 errors).
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1434 passed, 2 failed, 47 ignored (8 SKIPPED: 6 per-lane DXIL forms refused by host adapter/driver, 1 heap_window_out_of_memory_falls_back_to_the_switch_form no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record Windows Developer Mode off).
    • The new test eh::tests::the_process_ends_while_another_thread_holds_the_heap passed.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and fuzz_validate_and_gpu_3) are pre-existing on unmodified main on this RX 9060 XT / driver 32.0.31044.16.
  • cargo build --release -p xcl + 60 s retail-title smoke test (scripts/smoke.ps1, offline):
xcl-smoke v1
commit: 88f29d183684c61f09b432e2c2650e2285b7cc8f
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18741 MB

(Compare against main b49be183 on this machine: 1603 frames, 18576 MB peak, 0 device removals, 0 crashes.)

Not tested

  • NVIDIA / Intel GPUs, Linux / Wine.

AI use

  • Verification run and report prepared with Antigravity (Gemini 4 Neon); all build, test, and smoke results are from live runs on this machine.

Osanchez pushed a commit to Osanchez/xcl that referenced this pull request Nov 26, 2026
Runs 1-6 on an RTX 5080 showed that a draw binding an unbuilt pipeline
builds it on the title's thread (about 3.7 s each, back to back), so the
title presents nothing after its loading screen. The entry holds the
approved spec: adopt xcl-dev#2579, xcl-dev#2098, xcl-dev#2698 and xcl-dev#751 through the gate, then
units U1-U9 (draws wait inside a shared 100 ms frame budget and never
build, compute waits for a worker, a graphics lane and RAM-scaled slots
at the gate, replaced parked workers, an end watchdog, telemetry).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018RbZY1Ag73eDeCUZHpW3is
Osanchez pushed a commit to Osanchez/xcl that referenced this pull request Nov 26, 2026
Commit:   88f29d1
Reviewer: Claude Code (Opus 5.5, claude-opus-5-5), Opus worker, full read (clean)
Review:   sha256 4d485ea1742d4be60a27464cf11646f5521d6dfef1a7b6c4709f44cfe51333f1
Osanchez pushed a commit to Osanchez/xcl that referenced this pull request Nov 26, 2026
A run with XCL_RUN_SECONDS=300 whose title was stalled in pipeline builds
was still alive at about 430 s: the only watchdog starts inside end_title,
which the run-seconds thread reaches after the report is written, and the
ending can block before that.

Both threads now arm a watchdog first: 30 s later the process ends through
eh::end_process_now (the real NtTerminateProcess, xcl-dev#2698) whatever the rest
of the ending does. end_title's own 15 s watchdog is unchanged.

Tested on Windows 11, RTX 5080, driver 32.0.16.2140:
cargo test -p xcl --lib -- host:: : 4 passed, 0 failed (2 new);
cargo test -p xcl --test telemetry_e2e: 8 passed, 0 failed.
Not tested: a stalled retail run ending at its limit (the acceptance run
of the stall-fix entry does that). Unit U1 of that entry in decisions.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018RbZY1Ag73eDeCUZHpW3is
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