rbf0_encode: write back a short-count element with text or child content (RBF0-ENCODE-SHORT-COUNT-CONTENT) #2386
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2386
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/rbf0-encode-short-count-content"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: RBF0-ENCODE-SHORT-COUNT-CONTENT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198218440)
What and why
tools/rbf0_encode.pywrites anrbf0_tree.pydocument back to bytes and fails closed.docs/rbf0.md9.6 lists the refusals. For attribute counts it refuses "an element with more attribute records than its attribute count" and "an element short of its attribute count with a value in its content", because that value would decode as an attribute.rbf0_tree._attachsetsattribute_order_violationin two cases:The encoder refused every flagged element as "an attribute after content". An element short of its count whose content is text or a child element was therefore refused, although no attribute follows its content, no value is in it, and its bytes write back exactly. A short-count element with no content at all already encoded (
test_fewer_attribute_records_than_the_count).The encoder now refuses on the flag when an attribute record's offset comes after the first content record's, the real attribute-after-content case. It also still refuses when the records carry no offsets to tell (a tree built by hand fails closed as before). The existing check for a value in the content of a short-count element is unchanged, and
rbf0_treeis untouched, so its counts and reports stay the same.Measured corpus effect: none. 9.6 found no such element among the 1,263
data.rpfresources, and the only refusals there are the 23 invalid-UTF-8 ones. This is the encoder agreeing with its documented rule.Different topic from #1574 (same files); the two merge cleanly.
Tested
Windows 11, Python 3.14.7, synthetic RBF0 streams only:
python -I tests/test_rbf0_encode.py: 37 tests OK.test_fewer_attribute_records_than_the_countnow also takes a root withattrs=2, one int attribute, then text or a child element:okand flagged;mainrefuses both;order.test_attribute_after_content(a value after text with a short count) still refuses withorder.tests/test_rbf0_tree.pyOK.python -m compileall;scripts/check_no_game_data.pyon both files.GPUs tested: n/a (CPU-only tool)
AI-assisted: yes (Claude Code, Claude Opus 5.5)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
VERIFY-2386 — Linux, Python 3.15, CPU only, no game files
Claimed as
VERIFY-2386. Two-step method: merge into a clean worktree atmain(9d231d37) and run the test file; then take only the test file onto cleanmainand run it again, which is both the baseline reproduction and the reverse control.Result: the change does what it says, but merging it into
maintoday turns 41 green tests into 4 errors.python -I tests/test_rbf0_encode.pymain(9d231d37)main+ this pull requestmain+ only this pull request's tool change (test file untouched)main+ only this pull request's test file (tool untouched)The last row is the reverse control working as intended: the two new tests do fail without the change, so they are not vacuous.
The third row isolates the cause to
tools/rbf0_encode.py.The cause
main'stests/test_rbf0_encode.py:344-348deliberately feeds malformed shapes and expects the encoder to take its documented fail-closed path:The two lines this pull request adds are evaluated before the
attribute_order_violationtest that guards them:node.get("content", [])returnsNonewhen the key is present andNone(a default applies only to an absent key), and["bad"]holds strings, not dicts. So the list comprehensions raise before theifis even reached:Four subtests, four errors. The refusal the test asks for (
"value") never runs.Fairness
This is not something the pull request could have been tested against as written. Its base is
d5634def, where this file had 37 tests;mainhas since added 78 lines and 4 test methods to it (now 41). The "37 tests OK" in the description is accurate for that base, and I could not find any open report of this —"test_bool_recorded_lengths"has zero hits in issues and pull requests.The smallest fix is to not compute the offset lists until they are needed — move them inside the
if node.get("attribute_order_violation")branch so the existing fail-closed checks still see malformed input first — and to tolerate non-dict children there. Whether a non-dict child should count as "no offsets to tell" is the author's call; I have not changed anything.Verified: the change's own 2 tests catch it, the stated behaviour holds on its own base, and the tree was restored to clean
mainafterwards.AI-assisted: yes — MiMo-V2.6-Flash (OpenCode). It built the worktrees, ran the isolation matrix and drafted this report; the failure text above is verbatim from the runs.
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.)
Verification — VERIFY-2386
Verdict: FAIL in the merged state — the PR head passes its own tests, but merging current main breaks 4 subtests (details below)
4f1ca189643e738bf7b4c72a557f49d474fadc5d| merge state vs main8422def759cda12c89f918438eeb8d53dd5972a6: merges CLEAN, but the merged tree fails testspython3 -I tests/test_rbf0_encode.pytest_fewer_attribute_records_than_the_countERRORs on both new subtests (content=text and content=child) —Ran 37 tests — FAILED (errors=2), so the red is real. On the PR head alone:Ran 37 tests — OK.Ran 41 tests — FAILED (errors=4). All 4 errors are in main's newertest_bool_recorded_lengths_and_malformed_element_children(fields attributes/content with values None, [123], ['bad']), raisingAttributeError: 'str' object has no attribute 'get'(and the int equivalent). Plain main passes all 41. Cause, READ IN CODE: the PR's new guard intools/rbf0_encode.pyelement()calls.get("offset")on every attribute/content record before any type validation, so a malformed non-dict record crashes with AttributeError instead of the EncodeError main's test expects. The guard needs to treat a non-dict record as "no offset to tell" (fail closed with EncodeError) rather than calling.geton it.AI-assisted: yes (Muse Wonder, Muse by Meta)
For information: this pull request is carried in #3096, which merges your head (your commits are kept) into current
main, resolves the conflicts keeping both sides, and fixes the points raised in review here (details in its description). This one stays open until a maintainer decides; if you pick it up again, say so and the carry can be closed.AI-assisted (Claude Code, Claude Opus 5.5)
Superseded: MoonEyes carries this head in #3096 ("rbf0_encode: write back a short-count element with text or child content (carry of #2386)"), which keeps your commits. No deep work here.
A quick check confirms what aegish-zagi reported today: the merged state is not green.
main+ this head)python -I tests/test_rbf0_encode.pypython -I scripts/check_no_game_data.py tools/rbf0_encode.py tests/test_rbf0_encode.pyThose errors are what #3096 resolves against current
main, so review and CI belong there.Verdict: superseded by #3096. Close this one when #3096 merges.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code