Repository navigation
Description
Summary
pkgs/id/src/didit/body.rs can encode did-it bodies that its own decoder refuses: two collections have no count cap in check(), so they can exceed the CBOR decoder's per-array element limit. A body this code writes is then unreadable by itself and by every peer — the module's stated contract ("a body that decodes is a body that would re-encode to itself", and encoders/decoders applying the same shape rules) only holds in one direction.
Evidence (verified this run, laptop primary @ ec2ac0e8eb)
- The decoder is configured with a declared-element limit:
top_level()(body.rs:873-895) decodes withDecodeOptions … .length_limit(LENGTH_LIMIT)whereconst LENGTH_LIMIT: u64 = 8192(body.rs:63, "Declared element limit for one array, map, or string"). - The model checks cap the collections the authors remembered:
check_subjectsrefuses more thanMAX_SUBJECTS = 512(body.rs:54, 839-858) andRecord::checkrefuses more thanMAX_DETAILS = 512details (body.rs:57, 253-258). The sibling CBOR modules do the same:idset.rscapsMAX_ENTRIES = 4096against the same 8192 decoder limit, andchain.rscapsMAX_AFTER = 32against its 512 limit. - But
Entity::check(body.rs:96-110) validates each alias's text and rejects duplicates — with no cap on the alias count — andActiveWindow::check/HoursSpan::check(body.rs:399-430, 453-500) validates each span's minutes/days with no cap on the span count. Nothing else bounds these counts beforecheck_size(which only caps total bytes atMAX_BODY_BYTES = 1 MiB,body.rs:816-821). - Probe (laptop,
~/git/fleet/probe-didit-aliases, realidcrate @ec2ac0e8eb,cargo run --release):- Entity with 8,193 distinct aliases (
a0…a8192):encode_entity_body→ Ok, 48,143 bytes (well under the 1 MiB cap);decode_entity_bodyon those exact bytes → ErrDiditError::Cbor("the did-it body is not CBOR: length exceeds reasonable size")— the decoder's length limit refusing the array the encoder just wrote. - Control at the limit, 8,192 aliases: encodes (48,137 bytes) and decodes Ok — the failure is exactly the 8,192 element boundary, not size or content.
- Expectation with 8,193 identical hours spans (420→1320, days
None):encode_expectation_body→ Ok, 65,689 bytes;decode_expectation_body→ Err, same Cbor length error. - Normal control (entity with 1 alias): encodes and decodes Ok.
- Entity with 8,193 distinct aliases (
Why it matters
encode_entity_body / encode_expectation_body are the write path for did-it events (#2031 tracker, body persistence in #4837). An entity with many aliases (importers and household merges are the realistic source — an entity accumulates aliases over its life) or an expectation with many active-hours spans can be constructed, pass check(), encode, and be signed/published — and then no decoder in the fleet can read it back, including the writer's own store on the next load. That is a self-inflicted unreadable event in an append-only log: it cannot be repaired by editing, only by superseding events that themselves reference data peers cannot decode. The caps exist for exactly this reason on subjects/details; aliases and hours spans were simply missed.
The fix direction (for triage to confirm): add explicit count caps for entity aliases and hours spans in check() — sized like the sibling caps (well under the 8192 decoder limit, e.g. in line with MAX_SUBJECTS/MAX_DETAILS) — with tests pinning that a body at the cap round-trips and one over the cap is refused at encode time with a named DiditError::Invalid, rather than producing an undecodable body.
Acceptance criteria
-
Entity::check(and therefore bothencode_entity_bodyanddecode_entity_body) refuses an entity whose alias count exceeds a named maximum, with the error naming the count and the limit — mirroringcheck_subjects/ the details cap. -
ActiveWindow::Hourschecking refuses an expectation whose hours-span count exceeds a named maximum, same error shape. - Pinning tests: an entity/expectation exactly at each new cap encodes and round-trips through its decoder; one over the cap is refused by
encode_*_body(this is the regression test for this issue — pre-fix the over-cap bodies encode successfully and fail decode). - Existing didit tests stay green:
cargo test -p id --lib diditon the laptop or in CI. - A sweep of the other
diditbody collections confirms no remaining uncappedVecfield can exceed the decoder's 8192 element limit under the 1 MiB body cap (subjects, details,about, days are already bounded — see the issue body).
Activity
developing-today commentedon Nov 5, 2026
CODE-1657
dezren39 commentedon Nov 5, 2026
🤖 Agent note · filed
encode_*_bodycan never produce a body the decoder's 8192-element limit refuses; pin the boundary with round-trip tests.Entity::check/ActiveWindow::checkmirroring the subjects/details caps, at-cap bodies round-trip, over-cap bodies refused at encode with a named error,cargo test -p id --lib diditgreen.~/git/fleet/probe-didit-aliases(laptop); queue packet enqueued this run to repo-health-code-pilot.dezren39 commentedon Nov 5, 2026
🤖 Agent note · picked up
17 remaining items
Merge pull request #6030 from developing-today/queue/9865-5991-didit-…
dezren39 commentedon Nov 5, 2026
🤖 Agent note · done
cargo test --lib diditin pkgs/id — 27 passed, 0 failed (incl. entity_alias_count_is_capped, hours_span_count_is_capped); Codex review on PR fix(id): cap didit entity aliases and hours spans at 512 (#5991) #6030 completed with no findings. PR-tier checks were still QUEUED (not started) after ~35 minutes across two poll windows — merged under Drew's merge-authority rule (verified done; PRs do not wait for CI; CI runs on main) with the change verified on the laptop; main-tier CI on the merge is the backstop and a failure gets a fix-forward.