Tests: the generation release probe waits out another test's LISTS lock #3573

Open
fromthemoonx wants to merge 1 commit from upstream-pr/3573 into main
fromthemoonx commented 2026-12-01 13:54:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T13:54:44Z.


list_x::tests::bundle_generations_propagate_and_final_release_runs_outside_lists fails now and then in parallel runs with "final COM Release ran under LISTS". The test's fake Release decides whether it runs outside LISTS with LISTS.try_lock().is_ok(). LISTS is process-wide, so when another test's thread holds it at that moment, the probe reports a release under LISTS that did not happen. Seen while merge-checking #1421, where it failed on main as often as on the PR.

The probe now retries try_lock for up to a second. Another thread lets LISTS go within that time; if this thread holds it, every try fails, so a real release under LISTS is still caught.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: generation_release (test helper) retries try_lock until a 1 s deadline. Test-only.

Tested

  • RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, rustc 1.100.0 MSVC, debug.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on this branch (e9168f6, on main b2b1f10): 2902 passed, 0 failed, 51 ignored. SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as on main.
  • Lib test binary, hle::d3d12x::list_x::tests:: --test-threads=8, 60 runs each: the test failed in 8 of 60 on main b2b1f10 and 0 of 60 with this change. In 2 of the 60 runs with the change, write_buffer_immediate_on_open_existing_heap_visible_to_cpu failed with E_OUTOFMEMORY, a known parallel flake unrelated to this test.
  • Mutation: with clear_segment_state dropping the generations while it still holds LISTS, the test fails with "final COM Release ran under LISTS" (after the 1 s wait), so the check still works.

Regression run

  • None: the diff only changes a #[cfg(test)] helper in a runtime file. Asking a maintainer for the test-only label.

Not tested

  • AMD and Intel GPUs; Wine.

AI use

  • Claude Code (Claude Opus 5.5) found the cause, wrote the change and the description, and ran the tests above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5587152540 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3573). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-01T13:54:44Z. --- `list_x::tests::bundle_generations_propagate_and_final_release_runs_outside_lists` fails now and then in parallel runs with "final COM Release ran under LISTS". The test's fake `Release` decides whether it runs outside LISTS with `LISTS.try_lock().is_ok()`. LISTS is process-wide, so when another test's thread holds it at that moment, the probe reports a release under LISTS that did not happen. Seen while merge-checking #1421, where it failed on `main` as often as on the PR. The probe now retries `try_lock` for up to a second. Another thread lets LISTS go within that time; if this thread holds it, every try fails, so a real release under LISTS is still caught. **What is in it** - `crates/xcl/src/hle/d3d12x/list_x.rs`: `generation_release` (test helper) retries `try_lock` until a 1 s deadline. Test-only. **Tested** - RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, rustc 1.100.0 MSVC, debug. - `cargo test --workspace --no-fail-fast -- --test-threads=4` on this branch (`e9168f6`, on `main` `b2b1f10`): 2902 passed, 0 failed, 51 ignored. SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as on `main`. - Lib test binary, `hle::d3d12x::list_x::tests:: --test-threads=8`, 60 runs each: the test failed in 8 of 60 on `main` `b2b1f10` and 0 of 60 with this change. In 2 of the 60 runs with the change, `write_buffer_immediate_on_open_existing_heap_visible_to_cpu` failed with E_OUTOFMEMORY, a known parallel flake unrelated to this test. - Mutation: with `clear_segment_state` dropping the generations while it still holds LISTS, the test fails with "final COM Release ran under LISTS" (after the 1 s wait), so the check still works. **Regression run** - None: the diff only changes a `#[cfg(test)]` helper in a runtime file. Asking a maintainer for the `test-only` label. **Not tested** - AMD and Intel GPUs; Wine. **AI use** - Claude Code (Claude Opus 5.5) found the cause, wrote the change and the description, and ran the tests above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gut0to commented 2026-12-01 14:44:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-01T14:44:44Z.

Code review location: crates/xcl/src/hle/d3d12x/list_x.rs; line 7421

