restofworld_index: judge text on the same 512 bytes in an archive (RESTOFWORLD-INDEX-TEXT-SAMPLE) #2388

Merged
syfyra merged 1 commit from upstream-pr/2388 into main 2026-12-01 15:22:12 +00:00
syfyra commented 2026-11-26 16:57:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-26T16:57:15Z.


Claimed in the coordination issue as: RESTOFWORLD-INDEX-TEXT-SAMPLE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198290287)

What and why

tools/restofworld_index.py classifies each zlib stream of an RPF9 archive, or each carved file of a folder, by its first bytes. Its text class comes from _printable, which samples the first 512 bytes: text when the sample is at least 64 bytes and more than 90% printable.

A carved file is classified from its whole data. scan_rpf keeps a stream whole only when it may be a PSIN or a CPU resource (texture scan). For every other stream it passed classify a 256-byte head, so _printable saw at most 256 bytes there. One stream could therefore get two signatures. A stream whose first 306 bytes are printable, followed by binary data, read as text from the archive and as raw:6e616d65 from its carved file. af55ea1b4 removed the same archive-versus-folder split for PSIN streams.

The archive scan now keeps a 512-byte head, the sample _printable takes. The other head checks (PSIN, CPU-resource prefix) read at most 16 bytes, so nothing else changes. A stream that was text under the 256-byte sample is still text unless bytes 256-511 bring it under 90% printable, which is what a carved-file scan already says.

Different topic from #1535 (validation and I/O, same files); the two merge cleanly.

Tested

Windows 11, Python 3.14.7, synthetic streams only:

  • python -I tests/test_restofworld_index.py: 35 tests OK. New test_text_is_judged_on_the_same_512_bytes_as_a_carved_file puts the stream above into an archive and expects the signature classify gives for its whole data, which is not text. On main it gets 'text' != 'raw:6e616d65'. The existing signature, PSIN-chain and scan tests are unchanged.
  • python -m compileall; scripts/check_no_game_data.py on both files.

