Skip to content

fix(tools): clear stale First Light draw results (Codex) - #4136

Open
evilclanker9000 wants to merge 7 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/first-light-failed-redraw
Open

evilclanker9000 wants to merge 7 commits into
ItsNotRexed:mainfrom
evilclanker9000:codex/first-light-failed-redraw

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: EGEN-FIRST-LIGHT-FAILED-REDRAW

What and why

A rejected First Light redraw could leave the previous preview and coverage result alongside its new raw readback. Starting a draw now clears the previous preview and result. If the new frame fails the coverage check, its raw readback stays available for diagnosis. A successful retry writes a fresh preview and result.

Tested

  • Windows x64, Python 3.12.10, synthetic readback stub. The new success → blank frame → success regression failed on the base because the old preview still existed. With the change it verifies the blank raw frame remains, the old preview and result are cleared, and the retry writes a new preview and records 50% coverage.
  • python -B -I tests/test_first_light.py -v reported 16 passed and 4 hardware/package-gated skips.
  • python -B -I tests/test_text_write_line_endings.py reported 3 passed. git diff --check passed.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

Notes

The check uses Windows CPU only. No GPU, driver or native harness was used. The translator checklist item is inapplicable.

AI-assisted.

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

AI-assisted Windows verification of 5672a222 against parent aa2988cc, uv CPython 3.12.13, synthetic readback only. A separate child-process fixture started with a 50%-covered draw. On exit 7 with and without fresh bytes, and on exit 0 without a readback, the parent kept the old PPM and result while this PR cleared both. Any new raw bytes survived. Retrying in the same directory wrote the exact expected raw and PPM and published 75% coverage in all cases.

Harness lookup happens before cleanup, so a missing harness preserves the previous raw, preview, and result together on both revisions. The stock suite passed 16 tests with four gated skips on head, and the head regression failed on parent as expected. No GPU or game data used.

@tupacfan04

Copy link
Copy Markdown
Contributor

Verified at the head on Windows 11 / Python 3.13.0: 36 run / 4 skip / 0 fail, the new test passes, compileall and git diff --check clean, merge clean. Negative control: restoring main's tools/first_light.py fails exactly the new test (tests/test_first_light.py:182).

The behaviour is right: tools/first_light.py:506-516 deletes raw and PPM and removes manifest["result"] before every draw; a rejected frame keeps only the new raw readback with no preview or result; a success writes both (:529-537). The harness-not-found path exits before cleanup (:496), but there is no new readback there, so nothing stale is left.

Approve. AI-assisted review, no game files, no GPU.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 5672a22 merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass.
Ran tests/test_first_light.py (29 tests, OK, 4 skipped).
Negative control: with main's tools/first_light.py the new test_failed_recheck_clears_previous_preview_and_result FAILS (1 failure), passes with the PR.
Read tools/first_light.py: image.raw and image.ppm are now removed and a stale manifest "result" is dropped before the harness runs, so a failed re-draw cannot leave an old preview or success report. Looks correct.

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

Tested 2c63a0d6 on Windows, then merged #3751 (22d8c9cd) and #3606 (d2120f41) locally without conflicts. I ran the real first_light.py --check CLI against a synthetic CPU harness, reusing the same saved run.

A frame with 25% coverage failed at a 30% threshold. A separate frame failed on a NaN UV probe. Both times the new raw bytes were retained and the old preview and success result were cleared. A retry at exactly 25% wrote the changed preview, and a later run used the saved 20% threshold. The same sequence on #3751 alone reproduced the stale preview and result on both failures.

The First Light suite reported zero failures on the PR head (30 tests) and the combined tree (33). Both reported eight skips for fixture, harness, or Windows symlink availability. CPU only, no game files. AI-assisted.

@Kadthicu

Copy link
Copy Markdown
Contributor

At 2c63a0d6, the existing test_only_successful_prepare_invalidates_previous_readback passes on Linux (CPython 3.12.14). I extended that synthetic test to seed image.ppm beside the prior image.raw and assert it is gone after the successful prepare-only run. That assertion fails: the new manifest has no result and the raw file is gone, but image.ppm still shows the previous mesh. Could the successful prepare path invalidate the old preview too, with a test that also preserves it on failed preparation? CPU only, no game files. AI-assisted (Codex).

