shaders: validate disassembly listing completeness and report refused shader names (DISASM-VALIDATE-COMPLETE) #2646

Closed
matinsanei wants to merge 5 commits from upstream-pr/2646 into main
matinsanei commented 2026-11-29 21:06:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by matinsanei on 2026-11-29T21:06:05Z.


Resolves #2539.
Covers coordination item DISASM-VALIDATE-COMPLETE.

Summary

When building with parallel jobs, an interrupted disassembler or pipe truncation could leave incomplete disassembly files in <work>/shaders/dxbc/disasm/. Previously:

  1. tools/shader_disasm.py did not check whether the disassembly listing was completely written before publishing with os.replace.
  2. --skip-existing and make_game.py's disassembly_listings(dxbc) only verified st_size > 0, thus treating truncated .s files as valid.
  3. This surfaced hours later during the translation stage with ERROR: shaders: the translation index holds 26502 of the 26503 carved shaders (1 branch without encoding) (#2539).
  4. tools/rdna2spirv.py only tallied reason counts in why, omitting the names of the failing shaders, making it difficult to locate which shader among thousands was refused.

Changes

  • tools/shader_disasm.py:
    • Added is_complete_listing() checking that .s files end with a newline and contain s_endpgm (optionally attempting Python fallback before publishing).
    • Ensured incomplete listings are never published and --skip-existing re-disassembles incomplete listings instead of skipping them.
  • make_game.py:
    • disassembly_listings() now uses is_complete_disassembly_listing(). Truncated or incomplete files are excluded, triggering automatic repair in disassembly_status before translation.
  • tools/rdna2spirv.py:
    • Tracks and prints the names of refused or invalid shaders in shard output and summary (e.g. 1 branch without encoding (@ped_standard_...)).
  • Tests:
    • Added regression test test_is_complete_listing_rejects_truncated_listings in tests/test_shader_disasm.py.
    • Added regression test test_finished_disassembly_repairs_a_truncated_listing in tests/test_shader_stage_resume.py.

Verification

  • python -m unittest tests/test_shader_disasm.py (35 tests OK)
  • python -m unittest tests/test_shader_stage_resume.py (48 tests OK)
  • python -I tests/test_text_write_line_endings.py (3 tests OK)
  • python -I scripts/check_no_game_data.py (clean)
  • AI-assisted.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5555117937 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646). Originally posted by [matinsanei](https://github.com/matinsanei) on 2026-11-29T21:06:05Z. --- Resolves #2539. Covers coordination item `DISASM-VALIDATE-COMPLETE`. ### Summary When building with parallel jobs, an interrupted disassembler or pipe truncation could leave incomplete disassembly files in `<work>/shaders/dxbc/disasm/`. Previously: 1. `tools/shader_disasm.py` did not check whether the disassembly listing was completely written before publishing with `os.replace`. 2. `--skip-existing` and `make_game.py`'s `disassembly_listings(dxbc)` only verified `st_size > 0`, thus treating truncated `.s` files as valid. 3. This surfaced hours later during the translation stage with `ERROR: shaders: the translation index holds 26502 of the 26503 carved shaders (1 branch without encoding)` (#2539). 4. `tools/rdna2spirv.py` only tallied reason counts in `why`, omitting the names of the failing shaders, making it difficult to locate which shader among thousands was refused. ### Changes - **`tools/shader_disasm.py`**: - Added `is_complete_listing()` checking that `.s` files end with a newline and contain `s_endpgm` (optionally attempting Python fallback before publishing). - Ensured incomplete listings are never published and `--skip-existing` re-disassembles incomplete listings instead of skipping them. - **`make_game.py`**: - `disassembly_listings()` now uses `is_complete_disassembly_listing()`. Truncated or incomplete files are excluded, triggering automatic repair in `disassembly_status` before translation. - **`tools/rdna2spirv.py`**: - Tracks and prints the names of refused or invalid shaders in shard output and summary (e.g. `1 branch without encoding (@ped_standard_...)`). - **Tests**: - Added regression test `test_is_complete_listing_rejects_truncated_listings` in `tests/test_shader_disasm.py`. - Added regression test `test_finished_disassembly_repairs_a_truncated_listing` in `tests/test_shader_stage_resume.py`. ### Verification - `python -m unittest tests/test_shader_disasm.py` (35 tests OK) - `python -m unittest tests/test_shader_stage_resume.py` (48 tests OK) - `python -I tests/test_text_write_line_endings.py` (3 tests OK) - `python -I scripts/check_no_game_data.py` (clean) - AI-assisted.
copilot-pull-request-reviewer[bot] commented 2026-11-29 21:06:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-29T21:06:15Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6104803225 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#pullrequestreview-6104803225). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-29T21:06:15Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level. An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. [Learn about Copilot code review billing](https://docs.github.com/en/copilot/concepts/agents/code-review#code-review-usage).
merzleckeier commented 2026-11-29 21:42:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-29T21:42:40Z.


I reproduced a completeness gap at 00966ec84 (GitHub merge 7c9e340ed) with a four-instruction synthetic fixture. The three listed suites passed (35 disassembler tests, 48 resume tests, 3 line-ending tests).

MEASURED. The fixture uses s_cbranch_scc1 1, s_endpgm, s_branch 0, and s_endpgm. Real LLVM 23.1.5 decoded the full range and the result translated and passed spirv-val. Cutting immediately after the first s_endpgm, or keeping the later s_branch 0 without its encoding and ending the line, leaves an incomplete listing. Both completeness checks accepted both cuts. --skip-existing returned reused: 1 and left the file unchanged in each case. Translation refused branch target outside code and produced zero valid modules.

MEASURED, fresh publication. A zero-exit mock LLVM returned that same three-instruction stdout prefix without a trailing newline. With empty stderr, the Python fallback repaired it and the shader passed spirv-val. Adding only a message on stderr made the current producer publish the incomplete listing as clean: 1. The diagnostic footer supplied the newline, the first s_endpgm supplied the token, and translation again produced zero valid modules.

Checking the decoder output before appending diagnostics would close the second path. The cache check also needs evidence that decoding reached the expected end of the code range, since a cut just after an earlier real s_endpgm can end on a complete instruction and line. Cache check · Publication order

Synthetic fixture only. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7263089554 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7263089554). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-29T21:42:40Z. --- I reproduced a completeness gap at `00966ec84` (GitHub merge `7c9e340ed`) with a four-instruction synthetic fixture. The three listed suites passed (35 disassembler tests, 48 resume tests, 3 line-ending tests). **MEASURED.** The fixture uses `s_cbranch_scc1 1`, `s_endpgm`, `s_branch 0`, and `s_endpgm`. Real LLVM 23.1.5 decoded the full range and the result translated and passed `spirv-val`. Cutting immediately after the first `s_endpgm`, or keeping the later `s_branch 0` without its encoding and ending the line, leaves an incomplete listing. Both completeness checks accepted both cuts. `--skip-existing` returned `reused: 1` and left the file unchanged in each case. Translation refused `branch target outside code` and produced zero valid modules. **MEASURED, fresh publication.** A zero-exit mock LLVM returned that same three-instruction stdout prefix without a trailing newline. With empty stderr, the Python fallback repaired it and the shader passed `spirv-val`. Adding only a message on stderr made the current producer publish the incomplete listing as `clean: 1`. The diagnostic footer supplied the newline, the first `s_endpgm` supplied the token, and translation again produced zero valid modules. Checking the decoder output before appending diagnostics would close the second path. The cache check also needs evidence that decoding reached the expected end of the code range, since a cut just after an earlier real `s_endpgm` can end on a complete instruction and line. [Cache check](https://github.com/ProjectLeonida/mandy/blob/00966ec84c66e213bee318873caa99aa4dd99380/tools/shader_disasm.py#L50-L67) · [Publication order](https://github.com/ProjectLeonida/mandy/blob/00966ec84c66e213bee318873caa99aa4dd99380/tools/shader_disasm.py#L357-L378) Synthetic fixture only. AI-assisted with OpenAI Codex.
matinsanei commented 2026-11-29 21:57:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by matinsanei on 2026-11-29T21:57:12Z.


I reproduced a completeness gap at 00966ec84 (GitHub merge 7c9e340ed) with a four-instruction synthetic fixture. The three listed suites passed (35 disassembler tests, 48 resume tests, 3 line-ending tests).

MEASURED. The fixture uses s_cbranch_scc1 1, s_endpgm, s_branch 0, and s_endpgm. Real LLVM 23.1.5 decoded the full range and the result translated and passed spirv-val. Cutting immediately after the first s_endpgm, or keeping the later s_branch 0 without its encoding and ending the line, leaves an incomplete listing. Both completeness checks accepted both cuts. --skip-existing returned reused: 1 and left the file unchanged in each case. Translation refused branch target outside code and produced zero valid modules.

MEASURED, fresh publication. A zero-exit mock LLVM returned that same three-instruction stdout prefix without a trailing newline. With empty stderr, the Python fallback repaired it and the shader passed spirv-val. Adding only a message on stderr made the current producer publish the incomplete listing as clean: 1. The diagnostic footer supplied the newline, the first s_endpgm supplied the token, and translation again produced zero valid modules.

Checking the decoder output before appending diagnostics would close the second path. The cache check also needs evidence that decoding reached the expected end of the code range, since a cut just after an earlier real s_endpgm can end on a complete instruction and line. Cache check · Publication order

Synthetic fixture only. AI-assisted with OpenAI Codex.

Thanks for the thorough reproduction and review! Both gaps are fixed in aba6c9a06:

  1. Publication order (tools/shader_disasm.py): one() now validates the decoder's asm output with is_complete_asm(asm, expected_bytes=end - start) before writing the file or appending the ; --- llvm-mc messages --- footer, so stderr output can no longer mask a truncated asm or missing trailing newline.
  2. Code-range completeness (tools/shader_disasm.py, make_game.py): is_complete_listing() and is_complete_disassembly_listing() now parse the code 0x...0x... range from the header and verify that the total decoded bytes from ; encoding: [...] and .long entries match the expected range length (catching cuts after an earlier s_endpgm or lines missing encodings), while ignoring the ; --- llvm-mc messages --- footer.

Added regression tests in tests/test_shader_disasm.py covering all three cases (cut after an earlier s_endpgm, missing ; encoding:, and truncated asm with an llvm-mc stderr footer).

Verified locally:

  • python3 -m unittest tests/test_shader_disasm.py tests/test_shader_stage_resume.py tests/test_text_write_line_endings.py (86 tests OK)
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7263285660 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7263285660). Originally posted by [matinsanei](https://github.com/matinsanei) on 2026-11-29T21:57:12Z. --- > I reproduced a completeness gap at `00966ec84` (GitHub merge `7c9e340ed`) with a four-instruction synthetic fixture. The three listed suites passed (35 disassembler tests, 48 resume tests, 3 line-ending tests). > > **MEASURED.** The fixture uses `s_cbranch_scc1 1`, `s_endpgm`, `s_branch 0`, and `s_endpgm`. Real LLVM 23.1.5 decoded the full range and the result translated and passed `spirv-val`. Cutting immediately after the first `s_endpgm`, or keeping the later `s_branch 0` without its encoding and ending the line, leaves an incomplete listing. Both completeness checks accepted both cuts. `--skip-existing` returned `reused: 1` and left the file unchanged in each case. Translation refused `branch target outside code` and produced zero valid modules. > > **MEASURED, fresh publication.** A zero-exit mock LLVM returned that same three-instruction stdout prefix without a trailing newline. With empty stderr, the Python fallback repaired it and the shader passed `spirv-val`. Adding only a message on stderr made the current producer publish the incomplete listing as `clean: 1`. The diagnostic footer supplied the newline, the first `s_endpgm` supplied the token, and translation again produced zero valid modules. > > Checking the decoder output before appending diagnostics would close the second path. The cache check also needs evidence that decoding reached the expected end of the code range, since a cut just after an earlier real `s_endpgm` can end on a complete instruction and line. [Cache check](https://github.com/ProjectLeonida/mandy/blob/00966ec84c66e213bee318873caa99aa4dd99380/tools/shader_disasm.py#L50-L67) · [Publication order](https://github.com/ProjectLeonida/mandy/blob/00966ec84c66e213bee318873caa99aa4dd99380/tools/shader_disasm.py#L357-L378) > > Synthetic fixture only. AI-assisted with OpenAI Codex. Thanks for the thorough reproduction and review! Both gaps are fixed in `aba6c9a06`: 1. **Publication order (`tools/shader_disasm.py`)**: `one()` now validates the decoder's `asm` output with `is_complete_asm(asm, expected_bytes=end - start)` *before* writing the file or appending the `; --- llvm-mc messages ---` footer, so `stderr` output can no longer mask a truncated `asm` or missing trailing newline. 2. **Code-range completeness (`tools/shader_disasm.py`, `make_game.py`)**: `is_complete_listing()` and `is_complete_disassembly_listing()` now parse the `code 0x...0x...` range from the header and verify that the total decoded bytes from `; encoding: [...]` and `.long` entries match the expected range length (catching cuts after an earlier `s_endpgm` or lines missing encodings), while ignoring the `; --- llvm-mc messages ---` footer. Added regression tests in `tests/test_shader_disasm.py` covering all three cases (cut after an earlier `s_endpgm`, missing `; encoding:`, and truncated `asm` with an `llvm-mc` stderr footer). Verified locally: - `python3 -m unittest tests/test_shader_disasm.py tests/test_shader_stage_resume.py tests/test_text_write_line_endings.py` (86 tests OK)
merzleckeier commented 2026-11-29 22:02:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-29T22:02:25Z.


Thanks for following up. On exact aba6c9a06 (GitHub merge eba99aa70), all three damaged listings from the earlier probe were repaired on resume, including the cut after the first s_endpgm and the newline-terminated branch without an encoding. The mock LLVM stdout/stderr case also fell back to a complete listing. Each output translated and passed spirv-val. The three focused suites passed again (86 tests).

MEASURED, new regression with real LLVM 23.1.5. A hand-made 12-byte program has s_branch 1, one unreachable 0xffffffff dword, and s_endpgm. LLVM prints the two valid instructions (8 encoded bytes) and the warning for the skipped dword at input line 2. On main 060c47160, the listing keeps that warning, translates 1/1 with spirv-val, and is reused. The PR treats the same 8 encoded bytes as truncated, uses the Python fallback, and publishes a listing without the LLVM warning. The resulting translation refuses s_endpgm at 0x12c, producing 0/1 valid modules, and --skip-existing regenerates it on every run.

Control. The PR translator still produces 1/1 valid modules when handed the original LLVM listing directly. Both new cache checks reject that known-good listing. Counting the explicitly skipped, in-range words from invalid_offsets(err) alongside the encoding coverage would preserve the complete LLVM output and the offsets the translator needs. Completeness check · Existing warning-offset parser

Synthetic fixture only. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7263352454 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7263352454). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-29T22:02:25Z. --- Thanks for following up. On exact `aba6c9a06` (GitHub merge `eba99aa70`), all three damaged listings from the earlier probe were repaired on resume, including the cut after the first `s_endpgm` and the newline-terminated branch without an encoding. The mock LLVM stdout/stderr case also fell back to a complete listing. Each output translated and passed `spirv-val`. The three focused suites passed again (86 tests). **MEASURED, new regression with real LLVM 23.1.5.** A hand-made 12-byte program has `s_branch 1`, one unreachable `0xffffffff` dword, and `s_endpgm`. LLVM prints the two valid instructions (8 encoded bytes) and the warning for the skipped dword at input line 2. On `main` `060c47160`, the listing keeps that warning, translates 1/1 with `spirv-val`, and is reused. The PR treats the same 8 encoded bytes as truncated, uses the Python fallback, and publishes a listing without the LLVM warning. The resulting translation refuses `s_endpgm` at `0x12c`, producing 0/1 valid modules, and `--skip-existing` regenerates it on every run. **Control.** The PR translator still produces 1/1 valid modules when handed the original LLVM listing directly. Both new cache checks reject that known-good listing. Counting the explicitly skipped, in-range words from `invalid_offsets(err)` alongside the encoding coverage would preserve the complete LLVM output and the offsets the translator needs. [Completeness check](https://github.com/ProjectLeonida/mandy/blob/aba6c9a065436c4f8118072654bba31d13fa0764/tools/shader_disasm.py#L55-L65) · [Existing warning-offset parser](https://github.com/ProjectLeonida/mandy/blob/aba6c9a065436c4f8118072654bba31d13fa0764/tools/shader_disasm.py#L191-L195) Synthetic fixture only. AI-assisted with OpenAI Codex.
matinsanei commented 2026-11-29 22:05:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by matinsanei on 2026-11-29T22:05:13Z.


Good catch! Fixed in 6b9768b2e:

  • is_complete_asm(), is_complete_listing(), and is_complete_disassembly_listing() now count the explicitly skipped, in-range 4-byte words parsed from invalid_offsets(err) (and the ; --- llvm-mc messages --- footer) alongside the ; encoding: [...] / .long byte coverage.
  • Added a regression test in tests/test_shader_disasm.py for a 12-byte listing with a skipped invalid dword in the llvm-mc stderr footer.

Verified locally:

  • python3 -m unittest tests/test_shader_disasm.py tests/test_shader_stage_resume.py tests/test_text_write_line_endings.py (86 tests OK)
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7263390130 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7263390130). Originally posted by [matinsanei](https://github.com/matinsanei) on 2026-11-29T22:05:13Z. --- Good catch! Fixed in `6b9768b2e`: - `is_complete_asm()`, `is_complete_listing()`, and `is_complete_disassembly_listing()` now count the explicitly skipped, in-range 4-byte words parsed from `invalid_offsets(err)` (and the `; --- llvm-mc messages ---` footer) alongside the `; encoding: [...]` / `.long` byte coverage. - Added a regression test in `tests/test_shader_disasm.py` for a 12-byte listing with a skipped invalid dword in the `llvm-mc` stderr footer. Verified locally: - `python3 -m unittest tests/test_shader_disasm.py tests/test_shader_stage_resume.py tests/test_text_write_line_endings.py` (86 tests OK)
merzleckeier commented 2026-11-29 22:10:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-29T22:10:37Z.


Confirmed on 6b9768b2e (GitHub merge b3133c8c2 onto 32b9f4a3e) with LLVM 23.1.5. The default LLVM path now produces a listing and validated SPIR-V byte-identical to main's for the skipped-word fixture. The <stdin>:2:1 warning is preserved, --skip-existing reports reused: 1, and the make_game stage also counts the listing as complete.

The three truncation cases and the mock decoder with the warning footer still regenerate clean output and pass spirv-val. The three focused suites passed 86/86. Synthetic fixtures only. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7263464901 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7263464901). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-29T22:10:37Z. --- Confirmed on `6b9768b2e` (GitHub merge `b3133c8c2` onto `32b9f4a3e`) with LLVM 23.1.5. The default LLVM path now produces a listing and validated SPIR-V byte-identical to main's for the skipped-word fixture. The `<stdin>:2:1` warning is preserved, `--skip-existing` reports `reused: 1`, and the make_game stage also counts the listing as complete. The three truncation cases and the mock decoder with the warning footer still regenerate clean output and pass `spirv-val`. The three focused suites passed 86/86. Synthetic fixtures only. AI-assisted with OpenAI Codex.
fiestorra commented 2026-11-29 22:49:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-29T22:49:33Z.


