Shaders: bound direct sweep workers and report panics #1997

Open
github-bot wants to merge 1 commit from github-bot/gh-1997 into main AGit
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 00:32 UTC · original
luckyteagirl:codex/shader-sweep-workers → main · +102 −19 · 1 files · 1 commits · open

Addresses item 3 of #1896. xcl shaders --direct could accumulate detached translation workers after timeouts, each using a large translator stack. The sweep also conflated panics with timeouts. This rebases the fix onto current main after #2285 changed the option parser.

What is in it

  • Bound live translations to --threads (maximum 32). A timed-out translation keeps its slot until it actually completes. If --threads workers remain active after their callers time out, the sweep stops early with exit 2 and marks its sample incomplete; it does not launch more detached workers.
  • Catch and name worker panics separately from timeouts and channel disconnects.
  • Release a completed worker's slot before publishing its result, closing the receive-before-release race identified by reviewers.

Tested

  • Clean rebased head f053f279fe899f341cdfc9d0aa5e1de09cfbe116 on main 6d12f58a229bc73889878a448c64dc3af25eeba0. Windows 11 build 26200, Ryzen 9 5980HX, AMD Radeon RX 6800M (driver 30.0.13002.13003), Rust 1.99.0 MSVC, debug targeted tests and release binary.
  • XCL_ADAPTER=6800M cargo test --locked -p xcl --lib shaders::tests -- --test-threads=1 --show-output: 10 passed, 0 failed, 0 ignored, 1 explicit SKIPPED (pso_measurement_compiles_an_exact_synthetic_record: driver cache control unavailable without Windows Developer Mode). The three worker-bound regression tests passed.
  • cargo build --locked --release -p xcl --bins -j 2: passed on the rebased head and on current main.
  • On the previous head f1331cd, the full GPU workspace run reported 996 passed, 161 failed, 46 ignored, with 9 explicit skips. The failures followed D3D12 device suspension 0x887A0005 on this RX 6800M; this is previous-head evidence, not a green current-head suite.
  • git diff --check: clean.

Regression run

The repository's scripts/smoke.ps1 ran each committed release binary for seven seconds on the same owned title, using separate fresh data and DXIL cache roots. Both exited normally with no crash or device removal. This short run reached intro frames only; it does not exercise the offline shader sweep.

Current main:

xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 4 (PresentX 4)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 6898 MB

This PR:

xcl-smoke v1
commit: f053f279fe899f341cdfc9d0aa5e1de09cfbe116
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 7
exit: 0x0
frames shown: 14 (PresentX 14)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 6946 MB

Not tested

  • A full GPU workspace suite on the rebased head, a whole-pack shader sweep under persistent translator timeouts, world loading, other adapters, or newer AMD drivers. No game data was uploaded.

AI use

OpenAI Codex (GPT-6; exact variant unavailable) implemented and rebased the worker bound, ran the focused checks and paired smoke, and drafted this description. The slot-order race was first reported by @⁠JJAutoCompare and confirmed by @⁠raylitebull.

