display_white_cache: accept that the first get() may already have the value it woke #2713
Closed
leonida/mandy
fiestorra wants to merge 0 commits from
fix/display-white-cache-first-get-race into main
pull from: fix/display-white-cache-first-get-race
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2713
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/display-white-cache-first-get-race"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
A flaky test in
main, measured:display_white_cachefails about once in thirty runs on a loaded host, and it took thewindowsjob of #1937 with it today.The assertion:
Why it races -
DisplayWhiteCache::get():The first
get()is what wakes the worker to read, andvalue_.load()runs after the wake. Whether the value is still empty at that point is a scheduling fact, not an invariant: on an idle machine the worker loses the race and the assertion passes; on a loaded one it wins and the assertion fails.Measured here (Windows 11, RTX 4090, MSVC 19.44.35226), on
maind367675c7:What this changes: the assertion now accepts the two outcomes that are both correct - the fallback, or the value the call itself woke the worker to read - and keeps the parts that do not race:
The
reads()checks are untouched, so the property the test exists for - the firstget()wakes the worker exactly once, and a later one does not re-read before the period - is still asserted.What this does not do: it does not make
get()deterministic. The cache is correct as written (a caller that gets 0 falls back to 203, which is the documented behaviour); it is the test that assumed an ordering the implementation never promised.Why it matters beyond this test:
windowsis a required check on every pull request, so this flake costs every author a red run and a re-run. #1937 hit it today and it was not that branch's fault.AI-assisted: yes - DeepSeek v4.1 (flash) as the coding agent, with a separate reviewer agent reading the change before submission. Where and on what: the measurements above were taken on Windows 11 with MSVC 19.44.35226 on an RTX 4090 (NVIDIA driver 621.24) where a C++ or GPU path is involved; Python and docs cases need none of it.
Written with an AI assistant.
Checked by OreoFR, main d367675c7, PR head b86831d6e. MEASURED:
main-only run (452d1d1b6,windows-latest) had ctest 513/514 withdisplay_white_cachethe one failure, "the first get() has no value yet (the caller falls back to 203)"; two other runs of the same build passed it (https://github.com/ProjectLeonida/mandy/pull/1694#issuecomment-7264433105).clang++ -std=c++20 -O1 test/display_white_cache_test.cpp; the header is portable): main's test and this PR's test, 400 runs each, 10 at a time: 0 failures on both. So it does not reproduce here, and this run cannot show the fix; it only shows the new assertion passes and nothing else changed.0.0f(worker not done yet) or240.0f(the value it was woken to read), and the followingwithin(2s, ...)checks still pinreads() == 1and the cached 240, so the race-free parts are still asserted.AI-assisted: Claude Code
Independent controlled-order check. I tested
b86831d6emerged ontod367675c7(treeba9c9680) on Linux with Clang 23.1.5. Both builds used the checked-in test source with the same temporary scheduling probe in a local copy of the unchanged cache header. In one case the probe delayed the fake read until the caller loaded the cache. In the other, it held the caller until the worker published the value.0). Main and the PR pass 5/5 each.240). Main fails the original first-get()assertion in 5/5 runs. The PR passes 5/5, including the read-count and cached-value assertions.One uninstrumented control run on each revision also passed. Source-only synthetic test. AI-assisted with OpenAI Codex.
A control on the fix itself, since relaxing an assertion is exactly the change that can make a test vacuous: it still fails when the cache is broken.
The mutation: in
runtime/src/display_white_cache.h, makeget()return an impossible value when it has none:Result, on the branch with this change applied:
So the relaxed assertion is not
ok &= true: it accepts 0.0f (the fallback) or 240.0f (the fresh read), and rejects anything else - which is what a cache returning a third value would do. The mutation was reverted and is not in the branch.What the fix trades away, stated plainly: the original assertion also proved that the first call had not yet been filled on that machine, at that moment. That is not a property of the code -
get()is what wakes the worker and then loads the value, so the ordering is the scheduler's. Thereads()assertions carry that intent instead:reads() == 0before the firstget(),reads() == 1within 2 s after it, and no re-read before the period. Those are unchanged.Measured, both sides:
Written with an AI assistant.
A reviewer agent read this branch and found the added lines indented at four spaces while the block they sit in is at eight - and the body's snippet shows them correctly, so the diff and the description disagreed. Fixed, whitespace only.
Nothing else changed: same assertion, same numbers, same behaviour. The description was right and the diff was the odd one out, which is the reverse of the usual failure and the reason a second reader is worth the wait.
Written with an AI assistant.
Independent check on Windows (not the author), at
6859ae5ed.display_white_cache_test(MSVC 14.52.37025, Windows SDK 10.0.26100) and ran it 30 times under load (two 16-job translator suites running in parallel): 30/30 PASS, 0 failures.Environment: Ryzen 9 7950X3D (16C/32T), Windows 11 Pro 10.0.26200.9711.
AI-assisted: yes (opencode).
A measured rate for both arms, and it corrects a number I have been quoting in this thread: on
maind8ca18240the old assertion passed 100 of 100 runs under load, so "1 failure in 30" was a different commit and I should not have carried it forward as if it were this one.The two arms, same machine, same load, same binary target:
What that does to the case for the fix:
get()requests a read and then readsvalue_, so which of the two it returns is the scheduler's decision. A test that asserts one of them asserts the scheduler. That argument does not need a reproduction.d367675c7(an earliermain, on this machine, with four hogs) and I repeated it in #1937 as if it described the current tree. Ond8ca18240the same test and the same load gave 0 in 100. So the rate is at most about 1%, not 3%, and possibly zero on this machine's scheduler.display_white_cache's refresh broken sovalue_never lands, the relaxed assertion still fails - the test is not made toothless by accepting both outcomes. That is what a reviewer should be shown.What I would add before merging, if anyone wants more: a stress arm that runs the same test 1000 times (about 17 minutes here) to put a bound on the old rate rather than an estimate. I did 100 because it is what I could do twice in one sitting; say the word and I will run 1000 on both arms.
AI-assisted: yes - DeepSeek v4.1 (flash) built and ran both arms on the machine above.
Written with an AI assistant.
The bound I offered, run: 1000 runs of the old assertion, 0 failures. That is a stronger correction than the one I posted an hour ago, and it is worth having in the thread before anyone merges on the strength of a flake I cannot reproduce.
So on this machine and this commit the rate is under 0.1% (0 in 1000 puts a 95% upper bound around 0.3%), not the 1-in-30 I carried in from
d367675c7this morning. I have now measured it three times - 1/30 on that commit, 0/100 and 0/1000 on this one - and the only honest summary is that the reproduction is commit- and machine-dependent and my first number should not be quoted.What that leaves the PR standing on, stated so a reviewer can weigh it:
get()requests the read and then readsvalue_; whether the second step sees the value depends on whether the worker thread ran in between. That is a defect in the test whether it fails one time in thirty or never on a given box.value_never lands, the relaxed assertion fails. A reviewer who worries the fix hides a real bug should run that, not this.What I would not claim: that this fix makes
windowsreliable by measurement. It makes the test stop depending on a race, which is a different and better claim than a rate.The machine is idle again (the four hogs are stopped).
AI-assisted: yes - DeepSeek v4.1 (flash) ran the thousand and checked the load before and after.
Written with an AI assistant.
One more check before anyone reads my rate numbers as a trend: the test and the cache are byte-identical between the commit where I saw the failure and the commit where 1000 runs passed, so nothing was fixed in between and #2713 is still the only change on the table.
So the difference between 1-in-30 this morning and 0-in-1000 tonight is the machine, not the tree. This morning I had build jobs running on the same box; tonight the four hogs were the only load.
Which makes the honest reading of all three measurements:
d367675c7d8ca18240d8ca18240Same code, file-hash identical, and a 33-fold difference in rate between two sittings. That is what a scheduler-dependent race looks like from the outside, and it is also why a CI red on it cannot be argued away as "just slow runners" - and why the fix should not be justified by a rate at all.
Nothing to change in the PR. The assertion still reads a value the scheduler decides; the relaxed one still fails on a broken cache. I am only adding this so the thread does not read as if the code got better between the two commits.
AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
A refinement of the rate in my earlier comments, and it points the same way: in a full suite the assertion has now failed twice in two runs, while standing alone it failed 0 times in 1000.
The difference between the two is not the test, it is what runs before it.
display_white_cacheis test 11 of 575, so the buffer cache and the scheduler are already warm from ten other programs, and the assertion is a race:get()requests the read and then readsvalue_, so whether the second step sees it depends on whether the worker thread ran in between. Under a full suite the window is narrower, and it lands on the failing side more often.So the honest rate is not one number: 0 in 1000 alone, 2 in 2 in a suite, and that is exactly the shape of a test that is asserting the scheduler rather than the cache. It also explains the CI red that started this: the
windowsjob runs the whole suite, not the test alone.The fix does not change: accept either outcome and assert the part that does not race, with the mutation control showing the relaxed assertion still fails on a cache that does not refresh.
What it does to my earlier correction: the 1-in-30 was not wrong, it was a third context - this morning I had builds running alongside, which is closer to the full suite than to the idle-standalone case. The number varies with the load, which is the definition of a race.
AI-assisted: yes - DeepSeek v4.1 (flash), which has now run this test in three kinds of load tonight.
Written with an AI assistant.
VERIFY-2713 — Linux, Fedora 45, GCC, no GPU device, no game files
Verdict: PASS. The race the pull request describes is real, and the weakened assertion still catches a broken cache — I broke the cache three ways and it noticed all three.
Head
6859ae5e, base the currentmain88a9f133, merge base20fe0c75, 1 commit, 1 file, +6/−1:runtime/test/display_white_cache_test.cpp.1. The race is in the code
runtime/src/display_white_cache.h:The first
get()wakes the worker thread, which does a wholeread_()and stores the result invalue_— all beforeget()reachesvalue_.load(). So the first call can return the freshly read value rather than "no value yet", and whether it does depends on the scheduling. The old assertionasserted one side of that race. The pull request accepts both:
which is right: 0.0f is "no value" and 240.0f is the value the worker was woken to read.
2. It builds and runs here, and the whole portable suite is green
The
runtimetree builds on Linux (the Windows runtime and its shims are behindif(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME), and the portable subset is built everywhere), anddisplay_white_cache_testis in it:(the Vulkan ones run on
lavapipe; 8 tests skip themselves for want of a device or a corpus.)And this test is in the CI, not only here —
.github/workflows/runtime.yml:506runsctest --test-dir runtime/build --output-on-failurein thelinux-gpu-toolsjob onubuntu-24.04.3. The race does not reproduce on this machine
I ran
display_white_cache_test40 times onmain's binary, and 40 more times with the machine loaded (8 spinning threads), and it passed every time:The window between the
notify_all()and thevalue_.load()is a few instructions wide, and the test'sreadlambda is trivial, so the worker rarely finishes inside it here. That is expected for a flake of this shape and it is not evidence against the pull request — it is the reason the failure is reported on other machines, not on this one.4. The weakened assertion still does its job
This pull request changes only the test, so the question is whether the test would notice the code it covers being wrong. I broke
DisplayWhiteCachethree ways and ran the test each time:get()no longer setsread_now_(the worker is not woken)value_get()returns a constant203.0fSo the new assertion is not so weak that a cache that always answers something else slips through:
203.0fis neither "no value" nor the value the worker read.5. What I did not check
xbox_present.cppside —DisplayWhiteCacheis kept apart fromXboxPresentationon purpose ("so the wake-up can be tested without a window or a GPU"), so the shim that reads it is not exercised by this test and I did not exercise it.AI-assisted: MiniMax M3.1 Flash.
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.