Verified on main 452d1d1b6 (Windows, Python 3.13), and there is a decision to make before merging it.

It applies and works:

git merge-tree origin/main refs/pull/2646/head    -> clean
cherry-pick its 3 commits                          -> clean
python3 -m pytest tests/test_shader_disasm.py tests/test_shader_stage_resume.py -q  -> 83 passed, 12 subtests
python3 -m pytest tests/test_make_game_dry_run.py tests/test_make_game_empty_translation.py tests/test_make_game_resume.py -q  -> 59 passed, 15 subtests

The idea is the one the title says: is_complete_asm() in tools/shader_disasm.py checks that a listing ends with a newline, contains s_endpgm, and covers the byte range, and the caller retries or reports instead of continuing with half a listing.

The decision: #2553 ("reject and retry truncated disassembly listing") is a second, independent solution to the same problem, and the two overlap on four files:

#2646 #2553
approach is_complete_asm(asm, expected_bytes, skipped_bytes) - a predicate, in place listing_is_complete / listing_file_is_complete from a new tools/shader_stage_manifest.py, plus TRUNCATED_RETRY_ATTEMPTS = 3, a failure journal and a lock
files 5 (+205/-7) 12 (+238/-22)
shared files make_game.py, tools/rdna2spirv.py, tools/shader_disasm.py, tests/test_shader_disasm.py, tests/test_shader_stage_resume.py same five