**@⁠luckyteagirl** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997) `luckyteagirl:codex/shader-sweep-workers` → `main` · +102 −19 · 1 files · 1 commits · open Addresses item 3 of #1896. `xcl shaders --direct` could accumulate detached translation workers after timeouts, each using a large translator stack. The sweep also conflated panics with timeouts. This rebases the fix onto current `main` after #2285 changed the option parser. **What is in it** - Bound live translations to `--threads` (maximum 32). A timed-out translation keeps its slot until it actually completes. If `--threads` workers remain active after their callers time out, the sweep stops early with exit 2 and marks its sample incomplete; it does not launch more detached workers. - Catch and name worker panics separately from timeouts and channel disconnects. - Release a completed worker's slot before publishing its result, closing the receive-before-release race identified by reviewers. **Tested** - Clean rebased head `f053f279fe899f341cdfc9d0aa5e1de09cfbe116` on `main` `6d12f58a229bc73889878a448c64dc3af25eeba0`. Windows 11 build 26200, Ryzen 9 5980HX, AMD Radeon RX 6800M (driver `30.0.13002.13003`), Rust 1.99.0 MSVC, debug targeted tests and release binary. - `XCL_ADAPTER=6800M cargo test --locked -p xcl --lib shaders::tests -- --test-threads=1 --show-output`: **10 passed, 0 failed, 0 ignored**, 1 explicit `SKIPPED` (`pso_measurement_compiles_an_exact_synthetic_record`: driver cache control unavailable without Windows Developer Mode). The three worker-bound regression tests passed. - `cargo build --locked --release -p xcl --bins -j 2`: passed on the rebased head and on current main. - On the previous head `f1331cd`, the full GPU workspace run reported **996 passed, 161 failed, 46 ignored**, with 9 explicit skips. The failures followed D3D12 device suspension `0x887A0005` on this RX 6800M; this is previous-head evidence, not a green current-head suite. - `git diff --check`: clean. **Regression run** The repository's `scripts/smoke.ps1` ran each committed release binary for seven seconds on the same owned title, using separate fresh data and DXIL cache roots. Both exited normally with no crash or device removal. This short run reached intro frames only; it does not exercise the offline shader sweep. Current `main`: ``` xcl-smoke v1 commit: 6d12f58a229bc73889878a448c64dc3af25eeba0 gpu: AMD Radeon RX 6800M title: 2ef5fd64 seconds: 7 exit: 0x0 frames shown: 4 (PresentX 4) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 6898 MB ``` This PR: ``` xcl-smoke v1 commit: f053f279fe899f341cdfc9d0aa5e1de09cfbe116 gpu: AMD Radeon RX 6800M title: 2ef5fd64 seconds: 7 exit: 0x0 frames shown: 14 (PresentX 14) presents per 2 s (last 3): 0 0 1 device removals: 0 crashes: 0 peak commit: 6946 MB ``` **Not tested** - A full GPU workspace suite on the rebased head, a whole-pack shader sweep under persistent translator timeouts, world loading, other adapters, or newer AMD drivers. No game data was uploaded. **AI use** OpenAI Codex (GPT-6; exact variant unavailable) implemented and rebased the worker bound, ran the focused checks and paired smoke, and drafted this description. The slot-order race was first reported by @⁠JJAutoCompare and confirmed by @⁠raylitebull.
Keep a permit until a translation completes, including after its caller
times out, so a sweep cannot accumulate unlimited detached translator
threads. Release the permit before publishing a completed result: a
single-worker sweep can immediately start its next translation without a
false worker-limit failure. Stop an incomplete sweep when all permits
are occupied, and report worker panics separately from timeouts.

Assisted-by: OpenAI Codex (GPT-6)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:50 +00:00
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 00:33 UTC · original

There is a completion race at e6aeef4. The worker sends its result while its ActiveWorker guard is still live. Once the receiver gets the result, it can start the next translation before the guard decrements the counter. With --threads 1, this can report a worker-limit failure and stop a sweep even though the previous translation has already returned. It can also happen between the direct and per-lane runs for one shader. Worker and receive path

Release the slot after the translation returns and before publishing the result. A timed-out translation should retain its slot until the translation itself returns, as the existing cap test expects. Verified by code inspection. I did not run this PR’s binaries. Review assisted by Codex (gpt-6.2-sol).

