rbf0_encode: write back a short-count element with text or child content (RBF0-ENCODE-SHORT-COUNT-CONTENT) #2386
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2386"
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?
Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-26T16:53:47Z.
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
Imported from ubiquitarianism/leonida. Originally posted by MSedgeMC on 2026-11-26T18:03:03Z.
Review: COMMENTED
Verified on the PR branch: python3 -m unittest tests.test_rbf0_encode -v -> 37 tests OK, including the new short-count write-back cases. Not approving yet: this branch carries 522 commits not on current main, so merging as-is would drag in unrelated history. Please rebase onto main and re-run the suite.
Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:39:59Z.
Review: COMMENTED
macOS arm64 check of #2386 (RBF0-ENCODE-SHORT-COUNT-CONTENT). A tools-only encoder change.
Tested head
4f1ca1896with its diff applied to a copy ofmainbdbc7e923(branch 10 commits behind;git apply/git merge-treeclean).Environment: Apple M3 Pro, arm64, macOS 27.2.1, CPython 3.15.2.
Result
python -I tests/test_rbf0_encode.py: 37 tests, OK.tools/rbf0_encode.pyput back tomain's): 2 errors - bothtest_fewer_attribute_records_than_the_countsubtests (content='text',content='child') raiseEncodeError("order")where the test expects the original bytes back. So the short-count case is exactly what changed.python -I scripts/run_semantic_tests.py tests/semantic: 500 files / 6,367 tests / 0 failed, same asmain.Review
offset(a hand-built tree), which is the right way round: without offsets the encoder cannot know whether an attribute record follows the content, so it fails closed. The test pops the offsets and expects"order", matching.max(attr_at) > min(content_at)catches every layout with an attribute after the first content record, including an attribute between two content records; an element whose content follows all attribute records writes back unchanged, which is what the new subtests check.offset0 and large offsets are treated byisinstance, not truthiness, so a zero offset would not be misread; the header makes a real 0 impossible anyway.test_fewer_attribute_records_than_the_countcase (one attribute, declared two, no content) still encodes identically, so the flag alone no longer refuses a reproducible element.I found no bug in the change. The comment above the condition is a good explanation of why
attribute_order_violationis not enough on its own; no follow-up needed from this side.python -I scripts/check_no_game_data.pyon both changed files: clean.No game files. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T04:16:35Z.
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.
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:03:37Z.
Review: COMMENTED
Draft review against current
main: checkingmax(attr_at) > min(content_at)(and integer offsets) forattribute_order_violationintools/rbf0_encode.py:165-171so short-count elements with text/child content write back cleanly looks solid and clean-room verified. Still Draft with no CI run yet — please mark Ready for Review so CI runs green.(AI-assisted review.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:35:18Z.
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.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T13:01:30Z.
Review: CHANGES_REQUESTED
Now ready for review, requesting changes before merge:
main(tools/rbf0_encode.py:165-171): as reproduced by@imShangLi, the added list comprehensions[c.get("offset") for c in node.get("content", [])]and[a.get("offset") for a in node.get("attributes", [])]execute before shape validation, raisingTypeError/AttributeErrorand failing 4 existing fail-closed tests intests/test_rbf0_encode.py:344-348(attributes/contentset toNoneor containing non-dict elements like[123]/["bad"]). Please guard onisinstance(..., list)and dict items (or run after shape validation) so malformed inputs still refuse cleanly with"value".(AI-assisted review.)
Imported from ubiquitarianism/leonida. Originally posted by aegish-zagi on 2026-12-02T04:52:12Z.
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)
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T10:32:55Z.
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)
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:14:44Z.
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