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

Open
github-bot wants to merge 1 commit from github-bot/gh-2388 into main AGit
Owner

@⁠syfyra on GitHub · 2026-11-26 16:57 UTC · original
syfyra:fix/restofworld-index-text-sample → main · +13 −2 · 2 files · 1 commits · draft

Claimed in the coordination issue as: RESTOFWORLD-INDEX-TEXT-SAMPLE (#1608)

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

**@⁠syfyra** on GitHub · 2026-11-26 16:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2388) `syfyra:fix/restofworld-index-text-sample` → `main` · +13 −2 · 2 files · 1 commits · draft Claimed in the coordination issue as: RESTOFWORLD-INDEX-TEXT-SAMPLE (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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)
_printable decides "text" from the first 512 bytes of a stream (more
than 90% printable). A carved file is classified from its whole data,
but scan_rpf passed only a 256-byte head for streams it does not keep
whole, so one stream could get two signatures: a stream whose first
306 bytes are printable read as "text" from the archive and as
"raw:..." from its carved file. af55ea1b4 removed the same split for
PSIN streams.

Keep a 512-byte head in the archive scan, the sample _printable takes.
The other head checks read at most 16 bytes, so nothing else changes.

Tested: new test_text_is_judged_on_the_same_512_bytes_as_a_carved_file
(fails before: 'text' from the archive, 'raw:6e616d65' from the data).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 16:59:00 +00:00
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-26 18:04 UTC · original · reviewed

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.

**@⁠MSedgeMC** on GitHub · 2026-11-26 18:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2388#pullrequestreview-6078749327) · **reviewed** 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.
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 18:27 UTC · original · reviewed

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.

**@⁠wavehs** on GitHub · 2026-11-26 18:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2388#pullrequestreview-6078972541) · **reviewed** **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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2388/head:github-bot/gh-2388'
git switch 'github-bot/gh-2388'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2388'
git switch 'github-bot/gh-2388'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2388'
git switch 'github-bot/gh-2388'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2388'
git switch 'main'
git merge --squash 'github-bot/gh-2388'
git switch 'main'
git merge --ff-only 'github-bot/gh-2388'
git switch 'main'
git merge 'github-bot/gh-2388'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.