mem_diff: narrow skip catch to UnsupportedConstruct, guard memory/export compares, deduplicate families #1679

Merged
IlyassRS3 merged 1 commit from upstream-pr/1679 into main 2026-11-28 14:52:29 +00:00
IlyassRS3 commented 2026-11-25 07:55:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T07:55:04Z.


Item ID: MEM-DIFF-COMPARE-AND-HARNESS-ERRORS (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156347986)

Summary

  • Narrow run_fragment skip handling (tools/mem_diff.py):
    • Catch only spirv_mini_interp.UnsupportedConstruct instead of broad Exception in run_one() (matching tools/shader_diff.py), so real interpreter/harness failures (RuntimeError, AssertionError, KeyError, etc.) surface as harness-error (exit 2) instead of being silently downgraded to "skip".
  • Fix IndexError crashes in run_one() comparison logic:
    • Compute differing memory addresses ((memory.get(a, 0) & MASK32) != (ref.mem.get(a, 0) & MASK32)) before indexing bad[0], preventing an IndexError: list index out of range whenever one side explicitly stores 0 at an unseeded address absent from the other side.
    • Handle overlong %out_mrt0 exports (len(got) > 4 whose first 4 words match want) by reporting "export shape mismatch: expected 4 words, translated N" instead of crashing on bad[0], and mask exported words to 32 bits (MASK32).
  • Deduplicate --family selections:
    • Deduplicate families via sorted(set(families)) in generate_program() so repeated --family flags do not skew random family sampling.
  • Regression tests (tests/test_mem_diff.py):
    • Added CompareAndHarnessRegression covering UnsupportedConstruct vs unexpected RuntimeError harness error, zero-valued extra memory entries, overlong %out_mrt0 exports, and duplicate --family deduplication.

Checklist & Verification

  • AI-assisted: yes
  • Game data included: none (python3 -I scripts/check_no_game_data.py tools/mem_diff.py tests/test_mem_diff.py passed)
  • GPUs tested: none (hostless macOS CPU/unit test run)
  • Tests run:
    • python3 -W error -I tests/test_mem_diff.py -v: Ran 23 tests ... OK
    • Mutation test (CompareAndHarnessRegression against unpatched main tools/mem_diff.py): Ran 4 tests ... FAILED (failures=1, errors=3)
    • python3 -m compileall -q make_game.py tools tests: passed
    • python3 -I tests/test_text_write_line_endings.py: Ran 3 tests ... OK
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5487392165 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1679). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T07:55:04Z. --- Item ID: `MEM-DIFF-COMPARE-AND-HARNESS-ERRORS` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156347986) ## Summary - **Narrow `run_fragment` skip handling (`tools/mem_diff.py`)**: - Catch only `spirv_mini_interp.UnsupportedConstruct` instead of broad `Exception` in `run_one()` (matching `tools/shader_diff.py`), so real interpreter/harness failures (`RuntimeError`, `AssertionError`, `KeyError`, etc.) surface as `harness-error` (exit `2`) instead of being silently downgraded to `"skip"`. - **Fix `IndexError` crashes in `run_one()` comparison logic**: - Compute differing memory addresses (`(memory.get(a, 0) & MASK32) != (ref.mem.get(a, 0) & MASK32)`) before indexing `bad[0]`, preventing an `IndexError: list index out of range` whenever one side explicitly stores `0` at an unseeded address absent from the other side. - Handle overlong `%out_mrt0` exports (`len(got) > 4` whose first 4 words match `want`) by reporting `"export shape mismatch: expected 4 words, translated N"` instead of crashing on `bad[0]`, and mask exported words to 32 bits (`MASK32`). - **Deduplicate `--family` selections**: - Deduplicate `families` via `sorted(set(families))` in `generate_program()` so repeated `--family` flags do not skew random family sampling. - **Regression tests (`tests/test_mem_diff.py`)**: - Added `CompareAndHarnessRegression` covering `UnsupportedConstruct` vs unexpected `RuntimeError` harness error, zero-valued extra memory entries, overlong `%out_mrt0` exports, and duplicate `--family` deduplication. ## Checklist & Verification - **AI-assisted**: yes - **Game data included**: none (`python3 -I scripts/check_no_game_data.py tools/mem_diff.py tests/test_mem_diff.py` passed) - **GPUs tested**: none (hostless macOS CPU/unit test run) - **Tests run**: - `python3 -W error -I tests/test_mem_diff.py -v`: `Ran 23 tests ... OK` - Mutation test (`CompareAndHarnessRegression` against unpatched `main` `tools/mem_diff.py`): `Ran 4 tests ... FAILED (failures=1, errors=3)` - `python3 -m compileall -q make_game.py tools tests`: passed - `python3 -I tests/test_text_write_line_endings.py`: `Ran 3 tests ... OK`
copilot-pull-request-reviewer[bot] commented 2026-11-25 07:55:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T07:55:17Z.

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6053753014 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1679#pullrequestreview-6053753014). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T07:55:17Z. **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.
GrahamboJangles commented 2026-11-25 11:57:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GrahamboJangles on 2026-11-25T11:57:54Z.


