Skip to content

first_light: honor explicit minimum coverage on recheck - #3751

Open
Desamodeth wants to merge 3 commits into
ItsNotRexed:mainfrom
Desamodeth:fix/first-light-check-min-coverage
Open

Desamodeth wants to merge 3 commits into
ItsNotRexed:mainfrom
Desamodeth:fix/first-light-check-min-coverage

Conversation

@Desamodeth

@Desamodeth Desamodeth commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

BUILD-1069 (claim).

On main (f847748c), rechecking a prepared output with --min-coverage 0.285 exited 0 for a draw covering 288/1024 pixels (0.28125). The parser accepted the flag, but the recheck only consulted the manifest's saved minimum of 0.28.

An explicit minimum now applies to that recheck. A successful draw records the effective threshold in result.min_coverage; the top-level minimum still governs subsequent runs without the flag. A new preparation still defaults to 0.5. Main already rejects thresholds outside [0, 1], including nonfinite values, via #6611. This PR adds test coverage for that existing validation. Its regression test covers the explicit threshold being ignored on recheck.

Tested on Windows 11 with an RTX 5070, driver 621.24, and a synthetic triangle. With the patch, the same command exits 1 at 0.285 and succeeds exactly at 0.28125. A following run without the flag uses 0.28. Also checked an older manifest with no minimum. Both First Light test files pass (22 tests), including the new regression, which failed on main. The same suite passes when combined locally with #3606 (23 tests). No game data used.

AI-assisted (Codex Astra 6.2 High).

Textured GPU recheck at 22d8c9cd. Native Windows, MSVC 19.44, RTX 5070 (621.24), Release vk_harness built from this head. A synthetic indexed triangle sampled a fully transparent RGBA8 texture. The raw 32x32 frame contained 288 transparent green pixels and 736 clear pixels. On the same input, main (3faac557) accepted a 28.5% minimum. This head rejected it, accepted exactly 28.125%, and used the saved 28% on the next plain recheck. Switching the texture to transparent blue kept coverage identical and failed the green color probe; updating the expected color passed. All 9 targeted FirstLightTests and OracleTests passed without skips.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Second check on Windows at 00097b9d. Ten focused CPU tests passed, including the 0.5 default for a new preparation. An independent stub readback covered 4/16 pixels. With a saved minimum of 0.20, the base accepted an explicit 0.30 and this head rejected it. An explicit 0.25 passed and was recorded for that draw. With a saved minimum of 0.35, an explicit zero passed on this head, and the next run without the flag still failed against 0.35. Legacy manifests without the field still used zero when no flag was passed.

NaN, both infinities, and values below zero or above one exited 2 on this head before launching the stub. These checks used synthetic bytes and a stub harness. The GPU measurements are from the author's run.

AI-assisted.

@kacper-serewis kacper-serewis 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.

At 00097b9 a 4/16 synthetic draw passed the explicit 0.25 boundary, failed at 0.250001, and used the saved 0.3 when omitted. Failed runs preserved the manifest byte for byte. Nonfinite arguments exited 2 before the harness. 19 suite tests passed and three skipped. CPU CLI review, AI-assisted.

@leoleahy

Copy link
Copy Markdown
Contributor

Independent CPU review at 00097b9d on Windows (CPython 3.14.8, no GPU, no game files): pass.

  • python -I tests/test_first_light.py: 13 tests (10 OK, 3 skipped).
  • Negative control (head tests against merge base f847748c tools/first_light.py): 6 failures, confirming the tests pin the --min-coverage recheck override and bounds check.
  • Code check: not 0 <= a.min_coverage <= 1 also rejects NaN cleanly; recheck passes min_coverage=a.min_coverage into run_draw() without mutating the saved manifest.json default.

AI-assisted.

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 22d8c9cd with CPython 3.12.8. Applied the published patch to a scratch copy of base 3faac557.

  • python -B -I tests/test_first_light.py -v completed successfully. The four companion test_first_light_*.py modules passed all 17 tests. The main module reported 12 skips covering package and GPU checks and link-creation subtests.
  • The recheck used an explicit minimum for one draw, including an override of zero, then used the saved minimum on the next draw. Invalid and non-finite thresholds were rejected. Both new regression tests passed with the patch and failed using the base implementation.

