Skip to content

vk_pipeline_check --module-timeout: a hung compile no longer stops the pipelines stage (BUILD-1646) - #5255

Open
ashiikins wants to merge 5 commits into
ItsNotRexed:mainfrom
ashiikins:pipeline-check-timeout
Open

ashiikins wants to merge 5 commits into
ItsNotRexed:mainfrom
ashiikins:pipeline-check-timeout

Conversation

@ashiikins

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: BUILD-1646 (claim)

What and why

On an Apple M2 Max with Homebrew MoltenVK 1.4.2, Apple's Metal compiler never finishes some translated compute modules. One 2.2 MB module (Int64 and buffer device address, no subgroup operations) was still compiling after 65 minutes in a full pipelines run, and after 19 minutes when checked alone, with MTLCompilerService at 100% CPU. vk_pipeline_check only has a crash path (--inflight-file/--skip-file, --isolate), so a hung compile holds make_game.py's pipelines stage forever, without a message.

vk_pipeline_check --module-timeout SEC (default 0, off):

  • The existing watchdog checks how long each in-flight module has been in the driver. Past SEC it prints MODULE TIMEOUT <name> (<phase> still in the driver after Ns), rewrites --inflight-file with only the timed-out modules, saves the cache and exits with status 3. The hung compile itself can't be cancelled.
  • Refused together with --isolate, which would bisect a timed-out batch and wait the timeout at every split.
  • --skip-file lines may add a TAB and a reason to print; plain lines print as before ("killed the driver in an earlier run").
  • Test hook: VK_PIPELINE_CHECK_SIMULATE_CRASH=<name>:HANG sleeps before that module's pipeline instead of raising a signal.

make_game.py:

  • Passes --module-timeout 1800 to a checker that has it (checker_supports). The slowest compiles that do finish are minutes (457 s for a --f64-soft compute shader on the same Mac).
  • On exit 3 the named modules go straight into the skip file, with the reason, and count as failed. Unlike a crash's suspects they are not compiled alone again, which would only hang again.
  • A crash's skip-file line is unchanged (the name alone), so the existing tests and older checkers see the same file.

Tested

On an Apple M2 Max, macOS, Homebrew MoltenVK 1.4.2, native build of runtime/ (Apple clang 21):

  • New tests/test_vk_pipeline_check_timeout.py against the real checker: the HANG hook ends the run with exit 3 after the timeout, MODULE TIMEOUT once, and the in-flight file names only that module; a skip-file reason is printed; no timeout hit changes nothing; bad values and --isolate are refused. 5/5 pass.
  • tests/test_make_game_pipelines.py (4 new cases: the timeout is passed, a timed-out module is skipped without a probe, a crash after a timeout keeps both lines, a timeout naming no module stops the stage) and tests/test_make_game_pipeline_batches.py: 29 pass. test_vk_pipeline_check_isolate.py, _index.py, the other test_make_game_* files and test_docs_links.py pass.
  • Not built on Windows here: the change uses std::_Exit and the existing watchdog, nothing POSIX-only. CI's Windows job will compile it.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator rule.)

AI-assisted. No game files.

…longer stops the pipelines stage (BUILD-1646)

On an Apple M2 Max with MoltenVK, Apple's Metal compiler never finishes some translated compute modules (one
2.2 MB module was still compiling after 65 minutes in a full run and 19 minutes alone). vk_pipeline_check only had
a crash path, so a hung compile held make_game.py's pipelines stage forever, with no message.

