Skip to content

fix(tools): validate First Light manifest coverage bounds (Codex) - #5843

Open
evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:codex/first-light-finite-coverage-bounds
Open

evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:codex/first-light-finite-coverage-bounds

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: EGEN-FIRST-LIGHT-FINITE-COVERAGE-BOUNDS

Depends on: #3751 (its existing First Light merge conflicts still need resolution)

What and why

Reject non-finite and nonnumeric coverage bounds in saved First Light manifests. A bound that cannot represent a numeric threshold can either admit an invalid frame or raise a Python error. Name the invalid field and preserve inclusive comparisons and the defaults for omitted bounds.

Tested

AI-assisted: yes

Checklist

  • No game data, keys or decryption.
  • Translator rule contract update (inapplicable to this manifest check).

@whattheflop

whattheflop commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted Windows CPU compatibility check with uv CPython 3.12.13. #5843 88c1a51a and #5782 cf9dfe23 applied cleanly onto the tested #4763 source at 298c43ce in a disposable tree. Its First Light suite passed 41 with 8 existing skips, and mesh CLI tests passed 8/8.

With a stock-style mocked 2×2 RGBA readback, --check --png produced a 74-byte PNG for each of default bounds, explicit finite clear, and exact inclusive min=max=0.5. Omitting --png produced no preview. On #4763 alone an infinite max let the PNG through. In the combination, the CLI named the non-finite bound or clear value and produced neither PNG nor PPM. A previously seeded stale PNG was removed in both failure cases. This verifies the optional preview lifecycle on the combined helper, without Vulkan or game inputs.

@leozinhoszg

Copy link
Copy Markdown
Contributor

Tested 88c1a51a on Windows 11 Pro (26200), CPython 3.14.7, CPU only, no game files: pass with notes. NumPy was used only in a probe.

  • python -I tests/test_first_light.py: 48 tests OK (4 skipped). compileall on both files and git diff --check origin/main...HEAD are clean.

  • Negative control (tools/first_light.py from main, the new tests kept): test_coverage_bounds_must_be_finite_numbers fails 12 subtests. That is 8 failures (NaN, ±inf and True for both fields) and 4 TypeErrors (None and "0.5"). The inclusive/optional test passes on main, which is expected because it guards behaviour that should stay the same.

  • Merged trees: with fix(tools): reject non-finite First Light clear values (Codex) #5782 (non-finite clear) the merge is clean and 49 tests pass, both PRs' new tests included. With first_light: honor explicit minimum coverage on recheck #3751 the merge is also clean and 50 tests pass.

  • I ran a probe on a 2x2 image with ratio 0.25 and set each bound alone. The table compares main with this PR:

    bound main this PR
    0, 1, 0.25, -0.0 (int or float) same result same result
    NaN, either field refused: coverage 0.2500 outside [nan, ...] refused: <field> must be a finite number
    min=inf, max=-inf refused (coverage message) refused (named field)
    min=-inf, max=inf (also 1e999 from JSON) accepted refused
    None, "0.5" TypeError traceback refused, one line through run_draw's SystemExit
    min=False, max=True accepted as 0 / 1 refused
    min=-1, max=2 accepted accepted
  • No legitimate bound is refused. type(value) not in (int, float) also refuses int subclasses, NumPy scalars, Fraction and Decimal, but no caller produces those. A recheck reads the manifest with a plain json.load (tools/first_light.py:868), which returns only int/float. --min-coverage is type=float (:919-920). The written defaults are the float literals 0.2/0.5 (:969) and 0.99 (:1077), and the omitted-key defaults are 0.0/1.0 (:716-717). Integer 0 and 1 still pass.

  • FYI on the description: on main, NaN already failed closed, because not nan <= ratio is true and raises. The only non-finite bounds main accepted were min=-inf and max=inf. They admit exactly the frames that min=-1/max=2 admit, and this PR still accepts those finite values, because ratio is always in [0, 1]. So no invalid frame could get through. What this PR really adds is the field-named error for NaN/inf/bool and one error line instead of a traceback for None or a string. That is worth having.

  • The CLI side is not covered here. --min-coverage nan, inf or --min-coverage=-inf still passes argparse. The value is then written into manifest.json as NaN/Infinity (:1076, :1134-1135) and caught only after the harness draw (run_draw, :827 then :833). first_light: honor explicit minimum coverage on recheck #3751's 0 <= a.min_coverage <= 1 ap.error closes that, NaN included, so nothing is needed in this PR. One small point: this branch does not use any code from first_light: honor explicit minimum coverage on recheck #3751. It merges cleanly on main by itself, and first_light: honor explicit minimum coverage on recheck #3751 now merges cleanly with both main and this PR. So "Depends on: first_light: honor explicit minimum coverage on recheck #3751" and the note about shared conflicts look out of date.

  • Optional, and already true on main: a bad bound in a saved manifest is reported only after --check has deleted the old image.raw/image.ppm (:820-826) and run the harness (:827). A check before the draw, or a small coverage_bounds(manifest) helper called from both places, would fail before any GPU work.

  • FYI, not from this PR: a manifest with width: 0, height: 0 and an empty raw passes the size check. It then raises ZeroDivisionError at ratio = covered / (width * height) (:715) instead of an AssertionError.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 88c1a51 merged with main 561b65a on Linux (WSL2) Python 3.12.16: pass

tests/test_first_light.py: 48 run, 44 passed, 0 failed, 4 skipped (the same 4 skips occur with the upstream/main tools file).

Negative control: restoring tools/first_light.py from upstream/main (keeping the PR's test) gives 48 run, 8 failures + 4 errors, all in test_coverage_bounds_must_be_finite_numbers subtests (nan, +/-inf and True accepted silently; None and "0.5" raise a TypeError instead of the AssertionError). With the PR's change all subtests pass. File restored afterwards.

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.

4 participants