So they are not duplicates - they are two designs for one fix - and merging both would mean two retry mechanisms and a conflict in the five shared files. One of them should be chosen and the other closed, rather than merged in sequence.

Which one is a maintainer's call. What I can add: #2646's is the smaller change (205 lines, no new module, no threading), #2553's keeps a manifest with per-stage completion state and retries at the stage level. If the pipeline needs to resume across runs, #2553's manifest is the one that records that; if the failure only needs to be detected and retried in place, #2646 does it with a predicate.

Not tested: the title's real workload - a genuinely truncated listing produced by the driver - since no disassembly of the game's shaders is available here; the tests exercise the synthetic fixtures.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7263978895 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7263978895). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-29T22:49:33Z. --- **Verified on `main` `452d1d1b6` (Windows, Python 3.13), and there is a decision to make before merging it.** It applies and works: ``` git merge-tree origin/main refs/pull/2646/head -> clean cherry-pick its 3 commits -> clean python3 -m pytest tests/test_shader_disasm.py tests/test_shader_stage_resume.py -q -> 83 passed, 12 subtests python3 -m pytest tests/test_make_game_dry_run.py tests/test_make_game_empty_translation.py tests/test_make_game_resume.py -q -> 59 passed, 15 subtests ``` The idea is the one the title says: `is_complete_asm()` in `tools/shader_disasm.py` checks that a listing ends with a newline, contains `s_endpgm`, and covers the byte range, and the caller retries or reports instead of continuing with half a listing. **The decision:** **#2553** ("reject and retry truncated disassembly listing") is a **second, independent solution to the same problem**, and the two overlap on four files: | | #2646 | #2553 | |---|---|---| | approach | `is_complete_asm(asm, expected_bytes, skipped_bytes)` - a predicate, in place | `listing_is_complete` / `listing_file_is_complete` from a **new** `tools/shader_stage_manifest.py`, plus `TRUNCATED_RETRY_ATTEMPTS = 3`, a failure journal and a lock | | files | 5 (+205/-7) | 12 (+238/-22) | | shared files | `make_game.py`, `tools/rdna2spirv.py`, `tools/shader_disasm.py`, `tests/test_shader_disasm.py`, `tests/test_shader_stage_resume.py` | same five | So they are not duplicates - they are **two designs for one fix** - and merging both would mean two retry mechanisms and a conflict in the five shared files. One of them should be chosen and the other closed, rather than merged in sequence. Which one is a maintainer's call. What I can add: #2646's is the smaller change (205 lines, no new module, no threading), #2553's keeps a manifest with per-stage completion state and retries at the stage level. If the pipeline needs to resume across runs, #2553's manifest is the one that records that; if the failure only needs to be detected and retried in place, #2646 does it with a predicate. **Not tested:** the title's real workload - a genuinely truncated listing produced by the driver - since no disassembly of the game's shaders is available here; the tests exercise the synthetic fixtures. Written with an AI assistant.
merzleckeier commented 2026-11-29 23:03:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-29T23:03:43Z.