Independent review (CPU-only Windows 11, python 3.14.9 python -I, fresh clone; head c064f0718, current main 57ba40bd6).

Coordination. Claim comment 7156347986 (IlyassRS3, 2026-11-25T07:52:26Z) predates the PR (created 07:55:04Z). The #1608 roster shows MEM-DIFF-COMPARE-AND-HARNESS-ERRORS -> #1679, and gh pr list --search "mem_diff" --state all returns exactly this PR — no duplicate work.

The new test bites (inverse check). tests/test_mem_diff.py at head: Ran 23 tests ... OK (the file at main runs 19, so +4 exactly as claimed). The same test file against main's tools/mem_diff.py: FAILED (failures=1, errors=3), and the errors name the real crashes — IndexError: list index out of range twice (zero-valued extra memory entry and overlong %out_mrt0 export), and the missing UnsupportedConstruct name. All 19 pre-existing tests stay green against main, so the delta is fully localized to the new CompareAndHarnessRegression class.

Whole-suite check. Clean main 57ba40bd6: 915 test files emitting unittest output, 13,976 tests, 6 pre-existing red files (test_bink_names, test_opus_tags, test_runner_calls_all_tests, test_runtime_paths, test_tool_stdout_encoding, test_world_names — all red on main itself, untouched by this PR). On the pr1679 branch tree: 914 files / 13,972. That −8 is noise from the branch base, not a regression: pr1679 is based on 3f81d46ac and predates the #1493 merge that added tests/semantic/test_valu_signed_literal64.py (−8) to main; +4 is the new class. Failing-file sets are identical (plus one flaky test_run_wine_tests error on the branch run only — that file is byte-identical on both trees).

