{"record":{"id":"fc2e994e84ff2808","repo":"siyuan-note/siyuan","slug":"inconsistent-attribute-view-rich-text-style-entity","errorCode":null,"errorMessage":"inconsistent attribute view rich text style entity sentinel","messagePattern":"inconsistent attribute view rich text style entity sentinel","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/av/value.go","lineNumber":1929,"sourceCode":"\t}\n\treturn builder.String(), protections\n}\n\nfunc restoreValueTextRichTreeStyleEntities(tree *parse.Tree,\n\tprotections []valueTextRichStyleEntityProtection) (err error) {\n\tif 1 > len(protections) {\n\t\treturn\n\t}\n\tsentinel := protections[0].sentinel\n\tstylePairs := make([]string, 0, len(protections)*2)\n\tliteralPairs := make([]string, 0, len(protections)*2)\n\ttextMarkCodePairs := make([]string, 0, len(protections)*2)\n\ttextMarkInlineMathPairs := make([]string, 0, len(protections)*2)\n\ttokenIndexes := make(map[string]int, len(protections))\n\trestored := make([]bool, len(protections))\n\tfor i, protection := range protections {\n\t\tif sentinel != protection.sentinel {\n\t\t\treturn fmt.Errorf(\"inconsistent attribute view rich text style entity sentinel\")\n\t\t}\n\t\ttokenIndexes[protection.token] = i\n\t\tstylePairs = append(stylePairs, protection.token, protection.decoded)\n\t\tliteralPairs = append(literalPairs, protection.token, protection.encoded)\n\t\tencoded := strings.ReplaceAll(protection.encoded, \"&\", \"&amp;\")\n\t\ttextMarkCodePairs = append(textMarkCodePairs, protection.token, encoded)\n\t\ttextMarkInlineMathPairs = append(textMarkInlineMathPairs, protection.token,\n\t\t\tstrings.ReplaceAll(encoded, \"&\", \"&amp;\"))\n\t}\n\tstyleReplacer := strings.NewReplacer(stylePairs...)\n\tliteralReplacer := strings.NewReplacer(literalPairs...)\n\ttextMarkCodeReplacer := strings.NewReplacer(textMarkCodePairs...)\n\ttextMarkInlineMathReplacer := strings.NewReplacer(textMarkInlineMathPairs...)\n\n\tast.Walk(tree.Root, func(node *ast.Node, entering bool) ast.WalkStatus {\n\t\tif !entering {\n\t\t\treturn ast.WalkContinue\n\t\t}","sourceCodeStart":1911,"sourceCodeEnd":1947,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/av/value.go#L1911-L1947","documentation":"During restore of protected style entities, each recorded protection must carry the same sentinel token that was generated for this run; one protection record's sentinel differs from the loop's sentinel, so restoration cannot proceed safely. This is an internal consistency check on the protect/restore machinery that hides HTML-escaped entities in styles during parsing.","triggerScenarios":"restoreValueTextRichTreeStyleEntities (kernel/av/value.go:1929 region) invoked with protections produced by a different protect call, or protections mixed from multiple runs so their sentinel fields disagree.","commonSituations":"Custom Go code calling the protected internal functions directly and caching protections across calls; concurrent/mis-sequenced protect-restore pairing; a refactor that passed stale protection slices.","solutions":["Always obtain protections and their sentinel from the same protectValueTextRichStyleEntities call and pass them together to restore in the same call","Do not cache or merge protection slices across separate parse invocations","If implementing custom processing, generate one sentinel per content string and reuse it for all protections of that string","This is internal-invariant breakage: if seen in stock SiYuan without custom code, capture the content and file an issue"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"for _, p := range protections { if p.sentinel != expectedSentinel { return errors.New(\"stale protection slice\") } }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair protect and restore calls one-to-one, never across invocations","Don't cache protection slices; regenerate per content string","Scope sentinel generation per call site","Cover protect/restore pairing with round-trip tests"],"tags":["attribute-view","rich-text","internal-invariant","entity-protection"],"backgroundTag":"internal-invariant-violation","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}