The document magic as an item magic is a nested document, not a defect - #281
Conversation
Closes #204. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Warning Review limit reachedNext included review available in 46 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment: S/M/L PR Classification Guidelines:This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed. Small (S)Characteristics:
Review Effort: Would have taken 5-10 minutes Examples:
Medium (M)Characteristics:
Review Effort: Would have taken 15-30 minutes Examples:
Large (L)Characteristics:
Review Effort: Would have taken 45+ minutes Examples:
Additional Factors to ConsiderWhen deciding between sizes, also consider:
Notes:
|
Closes #204.
The adjudication
#204 asks, neutrally, whether the codec should reject
KnownMagic::RainMetaDocumentV1as an item's own key-1 magic, on the premise that such an item is "representable-but-meaningless" becauseunpack_intoandKnownMeta::try_fromboth answerUnsupportedMeta.It must not reject, and the premise does not hold. The document magic as an item's own magic already has a defined meaning in this crate: the payload is itself a complete rain meta document.
OrderBuilderStateV1::extract_from_meta(crates/cli/src/meta/types/dotrain/order_builder_state_v1.rs:99) branches on exactly that and recurses:That branch is human-authored and shipped -- introduced in
ddaf63d(2025-07-11,feat: implement DotrainInstance1::extract_from_meta), carried through the rename ina712031, and pinned by the pre-existingtest_extract_from_meta_nested_rain_document. Rejecting the magic at encode or decode deletes nesting from the crate. Verified, not assumed: applying the rejection makes that pre-existing test fail (evidence under QA).The reading is the spec's own. Key 1 is defined as "a signal of intent for the payload"; the payload of a nesting item is a rain meta document, so the document magic is the correct signal for it. The magic-number table's "Prefixes every rain meta document" says where the number is required, not that it may appear nowhere else, and the design goals ask for "a graph structure between meta such that meta can be about other meta".
The unpack layer is right to keep rejecting it, and that is the answer to the issue's second clause: nesting is not a leaf meta type, so
unpack_intomust never hand a whole document to a payload conversion. Representability here is not "harmless", it is load-bearing, and theUnsupportedMetaat the unpack layer is the correct boundary rather than evidence of meaninglessness.The issue's scanner-confusion note is real but external to this repo. Every prefix check here is at offset 0 --
cbor_decodeandStore::store_contentusestarts_with, and Solidity'sLibMeta.isRainMetaV1reads the leading 8 bytes. Nothing scans mid-stream, and cbor's length-prefixed framing disambiguates for any correct decoder, as the issue itself notes.What changed
No behaviour change. The decision is stated where the wrong inference was drawn, and enforced where a future change would otherwise make it silently.
crates/cli/src/meta/magic.rs-- theRainMetaDocumentV1doc comment read only "Prefixes every rain meta document", which is the text that invites RainMetaDocumentV1 document magic is encodable as an item's own magic, producing representable-but-unusable metas #204's reading. It now names both roles.crates/cli/src/meta/mod.rs-- three tests pin the semantic at the codec level, where it previously existed only inside one consumer in another module:test_cbor_decode_handwritten_document_magic_item-- a handwritten{0: h'01', 1: 0xff0a89c674ee7874}map decodes, so acceptance is the decoder's own behaviour and not an artefact of this crate's encoder.test_document_magic_item_carries_a_nested_document-- an item whose magic is the document magic and whose payload is a complete prefixed document survivescbor_encode_seq->cbor_decodewith its payload byte for byte intact, and that payload decodes to the inner item.test_document_magic_item_is_not_unpackable-- the boundary:KnownMeta::try_fromandunpack_intostill answerUnsupportedMeta.Relation to the other cbor_decode / KnownMagic work
All read before writing this.
RainMetaDocumentV1is a known magic, so it is never on the drop path; the tests here would pass unchanged on top of it.test_cbor_decode_mandatory_keys_present_still_type_checkedstates the same rule this PR relies on: an item carrying both mandatory keys is not "unexpected" and is not dropped. A nesting item carries both.WebDataV1) -- different concern, but it also editsmagic.rs. The edits are on different lines (its variant sits after the rain-specific numbers; this changes the doc comment of the first variant), so they rebase cleanly.cbor_decode's corrupt-meta guard.cbor_decodeis document-level or item/sequence-level. The nesting semantic pinned here is evidence for the item/sequence reading:extract_from_metahands a prefixed inner document straight back tocbor_decode, so the same entry point has to accept both prefixed and bare input. Whatever cbor_decode accepts input without the rain meta document prefix; spec says tooling MUST discard data not beginning with the magic number #203 decides must not break that recursion.No open PR in the group decides anything that contradicts this one; #204 is the only issue of the six that proposed narrowing what a known magic may mean.
QA
test_cbor_decode_handwritten_document_magic_item,test_document_magic_item_carries_a_nested_document,test_document_magic_item_is_not_unpackable(all new,crates/cli/src/meta/mod.rs). These pin behaviour that already holds on base, so they do NOT fail on base by construction -- the discriminator is the remedy RainMetaDocumentV1 document magic is encodable as an item's own magic, producing representable-but-unusable metas #204 proposed, applied as a mutation and run (see below). Stated plainly so no one mistakes them for regression tests: base is green, and the point is that the proposed change is not.mod.rs:310Serialize::serialize-- guard at the top returningserde::ser::Error::custom("document magic is not an item magic")whenself.magicisRainMetaDocumentV1(encode-side rejection, half the remedy) -> killedtest_document_magic_item_carries_a_nested_documentAND the pre-existingtest_extract_from_meta_nested_rain_document(called Result::unwrap() on an Err value: SerdeCborError(... Message("document magic is not an item magic"))atorder_builder_state_v1.rs:431);test_cbor_decode_handwritten_document_magic_itemcorrectly survives, it never encodes. (2)mod.rs:380Deserializevisitor -- same guard after the magic resolves (decode-side rejection, the other half) -> killed all three oftest_cbor_decode_handwritten_document_magic_item,test_document_magic_item_carries_a_nested_documentandtest_extract_from_meta_nested_rain_document. (3) both guards together (the full remedy) -> same three fail, 21 other tests under the same filter still pass, so the kills are specific and not collateral. (4)unpack_into-- add| KnownMagic::RainMetaDocumentV1to the accepted arm -> killedtest_document_magic_item_is_not_unpackableatmod.rs:1671(theunpack_intoassert). (5)KnownMeta::try_from-- addKnownMagic::RainMetaDocumentV1 => Ok(KnownMeta::DotrainV1)-> killed the same test atmod.rs:1667(theKnownMeta::try_fromassert). Every mutation was reverted and the tree re-verified green afterwards.extract_from_metanesting branch and its commit history (ddaf63d,a712031). The decode-only case is handwritten cbor bytes (0xa2 0x00 0x41 0x01 0x01 0x1b ff0a89c674ee7874) written from RFC 8949, never produced bycbor_encode, so the decoder is not validated against this crate's own encoder. The nesting case asserts at both levels (outer item recovered, inner document re-decoded) rather than a single round trip of one function against itself.Verification
~70 agents are building on this machine, so no full local suite. Ran
cargo test -p rain-metadata --lib -- meta::-- 235 passed, 0 failed.cargo fmt --all -- --checkclean.cargo clippy -p rain-metadata --all-targetsclean.rainix-rs / static / rs-staticfails repo-wide on an unrelated rainix hook bug.🤖 Generated with Claude Code