CPU only, with synthetic fixtures. AI-assisted.

@Andretuta

Copy link
Copy Markdown
Contributor

Tested 22d8c9c on Linux, CPU only: pass

  • python -I tests/test_first_light.py: 30/30 OK (4 skipped); compileall clean.
  • nan/inf/negative/>1 rejected at exit 2; explicit override applies to one recheck without rewriting the saved minimum (saved 0.2, result 0, both verified); boundaries 0 and 1 behave.

AI-assisted (Devin); no game files

@B0D0PAD

B0D0PAD commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Independent check on Windows 11 (Python 3.14.6) — CPU only, no game files, no GPU.

PASS at 22d8c9cd584c:

  • python -I tests/test_first_light.py → 30 tests, OK. The 8 skips are environmental (LEONIDA_FIRST_LIGHT_DIR unset, no symlink privilege on Windows, vk_harness not built) and none of them covers this change.
  • Negative control: with main's tools/first_light.py (3faac557) the same file fails 6 tests, including test_recheck_honors_explicit_coverage_without_changing_the_saved_minimum and test_min_coverage_must_be_a_fraction.

Checked the contract beyond the tests:

  • A recheck with --min-coverage overrides only the copy handed to check_image() (criteria); manifest["min_coverage"] itself is untouched and only manifest["result"] records the value used, so the next bare --check is back on the saved 0.2 — which the test asserts.
  • A fresh draw still saves 0.5 when the flag is omitted, and check_image() reads the value with manifest.get("min_coverage", 0.0) (tools/first_light.py:550), so manifests written before this change keep working.
  • nan/inf/-inf and out-of-range values exit 2 through ap.error() (NaN fails the 0 <= x <= 1 comparison), with the message the test matches.

Nothing else references the flag (no min-coverage in README.md or under docs/), so no doc needs syncing with the new "overrides the saved minimum for one recheck" behaviour.

@KkelebekK

Copy link
Copy Markdown