**@⁠JJAutoCompare** on GitHub · 2026-11-25 00:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7148628525) There is a completion race at `e6aeef4`. The worker sends its result while its `ActiveWorker` guard is still live. Once the receiver gets the result, it can start the next translation before the guard decrements the counter. With `--threads 1`, this can report a worker-limit failure and stop a sweep even though the previous translation has already returned. It can also happen between the direct and per-lane runs for one shader. [Worker and receive path](https://github.com/xcl-dev/xcl/blob/e6aeef44a46a66013ea01dc76cb9a0cc6d151ccc/crates/xcl/src/shaders.rs#L1876-L1908) Release the slot after the translation returns and before publishing the result. A timed-out translation should retain its slot until the translation itself returns, as the existing cap test expects. Verified by code inspection. I did not run this PR’s binaries. Review assisted by Codex (`gpt-6.2-sol`).
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 01:25 UTC · original

Code review on e6aeef4:

  • Diff audited and CI workflow approved.
  • Confirming @JJAutoCompare's race catch in bounded_translation (crates/xcl/src/shaders.rs): let _active_worker = ActiveWorker(worker_active) drops after tx.send(result), so a caller receiving result (especially with --threads 1) can immediately re-enter bounded_translation before ActiveWorker::drop runs fetch_sub(1, Ordering::AcqRel) and trip "worker limit: ...". Dropping _active_worker right before tx.send(result) (or drop(_active_worker) once catch_unwind finishes) avoids that race while still keeping the slot held until translation completes or times out.

Remaining before merge: Fixing the ActiveWorker drop order, fixing PR description, CI green, and dual-vendor verification on the updated head.

**@⁠raylitebull** on GitHub · 2026-11-25 01:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7149536868) Code review on `e6aeef4`: - Diff audited and `CI` workflow approved. - Confirming `@JJAutoCompare`'s race catch in `bounded_translation` (`crates/xcl/src/shaders.rs`): `let _active_worker = ActiveWorker(worker_active)` drops after `tx.send(result)`, so a caller receiving `result` (especially with `--threads 1`) can immediately re-enter `bounded_translation` before `ActiveWorker::drop` runs `fetch_sub(1, Ordering::AcqRel)` and trip `"worker limit: ..."`. Dropping `_active_worker` right before `tx.send(result)` (or `drop(_active_worker)` once `catch_unwind` finishes) avoids that race while still keeping the slot held until translation completes or times out. **Remaining before merge:** Fixing the `ActiveWorker` drop order, fixing `PR description`, CI green, and dual-vendor verification on the updated head.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 03:42 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 03:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7152171259) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 11:03 UTC · original

Updated review on f1331cd (crates/xcl/src/shaders.rs):

  • Moving drop(active_worker_guard); ahead of tx.send(result) cleanly closes the slot-release race before the caller observes completion, and threads.min(32) + worker_limit_hit returning exit code 2 bounds leaked timed-out worker threads cleanly.
  • Both Build and test and PR description are green on f1331cd.

Remaining before merge: Independent Windows verification (shaders::tests including the three new bounded_translation tests) on f1331cd.

**@⁠raylitebull** on GitHub · 2026-11-25 11:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7160526201) Updated review on `f1331cd` (`crates/xcl/src/shaders.rs`): - Moving `drop(active_worker_guard);` ahead of `tx.send(result)` cleanly closes the slot-release race before the caller observes completion, and `threads.min(32)` + `worker_limit_hit` returning exit code `2` bounds leaked timed-out worker threads cleanly. - Both `Build and test` and `PR description` are green on `f1331cd`. **Remaining before merge:** Independent Windows verification (`shaders::tests` including the three new `bounded_translation` tests) on `f1331cd`.
Author
Owner

@⁠tiagonleal on GitHub · 2026-11-25 14:09 UTC · original

Verification on NVIDIA RTX 5070 Ti (Windows 11), head f1331cd3ca80d0fc52be3b845c09fb5841285ee7