Mergeability. git diff 3f81d46ac..origin/main over the PR's two files is empty — main's moves since the base (#1493 etc.) touch disjoint files, so this rebases clean. (GitHub still reports mergeable: UNKNOWN at posting time; the checks change-scope and no-game-data were pending at head when I looked.)

Code notes.

  • The narrowed except UnsupportedConstruct matches the sibling tools/shader_diff.py exactly (same import form at its line 42, same catch at its line 252). Worth knowing: spirv_mini_interp also raises InvalidModule (an AssertionError subclass), UndefinedResult, and ValueError, which the old broad except Exception silently turned into skip; these now surface as harness errors (exit 2). That's the item's stated intent — bad module shapes and undefined lane reads are harness bugs, not untested constructs — and it matches the rest of the tool family, so not a concern, just flagging the reclassification.
  • The memory-diff fix is right: main computed bad with unmasked != only after memory != ref.mem, so a zero at an address present on one side only crashed on bad[0]; the new code masks both sides and guards the empty list, and the export compare now masks words to MASK32 and reports export shape mismatch: expected 4 words, translated N for overlong exports instead of crashing.
  • sorted(set(families)) dedup verified: generate_program with families=["s_load","s_load","s_load","global"] reproduces the same lines/memory as the deduped call; without dedup main skews the family sampling.

python -I scripts/check_no_game_data.py tools/mem_diff.py tests/test_mem_diff.py exits 0; compileall clean on both files.

Verdict: LGTM — the four fixes are real crash fixes against the interpreter's known raise types, the regression tests bite only on unpatched main, and the branch rebases onto current main with zero file overlap.

AI-assisted (Hermes overnight shift). Environment: Windows 11, python 3.14.9 -I, no GPU involved.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7161739650 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1679#issuecomment-7161739650). Originally posted by [GrahamboJangles](https://github.com/GrahamboJangles) on 2026-11-25T11:57:54Z. --- Independent review (CPU-only Windows 11, python 3.14.9 `python -I`, fresh clone; head `c064f0718`, current main `57ba40bd6`). **Coordination.** Claim comment 7156347986 (IlyassRS3, 2026-11-25T07:52:26Z) predates the PR (created 07:55:04Z). The #1608 roster shows `MEM-DIFF-COMPARE-AND-HARNESS-ERRORS -> #1679`, and `gh pr list --search "mem_diff" --state all` returns exactly this PR — no duplicate work. **The new test bites (inverse check).** `tests/test_mem_diff.py` at head: `Ran 23 tests ... OK` (the file at main runs 19, so +4 exactly as claimed). The same test file against **main's** `tools/mem_diff.py`: `FAILED (failures=1, errors=3)`, and the errors name the real crashes — `IndexError: list index out of range` twice (zero-valued extra memory entry and overlong `%out_mrt0` export), and the missing `UnsupportedConstruct` name. All 19 pre-existing tests stay green against main, so the delta is fully localized to the new `CompareAndHarnessRegression` class. **Whole-suite check.** Clean main `57ba40bd6`: 915 test files emitting unittest output, 13,976 tests, 6 pre-existing red files (test_bink_names, test_opus_tags, test_runner_calls_all_tests, test_runtime_paths, test_tool_stdout_encoding, test_world_names — all red on main itself, untouched by this PR). On the pr1679 branch tree: 914 files / 13,972. That −8 is noise from the branch base, not a regression: pr1679 is based on `3f81d46ac` and predates the #1493 merge that added `tests/semantic/test_valu_signed_literal64.py` (−8) to main; +4 is the new class. Failing-file sets are identical (plus one flaky `test_run_wine_tests` error on the branch run only — that file is byte-identical on both trees). **Mergeability.** `git diff 3f81d46ac..origin/main` over the PR's two files is empty — main's moves since the base (#1493 etc.) touch disjoint files, so this rebases clean. (GitHub still reports `mergeable: UNKNOWN` at posting time; the checks `change-scope` and `no-game-data` were pending at head when I looked.) **Code notes.** - The narrowed `except UnsupportedConstruct` matches the sibling `tools/shader_diff.py` exactly (same import form at its line 42, same catch at its line 252). Worth knowing: `spirv_mini_interp` also raises `InvalidModule` (an `AssertionError` subclass), `UndefinedResult`, and `ValueError`, which the old broad `except Exception` silently turned into `skip`; these now surface as harness errors (exit 2). That's the item's stated intent — bad module shapes and undefined lane reads are harness bugs, not untested constructs — and it matches the rest of the tool family, so not a concern, just flagging the reclassification. - The memory-diff fix is right: main computed `bad` with unmasked `!=` only after `memory != ref.mem`, so a zero at an address present on one side only crashed on `bad[0]`; the new code masks both sides and guards the empty list, and the export compare now masks words to `MASK32` and reports `export shape mismatch: expected 4 words, translated N` for overlong exports instead of crashing. - `sorted(set(families))` dedup verified: `generate_program` with `families=["s_load","s_load","s_load","global"]` reproduces the same lines/memory as the deduped call; without dedup main skews the family sampling. `python -I scripts/check_no_game_data.py tools/mem_diff.py tests/test_mem_diff.py` exits 0; `compileall` clean on both files. **Verdict: LGTM** — the four fixes are real crash fixes against the interpreter's known raise types, the regression tests bite only on unpatched main, and the branch rebases onto current main with zero file overlap. AI-assisted (Hermes overnight shift). Environment: Windows 11, python 3.14.9 `-I`, no GPU involved.
MoonEyes commented 2026-11-28 14:52:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:52:25Z.


Red/green: the PR tests fail on main (1 failed) and pass on head c064f0718e merged with main (23 passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7241002602 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1679#issuecomment-7241002602). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:52:25Z. --- Red/green: the PR tests fail on main (1 failed) and pass on head c064f0718e42 merged with main (23 passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
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!1679
No description provided.