vk_pipeline_check: --module-timeout SEC (default 0, off). When a module has been in the driver longer than that,
the watchdog prints MODULE TIMEOUT, leaves only the timed-out modules in --inflight-file, saves the cache and
exits with status 3 (the compile itself can't be cancelled). Refused with --isolate, which would bisect and wait
the timeout at each split. --skip-file lines may add TAB and a reason to print. Test hook: SIMULATE_CRASH
<name>:HANG sleeps before the pipeline instead of raising a signal.

make_game.py: passes --module-timeout 1800 to a checker that has it. On exit 3 the named modules go straight
into the skip file (with the reason) and count as failed; unlike a crash's suspects they are not compiled alone
again, which would hang again. Crash lines in the skip file are unchanged.

Tests: tests/test_vk_pipeline_check_timeout.py (real checker, HANG hook) and four make_game cases. Docs:
pipeline_check.md, and a Known problems row in testing.md.

AI-assisted. No game files.
@Kev-Ball

Copy link
Copy Markdown

Verified the watchdog during a real NVIDIA pipeline compile at c0de6259 on CachyOS, RTX 3080 Ti, driver 620.73.04. I used two translated modules from my own copy, a mesh pipeline previously measured at 37.43 s and a small pixel pipeline. Two workers, cold pipeline cache, NVIDIA disk cache disabled, no simulated hang.

  • With --module-timeout 2, the checker exited 3 after 5.27 s, consistent with the five-second watchdog poll. It emitted one timeout and the in-flight file contained only the mesh module, marked pipeline. A 23,616-byte cache was saved before exit.
  • I passed that cache and a reason-tagged skip file back to the checker. It loaded the cache, printed the reason for the mesh module and compiled the pixel control successfully. It exited 1 after 0.16 s, counting only the timed-out module as failed.

This exercises the checker’s timeout and restart against a slow, previously successful driver compile. I invoked the checker directly for both runs. AI-assisted.

@editrice

Copy link
Copy Markdown

Tested exact head c0de62594916f1b397385898bf57bcc586f86475 on Windows 11 with MSVC 19.44 and NVIDIA RTX 5070 driver 621.01. vk_pipeline_check builds, and the real-checker timeout suite passes 5/5: the synthetic hung pipeline exits 3 after the threshold, emits one MODULE TIMEOUT, and leaves only the timed-out module and phase in the in-flight file; the no-timeout control compiles all five pipelines. Exact merge base 3faac557 fails three new cases because --module-timeout is unknown. The 17 pipeline-stage tests, 12 batching tests, and vk_pipeline_check_cli also pass. This validates the Windows watchdog/process-exit path; it does not reproduce the original Metal compiler hang. Synthetic inputs only; no game data. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head c0de6259 (6 files, +291/-16).

Commands:

  • CMake/Ninja configure runtime/ with vcvars64, -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON, Vulkan 1.4.363; cmake --build ... --target vk_pipeline_check -> built clean (no warnings in the changed file).
  • python -I -m pytest tests/test_vk_pipeline_check_timeout.py -q with LEONIDA_VK_PIPELINE_CHECK=<build>/vk_pipeline_check.exe, LEONIDA_VK_DEVICE='RTX 5070 Ti', Vulkan Bin on PATH -> 5 passed, 3 subtests passed (real checker + HANG hook; exit 3, single MODULE TIMEOUT, in-flight file holds only the hanger; plain and reasoned skip lines; bad values).
  • python -I -m pytest tests/test_make_game_pipelines.py tests/test_make_game_pipeline_batches.py -q -> 29 passed.
  • ctest -R vk_pipeline_check_cli -> 1/1 passed.
  • python -I -m pytest tests/test_vk_pipeline_check_index.py tests/test_vk_pipeline_check_isolate.py tests/test_docs_cli_flags.py tests/test_docs_links.py tests/test_docs_table_rows.py tests/test_docs_env_vars.py -q -> 22 passed, 6 skipped.
  • git diff --check -> clean.

Read the C++ path: --module-timeout parses/rejects (nan, negative, non-number), refuses --isolate, exit 3 is unused elsewhere, the timed-out snapshot is written under the same lock as write_inflight, cache saved before _Exit(3), and maybe_simulate_crash/HANG runs outside mu so the watchdog can observe it. make_game puts timed-out names straight in the skip file with a reason and never retries them alone.

Minor, non-blocking: the timeout continue consumes one of PIPELINE_CRASH_RETRIES (5). Six or more hung modules in one 500-module range exhaust the loop and report "still crashed after 5 retries" even though every timeout made progress; only message/coverage suffers (the stage fails on a skip either way).

Verdict: OK to merge.

@Hiiva Hiiva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Keep the timeout on diagnostic probes after a batch crash

At exact head c0de62594916f1b397385898bf57bcc586f86475, pipelines() adds --module-timeout to its batch command, but the crash-recovery call at make_game.py:1866 enters crashes_alone(), which builds a new command at line 1970 without that option.

A batch can die while a second module is in flight. If that suspect's single-module retry hangs, the new 1800-second limit no longer applies and the pipelines stage can still wait indefinitely.

I reproduced the missing limit through the unchanged production orchestration and the existing real-child fixture in tests/test_make_game_pipeline_batches.py:

  • The first batch writes one in-flight suspect and exits 70. Its recorded argv includes --module-timeout 1800.
  • The diagnostic child runs with --jobs 1 --start 0 --count 1 and no --module-timeout. A synthetic hang in that child reaches the independent two-second outer deadline after 2.086 seconds; no later modules are checked.
  • A test-only adapter that forwards the timeout to that same child finishes in 0.403 seconds, checks all six healthy modules and counts the hanging module as failed.

Please carry the feature-gated timeout into diagnostic checker invocations and cover the batch-crash followed by probe-hang path. The reproduction uses a synthetic child, not a naturally reproduced driver hang; the missing option is also directly visible in the unchanged source.

Windows verification already completed

On Windows x64, Python 3.14.6, MSVC 19.44.35228, Windows SDK 26100 and Vulkan SDK 1.4.363:

  • The unchanged checker builds. The 17 pipeline-stage tests, 12 batching tests, five real-checker timeout tests and three line-ending tests pass.
  • Loading upstream 3faac557's orchestration in memory, with only the two new test protocol constants supplied, gives 13 passes and exactly four failures in the new timeout cases.
  • Additional RTX 4080 / NVIDIA 610.62 cache control: a synthetic HANG exits 3 after 5.211 seconds, reports exactly one timeout, leaves only that module in the in-flight file and saves a 22,673-byte cache. Restart loads that cache and finishes with four successful pipelines and one counted failure in 0.214 seconds, without retrying the HANG module. Captured output has no VUID entries.
  • The PR source tree remains unchanged and git diff --check is clean.

All inputs are synthetic. These checks do not reproduce the original Metal compiler hang.

AI-assisted: yes.

@Kam471

Kam471 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Follow-up: Hiiva's P2 at c0de6259 is correct and revises my verdict above. pipelines() adds --module-timeout only to the batch argv; crashes_alone() (make_game.py:1970) builds its single-module probe without it. A batch that dies while another module is hung therefore re-enters an unbounded probe, and the original indefinite wait is still reachable. I reached the same conclusion independently while reading the crash-recovery branch, but did not weight it as a defect in my posted review; it should be.

Not mergeable as-is: carry the feature-gated timeout into diagnostic checker invocations (and treat exit 3 there as a skip, not a crash), with a test for batch-crash-then-probe-hang. My other note stands unchanged: each timeout continue consumes one of the 5 PIPELINE_CRASH_RETRIES, so six or more hung modules in one range end the loop with a misleading "still crashed" message.

@DoubleD17 DoubleD17 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.

--module-timeout can still hang inside the watchdog when a cache file is configured.

At c0de62594916f1b397385898bf57bcc586f86475, the timeout path calls save_cache(false) before _Exit(3). The periodic checkpoint does the same thing on the same watchdog thread. With a cache pathname, both enter vkGetPipelineCacheData on the cache used by the compile workers.

MoltenVK 1.4.2 uses the same _shaderCacheLock for shader library lookup and compilation and for cache serialization. A cache miss calls the library compiler before releasing the lock. If the compile stalls there, the timeout-path save can wait forever before exit. With the 1800-second limit set by make_game.py, the 10-minute checkpoint can also block the watchdog before it observes the timeout.

Could the deadline and exit stay on a thread that never enters the driver, with the last successful cache checkpoint retained if a new save cannot finish? The current HANG fixture sleeps before the Vulkan call and supplies no cache pathname, so it cannot cover this case. A Windows CPython 3.13.3 probe with a fake compiler holding a shared cache lock confirmed both blocking orders and the no-save control. I inspected the pinned sources and did not run the PR or reproduce the Metal hang on hardware.

No game files. AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested c0de625 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_make_game_pipelines.py -> Ran 17 tests, OK
  • python -I tests/test_vk_pipeline_check_timeout.py -> skipped (needs the built vk_pipeline_check binary; no compiler on this machine)
  • C++ part untested.

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested c0de6259 (base 3faac557, current main) on an Apple M4 (10-core GPU), macOS 27.2.1, Homebrew MoltenVK 1.4.2 (Vulkan 1.4.357), AppleClang 21.0.0, with vk_pipeline_check built from this head. Result: pass. The hang you saw on the M2 Max also happens on the M4, and the watchdog handles it there.

Unit tests, run against this build (LEONIDA_VK_PIPELINE_CHECK, Python 3.14), all OK:

  • test_vk_pipeline_check_timeout.py: 5
  • test_make_game_pipelines.py: 17
  • test_make_game_pipeline_batches.py: 12
  • test_vk_pipeline_check_isolate.py: 6
  • test_vk_pipeline_check_index.py: 7
  • test_docs_links.py: 6

ctest -R vk_pipeline_check (vk_pipeline_check_cli) passed.

Real Metal compiles. I used three large translated compute modules from my own copy, 12.7 to 13.5 MB each and none compiled on this Mac before, so Metal's shader cache was cold. Only counts and times are below:

run result
--module-timeout 4 exit 3 after 5.07 s, MODULE TIMEOUT <m1> (pipeline still in the driver after 5s); the in-flight file holds only that module and pipeline
--module-timeout 600 still compiling <m0> every 60 s, then MODULE TIMEOUT <m0> (pipeline still in the driver after 600s), exit 3 at 600.55 s; the in-flight file holds only <m0>
--module-timeout 180, with <m0> in --skip-file plus a TAB and a reason MODULE CRASH <m0> (cs, still in the driver after 600 s in an earlier run; not retried), then <m2> hit the 180 s timeout, exit 3 at 180.20 s

So on the M4, a single real module stays in Apple's compiler for over 10 minutes, and another for over 3. Without this flag, make_game.py's pipelines stage would wait on them with no message.

Two more observations:

  • The process uses about 2 s of CPU in each run, because the compile runs in MTLCompilerService.
  • After each _Exit, every MTLCompilerService process was back at 0.0% CPU. The abandoned compile doesn't keep running after the checker exits.

Nit, not blocking: a skipped timed-out module still prints with the MODULE CRASH prefix. That's what test_the_skip_file_reason_is_printed expects, and the reason text makes the cause clear. But anything that counts MODULE CRASH lines will count timeouts as crashes.

No game data is quoted; module names are replaced with placeholders.

AI-assisted.

…bes too (review)

Review on ItsNotRexed#5255:
- The deadline ran on the watchdog thread, which also writes the 10-minute cache checkpoint, and the timeout path
  saved the cache before exiting. MoltenVK holds the pipeline cache's lock while it compiles, so either save could
  wait as long as the hung compile (@DoubleD17). The deadline now has its own thread that never enters the driver;
  on a timeout it saves on a side thread and waits at most min(SEC, 60) s, otherwise exits keeping the last
  checkpoint (cache files are replaced whole). New test hook VK_PIPELINE_CHECK_SIMULATE_SAVE_HANG and a test that
  the exit doesn't wait for a held cache.
- make_game.py's single-module probe after a batch crash ran without the timeout, so a hung suspect could still
  stop the stage (@Hiiva, @Kam471). Probes now get --module-timeout, and a probe that times out marks the module
  as timed out (skipped with the reason), not as a crasher. crashes_alone() becomes alone(), which tells the two
  apart.
- Each timeout used one of the 5 crash retries, so six hangs in one range ended with "still crashed" (@Kam471).
  Only crashes count now; each timeout names a module not yet skipped, so the loop still ends.

AI-assisted. No game files.
@ashiikins

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews and tests. All three points are fixed in 9e800b46:

  • Probes after a batch crash (@Hiiva, @Kam471): the single-module probe now gets --module-timeout too, and a probe that exits 3 marks its module as timed out (skipped with the reason), not as a crasher. crashes_alone() became alone(), which tells the two apart. New test: a batch crashes with one suspect in flight, the probe hangs, the module is skipped as timed out and the stage goes on.
  • A save the driver blocks (@DoubleD17): the deadline now runs on its own thread, which never calls into the driver, so neither the 10-minute checkpoint nor a held cache lock can delay it. On a timeout it saves on a side thread and waits at most min(SEC, 60) s; if the driver still holds the cache it exits anyway and the last checkpoint stays (cache files are replaced whole). New hook VK_PIPELINE_CHECK_SIMULATE_SAVE_HANG=1 and a test that the run still exits 3 with the old cache file untouched; that test fails on c0de6259.
  • Timeouts used up crash retries (@Kam471): only crashes count against PIPELINE_CRASH_RETRIES now. Each timeout names a module not yet skipped, so the loop still ends. New test with PIPELINE_CRASH_RETRIES + 4 hangs in one range.

Re-run on the M2 Max (Homebrew MoltenVK 1.4.2): test_vk_pipeline_check_timeout.py 6/6, test_make_game_pipelines.py + test_make_game_pipeline_batches.py 31/31, _isolate and _index pass, docs updated. @sovljanskii, thanks for the M4 run; good to know the hang isn't M2-specific.

AI-assisted.

@thehollowedone

Copy link
Copy Markdown

Native Windows check of 9e800b46 on 3faac557. Windows 11, RTX 3080 Ti / 621.35, MSVC 19.44.35230, Vulkan SDK 1.4.363.0.

Four stock checker tests and seven make_game tests passed, including timeout propagation to an individual probe and retry accounting. The healthy run compiled all five synthetic modules. With both delay hooks enabled and a valid driver-generated checkpoint as the seed, the checker exited 3, recorded only the timed-out module, and left the checkpoint byte-identical. Vulkan validation reported zero errors.

Synthetic inputs and delay hooks only. AI-assisted.

@Hiiva Hiiva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Keep the timeout-selected report fixed until exit

Remaining issue at exact head 9e800b460f4fe5307e44649740cf833166a6274c: the selected timeout snapshot can still be overwritten by a newer worker before exit.

The deadline writes only timed_out while holding mu, then unlocks at runtime/test/vk_pipeline_check.cpp:1773. It never freezes the normal snapshot writers. A concurrently admitted large worker publishes its name at lines 1471-1472 and calls the unchanged write_inflight, which writes every current entry. The final exit uses whatever report remains on disk. make_game.py:1861-1867 treats every name in that report as timed out and skips it without probing.

I reproduced this with explicitly test-only scheduling barriers in an ignored copy of the actual checker, not with a duplicated snapshot model or a naturally hung driver:

  • The unmodified checker compiled both original synthetic modules successfully: 2 modules, 2 pipelines, zero failures.
  • Both schedules use --jobs 2 --large-module-bytes 1 --large-parallel 2 --module-timeout 2, the existing a_old:HANG hook, and the existing cache-save-hang hook. The tiny threshold exercises the production large-worker publication path.
  • With the second worker held before publication, exit is 3 and the final report contains only a_old.
  • Releasing that worker immediately before the deadline's existing final flush/exit lets its actual publication overwrite the report. Exit remains 3 and stdout names only MODULE TIMEOUT a_old, but the final report contains a_old and b_new.
  • Under mu immediately before exit, a_old was 4.021812 seconds old and b_new only 0.002015 seconds old, against the 2-second timeout. Thus the added name had not reached the deadline. Both runs preserved the prior cache and finished in about 4.2 seconds.

The barriers only control scheduling and observe ages. They do not edit the in-flight map, snapshot contents, timeout selection, or writer implementation. This proves a permitted worker-publication ordering; it does not measure natural race frequency or reproduce a real driver hang. The watchdog is another source writer, but this measured case uses the worker path.

The final timeout report needs to remain fixed after selection, for example by stopping normal snapshot publication once the deadline takes ownership of it. Otherwise the Python retry loop can skip a healthy new module based on the overwritten report.

Original diagnostic-probe finding is fixed

The previous missing-timeout issue is resolved at this head. I reran the same batch-crash followed by a hanging diagnostic child through unchanged production orchestration. The old c0de6259 source reaches the independent 3-second limit after 3.085 seconds; 9e800b46 finishes in 0.455 seconds, checks all six healthy modules, and records the one hanging module with the timeout reason. The scripted child's only protocol update was recognizing the existing name<TAB>reason skip format.

The current MSVC checker builds, all 31 pipeline-stage/batching tests pass, and all six real-checker timeout methods pass on RTX 4080, including the blocked-cache-save test. These ordinary controls do not arrange a new worker publication after the deadline's selected-only report.

Exact test-only scheduling patch used for the remaining finding

Apply this to an ignored copy of the checker at the exact head. It controls thread scheduling without changing the production map or writer. Compile two identical synthetic empty compute modules named a_old.spv and b_new.spv, with CS entries in index.json, and first confirm that the unmodified checker creates both pipelines. Reuse the resulting valid cache as a seed.

Run the instrumented checker twice with LEONIDA_REVIEW_SNAPSHOT_SCHEDULE=held and late, respectively; both runs also set VK_PIPELINE_CHECK_SIMULATE_CRASH=a_old:HANG and VK_PIPELINE_CHECK_SIMULATE_SAVE_HANG=1, with the flags listed above. The same instrumented executable is used for both schedules. Read the actual in-flight file after exit and compare it with the REVIEW_FINAL ages and the single MODULE TIMEOUT line. Each run has an independent 15-second process deadline.

--- a/runtime/test/vk_pipeline_check.cpp
+++ b/ignored/snapshot_probe.cpp
@@ -1412,6 +1412,11 @@
         }
     };
 