@Kadthicu

Copy link
Copy Markdown
Contributor

Re-checked e28715cb on Linux (CPython 3.12.14). Both focused tests passed: test_only_successful_prepare_invalidates_previous_readback and test_failed_recheck_clears_previous_preview_and_result. The previous preview survives failed preparation and is cleared after successful preparation. This resolves my stale-preview finding. Synthetic fixtures only, CPU only. AI-assisted (Codex).

@S1m0ne1997

Copy link
Copy Markdown
Contributor

Reviewed and tested e28715cb on Windows 11 (CPython 3.12): pass.

  • tests/test_first_light*.py (5 files): all OK. The branch merges cleanly with current main.
  • Code read: the two new tests cover what the description says.
    • A failed prepare (bad OBJ, then a locked image.raw) leaves the previous readback, preview and result untouched.
    • A successful prepare drops all three.
    • On --check, a frame outside the coverage range keeps its own raw readback for diagnosis but removes the old image.ppm and result, and a good retry writes them again.
  • Overlap: this PR and first_light: a bad texture field in a rechecked manifest.json is one error line, not a traceback #5145 (also tools/first_light.py, the harness_env field checks) conflict with each other (git merge-tree pr-4136 pr-5145). Whichever is merged second will need a rebase.

AI-assisted (Claude Code).

@KkelebekK

Copy link
Copy Markdown

Reviewed e28715cb (head moved from 2c63a0d6; diff since then read, tests re-run, red/green re-done, merge re-tested): looks right; the gap I noted on 2c63a0d6 (stale image.ppm after a re-prepare) is now closed.

  • Since 2c63a0d6 (git diff 2c63a0d6 e28715cb, 2 files, +23 -5): in main() the prepare step now moves image.ppm into the manifest staging folder (tools/first_light.py:922-926), unlinks image.raw and os.replaces the manifest, and on OSError moves the preview back and re-raises (lines 927-939); the test (renamed test_only_successful_prepare_invalidates_previous_draw) now also writes a real preview and asserts it survives a bad OBJ and a locked image.raw, and is gone after a successful prepare. run_draw is unchanged (still clears raw, preview and result before the harness, find_harness first).
  • Head tests: test_first_light.py 30 run, OK, 4 skipped; test_first_light_bad_json 9 OK, _harness_paths 4 OK, _mesh_draw 3 OK, _stale_mesh 1 OK, test_text_write_line_endings 3 OK, test_tool_stdout_encoding 4 OK.
  • Red/green: with the 2c63a0d6 tool file, the new head tests fail 1 (test_only_successful_prepare_invalidates_previous_draw); with the merge-base tool (aa2988cc) they fail 2 (that one and test_failed_recheck_clears_previous_preview_and_result); with the head's file all pass. The earlier-failing case (success -> blank frame -> retry) is unchanged and still green.
  • The earlier gap, re-run with the same stubs: prepare, put a file named image.ppm in out/, prepare again with a changed OBJ: image.ppm survived on 2c63a0d6; on e28715cb it is gone. Failure injection: with os.replace raising PermissionError for manifest.json, the old preview is put back (image.ppm bytes equal the original) and the error propagates.
  • Merge: git merge-tree --write-tree origin/main with this head is clean; on the merge in a detached worktree (removed after) the five first-light test files and test_tool_stdout_encoding.py are OK (same counts as above).
  • Remaining nit, minor: if the manifest os.replace fails after image.raw was already unlinked, the old preview and manifest come back but the old raw does not (same order as before). Not reachable by the stated cases.
  • Not checked: a real harness/GPU draw (no GPU); Windows behaviour of os.replace onto a manifest another process holds open.

AI-assisted.

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

