xcl run: end the title when its launcher is gone #3431

Open
vakaobr wants to merge 1 commit from upstream-pr/3431 into main
vakaobr commented 2026-11-29 15:41:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vakaobr on 2026-11-29T15:41:20Z.


The host watched its launcher (the handle in XCL_PREPARATION_PARENT) only during shader preparation and closed the handle after it. Once the title ran, nothing tied the host to the launcher: with the launcher killed, the host went on alone, nobody waited for it or read its output, and report.json kept exit_code: null and an empty environment. Part of #258.

What is in it

  • crates/xcl/src/host.rs: host_main takes the launcher's handle (launcher_handle), lends it to preparation, and keeps it for the run. An xcl-launcher-watch thread waits on it; when the launcher ends it logs the launcher (xcl run) is gone – ending the title (…), writes the final report and ends through real::end_title (fences signalled, GPU drained), exit code 0x7C10003.
  • crates/xcl/src/hle/d3d12x/present/preparation.rs: before_guest borrows the handle instead of reading the variable itself; it still stops preparation when the launcher goes.
  • New test the_title_ends_when_the_launcher_is_gone: an event stands for the launcher's process handle; nothing happens before it is signalled, the callback runs after.

Tested

  • M5 Pro, macOS 27.2.1, CrossOver 26.3 (Wine) with D3DMetal, Rust 1.100, x86_64-pc-windows-gnu; head 87e472f on main 9dfbe3e.
  • host::tests and present::preparation::tests: 7 passed, 0 failed.
  • The test title with the Windows launcher process killed once the host was logging: the launcher (xcl run) is gone – ending the title, the process ended 14 ms later with status 0x7c10003, nothing left running.
  • On this Mac the test title stops after 31 checks on main 9dfbe3e with and without this PR, hanging in some runs and crashing (0xc0000005) in others; the watcher did not fire.

Regression run

  • None yet: I have no Windows machine for scripts/smoke.ps1. I am asking on #258 for a pair.

Not tested

  • Windows (any GPU), the whole suite, a retail title. Console Ctrl-C / close events (SetConsoleCtrlHandler) are not handled here; under CrossOver Ctrl-C delivers none.

AI use

  • Claude Code with Claude Opus 5.5: reproduced the problem with the test title, wrote the change and the test, ran them on my Mac, rebased it onto main, and drafted this description. I checked it before opening.