+    // REVIEW-ONLY instrumentation: gates scheduling, never edits the in-flight map or snapshot contents.
+    const char* review_env = std::getenv("LEONIDA_REVIEW_SNAPSHOT_SCHEDULE");
+    const std::string review_mode = review_env ? review_env : "";
+    const bool review_enabled = review_mode == "held" || review_mode == "late";
+    std::atomic<bool> review_release_second{false}, review_second_published{false};
     auto worker = [&] {
         for (size_t k; (k = next++) < work.size();) {
             const std::string& name = *work[k].first;
@@ -1466,12 +1471,30 @@
                 large_ticket = leonida::LargeModuleGate::Ticket(large_gate,
                                                                 leonida::large_module_estimate(file_size));
             }
+            // REVIEW-ONLY: park the second worker immediately before its normal publication.
+            if (review_enabled && name == "b_new") {
+                std::fprintf(stderr, "REVIEW b_new waiting before production in-flight publication\n");
+                const auto limit = std::chrono::steady_clock::now() + std::chrono::seconds(12);
+                while (!review_release_second) {
+                    if (std::chrono::steady_clock::now() >= limit) std::_Exit(91);
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                }
+            }
             {   // in flight from here: vkCreateShaderModule can also take long or die in the driver
                 std::lock_guard<std::mutex> g(mu);
                 inflight[std::this_thread::get_id()] = {name, std::chrono::steady_clock::now(), "module"};
                 if (isolated) write_inflight();   // a large module: name it now (alone with --large-parallel 1)
             }
 
+            // REVIEW-ONLY: acknowledge only after the production write_inflight has returned.
+            if (review_enabled && name == "b_new") {
+                std::fprintf(stderr, "REVIEW b_new production in-flight publication completed\n");
+                review_second_published = true;
+                const auto limit = std::chrono::steady_clock::now() + std::chrono::seconds(12);
+                while (std::chrono::steady_clock::now() < limit)
+                    std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                std::_Exit(92);
+            }
             const auto code = leonida::read_spirv_words(f, file_size);
             VkShaderModule sm = VK_NULL_HANDLE;
             bool mod_ok = false;
@@ -1782,6 +1805,24 @@
             if (!*saved)
                 std::fprintf(stderr, "the pipeline cache checkpoint did not finish within %.0fs (the driver still "
                                      "holds the cache); the last saved checkpoint is kept\n", wait.count());
+            // REVIEW-ONLY: force a permitted worker publication between the deadline's final wait and exit.
+            // The held control leaves the second worker parked at the same pre-publication gate.
+            if (review_enabled) {
+                if (review_mode == "late") {
+                    review_release_second = true;
+                    const auto limit = std::chrono::steady_clock::now() + std::chrono::seconds(2);
+                    while (!review_second_published) {
+                        if (std::chrono::steady_clock::now() >= limit) std::_Exit(93);
+                        std::this_thread::sleep_for(std::chrono::milliseconds(1));
+                    }
+                }
+                std::lock_guard<std::mutex> review_lock(mu);
+                const auto review_now = std::chrono::steady_clock::now();
+                for (const auto& [tid, job] : inflight)
+                    std::fprintf(stderr, "REVIEW_FINAL name=%s age=%.6f timeout=%.6f phase=%s\n",
+                        job.name.c_str(), std::chrono::duration<double>(review_now-job.since).count(),
+                        module_timeout, job.phase);
+            }
             std::fflush(nullptr);
             std::_Exit(3);
         }