One data-preservation issue at e28715cb: prepare accepted an existing directory at the preview path and removed it. I confirmed this on Windows with an empty disposable directory. Tested patch on your head rejects that layout before rewriting the mesh and checks again before staging the preview. The regression checks the directory, mesh, raw frame and manifest.

There is also one merge conflict with #5145 (8fa510d3) in run_draw. Keep its early harness_env call, this PR's ppm and manifest_path assignments, and this PR's single cleanup loop. On that resolution a rejected manifest left the previous frame intact without launching the harness; a newly drawn blank frame cleared the old preview/result; a valid retry wrote a fresh preview. Both controls failed on the respective single branches as expected.

First Light suite on Windows with the patch: 48 tests on this head, 55 on the combined tree, zero failures and eight environment skips in each. CPU only, synthetic fixtures, AI-assisted.

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

Rechecked 8a129927 on native Windows with CPython 3.12. The new test for an existing image.ppm directory passes. The other new test, test_prepare_preserves_a_directory_created_during_preview_move, fails with AssertionError: OSError not raised. I traced the stock test: its callback ran, os.replace returned successfully, and the staging destination was then a directory. The pre-created empty file therefore does not keep a directory out of recursive staging cleanup on this machine.

Please keep this regression and use cleanup that can only unlink the files owned by this operation. python -B -I -m unittest discover -s tests -p "test_first_light*.py" ran 49 tests with one failure and eight skips outside the sandbox. CPU only, synthetic fixtures. AI-assisted.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Reviewed 88d309f (CPU, Linux, Python 3.13): no defects found

  • Base: PR head merged onto origin/main 3faac55 (all merged cleanly), RunPod, CPU only, Linux, Python 3.13.18, python -I per test file. Negative control: the PR test files run against main's code.
  • Head moved while I worked (e28715c to 88d309f: preview path that is a directory is now rejected, preview is copied then unlinked instead of renamed). I read both diffs and ran the tests on 88d309f.
  • tests/test_first_light.py: 30 run, OK (4 skipped). On main's code with the PR tests: 30 run, 2 failures.
  • tests/test_first_light_mesh_draw.py: 5 run, OK. On main's code with the PR tests: 5 run, 2 failures.
  • Code read: run_draw deletes old raw and ppm and drops result before the harness runs, so a failed or rejected draw leaves no stale success. The prepare step stages the old preview and restores it if publishing the manifest fails. I found no case that loses data. I could not reproduce any defect.
  • I did not run the Windows-only branches (locked file on unlink).

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

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

Confirmed on native Windows at 88d309f2: both directory-preservation regressions pass, including the case that failed at 8a129927. First Light discovery ran 49 tests, zero failures, eight environment skips. My Windows finding is resolved. CPU only, AI-assisted.

ItsNotRexed added a commit that referenced this pull request Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@evilclanker9000

Copy link
Copy Markdown
Contributor Author

On fc6ce1c, the macOS build passed and all 62 CTest runtime tests passed. The MoltenVK GPU step failed on cs_fmt_int_narrow (120-second timeout) and cs_w32_permlane_fi (same output mismatch). The macOS run on the exact base 561b65a8 failed on those same two cases. PR job. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested fc6ce1c merged with main 561b65a on Linux (WSL2), CPython 3.12.16, CPU only: pass.

  • tests/test_first_light.py: 47 (4 skipped); tests/test_first_light_mesh_draw.py: 5/5.
  • Negative control: with main's tools/first_light.py the two files fail (failures=1 and failures=2).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Reviewed correctness fix in PR #4136: fix(tools): clear stale First Light draw results (Codex).

Scope: tests/test_first_light.py, tests/test_first_light_mesh_draw.py, tools/first_light.py
Diff: +156 / -2 across 3 file(s).

The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.

Reviewed by shayderrr via automated batch review.

@shayderrr

Copy link
Copy Markdown
Collaborator

Thanks @evilclanker9000 - I went through fix(tools): clear stale First Light draw results (Codex) and the diff around tests/test_first_light.py. The change is tight, the rationale matches the code, and there's nothing here that needs another pass from my side. Approved and squash-merging it into main now. Nice work.

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.

10 participants