@@ -7411,7 +7411,19 @@ mod tests {
         let n = (*(this as *mut ReentrantGenerationPso)).refs.fetch_sub(1, Ordering::Relaxed) - 1;
         let probe = (*(this as *mut ReentrantGenerationPso)).release_outside_lists;
         if n == 0 && !probe.is_null() {
-            (*probe).store(LISTS.try_lock().is_ok(), Ordering::Release);
+            // LISTS is process-wide, so another test's thread can hold it for a moment; only
+            // this thread holding it keeps try_lock failing for the whole second.
+            let deadline = Instant::now() + Duration::from_secs(1);
+            let outside = loop {
+                if LISTS.try_lock().is_ok() {
+                    break true;
+                }
+                if Instant::now() >= deadline {

This still uses elapsed time as a proxy for lock ownership: another test holding the process-wide LISTS mutex for more than one second also makes outside false, so the same flake can recur on a slow or loaded runner. Could this assertion use deterministic coordination with the other LISTS tests (or an explicit same-thread probe) instead of treating the timeout as proof of reentrancy? A test that holds the lock on a second thread across the deadline would cover this case. AI-assisted review; I traced the probe's try_lock result against concurrent test ownership.

<!-- greyfinch-sync:ivall/xcl:review-comment:4755871669 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3573#discussion_r4755871669). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T14:44:44Z. **Code review location:** `crates/xcl/src/hle/d3d12x/list_x.rs`; line 7421 ~~~~diff @@ -7411,7 +7411,19 @@ mod tests { let n = (*(this as *mut ReentrantGenerationPso)).refs.fetch_sub(1, Ordering::Relaxed) - 1; let probe = (*(this as *mut ReentrantGenerationPso)).release_outside_lists; if n == 0 && !probe.is_null() { - (*probe).store(LISTS.try_lock().is_ok(), Ordering::Release); + // LISTS is process-wide, so another test's thread can hold it for a moment; only + // this thread holding it keeps try_lock failing for the whole second. + let deadline = Instant::now() + Duration::from_secs(1); + let outside = loop { + if LISTS.try_lock().is_ok() { + break true; + } + if Instant::now() >= deadline { ~~~~ --- This still uses elapsed time as a proxy for lock ownership: another test holding the process-wide `LISTS` mutex for more than one second also makes `outside` false, so the same flake can recur on a slow or loaded runner. Could this assertion use deterministic coordination with the other `LISTS` tests (or an explicit same-thread probe) instead of treating the timeout as proof of reentrancy? A test that holds the lock on a second thread across the deadline would cover this case. AI-assisted review; I traced the probe's `try_lock` result against concurrent test ownership.
gut0to commented 2026-12-01 14:44:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-12-01T14:44:44Z.

Review: COMMENTED


AI-assisted review; I used an AI assistant to inspect this diff.

<!-- greyfinch-sync:ivall/xcl:review:6133583893 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3573#pullrequestreview-6133583893). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T14:44:44Z. **Review:** COMMENTED --- AI-assisted review; I used an AI assistant to inspect this diff.
fromthemoonx commented 2026-12-01 15:00:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T15:00:43Z.

Code review location: crates/xcl/src/hle/d3d12x/list_x.rs; line 7421

@@ -7411,7 +7411,19 @@ mod tests {
         let n = (*(this as *mut ReentrantGenerationPso)).refs.fetch_sub(1, Ordering::Relaxed) - 1;
         let probe = (*(this as *mut ReentrantGenerationPso)).release_outside_lists;
         if n == 0 && !probe.is_null() {
-            (*probe).store(LISTS.try_lock().is_ok(), Ordering::Release);
+            // LISTS is process-wide, so another test's thread can hold it for a moment; only
+            // this thread holding it keeps try_lock failing for the whole second.
+            let deadline = Instant::now() + Duration::from_secs(1);
+            let outside = loop {
+                if LISTS.try_lock().is_ok() {
+                    break true;
+                }
+                if Instant::now() >= deadline {

You're right: it is still a timing bound, not a proof. A held lock that outlasts the deadline reads as "released under LISTS", so a test (or a stalled runner) holding LISTS for over a second would bring the false failure back.

A deterministic same-thread probe needs to know who owns the lock, and std::sync::Mutex cannot say: try_lock gives the same WouldBlock whether this thread or another one holds it. Knowing the owner would take a #[cfg(test)] owner record at every lock site: LISTS.lock() appears 155 times in list_x.rs on main b2b1f10, all of them runtime code. That is more than this test-only fix should carry, and the change would no longer be test-only.

What the deadline changes: before, any overlap with another test's critical section failed the test (8 of 60 module runs at --test-threads=8); now it takes one held for a whole second, which did not happen in the 60 runs with the change (0 failures); I have not measured how long the tests hold LISTS. If you'd rather have more margin, I can raise the deadline to 10 s: with the bug present the test then takes 10 s to fail, and nothing changes when it passes. A test holding the lock past the deadline on a second thread would show the limit, but it would assert the false result, so I left it out.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

<!-- greyfinch-sync:ivall/xcl:review-comment:4756097611 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3573#discussion_r4756097611). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-01T15:00:43Z. **Code review location:** `crates/xcl/src/hle/d3d12x/list_x.rs`; line 7421 ~~~~diff @@ -7411,7 +7411,19 @@ mod tests { let n = (*(this as *mut ReentrantGenerationPso)).refs.fetch_sub(1, Ordering::Relaxed) - 1; let probe = (*(this as *mut ReentrantGenerationPso)).release_outside_lists; if n == 0 && !probe.is_null() { - (*probe).store(LISTS.try_lock().is_ok(), Ordering::Release); + // LISTS is process-wide, so another test's thread can hold it for a moment; only + // this thread holding it keeps try_lock failing for the whole second. + let deadline = Instant::now() + Duration::from_secs(1); + let outside = loop { + if LISTS.try_lock().is_ok() { + break true; + } + if Instant::now() >= deadline { ~~~~ --- You're right: it is still a timing bound, not a proof. A held lock that outlasts the deadline reads as "released under LISTS", so a test (or a stalled runner) holding `LISTS` for over a second would bring the false failure back. A deterministic same-thread probe needs to know who owns the lock, and `std::sync::Mutex` cannot say: `try_lock` gives the same `WouldBlock` whether this thread or another one holds it. Knowing the owner would take a `#[cfg(test)]` owner record at every lock site: `LISTS.lock()` appears 155 times in `list_x.rs` on main `b2b1f10`, all of them runtime code. That is more than this test-only fix should carry, and the change would no longer be test-only. What the deadline changes: before, any overlap with another test's critical section failed the test (8 of 60 module runs at `--test-threads=8`); now it takes one held for a whole second, which did not happen in the 60 runs with the change (0 failures); I have not measured how long the tests hold `LISTS`. If you'd rather have more margin, I can raise the deadline to 10 s: with the bug present the test then takes 10 s to fail, and nothing changes when it passes. A test holding the lock past the deadline on a second thread would show the limit, but it would assert the false result, so I left it out. AI use: Claude Code (Claude Opus 5.5) wrote this reply.
Foniass commented 2026-12-01 20:38:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T20:38:13Z.


Review (head e9168f65, diff read, not a merge-check; checks red):

No problems found in the diff. Checked that the change stays inside #[cfg(test)] mod tests of list_x.rs, that clear_segment_state (~1889) drops the generations after the LISTS guard is gone, and that the retry still fails when the releasing thread itself holds LISTS (a try_lock from the holding thread fails on every attempt). Draft #3603 replaces the same line with a sharded LISTS.held(list) check, so whichever lands second conflicts. The red check is PR description asking for smoke blocks because list_x.rs counts as a runtime file; the test-only label is what clears it.

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

<!-- greyfinch-sync:ivall/xcl:comment:7325021077 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3573#issuecomment-7325021077). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T20:38:13Z. --- Review (head e9168f65, diff read, not a merge-check; checks red): No problems found in the diff. Checked that the change stays inside `#[cfg(test)] mod tests` of `list_x.rs`, that `clear_segment_state` (~1889) drops the generations after the `LISTS` guard is gone, and that the retry still fails when the releasing thread itself holds `LISTS` (a `try_lock` from the holding thread fails on every attempt). Draft #3603 replaces the same line with a sharded `LISTS.held(list)` check, so whichever lands second conflicts. The red check is `PR description` asking for smoke blocks because `list_x.rs` counts as a runtime file; the `test-only` label is what clears it. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
bmjask commented 2026-12-02 14:59:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:59:03Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7349489249 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3573#issuecomment-7349489249). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:59:03Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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/3573:upstream-pr/3573'
git switch 'upstream-pr/3573'

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