Windows 11 x64 build 26200, MSVC 19.44.35228, Windows SDK 26100, Vulkan SDK 1.4.363.0, RTX 4080 / driver 610.62. The GPU use is synthetic pipeline creation, not a naturally reproduced driver hang. No game files or tracked production edits. AI-assisted: yes.

@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 9e800b46 (merge base 3faac557) on Windows 11 10.0.26300 with an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56. Result: pass.

  • Runtime built from this head: MSVC 19.44 (BuildTools 2022), Ninja, RelWithDebInfo, -DLEONIDA_VULKAN_HEADERS_FETCH=ON (no Vulkan SDK; the loader comes from the NVIDIA driver). glslangValidator and llvm-mc 21 came from WSL Ubuntu. Build exit 0.
  • ctest -j 3: 177/177 passed.
  • scripts/run_gpu_tests.py --build <this build>: 170/217 passed, 47 skipped, 0 failed.
  • vk_pipeline_check builds. I didn't run the pipelines stage, so --module-timeout wasn't exercised: it needs a folder of translated game shaders.
  • Every other test gives the same result as on main 3faac557 (ctest 177/177, GPU 170/217).
  • As on main, run_gpu_tests.py records cs_fmt_d16_xyz twice and skips cs_tbuffer_store. That's main's runner bug (fixed by run_gpu_tests: record cs_tbuffer_store's result; fail a run that records a test twice #4784), not this PR.

Not run: other GPUs/vendors, Linux, the Vulkan validation layer (not installed). No game files.

AI-assisted (Claude Code).

…exit (review)

Review on ItsNotRexed#5255 (@Hiiva): after the deadline wrote its report of the timed-out modules, a worker that started a
module, or the watchdog, could still write a full in-flight snapshot before the exit, so the file could name a
module that had only just started. make_game.py skips every module in that report without a probe. The deadline
now marks the report final (with mu held) before it writes it, and write_inflight does nothing after that.

Checked with the reviewer's scheduling-only instrumentation on an Apple M2 Max: with the second worker published
between the deadline's report and the exit, the old head leaves both modules in the report (the new one 0.001 s
old against a 2 s timeout); with this change only the timed-out module stays.