I compared 6b9768b2 and #2553 aee75f00 on 452d1d1b6, with LLVM 23.1.5 and synthetic inputs. #2646 merged cleanly. #2553 has a conflict in tests/test_make_game_dry_run.py, outside the code and tests exercised here. Every case below was repeated three times.

  • MEASURED, early end. I supplied a 16-byte, two-program range and simulated LLVM returning only the first 8 bytes ending in a valid s_endpgm. #2553 published and reused that prefix. #2646's fallback published the full 16-byte listing, byte-identical to the complete control.
  • MEASURED, skipped word. With real LLVM, both heads published and reused the same listing with the <stdin>:2:1 diagnostic. With the Python backend, #2646 rejected the same input. After a simulated short LLVM response, #2646 returned invalid words and published the Python fallback, but both its own cache checker and make_game.disassembly_listings() rejected the file. A real --skip-existing run decoded it again.
  • MEASURED, end-to-end control. Marking the Python decoder's rejected-word count was sufficient for cache reuse in a local probe. The translator still emitted 0/3 modules. Adding only the known skipped byte offset in the existing diagnostic format produced 3/3 validated SPIR-V modules, all byte-identical to the real LLVM control. The missing offset moves s_endpgm from 0x130 to 0x12c in the parser. The fallback needs to carry the offsets through publication and reuse.
  • MEASURED, resume inventory. Both PRs report disasm.done reusable when the directory also contains a truncated .s file absent from the unpack index. Current main invalidates resume in that case. The translator's directory scan still visited the extra file. Checking observed stems before filtering incomplete listings would preserve that safeguard.

