feat(shadows): decompose nested report_only(persist) fields to KV - #135
Merged
Merged
Conversation
`report_only(persist)` previously persisted each field as one whole-value postcard blob via a separate `ReportedFields::persist_report_only` path. That couldn't round-trip a nested `#[shadow_node]` (struct or adjacently-tagged enum) against the decomposed `load_from_kv`, and demanded `MaxSize` on the whole type — so a nested persisted enum simply didn't compile. Persist the `Reported` side decomposed instead, mirroring the State `persist_to_kv` key layout so `load_from_kv` reads it back. Because a `Reported` is a partial projection, unreported (`None`) fields keep their prior KV value: a partial report merges with prior state at load, with no read-modify-write. Terminal leaf types whose `Reported == Self` (primitives, std `String`/`Vec`, `heapless::String`) delegate to their existing `persist_to_kv`. The default `persist_reported_kv` errors with `KvError::Unsupported` rather than silently dropping data, for types that can't be decomposed without narrowing `ShadowNode` (`heapless::Vec`/`LinearMap`/arrays would force `T: MaxSize`) or need a per-entry walker (maps) / a non-adjacently-tagged enum — mark such a field `opaque`.
KennethKnudsen97
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
report_only(persist)persisted each field as one whole-value postcard blob via a separateReportedFields::persist_report_onlypath. That couldn't round-trip a nested#[shadow_node](struct or adjacently-tagged enum) against the decomposedload_from_kv, and demandedMaxSizeon the whole type — so a nested persisted enum didn't even compile.This persists the
Reportedside decomposed, mirroring the Statepersist_to_kvkey layout soload_from_kvreads it back. Since aReportedis a partial projection, unreported (None) fields keep their prior KV value — a partial report merges with prior state at load, with no read-modify-write. The shape parallelspersist_delta(the same skip-Nonedecomposed walk overDelta).The KV layout for a non-
opaquereport_only(persist)field changes. A nested#[shadow_node]value now persists as decomposed keys (/field/...) instead of a single whole-value blob at/field. A device that previously persisted such a field as a blob will not find the decomposed keys on upgrade, so the value resets to its default on first boot after the update.To keep the previous blob layout (and avoid the reset), add
opaqueto everyreport_only(persist)attribute you want unchanged:Notes:
report_only(persist)before this PR).Coverage
Reported == Self— primitives, stdString/Vec,heapless::String— delegate to their existingpersist_to_kv.persist_reported_kverrors withKvError::Unsupported(not a silent drop) for types that can't be decomposed without narrowingShadowNode(heapless::Vec/LinearMap/arrays would forceT: MaxSizeonto theirShadowNodeimpl), need a per-entry walker (maps), or are non-adjacently-tagged enums. Mark such a fieldopaqueto store it as a whole-value blob instead.Notes
MaxSizedemand are removed; the leafopaque(max_size)sizing from fix(shadows): honor opaque(max_size) for report_only(persist) KV buffer #133 is preserved for leaf fields.