build_dstorage_history: include packed depth-1 mips in first 256 blocks (DSTORAGE-FIT-SLICES-PACKED-MIP) #2148

Merged
abnalstlll-byte merged 3 commits from upstream-pr/2148 into main 2026-11-28 15:03:58 +00:00
abnalstlll-byte commented 2026-11-25 23:34:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-25T23:34:44Z.


Include packed depth-1 mips whose first block lies in the chunk's first 256 blocks in fit_slices() (DSTORAGE-FIT-SLICES-PACKED-MIP).

Problem

In tools/build_dstorage_history.py::fit_slices(), packed depth-1 mips were skipped if their first block fell within the chunk's first 256 blocks:

if d["depth"] == 1:
    first = start + calib.tiled_offset(layout, mip, 0, 0) - virt
    if not 256 * 16 <= first < blocks * 16:
        continue

This was based on the premise that "the usual 2D fit visits only the first 256 physical blocks". However, in packed tails, calibrate_from_pools() does not necessarily visit or fit all packed mips with sibling context (especially where sibling mips share packed tail layouts). Skipping these mips caused the affected BC7 predictor rows to be recorded with ep_bits=0, which runtime/src/bcpack.cpp treats as an unknown predictor entry and counts against the lost-block budget.

Solution

  1. In tools/build_dstorage_history.py::fit_slices(), change the check to if not 0 <= first < blocks * 16: continue. This ensures any packed depth-1 mip whose blocks lie within the chunk is visited and fitted against its sibling.
  2. In tests/test_bcpack_history_calib.py, add test_fit_slices_includes_packed_depth1_mip_in_first_256_blocks verifying that a packed depth-1 mip in the first 256 blocks is properly visited and recovers the expected predictor endpoint bits (depth 8 on entry 91).

Finding by @Undefined3301 in issue #1608.

Verification

  • python -I scripts/check_no_game_data.py tools/build_dstorage_history.py tests/test_bcpack_history_calib.py -> 0 violations.
  • python -I tests/test_text_write_line_endings.py -> 3/3 PASS.
  • python -m compileall -q make_game.py tools tests -> Clean.
  • python -I tests/test_bcpack_history_calib.py -> 20/20 PASS.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5501050557 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2148). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-25T23:34:44Z. --- Include packed depth-1 mips whose first block lies in the chunk's first 256 blocks in `fit_slices()` (DSTORAGE-FIT-SLICES-PACKED-MIP). ### Problem In `tools/build_dstorage_history.py::fit_slices()`, packed depth-1 mips were skipped if their first block fell within the chunk's first 256 blocks: ```python if d["depth"] == 1: first = start + calib.tiled_offset(layout, mip, 0, 0) - virt if not 256 * 16 <= first < blocks * 16: continue ``` This was based on the premise that "the usual 2D fit visits only the first 256 physical blocks". However, in packed tails, `calibrate_from_pools()` does not necessarily visit or fit all packed mips with sibling context (especially where sibling mips share packed tail layouts). Skipping these mips caused the affected BC7 predictor rows to be recorded with `ep_bits=0`, which `runtime/src/bcpack.cpp` treats as an unknown predictor entry and counts against the lost-block budget. ### Solution 1. In `tools/build_dstorage_history.py::fit_slices()`, change the check to `if not 0 <= first < blocks * 16: continue`. This ensures any packed depth-1 mip whose blocks lie within the chunk is visited and fitted against its sibling. 2. In `tests/test_bcpack_history_calib.py`, add `test_fit_slices_includes_packed_depth1_mip_in_first_256_blocks` verifying that a packed depth-1 mip in the first 256 blocks is properly visited and recovers the expected predictor endpoint bits (depth 8 on entry 91). Finding by @Undefined3301 in issue #1608. ### Verification - `python -I scripts/check_no_game_data.py tools/build_dstorage_history.py tests/test_bcpack_history_calib.py` -> 0 violations. - `python -I tests/test_text_write_line_endings.py` -> 3/3 PASS. - `python -m compileall -q make_game.py tools tests` -> Clean. - `python -I tests/test_bcpack_history_calib.py` -> 20/20 PASS. AI-assisted (Claude Code).
aslan2142 commented 2026-11-26 00:42:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-26T00:42:42Z.


Thanks! We merged main into the branch and pushed one review commit (45a7cbc67):

  • Comment: it now says why every 2D mip is fitted here. The usual 2D fit stops at each chunk's first 256 blocks, later blocks still reach built-in history entries through chains, and these results only fill entries the usual fit left empty.
  • Test: named after what it checks. Its mip is the top mip at block 0 of its own chunk, not a packed-tail mip. It fails without the change.

Measured on a full v1.0.2.1 copy (57 pools), running build_dstorage_history.py before and after:

  • The predictor profile is byte-identical: BC6H endpoints 210/256, indices 249/256; BC7 endpoint fields 4228/6144, index fields 8160/8192, both ways.
  • The build takes 410 s instead of 127 s.