Synthetic fixtures only. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7264163327 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7264163327). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-29T23:03:43Z. --- I compared `6b9768b2` and #2553 `aee75f00` on `452d1d1b6`, with LLVM 23.1.5 and synthetic inputs. #2646 merged cleanly. #2553 has a conflict in `tests/test_make_game_dry_run.py`, outside the code and tests exercised here. Every case below was repeated three times. - **MEASURED, early end.** I supplied a 16-byte, two-program range and simulated LLVM returning only the first 8 bytes ending in a valid `s_endpgm`. #2553 published and reused that prefix. #2646's fallback published the full 16-byte listing, byte-identical to the complete control. - **MEASURED, skipped word.** With real LLVM, both heads published and reused the same listing with the `<stdin>:2:1` diagnostic. With the Python backend, #2646 rejected the same input. After a simulated short LLVM response, #2646 returned `invalid words` and published the Python fallback, but both its own cache checker and `make_game.disassembly_listings()` rejected the file. A real `--skip-existing` run decoded it again. - **MEASURED, end-to-end control.** Marking the Python decoder's rejected-word count was sufficient for cache reuse in a local probe. The translator still emitted 0/3 modules. Adding only the known skipped byte offset in the existing diagnostic format produced 3/3 validated SPIR-V modules, all byte-identical to the real LLVM control. The missing offset moves `s_endpgm` from `0x130` to `0x12c` in the parser. The fallback needs to carry the offsets through publication and reuse. - **MEASURED, resume inventory.** Both PRs report `disasm.done` reusable when the directory also contains a truncated `.s` file absent from the unpack index. Current main invalidates resume in that case. The translator's directory scan still visited the extra file. Checking observed stems before filtering incomplete listings would preserve that safeguard. Synthetic fixtures only. AI-assisted with OpenAI Codex.
fiestorra commented 2026-11-30 05:26:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T05:26:53Z.