AI-assisted. No game files.
Conflicts: make_game.py's single-module probe now takes main's rule (a crash counts only when the probe's fresh
report names the module) beside the timeout result; the vk_pipeline_check header and --skip-file reasons keep
main's Windows --isolate and output-path checks; docs/testing.md keeps both new rows.
@ashiikins

Copy link
Copy Markdown
Contributor Author

@Hiiva thanks, confirmed and fixed in e726b753. The deadline now marks its report final (with mu held) before writing it, and write_inflight does nothing after that, so neither a worker nor the watchdog can replace it before the exit.

I ran your scheduling-only patch unchanged on an Apple M2 Max (MoltenVK 1.4.2), same flags and hooks:

head schedule exit report after exit
9e800b46 held 3 a_old
9e800b46 late 3 a_old, b_new (b_new 0.001 s old, timeout 2 s)
e726b753 held 3 a_old
e726b753 late 3 a_old

The branch also conflicted with main, so d041a62c merges it (no force-push). The one change in behaviour: alone() keeps main's rule that a crash counts only when the probe's fresh report names the module, and still returns "timeout" for exit 3. On the Mac, the 6 real-checker timeout tests, the 19 test_make_game_pipelines tests and the 15 test_make_game_pipeline_batches tests pass, and so do main's test_vk_pipeline_check_index and _isolate.

