page_index: a directory page is never a continuation (PAGE-INDEX-DIRECTORY-NOT-CONTINUATION) #2371

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

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


Claimed in the coordination issue as: PAGE-INDEX-DIRECTORY-NOT-CONTINUATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7197498211)

What and why

tools/page_index.py follows a 0DRP page whose q38 table or last record runs past its zlib stream into the next stream(s). index_streams appended the next stream to the waiting page's continuations before asking whether that stream is a directory page of its own, so the check that exists for exactly this ("treat this stream as the new directory page instead of swallowing it as a continuation") ran too late:

  • When the waiting page needed only a few more bytes, a following directory page covered them. The waiting page was reported complete, with the new page's header read as its record's payload, and the new page was never indexed (synthetic case: page A's last record runs 0x10 bytes past its 0x100-byte stream, page B follows → 1 page reported instead of 2).
  • When the waiting page stayed incomplete, the new page was reported correctly but was still listed among the waiting page's continuations and resource streams (added by 3eb5f8656 to keep "the last continuation", which in that branch is always the new page).

docs/page_directory.md measured that no continuation stream is a 0DRP page: "A resource therefore extends forward by payload, not by nesting another directory." tools/navmesh_nodes.py already stops a resource at a stream that opens one of its own. index_streams now checks is_page before appending. The waiting page is reported as parsed with the continuations it really had (the tuple in waiting always holds that parse) and marked resource ended before q38 was complete, and the stream is indexed as the new page. Archives where every page completes before the next one starts are unchanged.

Different topic from #1566 (versions, --limit, atomic writes), which also edits these files; the two merge cleanly.

Tested

Windows 11, Python 3.14.7, synthetic RPF streams only:

  • python -I tests/test_page_index.py: 22 tests OK. New test_a_directory_page_is_not_taken_as_a_continuation_even_when_it_would_complete_one: on main it gets one page (A complete, B as its continuation); with the fix A is incomplete with no continuation and B is indexed with its record. The existing test_new_page_after_a_continuation_is_reported_with_both_streams asserted the second page among the first page's continuations. It is renamed ..._ends_the_previous_resource and now expects the one real continuation and resource streams [page, continuation].
  • tests/test_csv_line_endings.py (imports the tool) OK. tests/test_opus_tags.py fails here on main too, in an unrelated Windows path assertion.
  • python -m compileall; scripts/check_no_game_data.py on both files.

Not measured: how many pages this recovers on real archives (no game files here). Where the docs' counts were taken, every continuation completed its page before the next page, which is the unchanged path.

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:5513569016 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2371). Originally posted by [syfyra](https://github.com/syfyra) on 2026-11-26T16:20:58Z. --- Claimed in the coordination issue as: PAGE-INDEX-DIRECTORY-NOT-CONTINUATION (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7197498211) ### What and why `tools/page_index.py` follows a `0DRP` page whose `q38` table or last record runs past its zlib stream into the next stream(s). `index_streams` appended the next stream to the waiting page's continuations *before* asking whether that stream is a directory page of its own, so the check that exists for exactly this ("treat this stream as the new directory page instead of swallowing it as a continuation") ran too late: - **When the waiting page needed only a few more bytes**, a following directory page covered them. The waiting page was reported **complete**, with the new page's header read as its record's payload, and the new page **was never indexed** (synthetic case: page A's last record runs 0x10 bytes past its 0x100-byte stream, page B follows → 1 page reported instead of 2). - **When the waiting page stayed incomplete**, the new page was reported correctly but was still listed among the waiting page's continuations and resource streams (added by 3eb5f8656 to keep "the last continuation", which in that branch is always the new page). `docs/page_directory.md` measured that no continuation stream is a `0DRP` page: "A resource therefore extends forward by payload, not by nesting another directory." `tools/navmesh_nodes.py` already stops a resource at a stream that opens one of its own. `index_streams` now checks `is_page` before appending. The waiting page is reported as parsed with the continuations it really had (the tuple in `waiting` always holds that parse) and marked `resource ended before q38 was complete`, and the stream is indexed as the new page. Archives where every page completes before the next one starts are unchanged. Different topic from #1566 (versions, `--limit`, atomic writes), which also edits these files; the two merge cleanly. ### Tested Windows 11, Python 3.14.7, synthetic RPF streams only: - `python -I tests/test_page_index.py`: 22 tests OK. New `test_a_directory_page_is_not_taken_as_a_continuation_even_when_it_would_complete_one`: on `main` it gets one page (A complete, B as its continuation); with the fix A is incomplete with no continuation and B is indexed with its record. The existing `test_new_page_after_a_continuation_is_reported_with_both_streams` asserted the second page among the first page's continuations. It is renamed `..._ends_the_previous_resource` and now expects the one real continuation and resource streams `[page, continuation]`. - `tests/test_csv_line_endings.py` (imports the tool) OK. `tests/test_opus_tags.py` fails here on `main` too, in an unrelated Windows path assertion. - `python -m compileall`; `scripts/check_no_game_data.py` on both files. Not measured: how many pages this recovers on real archives (no game files here). Where the docs' counts were taken, every continuation completed its page before the next page, which is the unchanged path. 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)
aslan2142 commented 2026-12-01 12:02:57 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Draft review against current main: checking is_page(data) before appending the stream as a continuation in tools/page_index.py:308-317 cleanly prevents a new directory page from being swallowed by an incomplete preceding resource, with regression tests in tests/test_page_index.py. 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:6130891849 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2371#pullrequestreview-6130891849). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:02:57Z. **Review:** COMMENTED --- Draft review against current `main`: checking `is_page(data)` before appending the stream as a continuation in `tools/page_index.py:308-317` cleanly prevents a new directory page from being swallowed by an incomplete preceding resource, with regression tests in `tests/test_page_index.py`. 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:32:35 +00:00 (Migrated from github.com)

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


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:7311282989 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2371#issuecomment-7311282989). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:32:35Z. --- 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:06:20 +00:00 (Migrated from github.com)

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

Review: APPROVED


Now ready for review and MERGEABLE. Clean-room verified: guarding continuation chaining with is_page(data) in tools/page_index.py:308-317 with tests in tests/test_page_index.py is clean and focused. (Note: #2373 also edits tools/page_index.py, so recheck mergeability after whichever lands first.)

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

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6131829888 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2371#pullrequestreview-6131829888). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T13:06:20Z. **Review:** APPROVED --- Now ready for review and `MERGEABLE`. Clean-room verified: guarding continuation chaining with `is_page(data)` in `tools/page_index.py:308-317` with tests in `tests/test_page_index.py` is clean and focused. (Note: `#2373` also edits `tools/page_index.py`, so recheck mergeability after whichever lands first.) Approving — ready to merge once CI runs green on current `main`. *(AI-assisted review.)*
merzleckeier commented 2026-12-01 13:57:13 +00:00 (Migrated from github.com)

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


I checked this with #2373 in both merge orders on 9f27ba2e (head 80c6f304). Both orders produced the same tree (8b14b141) and passed all 27 tests in tests/test_page_index.py. The subsequent main change through 3e7b34a5 touches only translator wording and comments.

One additional synthetic archive contains an unfinished page, two short continuations (24 and 20 bytes), and a complete directory page. With this PR alone, both pages are reported separately but the short fragments are omitted. With #2373 alone, the short fragments are kept but the second directory is swallowed. With both, the first report keeps both short continuations and remains incomplete, while the second directory is independently indexed as complete. The count of full-sized streams is two in all four cases, including main.

MEASURED on Linux, CPython 3.14.10, with synthetic fixtures. AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7313453918 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2371#issuecomment-7313453918). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T13:57:13Z. --- I checked this with #2373 in both merge orders on `9f27ba2e` (head `80c6f304`). Both orders produced the same tree (`8b14b141`) and passed all 27 tests in `tests/test_page_index.py`. The subsequent `main` change through `3e7b34a5` touches only translator wording and comments. One additional synthetic archive contains an unfinished page, two short continuations (24 and 20 bytes), and a complete directory page. With this PR alone, both pages are reported separately but the short fragments are omitted. With #2373 alone, the short fragments are kept but the second directory is swallowed. With both, the first report keeps both short continuations and remains incomplete, while the second directory is independently indexed as complete. The count of full-sized streams is two in all four cases, including `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!2371
No description provided.