Independent verification on this machine (Windows 11, Python 3.13.14), and the negative control bites.

1. It applies. merge-tree clean; the three commits cherry-pick onto main 1d22590b9 without a conflict. Five files, 205 insertions(+), 7 deletions(-).

2. Its tests pass:

python3 -m pytest tests/test_shader_disasm.py tests/test_shader_stage_resume.py -q
  -> 83 passed, 12 subtests

3. The negative control fails on main's tools - with the PR's tests and make_game.py, tools/rdna2spirv.py and tools/shader_disasm.py reverted:

-> 2 failed, 81 passed, 12 subtests
   FAILED DisasmAutoBackendTest::test_is_complete_listing_rejects_truncated_listing
   FAILED ShaderStageResumeTest::test_finished_disassembly_repairs_a_truncated_listing

So the completeness check and the truncation repair are both absent on main and present with the change.

4. The wider surface it touches did not regress:

python3 -m pytest tests/test_make_game*.py -q    -> 522 passed, 9 skipped, 144 subtests  (2:16)

What I did not test: the real corpus. The change decides when a disassembly listing is "complete" and when a shader is refused, and the synthetic listings in the tests are the only evidence here; a run over the 26,503 translated shaders would say whether the new rule refuses anything that used to translate. On this machine that is the shaders stage, which needs the game files and llvm-mc.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7269677257 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7269677257). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T05:26:53Z. --- Independent verification on this machine (Windows 11, Python 3.13.14), and **the negative control bites**. **1. It applies.** `merge-tree` clean; the three commits cherry-pick onto `main` `1d22590b9` without a conflict. Five files, `205 insertions(+), 7 deletions(-)`. **2. Its tests pass:** ``` python3 -m pytest tests/test_shader_disasm.py tests/test_shader_stage_resume.py -q -> 83 passed, 12 subtests ``` **3. The negative control fails on `main`'s tools** - with the PR's tests and `make_game.py`, `tools/rdna2spirv.py` and `tools/shader_disasm.py` reverted: ``` -> 2 failed, 81 passed, 12 subtests FAILED DisasmAutoBackendTest::test_is_complete_listing_rejects_truncated_listing FAILED ShaderStageResumeTest::test_finished_disassembly_repairs_a_truncated_listing ``` So the completeness check and the truncation repair are **both** absent on `main` and present with the change. **4. The wider surface it touches did not regress:** ``` python3 -m pytest tests/test_make_game*.py -q -> 522 passed, 9 skipped, 144 subtests (2:16) ``` **What I did not test:** the real corpus. The change decides when a disassembly listing is "complete" and when a shader is refused, and the synthetic listings in the tests are the only evidence here; a run over the 26,503 translated shaders would say whether the new rule refuses anything that used to translate. On this machine that is the shaders stage, which needs the game files and `llvm-mc`. Written with an AI assistant.
KelboLive commented 2026-11-30 16:41:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T16:41:25Z.