Tested

  • Head f1331cd3ca80d0fc52be3b845c09fb5841285ee7 (git rev-parse HEAD of a clean detached worktree, no local changes, built as is). The PR was open and the head unchanged when I started and again before writing this.
  • Windows 11 Pro 10.0.26300 (Developer Mode on), NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42, 32.0.16.1742), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), cargo 1.100.0, debug profile (the cargo test default).
  • cargo test -p xcl --lib shaders::tests -- --test-threads=4 --nocapture: 10 passed, 0 failed, 0 ignored (0.31 s after the build). That includes the three direct_worker tests: completed_direct_worker_releases_slot_before_result, direct_worker_reports_panic_separately_from_timeout, timed_out_direct_worker_holds_its_slot_until_exit.
  • The same filter at the default thread count, 3 more runs: 10 passed, 0 failed, 0 ignored each time. I did not see the 0xc0000005 flake mentioned in the thread.
  • No SKIPPED lines in the output.

Not tested

  • An AMD host.
  • cargo test --workspace, the rest of --lib, other test targets; release profile; an offline xcl shaders --direct sweep with real shaders; the retail game and xcl-smoke.

Run and written with Claude Code (Claude Fable 5.2 and Claude Sonnet 5.5).

**@⁠tiagonleal** on GitHub · 2026-11-25 14:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7164840650) Verification on NVIDIA RTX 5070 Ti (Windows 11), head `f1331cd3ca80d0fc52be3b845c09fb5841285ee7` **Tested** - Head `f1331cd3ca80d0fc52be3b845c09fb5841285ee7` (`git rev-parse HEAD` of a clean detached worktree, no local changes, built as is). The PR was open and the head unchanged when I started and again before writing this. - Windows 11 Pro 10.0.26300 (Developer Mode on), NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42, 32.0.16.1742), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), cargo 1.100.0, debug profile (the `cargo test` default). - `cargo test -p xcl --lib shaders::tests -- --test-threads=4 --nocapture`: 10 passed, 0 failed, 0 ignored (0.31 s after the build). That includes the three `direct_worker` tests: `completed_direct_worker_releases_slot_before_result`, `direct_worker_reports_panic_separately_from_timeout`, `timed_out_direct_worker_holds_its_slot_until_exit`. - The same filter at the default thread count, 3 more runs: 10 passed, 0 failed, 0 ignored each time. I did not see the 0xc0000005 flake mentioned in the thread. - No `SKIPPED` lines in the output. **Not tested** - An AMD host. - `cargo test --workspace`, the rest of `--lib`, other test targets; release profile; an offline `xcl shaders --direct` sweep with real shaders; the retail game and `xcl-smoke`. Run and written with Claude Code (Claude Fable 5.2 and Claude Sonnet 5.5).
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 18:28 UTC · original

Review update on f1331cd: both Build and test and PR description passed, and independent verification on f1331cd now covers both AMD (RX 6800M direct_worker 3/3) and NVIDIA (RTX 5070 Ti shaders::tests 10/10 across 4 runs).

After #2285 landed in crates/xcl/src/shaders.rs, #1997 now shows a merge conflict. Once rebased onto origin/main with CI green and a quick re-verify on the rebased commit, this is ready to merge.

**@⁠raylitebull** on GitHub · 2026-11-25 18:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7170955501) Review update on `f1331cd`: both `Build and test` and `PR description` passed, and independent verification on `f1331cd` now covers both AMD (RX 6800M `direct_worker` 3/3) and NVIDIA (RTX 5070 Ti `shaders::tests` 10/10 across 4 runs). After `#2285` landed in `crates/xcl/src/shaders.rs`, `#1997` now shows a merge conflict. Once rebased onto `origin/main` with CI green and a quick re-verify on the rebased commit, this is ready to merge.
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-25 22:15 UTC · original

Review on f053f27 (read from the diff, not built or run) – one behaviour change not raised above:

After threads timeouts the sweep stops. A timed-out worker keeps its slot until its thread exits, and the limit passed to bounded_translation is threads. So once threads translations have timed out and are still running (8 by default, 1 with --threads 1), every later call returns worker limit:, worker_limit_hit is set and the sweep ends with exit 2 – the rest of the sample is never tried. Before this PR a timeout only left a thread behind and the sweep finished. With big programs timing out routinely, a full --sample 0 run will likely stop early.