<!-- greyfinch-sync:ivall/xcl:issue:5552300137 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3431). Originally posted by [vakaobr](https://github.com/vakaobr) on 2026-11-29T15:41:20Z. --- The host watched its launcher (the handle in `XCL_PREPARATION_PARENT`) only during shader preparation and closed the handle after it. Once the title ran, nothing tied the host to the launcher: with the launcher killed, the host went on alone, nobody waited for it or read its output, and `report.json` kept `exit_code: null` and an empty `environment`. Part of #258. **What is in it** - `crates/xcl/src/host.rs`: `host_main` takes the launcher's handle (`launcher_handle`), lends it to preparation, and keeps it for the run. An `xcl-launcher-watch` thread waits on it; when the launcher ends it logs `the launcher (xcl run) is gone – ending the title (…)`, writes the final report and ends through `real::end_title` (fences signalled, GPU drained), exit code `0x7C10003`. - `crates/xcl/src/hle/d3d12x/present/preparation.rs`: `before_guest` borrows the handle instead of reading the variable itself; it still stops preparation when the launcher goes. - New test `the_title_ends_when_the_launcher_is_gone`: an event stands for the launcher's process handle; nothing happens before it is signalled, the callback runs after. **Tested** - M5 Pro, macOS 27.2.1, CrossOver 26.3 (Wine) with D3DMetal, Rust 1.100, `x86_64-pc-windows-gnu`; head `87e472f` on `main` `9dfbe3e`. - `host::tests` and `present::preparation::tests`: 7 passed, 0 failed. - The test title with the Windows launcher process killed once the host was logging: `the launcher (xcl run) is gone – ending the title`, the process ended 14 ms later with status `0x7c10003`, nothing left running. - On this Mac the test title stops after 31 checks on `main` `9dfbe3e` with and without this PR, hanging in some runs and crashing (`0xc0000005`) in others; the watcher did not fire. **Regression run** - None yet: I have no Windows machine for `scripts/smoke.ps1`. I am asking on #258 for a pair. **Not tested** - Windows (any GPU), the whole suite, a retail title. Console Ctrl-C / close events (`SetConsoleCtrlHandler`) are not handled here; under CrossOver Ctrl-C delivers none. **AI use** - Claude Code with Claude Opus 5.5: reproduced the problem with the test title, wrote the change and the test, ran them on my Mac, rebased it onto `main`, and drafted this description. I checked it before opening.
Foniass commented 2026-12-01 08:52:16 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:52:16Z.


Review (head 87e472f9, diff read, not a merge-check; draft, PR description red, no Windows run):

  • The launcher-gone exit skips two flushes the other exits make. The watcher's callback (host.rs ~124-130) goes from report::write_final and log::flush straight to end_title. The XCL_RUN_SECONDS path and the normal exit (host.rs ~301-302 / ~321-322 on main) also call pso_async::shutdown_used() and shutdown_indirect_split_records(500 ms). end_title suspends the other threads, so the last entries of used-pipelines.txt and the split records can be lost. The description says the exit works "like XCL_RUN_SECONDS"; with those two calls added it would.
  • The description claims more than it fixes. It names report.json's exit_code: null and empty environment, but only the launcher fills those in (launcher.rs summarize), so they stay null and empty after this PR. What it fixes is the orphaned host.
  • The launcher handle stays inheritable for the whole run (host.rs ~60-66; preparation used to close it), so every child process started later inherits it. Harmless, but clearing the inherit flag would be tidier.
  • The new log line reuses (N frames shown, N PresentX calls), the text smoke.ps1 looks for as the end of a run. It still reports killed (no exit), but it's worth checking that it parses the same.
  • The test covers watch_launcher with an event standing in for the process; the exit sequence isn't tested. Still missing: a Windows suite run and the smoke pair. The labels (area:d3d12, area:shaders) don't fit.

Fine: detection waits on the SYNCHRONIZE handle the launcher passes, not a PID, so PID reuse can't trigger it. A host started without XCL_PREPARATION_PARENT isn't watched. It's one thread blocked in WaitForSingleObject with no polling. The exit goes through end_title, which drains the GPU. The preparation.rs change is needed now that the host owns the handle. It also lets smoke.ps1 finish when it kills the launcher on timeout; #1073 and #1270 deal with the same orphan from the script side.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7305894559 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3431#issuecomment-7305894559). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:52:16Z. --- Review (head 87e472f9, diff read, not a merge-check; draft, `PR description` red, no Windows run): - **The launcher-gone exit skips two flushes the other exits make.** The watcher's callback (`host.rs` ~124-130) goes from `report::write_final` and `log::flush` straight to `end_title`. The `XCL_RUN_SECONDS` path and the normal exit (`host.rs` ~301-302 / ~321-322 on main) also call `pso_async::shutdown_used()` and `shutdown_indirect_split_records(500 ms)`. `end_title` suspends the other threads, so the last entries of `used-pipelines.txt` and the split records can be lost. The description says the exit works "like `XCL_RUN_SECONDS`"; with those two calls added it would. - **The description claims more than it fixes.** It names `report.json`'s `exit_code: null` and empty `environment`, but only the launcher fills those in (`launcher.rs` `summarize`), so they stay null and empty after this PR. What it fixes is the orphaned host. - The launcher handle stays inheritable for the whole run (`host.rs` ~60-66; preparation used to close it), so every child process started later inherits it. Harmless, but clearing the inherit flag would be tidier. - The new log line reuses `(N frames shown, N PresentX calls)`, the text `smoke.ps1` looks for as the end of a run. It still reports `killed (no exit)`, but it's worth checking that it parses the same. - The test covers `watch_launcher` with an event standing in for the process; the exit sequence isn't tested. Still missing: a Windows suite run and the smoke pair. The labels (`area:d3d12`, `area:shaders`) don't fit. Fine: detection waits on the `SYNCHRONIZE` handle the launcher passes, not a PID, so PID reuse can't trigger it. A host started without `XCL_PREPARATION_PARENT` isn't watched. It's one thread blocked in `WaitForSingleObject` with no polling. The exit goes through `end_title`, which drains the GPU. The `preparation.rs` change is needed now that the host owns the handle. It also lets `smoke.ps1` finish when it kills the launcher on timeout; #1073 and #1270 deal with the same orphan from the script side. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-01 09:54:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:54:47Z.


Triage (#1607) – head 87e472f

No open or merged PR ends the host when xcl run goes away. Main only uses the launcher handle (XCL_PREPARATION_PARENT) during shader preparation; #766's kill-on-close job object is in the e2e harness only.
Problem: host.rs LAUNCHER_GONE = 0x7C1_0003 is the exit code uma_driver.rs already uses for "coherent window could not be restored" (stop_unbacked, the restore path, and its test failed_restore_stops_before_importing_an_unbacked_window). Two different endings then share one code; please pick an unused one (0x7C1_0001/0002 are taken in host.rs too).
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7307389328 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3431#issuecomment-7307389328). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:54:47Z. --- **Triage (#1607)** – head 87e472f No open or merged PR ends the host when `xcl run` goes away. Main only uses the launcher handle (`XCL_PREPARATION_PARENT`) during shader preparation; #766's kill-on-close job object is in the e2e harness only. Problem: `host.rs` `LAUNCHER_GONE = 0x7C1_0003` is the exit code `uma_driver.rs` already uses for "coherent window could not be restored" (`stop_unbacked`, the restore path, and its test `failed_restore_stops_before_importing_an_unbacked_window`). Two different endings then share one code; please pick an unused one (0x7C1_0001/0002 are taken in `host.rs` too). Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3431:upstream-pr/3431'
git switch 'upstream-pr/3431'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3431'
git switch 'upstream-pr/3431'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3431'
git switch 'upstream-pr/3431'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3431'
git switch 'main'
git merge --squash 'upstream-pr/3431'
git switch 'main'
git merge --ff-only 'upstream-pr/3431'
git switch 'main'
git merge 'upstream-pr/3431'
git push origin 'main'
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
xcl-dev/xcl!3431
No description provided.