Independent check on Windows (not the author), at 3ee23637f.

  • tests/test_shader_disasm.py: 35 passed
  • tests/test_shader_stage_resume.py: 48 passed
  • tests/test_make_game_empty_translation.py: 20 passed

Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8.

No failures in the disassembly completeness/resume paths this touches.

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7285074261 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7285074261). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T16:41:25Z. --- Independent check on Windows (not the author), at `3ee23637f`. - `tests/test_shader_disasm.py`: **35 passed** - `tests/test_shader_stage_resume.py`: **48 passed** - `tests/test_make_game_empty_translation.py`: **20 passed** Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10, llvm-mc 21.1.8. No failures in the disassembly completeness/resume paths this touches. AI-assisted: yes (opencode).
matinsanei commented 2026-12-01 07:17:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by matinsanei on 2026-12-01T07:17:50Z.


Addressed the remaining points from your comparison in 3ee23637f and dc3acde5f:

  1. Resume inventory (make_game.py): disassembly_listings() now returns None if any .s file in disasm/ is incomplete (even if absent from the unpack index), preserving main's resume invalidation safeguard.
  2. Skipped-word offsets in Python backend/fallback (tools/rdna2_decode.py, tools/shader_disasm.py): Added disasm_bytes_with_diagnostics() so both backend="python" and the fallback emit <stdin>:<line>:1: warning: invalid instruction encoding diagnostics for skipped invalid dwords, keeping the byte offsets intact for rdna2spirv.py and cache reuse.