Suggestion: give stuck workers their own budget (e.g. a limit of threads + K, allowing K timed-out stragglers), or have the caller wait for a free slot instead of aborting, and exit 2 only when that budget is exhausted. A test with limit = 1 and two consecutive timeouts would pin whichever behaviour is chosen.

**@⁠Oliwettoo** on GitHub · 2026-11-25 22:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7176125089) Review on f053f27 (read from the diff, not built or run) – one behaviour change not raised above: **After `threads` timeouts the sweep stops.** A timed-out worker keeps its slot until its thread exits, and the limit passed to `bounded_translation` is `threads`. So once `threads` translations have timed out and are still running (8 by default, 1 with `--threads 1`), every later call returns `worker limit:`, `worker_limit_hit` is set and the sweep ends with exit 2 – the rest of the sample is never tried. Before this PR a timeout only left a thread behind and the sweep finished. With big programs timing out routinely, a full `--sample 0` run will likely stop early. Suggestion: give stuck workers their own budget (e.g. a limit of `threads + K`, allowing `K` timed-out stragglers), or have the caller wait for a free slot instead of aborting, and exit 2 only when that budget is exhausted. A test with `limit = 1` and two consecutive timeouts would pin whichever behaviour is chosen.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 22:48 UTC · original

Thanks for flagging the full-sweep consequence. Yes: --threads is deliberately the maximum number of live translation workers, including ones whose caller timed out. If all of them remain active, the sweep stops with exit 2 and says it is incomplete; it does not report a successful full sample. Launching another worker at that point would restore the detached-thread accumulation this PR addresses.

timed_out_direct_worker_holds_its_slot_until_exit pins the limit = 1 case: a timeout keeps the slot, the next translation is refused with worker limit:, and work resumes after that thread exits. A threads + K cap would let K additional timeouts through but would still need to stop if those workers also remain stuck; it also permits K more large translator stacks. I will keep the hard cap for this PR and make the early-stop limitation explicit in the description. A whole-pack sweep with persistent hangs was not validated on this head.

AI use: OpenAI Codex (GPT-6; exact variant unavailable) traced the current worker/sweep code and drafted this response; no new test was run for this comment.

**@⁠luckyteagirl** on GitHub · 2026-11-25 22:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7176819410) Thanks for flagging the full-sweep consequence. Yes: `--threads` is deliberately the maximum number of *live* translation workers, including ones whose caller timed out. If all of them remain active, the sweep stops with exit 2 and says it is incomplete; it does not report a successful full sample. Launching another worker at that point would restore the detached-thread accumulation this PR addresses. `timed_out_direct_worker_holds_its_slot_until_exit` pins the `limit = 1` case: a timeout keeps the slot, the next translation is refused with `worker limit:`, and work resumes after that thread exits. A `threads + K` cap would let K additional timeouts through but would still need to stop if those workers also remain stuck; it also permits K more large translator stacks. I will keep the hard cap for this PR and make the early-stop limitation explicit in the description. A whole-pack sweep with persistent hangs was not validated on this head. AI use: OpenAI Codex (GPT-6; exact variant unavailable) traced the current worker/sweep code and drafted this response; no new test was run for this comment.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 06:51 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 06:51 UTC · [original](https://github.com/xcl-dev/xcl/pull/1997#issuecomment-7184854799) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1997/head:github-bot/gh-1997'
git switch 'github-bot/gh-1997'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1997'
git switch 'github-bot/gh-1997'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1997'
git switch 'github-bot/gh-1997'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1997'
git switch 'main'
git merge --squash 'github-bot/gh-1997'
git switch 'main'
git merge --ff-only 'github-bot/gh-1997'
git switch 'main'
git merge 'github-bot/gh-1997'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.