AI-assisted. No game files.

@Kam471

Kam471 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Head 9e800b460 (on c0de62594).

Earlier blocker: resolved. alone(..., timeout) passes --module-timeout to the single-module probe. Synthetic real-child run (batch exits 70 with c_mod in flight): the one --jobs 1 --count 1 probe ends --module-timeout 1800, the stage ends in 0.72 s, skip line c_mod<TAB>did not finish within 1800 s in an earlier run, one timeout log, no crash retry and no extra probe. With the flag unsupported, timeout is None: no invocation carries it, exit 3 is not special-cased, and the old crasher path is unchanged. Real checker, one HANG module alone: exit 3 in 3.3 s (bounded); with SIMULATE_SAVE_HANG=1: exit 3 at 6.2 s (3 s deadline + min(60,3) wait), previous cache byte-identical, "last saved checkpoint is kept". The separate deadline thread fixes the old watchdog blocking inside vkGetPipelineCacheData.
Counts (Windows, RTX 5070 Ti): test_vk_pipeline_check_timeout.py 6 passed + 3 subtests (was 5); test_make_game_pipelines.py+_pipeline_batches.py 31 passed + 2 subtests (was 29); all test_make_game_* 227 passed, 1 skipped; ctest vk_pipeline_check_cli 1/1; docs 11 passed; git diff --check clean.

New P2 in the same held-cache path: the deadline thread writes only the timed-out modules, then unlocks and waits min(60, SEC) for the saver, but the watchdog keeps calling write_inflight() every 5 s during that wait and overwrites the file with every in-flight module. Repro (real checker, 150k tiny modules, --jobs 2 --module-timeout 6, HANG m000000, SAVE_HANG=1): exit 3 at 18.0 s and --inflight-file = m000000 and m027448, a module that had been compiling ~0.1 s and was far from its deadline. make_game would skip both as "did not finish within 1800 s" and count both failed. The new test uses timeout 2 and five modules, so the 5 s tick never lands in the wait.
Suggest an atomic "timing out" flag that suppresses write_inflight() (including the large-module entry/exit writes) once the timed-out snapshot is published, with a timeout >5 s test that keeps a second worker in flight.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested d041a62 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: concern
Real compute modules that the AMD compiler does not finish (hang) or finishes slowly; vk_pipeline_check built from this head, 3 runs at a time, each module alone (--jobs 1 --start I --count 1 --module-timeout 60 --inflight-file F). The checker part works as described. One problem in make_game.py on Windows.