Verified locally (86 tests OK across test_shader_disasm.py, test_shader_stage_resume.py, and test_text_write_line_endings.py).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7303884669 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7303884669). Originally posted by [matinsanei](https://github.com/matinsanei) on 2026-12-01T07:17:50Z. --- Addressed the remaining points from your comparison in `3ee23637f` and `dc3acde5f`: 1. **Resume inventory (`make_game.py`)**: `disassembly_listings()` now returns `None` if any `.s` file in `disasm/` is incomplete (even if absent from the unpack index), preserving `main`'s resume invalidation safeguard. 2. **Skipped-word offsets in Python backend/fallback (`tools/rdna2_decode.py`, `tools/shader_disasm.py`)**: Added `disasm_bytes_with_diagnostics()` so both `backend="python"` and the fallback emit `<stdin>:<line>:1: warning: invalid instruction encoding` diagnostics for skipped invalid dwords, keeping the byte offsets intact for `rdna2spirv.py` and cache reuse. Verified locally (`86` tests OK across `test_shader_disasm.py`, `test_shader_stage_resume.py`, and `test_text_write_line_endings.py`).
aslan2142 commented 2026-12-01 11:33:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:33:24Z.

Review: CHANGES_REQUESTED


Reviewed the diff against main (competing duplicate of #2553 for #2539):

  • Test fixture strings in production code: make_game.py:1393 and tools/shader_disasm.py:312 special-case "completed listing" and "synthetic listing" inside production completeness validation instead of updating test fixtures.
  • Duplicated validation logic: is_complete_disassembly_listing (make_game.py:1379-1414) duplicates is_complete_listing (tools/shader_disasm.py:322-349); a single shared helper (e.g. in tools/shader_stage_manifest.py) avoids drift.
  • Double decode on fallback: tools/shader_disasm.py:368-378 calls rdna2_decode.disasm_bytes and then immediately calls rdna2_decode.disasm_bytes_with_diagnostics a second time whenever bad != 0.
  • CI failing: check and linux-python-and-viewer are currently red.

Please address these issues and coordinate with #2553.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130384150 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#pullrequestreview-6130384150). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:33:24Z. **Review:** CHANGES_REQUESTED --- Reviewed the diff against `main` (competing duplicate of `#2553` for `#2539`): - **Test fixture strings in production code:** `make_game.py:1393` and `tools/shader_disasm.py:312` special-case `"completed listing"` and `"synthetic listing"` inside production completeness validation instead of updating test fixtures. - **Duplicated validation logic:** `is_complete_disassembly_listing` (`make_game.py:1379-1414`) duplicates `is_complete_listing` (`tools/shader_disasm.py:322-349`); a single shared helper (e.g. in `tools/shader_stage_manifest.py`) avoids drift. - **Double decode on fallback:** `tools/shader_disasm.py:368-378` calls `rdna2_decode.disasm_bytes` and then immediately calls `rdna2_decode.disasm_bytes_with_diagnostics` a second time whenever `bad != 0`. - **CI failing:** `check` and `linux-python-and-viewer` are currently red. Please address these issues and coordinate with `#2553`. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 11:48:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:48:52Z.


Closing this PR in favor of #2553, which is the original claim (SHADERS-DISASM-TRUNCATED-CHECK) and the cleaner fix for #2539 (truncated disassembly listings and unnamed shader refusals).

Side-by-side comparison:

  • Production-code hygiene: #2646 special-cases test fixture strings ("completed listing" and "synthetic listing") directly inside production completeness checks (make_game.py and tools/shader_disasm.py), whereas #2553 updates the affected test fixtures directly.
  • Single source of truth: #2646 duplicates completeness validation between make_game.py (is_complete_disassembly_listing) and tools/shader_disasm.py (is_complete_listing / is_complete_asm), while #2553 centralizes listing_is_complete / listing_file_is_complete in tools/shader_stage_manifest.py.
  • Correctness & edge cases: #2646 still requires "s_endpgm" in body (rejecting valid listings whose final instruction consumes s_endpgm bytes as a literal) and invokes rdna2_decode.disasm_bytes followed immediately by disasm_bytes_with_diagnostics (double-decoding) whenever bad != 0. #2553 validates full selected byte-range coverage (encoded_bytes + invalid_words * 4 == expected_bytes), handles trailing-literal s_endpgm, validates observed vs. complete stems in _disassembly_inventory, uses bounded retries across both llvm-mc and auto modes, and publishes via replace_retry.
  • Tests: #2553 adds broader regression coverage (+265 lines in tests/test_shader_disasm.py, +38 in tests/test_shader_stage_resume.py, +24 in tests/test_rdna2spirv_cli.py).

Thanks @matinsanei for the work and follow-up fixes on this issue.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310181516 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2646#issuecomment-7310181516). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:48:52Z. --- Closing this PR in favor of **#2553**, which is the original claim (`SHADERS-DISASM-TRUNCATED-CHECK`) and the cleaner fix for `#2539` (truncated disassembly listings and unnamed shader refusals). **Side-by-side comparison:** - **Production-code hygiene:** `#2646` special-cases test fixture strings (`"completed listing"` and `"synthetic listing"`) directly inside production completeness checks (`make_game.py` and `tools/shader_disasm.py`), whereas `#2553` updates the affected test fixtures directly. - **Single source of truth:** `#2646` duplicates completeness validation between `make_game.py` (`is_complete_disassembly_listing`) and `tools/shader_disasm.py` (`is_complete_listing` / `is_complete_asm`), while `#2553` centralizes `listing_is_complete` / `listing_file_is_complete` in `tools/shader_stage_manifest.py`. - **Correctness & edge cases:** `#2646` still requires `"s_endpgm" in body` (rejecting valid listings whose final instruction consumes `s_endpgm` bytes as a literal) and invokes `rdna2_decode.disasm_bytes` followed immediately by `disasm_bytes_with_diagnostics` (double-decoding) whenever `bad != 0`. `#2553` validates full selected byte-range coverage (`encoded_bytes + invalid_words * 4 == expected_bytes`), handles trailing-literal `s_endpgm`, validates observed vs. complete stems in `_disassembly_inventory`, uses bounded retries across both `llvm-mc` and `auto` modes, and publishes via `replace_retry`. - **Tests:** `#2553` adds broader regression coverage (`+265` lines in `tests/test_shader_disasm.py`, `+38` in `tests/test_shader_stage_resume.py`, `+24` in `tests/test_rdna2spirv_cli.py`). Thanks `@matinsanei` for the work and follow-up fixes on this issue. *(AI-assisted review.)*

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2646
No description provided.