xcl run: coordinate worker claims via OS locks and recover incomplete builds #2702
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2712"
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?
Imported from ivall/xcl. Originally posted by ZekkJJ on 2026-11-26T07:59:53Z.
Hardens multi-worker offline compute pipeline preparation (
crates/xcl/src/shaders.rs) against missing cache directories, corrupt cached blobs, timeout claim theft, orphaned.claimdeadlocks, and silent incomplete worker termination.Part of #2688 (Workstream 7). Based on
nvidia-dev(af2cecc4).What is in it
crates/xcl/src/shaders.rs:.claimacquisition and separate lock contention (HeldElsewhere) from filesystem errors (Unavailable).try_cached_pso+Claim::acquire+ post-claim cache reload recheck), holdingID3DBlobalive across atomicdriver_cache::writereplacement and warning/counting failed writes..claimownership with Windowsshare_mode(0) | FILE_FLAG_DELETE_ON_CLOSE(withDELETEaccess and boundedERROR_ACCESS_DENIEDretry for transientSTATUS_DELETE_PENDING) so active builds are never stolen after 30 minutes, crashed/killed workers release locks immediately, and unlocked orphaned.claimfiles from older builds are adopted and deleted on drop.PipelineCacheIdentityand panic-safeInflightGuard/RunningPermitdrop guards.compute pipelines:worker summaries on stderr underXCL_PRECOMPILE_PARENT, run automatic single-worker recovery on worker failure/missing summary, and returnErrwhenever incomplete pipelines remain.Tested
32.0.16.1656),rustc 1.98.1(48a229cea).cargo test --locked -j 2 -p xcl --lib shaders:: -- --test-threads=1:25 passed; 0 failed; 0 ignored(1.09s;SKIPPED shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required)andretail_pack_sampleskipped withoutXCL_SAMPLE_RPF). Covers OS subprocess tests forTerminateProcessclaim release, 4-worker simultaneous races over missing and corrupt blobs, orphaned.claimadoption,>2hactive claim preservation, failed writes,InflightGuardpanic unwinding, and worker recovery policy.cargo test --locked -j 2 -p xcl --test e2e -- --test-threads=1:4 passed; 0 failed; 0 ignored(18.85s).cargo build --locked --release -j 2 -p xcl: passed (0errors).8b113eebrelease binary, isolated caches, captured compute shader corpus with 69 pipeline entries / 43 unique native driver blobs):fresh_w4: 4/4 workers exited0in72,195.44 ms(65 made, 22 from_disk, 4 elsewhere, 0 errors, 0 write_errors,43/43blobs present,0leftover.claim/.tmp, peak aggregate commit1,516.23 MiB); warm 1-worker verification hit69/69 from_diskin5,340.57 ms.corrupt_w4(pre-corrupted driver blobs): 4/4 workers exited0in76,181.68 ms(66 made, 23 from_disk, 3 elsewhere,0leftover corrupt blobs/claims/tmps,43/43valid); warm verification hit69/69 from_diskin4,325.83 ms.orphan_claims_w4(pre-seeded unlocked.claimfiles): 4/4 workers exited0in61,108.44 ms(65 made, 22 from_disk, 4 elsewhere,43/43blobs,0leftover.claimfiles).kill_recovery_w2: terminating 1 of 2 workers (exit -1, 0) left10missing blobs and0orphaned.claimlocks; single-worker recovery finishedexit 0in104,600.68 ms(69 made, 59 from_disk,43/43blobs,0claims/tmps); warm verification hit69/69 from_diskin5,103.05 ms.nvidia-dev(af2cecc4) baseline comparison on this host (--test-threads=1):shaders::tests11 passed, 0 failed,e2e4 passed, 0 failed; pre-existing baseline failures on unmodifiedaf2cecc4intexture_upload::tests(6 passed, 2 failed),d3d12_mesh_stream(2 passed, 1 failed),gpu_compute_e2e(6 passed, 1 failed), andgpu_two_pass_cache_e2e(0 passed, 1 failed).Regression run
scripts/smoke.ps1execution on an unpacked retail build before marking ready for review.Not tested
cargo test --workspaceafter the final commit (unmodifiedaf2cecc4baseline already fails intexture_upload::tests,d3d12_mesh_stream,gpu_compute_e2e, andgpu_two_pass_cache_e2e), pairedscripts/smoke.ps1(no retail title directory on this machine), AMD / Intel GPUs, Linux / Wine.AI use
Gemini); assisted with implementation, subprocess/unit/GPU tests, multi-worker release verification, and PR preparation under author direction.Imported from ivall/xcl. Originally posted by gsucristo on 2026-11-26T08:10:34Z.
Review: COMMENTED
Nice hardening overall — replacing the timeout-based
.claimheuristic withshare_mode(0) | FILE_FLAG_DELETE_ON_CLOSE+DELETEaccess is the right primitive on Windows (and maps cleanly towineserverhandle teardown on Wine/Proton),ID3DBlobstays alive acrossdriver_cache::write, theInflightGuard/RunningPermit/DescGuarddrop guards have clean lock ordering (inflightbeforerunning) and panic safety, and the OS subprocess tests cover the tricky failure modes well.A few concrete issues and nits I noticed while reading through
crates/xcl/src/shaders.rs:1. Deterministic worker failures trigger a redundant recovery pass and lose the error breakdown
In
precompile, a worker running underXCL_PRECOMPILE_PARENTprints thecompute pipelines: ...summary to stderr and then returnsErr(...)wheneverfailed + refused + capped + write_failures > 0, causing the worker process to exit non-zero (worker_failures > 0).In
evaluate_compute_workers,worker_failures > 0is checked before inspectingtotals:Because of that ordering:
capped,refused, orrecord_errorscount causesevaluate_compute_workersto returnNeedsRecoveryinstead ofIncomplete, re-running the entire pack in a single-worker recovery pass.evaluate_compute_workers(1, 1, &rec_summaries)hitsNeedsRecoveryagain and returns"Shader preparation incomplete after worker failure: 1 of 1 workers failed (1/1 reported completion)", hiding the actualrefused/capped/record_errors/write_errorscounts.compute_summary_and_worker_policy_enforce_recovery_and_completenessdidn't catch this because it passesworker_failures = 0for theIncompletecases.)Checking
if parsed == workers && refused + capped + record_errors + write_errors > 0 { return ComputeWorkersOutcome::Incomplete(...); }before theworker_failures > 0branch (or letting workers exit 0 after emitting their summary and letting the parent fail ontotals) would fix both issues.2. Double
driver_cache::loadon the hot pathIn
make_one:let initial_cached = path.as_deref().and_then(driver_cache::load);reads the entire.psofile even when!over_cap, then discards it and reads the file again after acquiringInflightGuardandRunningPermit.if over_cap(e.g.if over_cap && path.as_deref().and_then(driver_cache::load).is_none()) avoids doubling file reads/allocations for normal cached pipelines.3. Windows
renamecontention when replacing a corrupt blobConcurrent workers call
driver_cache::load(path)beforeClaim::acquire(path). When the claim owner replaces a corrupt blob viadriver_cache::write(std::fs::rename(&tmp, p)), a concurrent reader still insidestd::fs::read(path)can transiently causerenameto fail withERROR_ACCESS_DENIEDon Windows (Rust'sstd::fs::renamedoes not useFILE_RENAME_FLAG_POSIX_SEMANTICS). Right now that incrementswrite_failuresand removespath. A short bounded retry onrenameindriver_cache::write(similar to theSTATUS_DELETE_PENDINGretry inClaim::acquire) would avoid spurious write failures under multi-worker contention on corrupt blobs.4. Minor nits
try_cached_psoleaves a dangling pointer indesc.CachedPSO: Whentry_cached_psoreturnsNone,desc.CachedPSO.pCachedBlobstill points to the droppedbytesslice. Line 1729 currently resetsdesc.0.CachedPSO = Default::default()before the uncached compile so there is no UB today, but clearingdesc.CachedPSOinsidetry_cached_psobefore returning keeps the helper self-contained.XCL_PRECOMPILE_SLICEin recovery:worker_commandstripsXCL_HOST,XCL_PREPARATION_PARENT, etc., but notXCL_PRECOMPILE_SLICE. ClearingXCL_PRECOMPILE_SLICEinworker_command(or in the recovery pass) ensures an inherited env var can't restrict the single-worker recovery pass to a single slice.Claim::acquirebackoff &Unavailablecleanup:3 × 2ms(6 ms) for transientSTATUS_DELETE_PENDINGis usually plenty, though under antivirus/filter-driver load on Windows a slightly longer stepped backoff (e.g.2, 5, 10, 20 ms) is cheap and reduces spuriousUnavailablefallbacks. Also, ifclaim.is_none()(Unavailable), consider skippingstd::fs::remove_file(path)onhad_corruptso an uncoordinated worker can't delete a blob another worker just published.over_cap: The comment aboveif initial_cached.is_none() && over_capstill says "the pass finishes without it, and the runtime builds it when a title needs the pipeline", whereaspipelines_in_workersnow fails closed withErrwhencapped > 0(matching single-workerprecompile). Worth confirming whethercapped > 0should fail multi-worker launch preparation or if the comment should be updated.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T08:12:26Z.
Review: COMMENTED
At head
8b113eeb3e306ba85aefcd3d146bbcbb25f07199, the fourrace_and_publishsubprocesses only wait for thegofile. The winner holds the.claimfor a fixed 40 ms (shaders.rs:2018), then releases it; the parent later requires exactly oneOUTCOME=ACQUIRED(shaders.rs:2181). A child delayed by process startup or scheduling for more than 40 ms can first tryClaim::acquireafter the winner has released it, legitimately acquire a second time, and fail this test despite correct exclusive ownership. Could the winner wait, with a bounded timeout, until the other children acknowledge their acquisition attempts before releasing, or could the assertion test non-overlap without assuming all attempts fit inside 40 ms? This would make the subprocess test robust on loaded CI hosts.This is a source-derived test-race review of the exact head; I did not run a delayed-child reproduction. AI use: OpenAI Codex (GPT-6.2 Sol) identified the interleaving, and I checked the child role and parent assertion before posting.
Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-26T08:12:52Z.
Source review of
8b113eeb, no run. A refused or capped pipeline seems to take the recovery path instead ofIncomplete:XCL_PRECOMPILE_PARENTset, soprecompilereturnsErrwhenfailed + refused + capped + write_failures > 0(shaders.rs:2847). The worker then exits non-zero, andin_workerscounts it infailed(:2449-2451).evaluate_compute_workerschecksworker_failures > 0first (:2316), so the result isNeedsRecovery, neverIncomplete. The refused/capped counts from the summaries are not reported.:2359). Its worker meets the same refusal, exits non-zero, and the pass ends inErr("… incomplete after worker failure …"). That reachesprepare_for_launchthrough?(:1843), andxcl runstops before the title.So one pipeline the driver refuses, or one over
XCL_PIPELINE_MAX_KB, costs a full single-worker pass and then the launch. IfIncompleteis meant for that case, the worker could exit 0 after printing its summary when only refusals, caps or write failures occurred (keeping a non-zero exit for crashes and record failures).evaluate_compute_workerswould then see the counts.Not tested: no build or run of this head on our side. We are running
nvidia-devaf2cecc4cold on an RTX 5090 tonight, and will say here if a refusal shows up there.AI use: Gemini (Antigravity) flagged it in a review; Claude Code (Claude Opus 5.5) traced it through the source at
8b113eeband wrote this.Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-26T11:42:05Z.
Tested
8b113eebon a retail pack, the case it fixes: a stopped warm-up's claims no longer block the next one. I hit this for real earlier today: a warm-up I stopped and restarted reportedpipelines left to another process that was building them 5with no other process running, and the next world run stood still for about 60 s on one of those five, a 1.68 MB compute pipeline the driver had never built, until the title's watchdog ended it.Setup: RTX 3060 12 GB, NVIDIA 581.80, i9-14900KF, 32 GB RAM, Windows 11 26200, release builds of
nvidia-devaf2cecc4and of this PR's exact head, same retail pack. Each step:XCL_PIPELINE_THREADS=16 XCL_ADAPTER=3060 xcl shaders <pack> --precompile --pipelines --only cs(without--used-only, so the programs are not in the driver cache yet), stopped withStop-Process -Forceafter 150 s at a moment when the NVIDIA DXCache had been quiet for 15 s. Claims counted in%LOCALAPPDATA%\XCL\dxil\driver..claimfiles after the stopaf2cecc4STALE) leaves them unbuilt.Not tested: the multi-worker path of
xcl run's preparation (XCL_PRECOMPILE_PARENT, recovery after a worker fails) with a stop in the middle; theshaders::unit tests and the suite on this machine; AMD; the point KDenKC raised about refused or capped pipelines.AI use: Claude Code (Claude Opus 5.5) ran these steps on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-26T12:28:48Z.
Review: COMMENTED
Needs changes — keep the useful work. Checked head
8b113eeb3e306ba85aefcd3d146bbcbb25f07199.The OS-lock change has useful behavior and should be kept, but the worker error/command paths still need changes. A complete summary containing known refusals/caps/write failures is classified as a crashed worker first, causing an unnecessary whole-pack recovery before failure. Initial and recovery children also need the configured adapter forwarded when no nonempty
XCL_ADAPTERoverride exists; a nonempty override was already inherited. A recovery child must clear an inheritedXCL_PRECOMPILE_SLICE. The local repair reports deterministic incomplete results before crash recovery and tests both child-command paths. The claim fixture was also changed to wait for bounded attempt acknowledgements instead of assuming every child runs inside 40 ms.Local validation: head plus an uncommitted repair and regression fixtures: 12 passed, 0 failed, 0 ignored, 0 skipped. These are CPU checks of the local repair, not a claim that the unmodified PR passed them. Separate negative-control checks produced 0 passes and 4 expected failures. The altered-sharing control checks the claim fixture's failure detection; it does not reproduce the original 40 ms scheduling race.
Build command:
cargo test --locked --offline -p xcl --lib --no-run --message-format=json --target-dir <isolated target>(only the private absolute target path is replaced here). Each selected test executable was then run separately as<test-exe> <exact-name> --exact --test-threads=1 --nocapture.Selected exact tests
shaders::tests::completed_compute_failures_report_the_cause_without_recoveryshaders::tests::compute_summary_and_worker_policy_enforce_recovery_and_completenessshaders::tests::preparation_workers_keep_the_titles_adapter_and_environment_overrideshaders::tests::recovery_workers_clear_inherited_slices_and_sliced_workers_set_their_ownshaders::claim_tests::subprocess_simultaneous_race_yields_one_owner_and_atomic_publishshaders::claim_tests::a_pipeline_is_claimed_by_one_builder_at_a_timeshaders::claim_tests::claim_creates_missing_cache_directories_before_lockingshaders::claim_tests::claim_distinguishes_contention_from_filesystem_errorsshaders::claim_tests::claim_adopts_orphaned_claim_file_left_by_older_buildshaders::claim_tests::claim_never_steals_active_long_running_ownershipshaders::claim_tests::subprocess_forced_termination_immediately_releases_delete_on_close_claimshaders::claim_tests::inflight_guard_and_identity_prevent_deadlock_and_distinguish_paramsLatest-main source comparison:
b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7; full-head merge-tree result: clean. This is a source compatibility check, not a tested integration build. The actual target remains nvidia-devaf2cecc40886a8682ecf3267f5328c6dc4b66ad7; merging the full head into main would also import its branch history. Local repair patch SHA-256:99a55473f39560eafbea0d41208a013c458ff95228214b9ecca57c24bf7309da.Windows 11 Pro build 26200, i5-10400, 32 GiB RAM, Rust 1.100.0 MSVC debug tests. RTX 3060 Ti / driver 32.0.16.1714 is present but was not exercised. No full-suite, GPU or title result is claimed; installed builds and game data were untouched.
AI use: Codex (GPT-6) reviewed the source, prepared the local repair/fixtures, ran the checks and drafted this report.
Optional temporary Discord for coordinating this contributor work, helping test and comparing results.
Imported from ivall/xcl. Originally posted by ZekkJJ on 2026-11-26T14:31:28Z.
@Prime1997 Thanks for preparing the local repair. Could you share the patch or branch so we can review it and preserve attribution?
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-26T15:19:04Z.
@ZekkJJ Here is the complete repair patch from my earlier review, based on
8b113eeb3e306ba85aefcd3d146bbcbb25f07199.The repair preserves reported refusal, cap, record, and cache-write counts when workers finish with known errors. It still retries missing completion reports and nonzero exits when every report is clean. It also forwards the title's adapter unless a nonempty override is set, clears inherited slices for whole-pack recovery, and makes the claim test wait for every contender's attempt.
Validation: The patch applies cleanly to the current PR head. The repaired tree previously ran 12 exact CPU tests: 12 passed, 0 failed, 0 ignored, 0 explicit skips, with 1,660 filtered out per invocation. The names and commands are in the earlier review. GPU execution, title behavior, and full-suite validation remain open.
Save the contents of the diff block as
2712-repair.patchwith LF line endings and a final newline. On the pinned revision, rungit apply --check 2712-repair.patch, thengit apply 2712-repair.patch. SHA-256:99a55473f39560eafbea0d41208a013c458ff95228214b9ecca57c24bf7309da.Please credit Prime1997 for this follow-up patch and fixtures. Thanks to KDenKC, gsucristo, and luckyteagirl for tracing the worker and claim-test issues.
Complete repair patch
AI use: Codex (GPT-6) prepared the repair and tests and verified the shared patch. Optional temporary Discord for coordinating contributor work, testing, and comparing results.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:46:57Z.
Triage (#1607) – head
8b113eeParts of this PR are now on main, adapted from it and credited: the delete-on-close
.claimlock withClaimAcquire::HeldElsewhere/Unavailable(9f6d8eb),InflightGuard/PipelineCacheIdentity(474ca3b) and the unwind-safeRunningPermit(733130a).Not on main yet: the post-claim recheck of rejected or corrupt cached blobs (
try_cached_pso), thecompute pipelines:worker summary parsing,write_errors, and the single-worker recovery pass. The PR conflicts and needs a rebase that keeps only those parts.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.