Reviewed 22d8c9cd (tools/first_light.py --min-coverage handling on --check recheck + tests/test_first_light.py, run on the head, red-before / green-after against main's tool): looks right

  • Green on the head: python3 -I tests/test_first_light.py Ran 30, OK (skipped=4: need LEONIDA_FIRST_LIGHT_DIR / a built vk_harness, unrelated). Sibling files test_first_light_bad_json.py, _harness_paths.py, _mesh_draw.py (3 tests), _stale_mesh.py (1 test): all OK.
  • Red on main: with origin/main's tools/first_light.py and the PR's test file, 6 failures: test_min_coverage_must_be_a_fraction for -inf, nan, inf, -0.1, 1.1 (main gets --game is required, not exit 2) and test_recheck_honors_explicit_coverage_without_changing_the_saved_minimum. I.e. on main, --check --min-coverage 0.3 is silently ignored on a recheck (the saved manifest's minimum is used) and out-of-range values are not rejected. (Tool restored afterwards; tree clean.)
  • Code: --min-coverage default is now None (:744); a new draw saves 0.5 if unset (:863, asserted by the new manifest["min_coverage"] == 0.5 line); a recheck passes the flag to run_draw (:792), which overrides the criteria for that one check (:656) and records the value it used in result.min_coverage (:671) without changing the saved top-level min_coverage (the test asserts saved 0.2, result 0 after --min-coverage 0, and 0.2 again after a plain --check). The other run_draw call after a fresh prepare (:932) has no override and uses the manifest, which now carries the flag value, so it is consistent.
  • Input probes: --min-coverage=nan and the bounds exit 2 with --min-coverage must be between 0 and 1; 1e-1000 (underflows to 0.0) is accepted as 0, which is in range. json.dump never sees a NaN because of the range check. I found no input that breaks it.
  • Not checked: --check against a real harness image (no vk_harness here); the test patches subprocess.run. Docs have no mention of the flag, so none to update.

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.

Review: head 22d8c9cd5 (base 3faac557b, Windows 11)

  • python -I -m pytest tests/test_first_light.py -q -> 26 passed, 8 skipped, 13 subtests passed
  • git diff --check -> clean

Skips are environmental: LEONIDA_FIRST_LIGHT_DIR unset (3), symlink creation not permitted (4), vk_harness not built (1) — none are in the touched recheck path.

The new tests check that an explicit --min-coverage overrides only that recheck, does not change the saved manifest bytes or its min_coverage, records the used threshold under result.min_coverage, and that the next plain recheck returns to the saved value; values outside [0, 1] exit 2. A new draw still records 0.5 by default.

Verdict: pass.

AI-assisted-by: Codex Astra 6.2 High
@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 1eeb4865 merged onto main 561b65a8 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I tests/test_first_light.py: 48 tests OK (skipped=8).
  • Negative control (tools/first_light.py from main, the PR's tests kept): tests/test_first_light.py 48 tests FAILED (failures=6, skipped=8).
  • py_compile on the 2 changed Python files: OK; git diff --check: clean.

No game files. AI-assisted (Claude Code).

@Desamodeth

Copy link
Copy Markdown
Contributor Author

Checked the red macOS job against the job on the exact base, 561b65a8. Both fail the same two MoltenVK GPU cases, cs_fmt_int_narrow and cs_w32_permlane_fi. On Windows, the five first-light test files on a trial merge with 8575d36e ran 66 tests with 12 skips and no failures (CPU only). AI-assisted.

@Desamodeth

Copy link
Copy Markdown
Contributor Author

Merged main bf85ff70 at 205afd12, retaining #6611's range check. The remaining change applies an explicit minimum to one recheck.

On Windows (MSVC 19.44 Release, RTX 5070, driver 621.24), I rebuilt the Vulkan harness and ran the same synthetic textured draw against main and this head. Both drew 288 of 1,024 pixels. Main accepted a 28.5% minimum. This head rejected 28.5%, accepted exactly 28.125%, and used the saved 28% on the next recheck. Changing the texture color still failed the color probe at the same coverage.

All five First Light test files ran (66 tests, no failures, four symbolic-link subcases skipped on this Windows account). AI-assisted.

@skorex

skorex commented Nov 23, 2026

Copy link
Copy Markdown

Tested 205afd1 on Linux (WSL), Python 3.13: pass.

Ran: python3 -I tests/test_first_light.py (49 tests, pass; 4 skipped: 3 need LEONIDA_FIRST_LIGHT_DIR, 1 needs a built vk_harness), tests/test_first_light_bad_json.py, _harness_paths.py, _mesh_draw.py, _stale_mesh.py (pass), python3 -m compileall -q make_game.py tools tests (clean). With this PR's test file on origin/main, only test_recheck_honors_explicit_coverage_without_changing_the_saved_minimum fails, as expected (the range-check test already passes there since #6611).
Not run: the GPU draw (no Vulkan, no MSVC here).

Code read: moving the 0.5 / 0.2 default below the recheck branch is safe, a.min_coverage has no other reader between the two points, and the preparation path ("min_coverage": a.min_coverage in the new manifest) still gets the default. A failed recheck leaves the saved min_coverage untouched because only criteria, a copy, carries the override; the second run_draw caller (after preparation) passes no override, so it is unchanged.

AI-assisted review (Claude Code).

@tulerws

tulerws commented Nov 23, 2026

Copy link
Copy Markdown

Tested 205afd1 on CPU-only, Pop!_OS 24.04 LTS (Linux x86_64 7.2.15), Python 3.12.3: pass

Checks run (no game files, no GPU):

  • git apply --check against origin/main (dde82f27e): clean (also applies cleanly combined with fix(first-light): select same-stage shader variants by archive offset (BUILD-834) #2893 at eaa6291317, with all 6 First Light suites passing together).
  • python3 -m compileall -q tools/first_light.py tests/test_first_light.py: pass
  • python3 -I scripts/check_no_game_data.py tools/first_light.py tests/test_first_light.py: pass
  • git diff --check origin/main...205afd1205: pass
  • python3 -I tests/test_first_light.py -v: 49 run, 45 passed, 4 skipped (all Linux symlink subcases ran; skips are LEONIDA_FIRST_LIGHT_DIR / vk_harness)
  • python3 -I tests/test_first_light_bad_json.py -v: 9/9 passed
  • python3 -I tests/test_first_light_harness_paths.py -v: 4/4 passed
  • python3 -I tests/test_first_light_mesh_draw.py -v: pass
  • python3 -I tests/test_first_light_stale_mesh.py -v: 1/1 passed
  • Negative control (this PR's tests/test_first_light.py against unmodified origin/main tools/first_light.py): 49 run, 1 failed (test_recheck_honors_explicit_coverage_without_changing_the_saved_minimum), 4 skipped.
  • Additional edge-case checks:
    • Failing a recheck with an explicit --min-coverage 0.3 clears a pre-existing stale result from manifest.json while keeping the saved min_coverage (0.2) intact.
    • Rechecking a manifest that omits min_coverage passes and records result.min_coverage: 0.0 (matching check_image()'s default) without adding a top-level min_coverage key.

Code looks clean and minimal; no issues found.

AI-assisted: yes

@Luqueze

Luqueze commented Nov 23, 2026

Copy link
Copy Markdown

Code read of 205afd12 against main dde82f27 (no checkout, nothing run): looks right.

  • tools/first_light.py (main(), ~977/997 on main): moving the 0.5 / 0.2 default below the recheck branch is the only change to defaults. a.min_coverage is read only at the range check (963) and when a fresh manifest is written (1085), so preparing a new output, and a plain --check with or without --camera, behave as before. Only an explicit flag on a recheck changes anything.
  • run_draw (808-853): the override goes only into the criteria copy passed to check_image. The saved top-level min_coverage is not touched. result.min_coverage uses criteria.get("min_coverage", 0.0), which matches check_image's own default at 720, so older manifests without the key record 0.0.
  • test_recheck_honors_explicit_coverage_without_changing_the_saved_minimum fails on main by reading. test_min_coverage_must_be_a_fraction already passes on main, because Validate first-light coverage thresholds #6611 (7deb162b) added the check at 963-964 without a test. That test is useful coverage, but not a regression test for this change, and the PR body still lists the bounds check as part of this PR.
  • Dropping import contextlib is safe (1003 was its only other use). No other open PR changes the same lines (first_light: a bad texture field in a rechecked manifest.json is one error line, not a traceback #5145 is close in run_draw but does not overlap).

AI-assisted (Claude Code).

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

Read 205afd12 on Linux (CPython 3.12.16): the change is correct.

Moving the 0.5/0.2 default below the recheck branch lets an explicit --min-coverage apply to that one draw through the copied criteria dict, while the saved manifest keeps its own value and result.min_coverage records the threshold actually applied. python3.12 -I tests/test_first_light.py: 49 ran, 45 passed, 4 skipped (the LEONIDA_FIRST_LIGHT_DIR / vk_harness skips). With tools/first_light.py reverted to bf85ff70 the new recheck test fails with SystemExit not raised, so it pins the change.

I also checked the one in-repo consumer of the saved minimum: runtime/test/d3d12_first_light_test.cpp:293 reads the top-level min_coverage, which this PR deliberately leaves alone, so the D3D12 oracle is unaffected. No defect found.

AI-assisted.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 205afd12 on Linux, CPython 3.14, CPU only, synthetic inputs, merged onto main dde82f27: pass

  • python -I tests/test_first_light.py: Ran 49 tests, OK (skipped=4). With only tools/first_light.py reverted to main: FAILED (failures=1, skipped=4), so the new recheck test exercises the change.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting; claimed in #8047.

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.