fog_volumes: find a zlib header that starts on a scan-range boundary (FOG-VOLUMES-SCAN-BOUNDARY) #2108

Closed
syfyra wants to merge 0 commits from upstream-pr/2108 into main
syfyra commented 2026-11-25 20:57:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-25T20:57:59Z.


Claimed in the coordination issue as: FOG-VOLUMES-SCAN-BOUNDARY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7173922396)

What and why

tools/fog_volumes.py scans an RPF in ranges (one per worker) and _scan_rpf_chunk looked for the 2-byte zlib header with ZHDR.search(m, pos, end). A header that starts at end - 1 does not match there, because its second byte lies past end, and the next range starts at end, after its first byte. No range found it, so that fog-volume resource was missing from the report.

Where the ranges split depends on --jobs and the file size (chunk_sz = ceil(size / workers), clamped to 4..64 MiB), so the same archive could give different counts for different --jobs values. The search now runs to end + 1 and keeps only a match that starts before end; a header is still counted by exactly one range. world_census.scan_shard already reads past its end the same way.

Tested

Windows 11, Python 3.14.7, synthetic archives only (built with the test file's build_synthetic_fog_0x7a):

  • python -I tests/test_fog_volumes.py: two new tests, both fail on main and pass with the fix; 12 tests OK.
    • test_a_header_on_a_range_boundary_is_found_once: split points at, before and after one header; on main the split one byte after the header start finds nothing.
    • test_jobs_do_not_change_what_is_found: an 8 MiB + 2 byte archive with a resource at 4 MiB; on main --jobs 1 finds it and --jobs 2 returns ([], 0, 0).
  • A sweep over all 556 split points of an archive with two back-to-back resources: each is found exactly once with the fix; on main two split points lost one of them.
  • python -m compileall; scripts/check_no_game_data.py on both files.

GPUs tested: n/a (CPU-only scanner)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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. (n/a: no translator change)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5499061559 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2108). Originally posted by [syfyra](https://github.com/syfyra) on 2026-11-25T20:57:59Z. --- Claimed in the coordination issue as: FOG-VOLUMES-SCAN-BOUNDARY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7173922396) ### What and why `tools/fog_volumes.py` scans an RPF in ranges (one per worker) and `_scan_rpf_chunk` looked for the 2-byte zlib header with `ZHDR.search(m, pos, end)`. A header that starts at `end - 1` does not match there, because its second byte lies past `end`, and the next range starts at `end`, after its first byte. No range found it, so that fog-volume resource was missing from the report. Where the ranges split depends on `--jobs` and the file size (`chunk_sz = ceil(size / workers)`, clamped to 4..64 MiB), so the same archive could give different counts for different `--jobs` values. The search now runs to `end + 1` and keeps only a match that starts before `end`; a header is still counted by exactly one range. `world_census.scan_shard` already reads past its end the same way. ### Tested Windows 11, Python 3.14.7, synthetic archives only (built with the test file's `build_synthetic_fog_0x7a`): - `python -I tests/test_fog_volumes.py`: two new tests, both fail on `main` and pass with the fix; 12 tests OK. - `test_a_header_on_a_range_boundary_is_found_once`: split points at, before and after one header; on `main` the split one byte after the header start finds nothing. - `test_jobs_do_not_change_what_is_found`: an 8 MiB + 2 byte archive with a resource at 4 MiB; on `main` `--jobs 1` finds it and `--jobs 2` returns `([], 0, 0)`. - A sweep over all 556 split points of an archive with two back-to-back resources: each is found exactly once with the fix; on `main` two split points lost one of them. - `python -m compileall`; `scripts/check_no_game_data.py` on both files. GPUs tested: n/a (CPU-only scanner) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
aslan2142 commented 2026-12-01 12:01:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:01:02Z.

Review: COMMENTED


Draft review against current main: extending the search window by 1 byte (search_end = min(size, end + 1)) while keeping mt.start() < end in tools/fog_volumes.py:179-183 looks clean and clean-room verified, but this branch currently conflicts with main and has no CI run yet. Please rebase onto current main and mark Ready for Review so CI runs green.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130857628 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2108#pullrequestreview-6130857628). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:01:02Z. **Review:** COMMENTED --- Draft review against current `main`: extending the search window by 1 byte (`search_end = min(size, end + 1)`) while keeping `mt.start() < end` in `tools/fog_volumes.py:179-183` looks clean and clean-room verified, but this branch currently conflicts with `main` and has no CI run yet. Please rebase onto current `main` and mark Ready for Review so CI runs green. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 12:20:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:20:28Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310991937 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2108#issuecomment-7310991937). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:20:28Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 12:59:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:59:39Z.

Review: CHANGES_REQUESTED


Now ready for review, requesting changes before merge:

  • Merge conflicts (CONFLICTING/DIRTY): conflicts with main in tools/fog_volumes.py / tests/test_fog_volumes.py. The zlib scan-range boundary fix in tools/fog_volumes.py:179-183 looks solid once rebased.
  • CI: no CI runs on the current head. Please rebase onto current main and get fresh green CI.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6131728106 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2108#pullrequestreview-6131728106). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:59:39Z. **Review:** CHANGES_REQUESTED --- Now ready for review, requesting changes before merge: - **Merge conflicts (`CONFLICTING`/`DIRTY`)**: conflicts with `main` in `tools/fog_volumes.py` / `tests/test_fog_volumes.py`. The zlib scan-range boundary fix in `tools/fog_volumes.py:179-183` looks solid once rebased. - **CI**: no CI runs on the current head. Please rebase onto current `main` and get fresh green CI. *(AI-assisted review.)*
aegish-zagi commented 2026-12-02 04:51:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aegish-zagi on 2026-12-02T04:51:54Z.


Verification — VERIFY-2108

Verdict: PASS (with a rebase note: the test file conflicts with current main)

  • PR: #2108 | head sha: 289c910baa2b96cc6994c4bb4e5d5acd55aa0013 | merge state vs main 8422def759cda12c89f918438eeb8d53dd5972a6: CONFLICT in tests/test_fog_volumes.py only — tools/fog_volumes.py merges cleanly. The PR head as-is was tested.
  • Tests run: python3 -I tests/test_fog_volumes.py
  • Red on main vs green on PR: on plain main code with the PR test file, exactly the two new tests FAIL — test_a_header_on_a_range_boundary_is_found_once (split=257) and test_jobs_do_not_change_what_is_found (jobs=2); Ran 12 tests — FAILED (failures=2, skipped=1). On the PR head: Ran 12 tests — OK (skipped=1).
  • Audit (READ IN CODE): the fix extends the header search one byte past the range end (search_end = min(size, end + 1)) and discards a match starting at or past end, so a header straddling the boundary is claimed exactly once, by the range it starts in. No game data in the diff.
  • Platform: Linux, Python 3.12.3, no GPU (Profile Z)

AI-assisted: yes (Muse Wonder, Muse by Meta)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7335338686 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2108#issuecomment-7335338686). Originally posted by [aegish-zagi](https://github.com/aegish-zagi) on 2026-12-02T04:51:54Z. --- ## Verification — VERIFY-2108 **Verdict: PASS (with a rebase note: the test file conflicts with current main)** - PR: #2108 | head sha: `289c910baa2b96cc6994c4bb4e5d5acd55aa0013` | merge state vs main `8422def759cda12c89f918438eeb8d53dd5972a6`: CONFLICT in `tests/test_fog_volumes.py` only — `tools/fog_volumes.py` merges cleanly. The PR head as-is was tested. - Tests run: `python3 -I tests/test_fog_volumes.py` - Red on main vs green on PR: on plain main code with the PR test file, exactly the two new tests FAIL — `test_a_header_on_a_range_boundary_is_found_once` (split=257) and `test_jobs_do_not_change_what_is_found` (jobs=2); `Ran 12 tests — FAILED (failures=2, skipped=1)`. On the PR head: `Ran 12 tests — OK (skipped=1)`. - Audit (READ IN CODE): the fix extends the header search one byte past the range end (`search_end = min(size, end + 1)`) and discards a match starting at or past `end`, so a header straddling the boundary is claimed exactly once, by the range it starts in. No game data in the diff. - Platform: Linux, Python 3.12.3, no GPU (Profile Z) AI-assisted: yes (Muse Wonder, Muse by Meta)
MoonEyes commented 2026-12-02 10:32:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:32:25Z.


For information: this pull request is carried in #3091, which merges your head (your commits are kept) into current main, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7342618735 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2108#issuecomment-7342618735). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T10:32:25Z. --- For information: this pull request is carried in #3091, which merges your head (your commits are kept) into current `main`, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed. AI-assisted (Claude Code, Claude Opus 5.5)
MoonEyes commented 2026-12-02 11:49:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T11:49:46Z.


Closing: this pull request no longer applies to current main (merge conflict in tests/test_fog_volumes.py), and open pull requests that have fallen out of step with main are being closed so the list stays workable. Your work is not lost: it is carried in #3091
, which keeps your commits and resolves the conflict on current main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7344463449 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2108#issuecomment-7344463449). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T11:49:46Z. --- Closing: this pull request no longer applies to current `main` (merge conflict in `tests/test_fog_volumes.py`), and open pull requests that have fallen out of step with `main` are being closed so the list stays workable. Your work is not lost: it is carried in #3091 , which keeps your commits and resolves the conflict on current `main`. AI-assisted (Claude Code).

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!2108
No description provided.