What works:

  • 6 modules from a set of 750 that did not answer in 180 s alone (0.98 MB to 45 MB, spread over sizes): 6 of 6 end with exit 3 after 61.6 s to 64.8 s, one MODULE TIMEOUT line each, and the in-flight file holds one line (that module).
  • 6 modules that did answer earlier (64 KB to 1.8 MB, 1.7 s to 154 s before): 4 pass with exit 0 (3.3 s, 34 s, 41 s, 59 s). 2 end with exit 3 at 60 s because they need more than 60 s on this GPU (earlier alone: 59.6 s and 154 s). Both pass with --module-timeout 400 (60 s and 132 s, exit 0, no timeout line). That is the limit working, not a defect. It does show that on RDNA4 a compile of 60 s or more is not always a hang, so 1800 s is the safer default.
  • Range of 7 index entries (6 normal compute and pixel modules, 1 hang module), --module-timeout 60: with --jobs 3 and with --jobs 1 the run ends with exit 3 after 61.1 s, one timeout line, in-flight file = the hang module only. It prints no result for the other modules, since the summary comes only after a full pass. Run again with a --skip-file line name<TAB>reason: exit 1 after 1.0 s, the reason is printed in the MODULE CRASH line, the other 6 are counted ok (4 cs + 2 ps skipped for a missing stub in my copy), 1 failed. The summary line for that module says "not retried after killing the driver", which is wrong for a timeout.
  • make_game.pipelines() on a 7-module work folder with PIPELINE_MODULE_TIMEOUT = 60: the batch ends with exit 3 at 61 s, the module goes into the skip file as name<TAB>did not finish within 60 s in an earlier run, the second run ends with the module counted failed, and the stage stops with "1 module(s) took the driver down or never finished". Total 61.4 s.
  • Bad values (-1, abc, nan) and --isolate together with the option are refused with the documented messages.
  • tests/test_vk_pipeline_check_timeout.py 6 OK, test_make_game_pipelines.py 19 OK, test_make_game_pipeline_batches.py 15 OK, against this build.

