rbf0_encode: write back a short-count element with text or child content (carry of #2386) #3096

Manually merged
github merged 3 commits from github-bot/gh-3096 into main 2026-12-02 20:49:43 +00:00 AGit
Owner

@⁠MoonEyes on GitHub · 2026-12-02 10:31 UTC · original
MoonEyes:carry/2386 → main · +32 −2 · 2 files · 3 commits · merged 2026-12-02 20:47 UTC

Claimed in the coordination issue as: RBF0-ENCODE-SHORT-COUNT-CONTENT (original author's item ID, claimed at #1608)

What and why

Carry of #2386 (syfyra), unchanged since 2026-11-26 (head 4f1ca189); branch = main (80910637f) + the author's head (commit kept, merged without conflicts) + my commit.

The author's change: tools/rbf0_encode.py refused every element flagged attribute_order_violation as "an attribute after content", including a short-count element whose content is text or a child element, although its bytes write back exactly (docs/rbf0.md 9.6). The encoder now refuses on the flag only when an attribute record's offset follows the first content record's, or when the records carry no offsets to tell.

Review defect fixed (reviewers imShangLi, aegish-zagi and the CHANGES_REQUESTED review from aslan2142): the new code read .get("offset") of every attribute and content record before the shape checks. On current main, a malformed attributes or content (None, [123], ["bad"]) raised TypeError or AttributeError instead of EncodeError("value"), which failed 4 subtests of test_bool_recorded_lengths_and_malformed_element_children. My commit moves the shape checks ahead of the offset lists and adds a regression subtest (a flagged element with each of the four malformed shapes must refuse with value).

Tested

Windows 11, Python 3.14, no GPU, no game files, on main 80910637f plus this branch:

  • python -I tests/test_rbf0_encode.py: 41 tests, OK.
  • python -I tests/test_rbf0_tree.py: 38 tests, OK (1 skipped).
  • Before my commit, the merged tree failed python -I tests/test_rbf0_encode.py with 41 tests, errors=4, as the reviewers reported.
  • Red: with tools/rbf0_encode.py restored to main's version and this branch's tests kept, python -I tests/test_rbf0_encode.py runs 41 tests, FAILED (failures=4, errors=2), all six in subtests of test_fewer_attribute_records_than_the_count: 2 errors for the text and child short-count cases, 4 failures for the flagged malformed-record cases. The file was restored afterwards.
  • python -I scripts/check_no_game_data.py tools/rbf0_encode.py tests/test_rbf0_encode.py: clean.

Not run: the full suite, CI.

GPUs tested: n/a (unit tests only)

AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: 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)

Supersedes #2386 once merged; the original stays open until a maintainer decides.

🤖 Generated with Claude Code

**@⁠MoonEyes** on GitHub · 2026-12-02 10:31 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3096) `MoonEyes:carry/2386` → `main` · +32 −2 · 2 files · 3 commits · merged 2026-12-02 20:47 UTC Claimed in the coordination issue as: RBF0-ENCODE-SHORT-COUNT-CONTENT (original author's item ID, claimed at https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why Carry of #2386 (syfyra), unchanged since 2026-11-26 (head `4f1ca189`); branch = main (`80910637f`) + the author's head (commit kept, merged without conflicts) + my commit. The author's change: `tools/rbf0_encode.py` refused every element flagged `attribute_order_violation` as "an attribute after content", including a short-count element whose content is text or a child element, although its bytes write back exactly (`docs/rbf0.md` 9.6). The encoder now refuses on the flag only when an attribute record's offset follows the first content record's, or when the records carry no offsets to tell. Review defect fixed (reviewers `imShangLi`, `aegish-zagi` and the CHANGES_REQUESTED review from `aslan2142`): the new code read `.get("offset")` of every attribute and content record before the shape checks. On current main, a malformed `attributes` or `content` (`None`, `[123]`, `["bad"]`) raised `TypeError` or `AttributeError` instead of `EncodeError("value")`, which failed 4 subtests of `test_bool_recorded_lengths_and_malformed_element_children`. My commit moves the shape checks ahead of the offset lists and adds a regression subtest (a flagged element with each of the four malformed shapes must refuse with `value`). ### Tested Windows 11, Python 3.14, no GPU, no game files, on main `80910637f` plus this branch: - `python -I tests/test_rbf0_encode.py`: 41 tests, OK. - `python -I tests/test_rbf0_tree.py`: 38 tests, OK (1 skipped). - Before my commit, the merged tree failed `python -I tests/test_rbf0_encode.py` with 41 tests, errors=4, as the reviewers reported. - Red: with `tools/rbf0_encode.py` restored to main's version and this branch's tests kept, `python -I tests/test_rbf0_encode.py` runs 41 tests, FAILED (failures=4, errors=2), all six in subtests of `test_fewer_attribute_records_than_the_count`: 2 errors for the text and child short-count cases, 4 failures for the flagged malformed-record cases. The file was restored afterwards. - `python -I scripts/check_no_game_data.py tools/rbf0_encode.py tests/test_rbf0_encode.py`: clean. Not run: the full suite, CI. GPUs tested: n/a (unit tests only) AI-assisted: yes. Models: Claude Opus 5.5 in Claude Code (carry, conflict resolution, fixes, tests); separate read-only reviewer agent: 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) Supersedes #2386 once merged; the original stays open until a maintainer decides. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
docs/rbf0.md 9.6: an element short of its attribute count is refused
only when it has a value in its content, because that value would
decode as an attribute. rbf0_tree also sets attribute_order_violation
when text or a child element arrives before the count is reached, and
the encoder refused every flagged element as "an attribute after
content", so such an element was refused although its bytes write back
exactly (an element short of its count with no content already encoded,
as tested).

Refuse on the flag only when an attribute record's offset follows the
first content record's, or when records carry no offsets to tell (a
hand-built tree fails closed as before). The short-count check for a
value in the content is unchanged.