So on this copy the wider pass costs about 4.7 minutes per build and fills no entry. We're keeping this open:

  • @Undefined3301, could you run build_dstorage_history.py on the pools where you saw the missing-endpoint failures, with and without this branch, and post the Available predictors line from both runs (counts only)? If your copy fills more entries with it, that shows where it helps.
  • The finding's second half (a packed sibling decoded without the local history) doesn't apply to fit_slices as it is: it only takes raw or zlib siblings, and the third read_range argument is a decode cache. If you saw it somewhere else, please say where.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7179037488 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2148#issuecomment-7179037488). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-26T00:42:42Z. --- Thanks! We merged `main` into the branch and pushed one review commit (`45a7cbc67`): - **Comment:** it now says why every 2D mip is fitted here. The usual 2D fit stops at each chunk's first 256 blocks, later blocks still reach built-in history entries through chains, and these results only fill entries the usual fit left empty. - **Test:** named after what it checks. Its mip is the top mip at block 0 of its own chunk, not a packed-tail mip. It fails without the change. **Measured on a full v1.0.2.1 copy (57 pools), running `build_dstorage_history.py` before and after:** - The predictor profile is byte-identical: BC6H endpoints 210/256, indices 249/256; BC7 endpoint fields 4228/6144, index fields 8160/8192, both ways. - The build takes 410 s instead of 127 s. So on this copy the wider pass costs about 4.7 minutes per build and fills no entry. We're keeping this open: - @Undefined3301, could you run `build_dstorage_history.py` on the pools where you saw the missing-endpoint failures, with and without this branch, and post the `Available predictors` line from both runs (counts only)? If your copy fills more entries with it, that shows where it helps. - **The finding's second half** (a packed sibling decoded without the local history) doesn't apply to `fit_slices` as it is: it only takes raw or zlib siblings, and the third `read_range` argument is a decode cache. If you saw it somewhere else, please say where. AI-assisted (Claude Code, Claude Opus 5.5).
real-rusher commented 2026-11-26 12:23:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by real-rusher on 2026-11-26T12:23:49Z.


Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU, no game data). Merges cleanly. With this PR, python -I tests/test_bcpack_history_calib.py: 20 tests OK. The PR's test file against main's tool: 1 failure, so the new test fails on main and passes with the change. compileall clean.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7191947318 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2148#issuecomment-7191947318). Originally posted by [real-rusher](https://github.com/real-rusher) on 2026-11-26T12:23:49Z. --- Verified on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU, no game data). Merges cleanly. With this PR, python -I tests/test_bcpack_history_calib.py: 20 tests OK. The PR's test file against main's tool: 1 failure, so the new test fails on main and passes with the change. compileall clean. AI-assisted: yes (Claude Code)
zmasi commented 2026-11-28 11:09:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:09:05Z.


#2148 | head 45a7cbc674 (merged cleanly with main 039870ea2) | python -I tests/test_bcpack_history_calib.py | red on main: FAILED (failures=1) (historyEndpointBits[91][:8] remained [0]*8 instead of [8]*8 when a 2D mip started inside its chunk's first 256 blocks) | green on PR+main: 20 tests OK | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited 0 <= first < blocks * 16 in fit_slices (tools/build_dstorage_history.py) and test_fit_slices_fits_a_2d_mip_that_starts_in_the_chunks_first_256_blocks in tests/test_bcpack_history_calib.py. Also verified clean merge (0 conflicts) and combined execution alongside #2236 (4/4 OK in test_dstorage_multilevel_fit.py and 20/20 OK in test_bcpack_history_calib.py), plus tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238360386 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2148#issuecomment-7238360386). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:09:05Z. --- #2148 | head 45a7cbc674ddd13e8c4d5a7e7efa688d870c2d98 (merged cleanly with main 039870ea2) | `python -I tests/test_bcpack_history_calib.py` | red on main: `FAILED (failures=1)` (`historyEndpointBits[91][:8]` remained `[0]*8` instead of `[8]*8` when a 2D mip started inside its chunk's first 256 blocks) | green on PR+main: `20 tests OK` | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `0 <= first < blocks * 16` in `fit_slices` (`tools/build_dstorage_history.py`) and `test_fit_slices_fits_a_2d_mip_that_starts_in_the_chunks_first_256_blocks` in `tests/test_bcpack_history_calib.py`. Also verified clean merge (`0` conflicts) and combined execution alongside #2236 (`4/4 OK` in `test_dstorage_multilevel_fit.py` and `20/20 OK` in `test_bcpack_history_calib.py`), plus `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
MoonEyes commented 2026-11-28 15:03:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T15:03:55Z.


Red/green: classified READY by oreo-lotK (red on main, green on head merged with main); head 45a7cbc674 unchanged since 2026-11-26, before that run.
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:7241171764 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2148#issuecomment-7241171764). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T15:03:55Z. --- Red/green: classified READY by oreo-lotK (red on main, green on head merged with main); head 45a7cbc674dd unchanged since 2026-11-26, before that run. 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!2148
No description provided.