Problem: exit status 3 is also what the Windows C runtime gives abort(), std::terminate and an unhandled raise(SIGABRT). PIPELINE_TIMEOUT_EXIT = 3 (make_game.py, next to PIPELINE_MODULE_TIMEOUT) and the code == PIPELINE_TIMEOUT_EXIT branch in check_range therefore also take such a crash for a timeout.

  • Checker alone with VK_PIPELINE_CHECK_SIMULATE_CRASH=<module>:ABRT on this build: exit 3 (the merge-base-era build and the vk_pipeline_check: link with an 8 MB stack; a driver's compiler overflows the 1 MB default (BUILD-1457) #4979 build do the same). At 9e800b4 SEGV and FPE also gave 3; at d041a62 they give 0xC0000005 and 0xC000008E.
  • make_game.pipelines() on the same 7-module folder, the ABRT hook on one module and the hang module in the batch: after 1.6 s three in-flight modules, including the hang module that had been in the driver for about 1 s, are written to the skip file as "did not finish within 60 s in an earlier run", none is probed alone, and the stage stops with "vk_pipeline_check gave up on a compile but named no module; report it". A module that crashes the checker by abort is labelled a hang, and innocent in-flight modules are skipped without a probe.
  • Same folder, ABRT hook only, no hang module: vk_pipeline_check: link with an 8 MB stack; a driver's compiler overflows the 1 MB default (BUILD-1457) #4979's build (no --module-timeout) retries the range in smaller batches (3 attempts, 4.1 s) before it stops; this head stops at once with the "named no module" message (0.9 s). On main the smaller-batch retry is how a memory crash that comes from batch size recovers; an exit 3 from std::terminate on bad_alloc would no longer reach it. I did not reproduce a bad_alloc run.
  • Suggested change: use an exit status the CRT does not use (not 3, for example 75), or have the checker write a marker (a line in the in-flight file or a file) that make_game.py checks before it treats exit 3 as a timeout.

Not done: the pipelines stage on the full corpus; macOS/MoltenVK; the cache-save hang hook and a run with a cache file argument.

AI-assisted (Claude Code).

@cynbun

cynbun commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested d041a62c on RTX 5080, NVIDIA 615.78.08, Linux: pass

vk_pipeline_check built from this head (Ninja, RelWithDebInfo, -DLEONIDA_VULKAN_HEADERS_FETCH=ON). Device line: NVIDIA GeForce RTX 5080 (subgroup 32..32).

  • LEONIDA_VK_PIPELINE_CHECK=<build>/vk_pipeline_check python -I tests/test_vk_pipeline_check_timeout.py: 6 tests OK. The same file against main 561b65a8's checker: 5 of 6 fail.

  • tests/test_make_game_pipelines.py: 19 tests OK. With main's make_game.py it gives 2 failures and 4 errors. test_make_game_pipeline_batches.py (15), test_vk_pipeline_check_isolate.py (10), test_vk_pipeline_check_index.py (11) and test_docs_links.py (6) also pass.

  • I re-ran @Kam471's held-cache case against the real checker. I used 150,000 tiny compute modules, each with a different constant so the driver can't answer from its cache, and __GL_SHADER_DISK_CACHE=0. Flags: --jobs 2 --module-timeout 6 --inflight-file F, a seeded cache file, VK_PIPELINE_CHECK_SIMULATE_CRASH=m000000:HANG and VK_PIPELINE_CHECK_SIMULATE_SAVE_HANG=1.

    checker exit in-flight file cache file
    9e800b46 3 after 12 s m003373 pipeline, m000000 pipeline unchanged
    d041a62c (two runs) 3 after 12 s m000000 pipeline unchanged

    So e726b753's report_final fixes that P2 on this driver: the second worker was still compiling during the save wait, and no snapshot replaced the timeout report. If every module is identical, every pipeline after the first is a driver cache hit and the whole set finishes in 2 s. The second worker then isn't in flight during the wait, so a repro needs distinct modules.

  • On @Jadiac5's exit-3 point: on Linux, VK_PIPELINE_CHECK_SIMULATE_CRASH=<module>:ABRT ends the checker with SIGABRT (shell status 134), not 3. The collision with an abort is specific to the Windows CRT.

Not run: a real driver hang, the whole pipelines stage on translated shaders, Wine. Synthetic modules only, no game data.

AI-assisted (Claude Code).

@Hiiva Hiiva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Follow-up at exact head d041a62c342816abea1c62ce952312a24430844f, based on 561b65a8: both findings from my earlier review are resolved in this scope.

Selected timeout report

The new report_final flag is set while holding mu, before the selected report is written. Every normal write_inflight() caller also holds mu, and that writer returns once the flag is set.

I reused the original scheduling-only instrumentation and identical synthetic modules on Windows/MSVC with RTX 4080. The instrumentation's added C++ lines are unchanged; the runner changes only the target head and the expected fixed report. The late worker still reaches its actual production publication before the deadline exits.

Head Schedule Exit Final report
9e800b46, retained earlier evidence held 3 a_old
9e800b46, retained earlier evidence late 3 a_old, b_new
d041a62c, this run held 3 a_old
d041a62c, this run late 3 a_old

In the new late run, b_new was 0.001506 seconds old immediately before exit, against a 2-second timeout. It completed the normal publication call but did not enter the final report. Both timeout runs preserved the seeded 5,694-byte cache. The unmodified checker also compiled both original modules successfully.

Diagnostic-child timeout

The original real-child control still passes through unchanged production orchestration after the main merge. Against c0de6259, the diagnostic child omits --module-timeout and reaches the independent 3-second limit. Against d041a62c, it receives the option, the stage checks all six healthy modules, and m_00 is skipped with its timeout reason. The stage returns the expected failure status for that skipped module.

Checks at this head

  • 19 pipeline-stage tests and 15 batching/recovery tests pass.
  • All 6 real-checker timeout methods pass, including the blocked cache-save case.
  • The unchanged checker and instrumented copy build with MSVC 19.44.35228, Windows SDK 26100 and Vulkan SDK 1.4.363.0.
  • The three recorded snapshot-control runs select RTX 4080, driver 610.62. Validation error/warning reporting was enabled; their captured output contains no VUID or synchronization-hazard diagnostics.

This is synthetic pipeline creation with explicit scheduling gates and the existing hang hooks. It does not reproduce a natural driver hang or assess the separately reported Windows abort/exit-code concern. Tracked source is clean. No game files. AI-assisted.

…iew)

Review on ItsNotRexed#5255 (@Jadiac5, RX 9070 XT): on Windows abort(), std::terminate and an unhandled SIGABRT end the
process with status 3, the code --module-timeout used. make_game.py took such a crash for a timeout: the
modules in flight went into the skip file as timed out without a probe, and the smaller-batch retry was never
reached. vk_pipeline_check now exits 75 after a timeout (EX_TEMPFAIL; nothing else in the checker or the C runtime
uses it), and PIPELINE_TIMEOUT_EXIT follows. The --skip-file summary line no longer says every skipped module
killed the driver. New test: a batch and probe that exit 3 go through the crash path.

AI-assisted. No game files.
@ashiikins

Copy link
Copy Markdown
Contributor Author

@Jadiac5 thanks, that's a real problem: fixed in 62009b69. vk_pipeline_check now exits 75 after --module-timeout (nothing else in the checker or the C runtime uses it), and PIPELINE_TIMEOUT_EXIT follows. A Windows abort() / std::terminate exit 3 now takes the crash path again: a probe of each suspect, a plain skip line, and the smaller-batch retry. New mock test: a batch and a probe that both exit 3 lead to one probe and a crash skip line, with no "still compiling" log. I also changed the --skip-file summary line, which said every skipped module had killed the driver.

Your RDNA4 numbers (two healthy modules at 60 s and 154 s) support keeping the 1800 s default.

@Hiiva thanks for the re-check on d041a62c.

The macos CI failure at d041a62c comes from two GPU tests from main that this PR doesn't touch: cs_w32_permlane_fi (#5895) and cs_fmt_int_narrow. The runtime tests passed in that job.

Mac check of 62009b69 (M2 Max, MoltenVK 1.4.2): 6 real-checker timeout tests (exit 75), 20 test_make_game_pipelines, 15 _batches, and test_vk_pipeline_check_isolate/_index pass.

AI-assisted. No game files.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.