Skip to content

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

Open
fromthemoonx wants to merge 1 commit into
xcl-dev:mainfrom
fromthemoonx:tests/bundle-generation-release-probe-retries
Open

fromthemoonx wants to merge 1 commit into
xcl-dev:mainfrom
fromthemoonx:tests/bundle-generation-release-probe-retries

Conversation

@fromthemoonx

Copy link
Copy Markdown

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

`bundle_generations_propagate_and_final_release_runs_outside_lists`
checks that the final COM Release of a native generation runs outside
LISTS by calling `LISTS.try_lock()` inside the fake Release. LISTS is
process-wide, so when another test's thread holds it at that moment the
probe reports "final COM Release ran under LISTS" although the release
ran outside it. On main b2b1f10 (RTX 3060), `list_x::tests::` at
--test-threads=8 failed it in 8 of 60 runs.

The probe now retries try_lock for up to a second. Another thread lets
LISTS go within that time; this thread holding it makes every try fail,
so a release under LISTS is still caught: dropping the generations
inside the lock in `clear_segment_state` fails the test (after the 1 s
wait). With the change, 0 of 60 module runs failed it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026

@gut0to gut0to left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

if LISTS.try_lock().is_ok() {
break true;
}
if Instant::now() >= deadline {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@fromthemoonx fromthemoonx Dec 1, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head e9168f6, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants