rdna2spirv: start a tool again when a Windows job refuses it with ERROR_NOT_ENOUGH_QUOTA (COMPUTE-WORKER-SPAWN-QUOTA) #2367
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2367"
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 ubiquitarianism/leonida. Originally posted by budanga on 2026-11-26T16:05:26Z.
Claimed in the coordination issue as: COMPUTE-WORKER-SPAWN-QUOTA (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7196128221)
What and why
scripts/translate_pipeline_compute.py --jobs Non native Windows fails now and then withand
tests/test_translate_pipeline_compute.py(WorkerParity) fails the same way.Cause: each Windows worker runs in a job that allows two active processes, itself and one tool (
TWO_ACTIVEinscripts/compute_workers_win.py). The worker runs spirv-as, then spirv-opt or spirv-val, one after another through_run_spirv_toolintools/rdna2spirv.py.subprocess.runreturns once the previous tool has exited, but the job can still count that process for a moment, soCreateProcessrefuses the next tool with ERROR_NOT_ENOUGH_QUOTA (1816).Measured with a minimal script that makes the job with
compute_workers_win.job(mib, True), puts a Python child in it and has the child start a short tool back to back (Windows 11 26300, Python 3.14.10, the machine busy with other work):spirv-val --version, in the jobcmd /c rem, in the jobspirv-val --version, no jobChange:
_run_spirv_toolstarts a tool again whenCreateProcessrefuses it with winerror 1816, with a doubling delay from 5 ms up to 100 ms, for at mostSPAWN_RETRY_SECONDS(10 s); then the error is raised as before, with a note saying how many times the tool was refused and for how long. The refused tool never started, so starting it again repeats nothing. It is the backofftools/replace_retry.pyuses for renames.New test,
tests/test_rdna2spirv_spawn_quota.py(standard library):cmd /c remthrough_run_spirv_toolinside a job made bycompute_workers_win.job(), as the worker does.On
mainthe new file fails (2 failures, 1 error, including the job test with WinError 1816); with the change it passes.Tested
On
fbf100b1b, Windows 11 Home 26300.9974, Python 3.14.10, SPIRV-Tools v2026.4 (Vulkan SDK 1.4.363.0), with the machine busy translating shaders in the background, as in the table:python -I tests/test_translate_pipeline_compute.py, 12 runs each:main3 passed, 9 failed (all WinError 1816); this branch 12 passed.python -I tests/test_rdna2spirv_spawn_quota.py: fails onmain; passes 7 of 7 runs here.python -m compileall -q make_game.py tools tests: clean.rdna2spirv: all pass. (test_make_game_argparse.pyfailed once under the load and passed 3 of 3 reruns, onmainas well.)python -I scripts/run_semantic_tests.py tests/semantic: 500 files, 6365 tests, 0 files failed.python -I scripts/check_no_game_data.pyon both files: passes.GPUs tested: n/a (no GPU involved)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator rule; this changes how the tools are started)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T18:02:06Z.
Review: COMMENTED
Windows 11: all 5 quota tests passed, including the native restricted worker's back-to-back tools, bounded retries and unrelated OSError handling. No findings from these checks.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:03:26Z.
Review: COMMENTED
macOS arm64 check of #2367 (COMPUTE-WORKER-SPAWN-QUOTA). The behaviour is Windows-only, so what runs here is the retry control flow and the rest of the tree; I say below what this machine cannot prove.
Tested head
80930f0d1merged ontomainbd6ba97abas merge9661baf6b(clean merge).mainhas moved two commits since (bdbc7e923, the precompile skip-list work); neither touchestools/rdna2spirv.pyortests/.Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, Apple clang 21.0.0, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0.
The new test bites
python -I tests/test_rdna2spirv_spawn_quota.py->Ran 5 tests ... OK (skipped=1). The skip is the nt-only job-object test.tools/rdna2spirv.pyput back tomain's version):FAILED (failures=1, errors=1, skipped=1)- ERRORtest_quota_refusals_are_started_again(noSPAWN_RETRY_SECONDS), FAILtest_a_refusal_that_lasts_is_raised_once_the_time_is_up. So the two behaviour tests are not vacuous.OSErrorhas no.winerror, so the fake inwin_error()is the only 1816 the code ever sees here, and the 150-spawn job test is skipped. I did not run it.No regressions
mainbd6ba97ab, and the same at9661baf6b. Delta 0. (The new file lives intests/, nottests/semantic/, so the suite does not count it; it was run on its own above.)mainand the merge; KosmicKrisp 190 / 5 / 73 at both. A line diff of the PASS/FAIL/SKIP output differs only in the per-run temp directory quoted in SKIP reasons. The failures are the pre-existing ones atmain(MV:cs_fma_fused,cs_imgatomic_ext,ps_ssharp; KK:cs_bvh,cs_bvh32,cs_imgatomic_ext,ps_cndmask_sign_mods,ps_valu16_mad_sel).Static
_run_spirv_toolis the onlysubprocess.runintools/rdna2spirv.py(line 19949 at the head), andspirv-as,spirv-optandspirv-valall go through it, so the shard path is covered. Nothing else inscripts/translate_pipeline_compute.pystarts a process; the worker imports the translator.info.basic.processes = (2 if worker else 0)inscripts/compute_workers_win.py(job()/verify()), and only CreateProcess can produce 1816 here. A refusedCreateProcessleaves no child behind, so re-running does not repeat work, andFileNotFoundErroris still caught before the genericOSError.check_no_game_data.pyon both changed files: clean.compileall: clean.Findings (none blocks)
tools/rdna2spirv.py:19941-19958: when the budget runs out the originalOSErroris re-raised unchanged, so the traceback is the same[WinError 1816]a first refusal gives. Nothing says ~28 starts were attempted over 2 s; on a loaded host the user has no clue the retry ran out rather than never existing. Anexc.add_note(...)(3.11+) with the attempt count and elapsed time would cost nothing.SPAWN_RETRY_SECONDS = 2.0is a guess at how long the job counts a tool that has exited. The PR measures refusal rates (5-9%), not the longest refusal streak, and the Windows test shows 150 back-to-back starts passing on one host. If a slower machine holds the slot longer than 2 s, the same failure returns with no way to raise the budget. Measuring the lag (loop until 1,000 starts pass and record the longest run of refusals) or taking the seconds from the environment would make the number defensible.tools/(tools/replace_retry.pyhas one with 5 s); keeping them separate is fine, but a line saying why it is not shared would help the next reader.The cause in the description matches the code: the job counts the worker plus one tool, the exited tool can be counted for a moment, and 1816 is CreateProcess refusing before the child exists.
No game files. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by budanga on 2026-11-26T20:41:41Z.
Thanks for the careful check. All three points are taken in the new commit:
The retry running out is now visible. When the time is up, the
OSErrorgets a note:spirv-as: refused N times in T s (SPAWN_RETRY_SECONDS = 10.0). The unit test checks the note, and that other errors get none.The budget is now measured, and 2 s was not enough. I measured the longest run of refusals: a child in the worker's job (
compute_workers_win.job(4096, True),BELOW_NORMAL) starts a short tool until 1,000 starts succeed, retrying each refused start at once, and records the longest streak (Windows 11 26300, Ryzen 5 9600X, 6 cores / 12 threads):cmd /c remspirv-val --versionBELOW_NORMALcmd /c remBELOW_NORMALspirv-val --versionWith every thread busy at the workers' priority, streaks went past 2 s, so
SPAWN_RETRY_SECONDSis now 10 s (about 2.7x the longest seen), with a comment giving the measurement. Under the same load, 3 x 1,000 starts through_run_spirv_toolitself: 0 failed; the slowest single call took 6.1 s. I kept it a constant rather than an environment variable, since the measured headroom seemed enough; happy to add one if you prefer.The comment now says why it does not share
tools/replace_retry.py: that one retries a rename, this one a process start.Re-tested on the new head:
tests/test_rdna2spirv_spawn_quota.py3 of 3;tests/test_translate_pipeline_compute.py6 of 6;compileallclean; the 63 standard-library test files that userdna2spirvpass; the 14 pytest files that use it, 1,244 passed / 11 skipped / 2 failed, the same asmain(the 2 arecs_dpp_cmp.asm, which thisllvm-mcrefuses onmain, #1444); semantic suite 500 files, 6,365 tests, 0 failed;check_no_game_data.pyclean on both files.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T20:50:21Z.
Review: COMMENTED
Retested the updated retry budget and error note on Windows 11 with CPython 3.12.1, merged with
fac8b4bb9. All five quota tests passed. For an additional check, I occupied the second slot in a real two-process Windows job for the whole retry window._run_spirv_toolraised WinError 1816 with the notecmd: refused 103 times in 10.0 s (SPAWN_RETRY_SECONDS = 10.0). After releasing the second slot, the next command completed successfully in the same worker.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T07:21:07Z.
Thanks for this! Retrying spirv-as/spirv-val when the Windows worker job refuses a start with ERROR_NOT_ENOUGH_QUOTA addresses a real flaky failure.
During maintainer testing (local, 2026-11-28) (head
1860dc591, merged on mainb1619e0a3/6dfca6428, Windows 11, Python tests via pytest/unittest) we found:tests/test_rdna2spirv_spawn_quota.py::TwoProcessJobTests::test_back_to_back_tools_in_the_worker_jobfails on our Windows 11 host with this PR alone on main (traceback in_run_spirv_tool(['cmd','/c','rem'])).To get this merged:
AI-assisted (Claude Code), posted for DadaCap (maintainer).
Imported from ubiquitarianism/leonida. Originally posted by budanga on 2026-11-28T13:45:03Z.
Thanks for testing it. I could reproduce the failure: it happens when the test runs from a virtual environment.
Cause. On Windows a venv's
python.exeis a launcher that starts the base interpreter as a second process. The test started its child withsys.executable, so inside the worker's job (two active processes allowed) the launcher and the real interpreter took both slots, and every tool start was refused; the note from the retry says so:cmd: refused 102 times in 10.0 s (SPAWN_RETRY_SECONDS = 10.0). AGENTS.md runs the pytest files from a venv, which fits your setup.Fix (new commit, test only,
tools/rdna2spirv.pyunchanged):sys._base_executable(the same assys.executableoutside a venv), so it is the job's one process, as the worker is.JOBOBJECT_BASIC_PROCESS_ID_LISTviacompute_workers_win.query_job). If the interpreter that starts the tools is not the job's only process, the test is skipped with that reason instead of failing. A check from inside the child is not enough: the venv launcher puts the real interpreter in a job of its own, nested in the worker's, where it sees one process.Checked on Windows 11 26300, Python 3.14.10, at the branch merged with
main259be59b9(merges cleanly):python -I tests/...python -I tests/...python -m pytest tests/test_rdna2spirv_spawn_quota.pyfrom a venv... is not the worker job's only process ([4344, 21508], runner 4344): a launcher in between leaves the tools no slotmain'stools/rdna2spirv.pywith the new testRelated, but not this pull request: on
main, without this change,tests/test_translate_pipeline_compute.pyalso fails from a venv (RuntimeError: Windows compute job limits not in force), becausescripts/compute_workers_win.pystarts the worker withsys.executabletoo. I'll post it as a finding in the coordination issue.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by budanga on 2026-11-28T14:04:59Z.
Note on the six red CI checks of this run: none of them comes from this pull request, which only touches
tools/rdna2spirv.pyandtests/test_rdna2spirv_spawn_quota.py(neither appears among the failures).check,stdlib-tests-linux,macos-python:tests/test_build_runtime_fallback.py(test_the_loader_gets_the_stack_reserve_cmake_gives_it).semantic-tests:tests/semantic/test_valu_cvt_f16_int16_mods.py(test_f16_to_int16_output_modifiers_still_rejected,v_cvt_u16_f16andv_cvt_i16_f16).Both fail the same way on plain
main9c49bd533without this change (run locally, Windows 11, Python 3.14).macosandlinux-gpu-toolsare GPU fixture runs on MoltenVK and llvmpipe, which this change does not touch. Thewindowsjob, the only one that runs the job-object test, passed.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T14:33:34Z.
Review: APPROVED
Re-reviewed
913b9aa4dand verified the Windows virtual-environment fix on Windows 11.Code audit (
913b9aa4d):tests/test_rdna2spirv_spawn_quota.py: launching the job child viagetattr(sys, "_base_executable", None) or sys.executablecleanly avoids placing both the Windows venv launcher and base interpreter inside the two-process worker job, and checkingJOBOBJECT_BASIC_PROCESS_ID_LISTfrom the parent skips with a clear diagnostic if an intermediate launcher is still present.Verification (Windows 11, CPython 3.12.1):
python -I tests/test_rdna2spirv_spawn_quota.py -v): 5/5 passed (0.818 s).venv(<venv>\Scripts\python.exe -I tests/test_rdna2spirv_spawn_quota.py -v): 5/5 passed (0.862 s).python -I scripts/check_no_game_data.py: passed.AI-assisted (Antigravity, Gemini).
Imported from ubiquitarianism/leonida. Originally posted by Rezn0r27 on 2026-11-28T22:21:59Z.
Tested commit
913b9aa4don Windows 11 (build 26300.9974) with Python 3.12.10. I ran py -3.12 -I tests/test_rdna2spirv_spawn_quota.py -v in PowerShell. All 5 tests passed in 1.976 seconds, including the Windows-specific test_back_to_back_tools_in_the_worker_job. No skips. Python exit code: 0Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T01:38:50Z.
#2367 | head
913b9aa4dd(merged cleanly onto origin/maind8c10dd5e1) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yesIndependent Verification (Windows 11 + Win32 Job Object)
tools/rdna2spirv.py(_run_spirv_toolbounded retry with exponential backoff up toSPAWN_RETRY_SECONDS = 10.0onwinerror == 1816ERROR_NOT_ENOUGH_QUOTAand exception__notes__on deadline expiry) andtests/test_rdna2spirv_spawn_quota.py.python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/test_rdna2spirv_spawn_quota.pypassed (rc=0).origin/maind8c10dd5e1tools/rdna2spirv.py): Running#2367'stests/test_rdna2spirv_spawn_quota.py -vagainst unpatchedtools/rdna2spirv.pyfailed (FAILED (failures=1, errors=1): unhandledOSError: [WinError 1816] Not enough quota is available to process this commandintest_quota_refusals_are_started_againandcall_count == 1intest_a_refusal_that_lasts_is_raised_once_the_time_is_up).#2367 + origin/main):python -I tests/test_rdna2spirv_spawn_quota.py -v->5/5passed (0skipped,OK,12.822s), including the Windows-onlyTwoProcessJobTests.test_back_to_back_tools_in_the_worker_jobexecuting150back-to-back child spawns inside a real 2-active-processcompute_workers_win.job(1024, True)Win32 Job Object (rc=0).python -I tests/test_compute_workers_win.py->4/4passed (OK,0.006s).Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T04:28:41Z.
Review: COMMENTED
Static audit of
913b9aa4donly. No builds, tests, or GPU runs.tools/rdna2spirv.pyroutesspirv-as,spirv-opt, andspirv-valthrough the same helper. The retry matches Windowswinerror1816, preserving the missing-tool diagnostic and propagation of POSIXerrnoerrors and subprocess timeouts. A refused start leaves the assembler's input bytes available for the next attempt. CPython closes the failed spawn's pipes, and the assemblyfinallyremoves the staging file if the exception escapes. The unit tests cover recovery, exhaustion, unrelated errors, and missing tools. The Windows integration test uses the two-process job fromscripts/compute_workers_win.pyand checks the interpreter PID before releasing its stdin gate.tools/rdna2spirv.py:19967— The final sleep can consume the remaining retry budget, but the loop still attempts another spawn. If the slot clears during that sleep, the tool can start at or after the deadline. Check the clock after sleeping, raise the last quota error with its note on expiry, and assert spawn times in the fake-clock test.tests/test_rdna2spirv_spawn_quota.py:152— The launcher precondition can skip beforecommunicate, leaving stdin, stdout, and stderr open until finalization even though the child is reaped. Close the parent streams after process and job teardown on this path.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T19:18:46Z.
Tested
913b9aa4dmerged (no commit) withmain7c330c76d: Python 3.12, Windows 11 10.0.26300, CPU only. Ran the PR's tests plus every test file that imports the changed tools, with the PR and with its tools back tomain.tests/test_rdna2spirv_spawn_quota.py5 OK with the PR,FAILED (failures=1, errors=1)withtools/back tomain.tests/test_bvh_shaders_stage.pyandtests/test_exe_shaders_stage.pyeach giveFAILED (failures=1)with this PR, while both pass onmain(13 OK and 11 OK in the same run on other PRs). They still fail with the tools back tomain, so it comes from the PR's non-tool changes. Not mergeable until those two pass.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by budanga on 2026-11-29T19:32:42Z.
Thanks for the further checks.
test_bvh_shaders_stageandtest_exe_shaders_stage(MoonEyes). They do not come from this pull request; they come from #1235, which reachedmainat545f610fa(2026-11-29 20:00). Run here (Windows 11 26300, Python 3.14),python -I tests/<file>.py:test_bvh_shaders_stagetest_exe_shaders_stage7c330c76d(yourmain)7c330c76d+ this PRcf6e55921(mainjust before #1235)545f610fa(the #1235 merge), without this PRmaindd87aa405+ this PRThe failing assertion is the second
stage()call, which should run nothing but runs['fspx_unpack.py', 'rdna2spirv.py']again. Sincebb68bb93a("make_game: rebuild empty cached compute shader modules"),make_gamerebuilds a cached empty.spv, and these two tests'fake_pystill writes an empty one (write("", out, name + ".spv")). #1235 updated the same fake intest_fspx_shaders_stage.pyandtest_library_shaders_stage.py, but not in these two. This pull request touches onlytools/rdna2spirv.pyand its own test file, and the two files pass with it on themainyou tested.timbot103's two points.
CreateProcesscall. If the slot has cleared by then, the tool runs; raising instead would turn a start that works into a failure. The unit test already asserts that the error comes no later thanSPAWN_RETRY_SECONDSon the fake clock.finally, after the child is killed and waited for, so the skip path no longer leaves them to finalization.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:43:43Z.
Review: APPROVED
Reviewed the diff against
main:tools/rdna2spirv.py:19938-19973cleanly retriessubprocess.runwith bounded exponential backoff (SPAWN_RETRY_SECONDS = 10.0) exclusively on WindowsERROR_NOT_ENOUGH_QUOTA(winerror == 1816), preservingFileNotFoundErrortool naming and attaching retry notes on timeout, with portable unit tests plus a Windows job-object test intests/test_rdna2spirv_spawn_quota.py. Clean-room verified. Approving; please merge/rebase currentmainfor a fresh green CI run before merge.(AI-assisted review.)