Tested: test_fewer_attribute_records_than_the_count now also encodes a
short-count element with text and with a child element exactly (both
refused before) and refuses them once the offsets are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The short-count change read the offset of every attribute and content
record before the shape checks, so a malformed record (None, a number or
a string in attributes/content) raised TypeError or AttributeError
instead of the documented EncodeError "value". This broke four
subtests of test_bool_recorded_lengths_and_malformed_element_children on
current main, as reported by reviewers (CHANGES_REQUESTED on #2386).

Move the attributes/content shape checks ahead of the offset lists, and
add a regression subtest with a flagged element and malformed records.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 10:36:04 +00:00
Author
Owner

@⁠OreoFR on GitHub · 2026-12-02 12:19 UTC · original

Verified by OreoFR (oreofr-agent, AI-assisted; third-party red/green). Head b56408e2d79ac1e048c0f53f7d06e80dcf450ecf merged into main f6dd2242e02b5f579d245f1c19dd5150d42e00a1 with no conflicts. Windows 11, Python 3.12, CPU only.

  • Green: tests/test_rbf0_encode.py OK; tests/test_rbf0_tree.py OK (skipped=1).
  • Red, with main's tools/rbf0_encode.py restored and this PR's tests kept: test_rbf0_encode.py FAILED (failures=4, errors=2), matching the description; test_rbf0_tree.py unchanged, OK.
    Safe to merge: it merges cleanly, CI is green, and it touches only a tool and its test. Not merged by me.
**@⁠OreoFR** on GitHub · 2026-12-02 12:19 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3096#issuecomment-7345158256) **Verified by OreoFR** (oreofr-agent, AI-assisted; third-party red/green). Head `b56408e2d79ac1e048c0f53f7d06e80dcf450ecf` merged into main `f6dd2242e02b5f579d245f1c19dd5150d42e00a1` with no conflicts. Windows 11, Python 3.12, CPU only. - Green: `tests/test_rbf0_encode.py` OK; `tests/test_rbf0_tree.py` OK (skipped=1). - Red, with main's `tools/rbf0_encode.py` restored and this PR's tests kept: `test_rbf0_encode.py` FAILED (failures=4, errors=2), matching the description; `test_rbf0_tree.py` unchanged, OK. Safe to merge: it merges cleanly, CI is green, and it touches only a tool and its test. Not merged by me.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-02 12:56 UTC · original

Ran natively on Windows 11, Python 3.13, head b56408e2d merged into current main (23a51c494), no conflicts.

py -3.13 -I tests/test_rbf0_encode.py: OK. Red/green is already shown twice above, so I tried to find an element the narrower check now lets through but does not write back exactly.

Sweep with throwaway streams built by the test file's Stream helper: root element with a declared attribute count of 0..3, followed by every sequence of 0..4 records drawn from {int, bool, string, text, empty child, child with one attribute}, in both the wide and the narrow form. That is 12,440 elements. Each one goes rbf0_tree.parse_resource -> rbf0_encode.encode and the output is compared with the input bytes.

result this PR main
written back byte-exact, not flagged 5,852 5,852
written back byte-exact, flagged attribute_order_violation 1,404 0
refused order 5,184 6,588
written back but bytes differ 0 0
any other exception 0 0

So the 1,404 shapes the PR now accepts all round-trip exactly, and nothing encodes to different bytes. To check that the 5,184 still refused really need refusing, I dropped the flag from each of them and encoded again: 1,188 then come out with different bytes and 3,996 are refused as descriptor. None of them would have written back exactly, so the new check does not refuse anything it could have kept, at least in this space.

Not checked: nesting deeper than one child, more than 4 records per element, real resources (no game files used).

GPUs tested: n/a (CPU-only tests).

AI-assisted: yes (Claude Code).

**@⁠Kal0s-design** on GitHub · 2026-12-02 12:56 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3096#issuecomment-7346102341) Ran natively on Windows 11, Python 3.13, head `b56408e2d` merged into current `main` (`23a51c494`), no conflicts. `py -3.13 -I tests/test_rbf0_encode.py`: OK. Red/green is already shown twice above, so I tried to find an element the narrower check now lets through but does not write back exactly. Sweep with throwaway streams built by the test file's `Stream` helper: root element with a declared attribute count of 0..3, followed by every sequence of 0..4 records drawn from {int, bool, string, text, empty child, child with one attribute}, in both the wide and the narrow form. That is 12,440 elements. Each one goes `rbf0_tree.parse_resource` -> `rbf0_encode.encode` and the output is compared with the input bytes. | result | this PR | main | |---|---|---| | written back byte-exact, not flagged | 5,852 | 5,852 | | written back byte-exact, flagged `attribute_order_violation` | 1,404 | 0 | | refused `order` | 5,184 | 6,588 | | written back but bytes differ | 0 | 0 | | any other exception | 0 | 0 | So the 1,404 shapes the PR now accepts all round-trip exactly, and nothing encodes to different bytes. To check that the 5,184 still refused really need refusing, I dropped the flag from each of them and encoded again: 1,188 then come out with different bytes and 3,996 are refused as `descriptor`. None of them would have written back exactly, so the new check does not refuse anything it could have kept, at least in this space. Not checked: nesting deeper than one child, more than 4 records per element, real resources (no game files used). GPUs tested: n/a (CPU-only tests). AI-assisted: yes (Claude Code).
Author
Owner

@⁠aegish-zagi on GitHub · 2026-12-02 14:37 UTC · original

Verification — VERIFY-3096

PR #3096 — rbf0_encode: write back a short-count element with text or child content (carry of #2386)
Head b56408e2d7; MERGEABLE against current main (acc350745)
Tests run The PR's tests/test_rbf0_encode.py run standalone in a scratch worktree: (a) PR test file against plain main code, (b) PR test file against the PR head
Red on main FAILED (failures=4, errors=2) of 41 tests on main code
Green on PR All 41 tests pass with the PR head (OK); the 35 tests that passed on main still pass — no regressions
Diff audit tools/rbf0_encode.py + its test only: the short-count element write-back now carries text/child content instead of dropping it. One topic, claim in place (carry of #2386), no game data
Verdict PASS — red on main, green on the PR
Platform Linux, Python 3.12.3, no GPU (Profile Z)

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

**@⁠aegish-zagi** on GitHub · 2026-12-02 14:37 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3096#issuecomment-7348874191) Verification — VERIFY-3096 | | | |---|---| | PR | #3096 — rbf0_encode: write back a short-count element with text or child content (carry of #2386) | | Head | b56408e2d79ac1e048c0f53f7d06e80dcf450ecf; MERGEABLE against current main (acc350745) | | Tests run | The PR's `tests/test_rbf0_encode.py` run standalone in a scratch worktree: (a) PR test file against plain main code, (b) PR test file against the PR head | | Red on main | **FAILED (failures=4, errors=2)** of 41 tests on main code | | Green on PR | All 41 tests pass with the PR head (OK); the 35 tests that passed on main still pass — no regressions | | Diff audit | tools/rbf0_encode.py + its test only: the short-count element write-back now carries text/child content instead of dropping it. One topic, claim in place (carry of #2386), no game data | | Verdict | **PASS** — red on main, green on the PR | | Platform | Linux, Python 3.12.3, no GPU (Profile Z) | AI-assisted: yes (Muse Wonder, Muse by Meta)
Author
Owner

@⁠MoonEyes on GitHub · 2026-12-02 20:36 UTC · original

Merging. Head b56408e2d merges cleanly with main b41763227 and does not force a rebase of #2566. Carry of #2386, CI green on this head Merged by MoonEyes.

AI-assisted (Claude Code).

**@⁠MoonEyes** on GitHub · 2026-12-02 20:36 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3096#issuecomment-7358001874) Merging. Head `b56408e2d` merges cleanly with `main` `b41763227` and does not force a rebase of #2566. Carry of #2386, CI green on this head Merged by MoonEyes. AI-assisted (Claude Code).
github manually merged commit c820dc975a into main 2026-12-02 20:49:43 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!3096
No description provided.