Not measured: how many streams of a real archive change class (no game files here).

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

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:5514087678 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2388). Originally posted by [syfyra](https://github.com/syfyra) on 2026-11-26T16:57:15Z. --- Claimed in the coordination issue as: RESTOFWORLD-INDEX-TEXT-SAMPLE (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198290287) ### What and why `tools/restofworld_index.py` classifies each zlib stream of an RPF9 archive, or each carved file of a folder, by its first bytes. Its `text` class comes from `_printable`, which samples the **first 512 bytes**: text when the sample is at least 64 bytes and more than 90% printable. A carved file is classified from its whole data. `scan_rpf` keeps a stream whole only when it may be a PSIN or a CPU resource (texture scan). For every other stream it passed `classify` a **256-byte** head, so `_printable` saw at most 256 bytes there. One stream could therefore get two signatures. A stream whose first 306 bytes are printable, followed by binary data, read as `text` from the archive and as `raw:6e616d65` from its carved file. af55ea1b4 removed the same archive-versus-folder split for PSIN streams. The archive scan now keeps a 512-byte head, the sample `_printable` takes. The other head checks (PSIN, CPU-resource prefix) read at most 16 bytes, so nothing else changes. A stream that was text under the 256-byte sample is still text unless bytes 256-511 bring it under 90% printable, which is what a carved-file scan already says. Different topic from #1535 (validation and I/O, same files); the two merge cleanly. ### Tested Windows 11, Python 3.14.7, synthetic streams only: - `python -I tests/test_restofworld_index.py`: 35 tests OK. New `test_text_is_judged_on_the_same_512_bytes_as_a_carved_file` puts the stream above into an archive and expects the signature `classify` gives for its whole data, which is not `text`. On `main` it gets `'text' != 'raw:6e616d65'`. The existing signature, PSIN-chain and scan tests are unchanged. - `python -m compileall`; `scripts/check_no_game_data.py` on both files. Not measured: how many streams of a real archive change class (no game files here). GPUs tested: n/a (CPU-only tool) 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)
MSedgeMC commented 2026-11-26 18:04:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MSedgeMC on 2026-11-26T18:04:13Z.

Review: COMMENTED


Verified on the PR branch: python3 -m unittest tests.test_restofworld_index -v -> 35 tests OK, including the new continuation-file and texture-detection cases. Not approving yet: this branch carries 522 commits not on current main, so a merge would include unrelated history. Please rebase onto main and re-run the suite.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6078749327 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2388#pullrequestreview-6078749327). Originally posted by [MSedgeMC](https://github.com/MSedgeMC) on 2026-11-26T18:04:13Z. **Review:** COMMENTED --- Verified on the PR branch: python3 -m unittest tests.test_restofworld_index -v -> 35 tests OK, including the new continuation-file and texture-detection cases. Not approving yet: this branch carries 522 commits not on current main, so a merge would include unrelated history. Please rebase onto main and re-run the suite.
wavehs commented 2026-11-26 18:27:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:27:13Z.

Review: COMMENTED


macOS arm64 check of #2388 (RESTOFWORLD-INDEX-TEXT-SAMPLE). A four-line indexer change, no GPU or translator code.

Tested head 16dde2277 with its diff applied to a copy of main bdbc7e923 (git apply clean; branch 10 commits behind). Working tree left untouched for this one because no build is involved.

Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2.

The new test passes, and the control bites

  • python -I tests/test_restofworld_index.py: Ran 35 tests ... OK at the head.
  • Negative control (test kept, tools/restofworld_index.py put back to main's): exactly one failure, test_text_is_judged_on_the_same_512_bytes_as_a_carved_file, which is the regression the PR names. The other 34 tests still pass, so the change does not move unrelated classifications.
  • The test's byte construction is synthetic (name= + 301 printable bytes + bytes(range(256)) + zeros), so it needs no game file.

The change is the right one
_printable() samples data[:512] and requires len(sample) >= 64 (line 138-144), while the archive path stopped collecting head at 256 bytes, so the 306-byte case in the test was text when carved and raw from the archive. Collecting 512 bytes makes both call the same function on the same amount of data; body (the carved payload) is unaffected, and head is only used for the PSIN/CPU and printable sniffing plus the fast-reject below 16 bytes.

No regressions

  • Semantic suite: 500 files / 6,367 tests / 0 files failed at main bdbc7e923; the PR adds no semantic test, so this is the same tree, unchanged.
  • GPU fixtures: not re-run. The diff is a len(head) < 256 constant in an offline archive indexer, which scripts/run_gpu_tests.py, tools/rdna2spirv.py and runtime/ do not load; I did not want to quote a green GPU run for a file the shader path never reads. The same-main baseline from this session is 195 PASS / 3 FAIL / 70 SKIP on MoltenVK and 190 / 5 / 73 on KosmicKrisp.

I found no bug in the change. The only thing I would add is a small comment on _printable's 512-byte sample saying the archive scan must collect the same 512 (the new comment on the head line says it the other way round, which is enough, but the two sites can drift again).

No game files. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6078972541 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2388#pullrequestreview-6078972541). Originally posted by [wavehs](https://github.com/wavehs) on 2026-11-26T18:27:13Z. **Review:** COMMENTED --- **macOS arm64 check of #2388** (RESTOFWORLD-INDEX-TEXT-SAMPLE). A four-line indexer change, no GPU or translator code. Tested head `16dde2277` with its diff applied to a copy of `main` `bdbc7e923` (`git apply` clean; branch 10 commits behind). Working tree left untouched for this one because no build is involved. Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2. **The new test passes, and the control bites** - `python -I tests/test_restofworld_index.py`: `Ran 35 tests ... OK` at the head. - Negative control (test kept, `tools/restofworld_index.py` put back to `main`'s): exactly one failure, `test_text_is_judged_on_the_same_512_bytes_as_a_carved_file`, which is the regression the PR names. The other 34 tests still pass, so the change does not move unrelated classifications. - The test's byte construction is synthetic (`name=` + 301 printable bytes + `bytes(range(256))` + zeros), so it needs no game file. **The change is the right one** `_printable()` samples `data[:512]` and requires `len(sample) >= 64` (line 138-144), while the archive path stopped collecting `head` at 256 bytes, so the 306-byte case in the test was text when carved and raw from the archive. Collecting 512 bytes makes both call the same function on the same amount of data; `body` (the carved payload) is unaffected, and `head` is only used for the PSIN/CPU and printable sniffing plus the fast-reject below 16 bytes. **No regressions** - Semantic suite: 500 files / 6,367 tests / 0 files failed at `main` `bdbc7e923`; the PR adds no semantic test, so this is the same tree, unchanged. - GPU fixtures: not re-run. The diff is a `len(head) < 256` constant in an offline archive indexer, which `scripts/run_gpu_tests.py`, `tools/rdna2spirv.py` and `runtime/` do not load; I did not want to quote a green GPU run for a file the shader path never reads. The same-main baseline from this session is 195 PASS / 3 FAIL / 70 SKIP on MoltenVK and 190 / 5 / 73 on KosmicKrisp. I found no bug in the change. The only thing I would add is a small comment on `_printable`'s 512-byte sample saying the archive scan must collect the same 512 (the new comment on the `head` line says it the other way round, which is enough, but the two sites can drift again). No game files. AI-assisted.
imShangLi commented 2026-12-01 04:16:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T04:16:41Z.


VERIFY-2388 — Linux, Python 3.15, CPU only, no game files

Claimed as VERIFY-2388 (+11/-0 test, +2/-2 tool). Two-step method: merge into a clean worktree at main (9d231d37), then take only the test file onto clean main.

tree python -I tests/test_restofworld_index.py
main test_restofworld_index.py baseline green
main + this pull request PASS
main + only this pull request's test file FAIL (assertion)

The failure on the last row is an AssertionError, not an import or attribute error, so the test is exercising the changed code rather than merely failing to load it. Reverse control holds: the change is what turns it green.

Verified. Nothing found against it; merges cleanly with main at 9d231d37.

AI-assisted: yes — MiMo-V2.6-Flash (OpenCode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7300563897 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2388#issuecomment-7300563897). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-01T04:16:41Z. --- ### VERIFY-2388 — Linux, Python 3.15, CPU only, no game files Claimed as `VERIFY-2388` (+11/-0 test, +2/-2 tool). Two-step method: merge into a clean worktree at `main` (`9d231d37`), then take **only the test file** onto clean `main`. | tree | `python -I tests/test_restofworld_index.py` | |---|---| | `main` | test_restofworld_index.py baseline green | | `main` + this pull request | **PASS** | | `main` + only this pull request's test file | **FAIL (assertion)** | The failure on the last row is an `AssertionError`, not an import or attribute error, so the test is exercising the changed code rather than merely failing to load it. Reverse control holds: the change is what turns it green. **Verified.** Nothing found against it; merges cleanly with `main` at `9d231d37`. AI-assisted: yes — MiMo-V2.6-Flash (OpenCode).
aslan2142 commented 2026-12-01 12:03:42 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Draft review against current main: increasing the archive text sample from 256 to 512 bytes in tools/restofworld_index.py:335-336 to match carved-file _printable sampling looks clean and clean-room verified. Still Draft with no CI run yet — please mark Ready for Review so CI runs green.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130904906 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2388#pullrequestreview-6130904906). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:03:42Z. **Review:** COMMENTED --- Draft review against current `main`: increasing the archive text sample from 256 to 512 bytes in `tools/restofworld_index.py:335-336` to match carved-file `_printable` sampling looks clean and clean-room verified. Still Draft with no CI run yet — please mark Ready for Review so CI runs green. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 12:35:58 +00:00 (Migrated from github.com)

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


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:7311372087 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2388#issuecomment-7311372087). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:35:58Z. --- 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 13:07:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T13:07:17Z.

Review: APPROVED


Now ready for review and MERGEABLE (1 commit). Clean-room verified: aligning archive text detection to the same 512-byte sample in tools/restofworld_index.py:335-336 with tests in tests/test_restofworld_index.py is clean and verified (@wavehs, @imShangLi, @MSedgeMC).

Approving — ready to merge once CI runs green on current main.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6131843540 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2388#pullrequestreview-6131843540). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T13:07:17Z. **Review:** APPROVED --- Now ready for review and `MERGEABLE` (1 commit). Clean-room verified: aligning archive text detection to the same 512-byte sample in `tools/restofworld_index.py:335-336` with tests in `tests/test_restofworld_index.py` is clean and verified (`@wavehs`, `@imShangLi`, `@MSedgeMC`). Approving — ready to merge once CI runs green on current `main`. *(AI-assisted review.)*
merzleckeier commented 2026-12-01 13:57:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T13:57:45Z.


I checked the exact text cutoff at 16dde227 + 9f27ba2e by running both the actual archive reader and the carve-folder reader. For 460 printable bytes among the first 512, main gives text for the archive and raw for the folder. The PR gives raw for both. At 461 of 512, both trees give text in both modes. I also appended 128 printable bytes to the first case and 128 nonprintable bytes to the second, so the probe would catch accidentally sampling beyond byte 512.

python -I tests/test_restofworld_index.py passed 38/38 with the PR and 37/37 on main. MEASURED on Linux, CPython 3.14.10, with synthetic fixtures. AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7313467943 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2388#issuecomment-7313467943). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T13:57:45Z. --- I checked the exact text cutoff at `16dde227` + `9f27ba2e` by running both the actual archive reader and the carve-folder reader. For 460 printable bytes among the first 512, `main` gives `text` for the archive and `raw` for the folder. The PR gives `raw` for both. At 461 of 512, both trees give `text` in both modes. I also appended 128 printable bytes to the first case and 128 nonprintable bytes to the second, so the probe would catch accidentally sampling beyond byte 512. `python -I tests/test_restofworld_index.py` passed 38/38 with the PR and 37/37 on `main`. MEASURED on Linux, CPython 3.14.10, with synthetic fixtures. AI-assisted (Codex).
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!2388
No description provided.