T09 · Insecure Skill Coding Practices
- Location
dedup.mjs:24- Finding
Lossy Deduplication Can Silently Destroy Persistent Memory Content
- Content
View full analysis
{ if (line.startsWith('###')) { if (currentSection) sections.push(currentSection); currentSection = { title: line.replace(/^###\s*/, ''), content: [], priority: line.match(/\[P(\d)\]/) ? parseInt(line.match(/\[P(\d)\]/)[1]) : 9 }; } else if (currentSection && line.trim()) { currentSection.content.push(line); } }); if (currentSection) sections.push(currentSection); return sections; } ``` ```javascript if (dup.similarity > 0.8) { toRemove.add(dup.index2); } else if (dup.similarity > 0.5) { if (!toRemove.has(dup.index1) && !toRemove.has(dup.index2)) { const mergedSection = mergeSections(dup.section1, dup.section2); merged.set(dup.index1, mergedSection); toRemove.add(dup.index2); } } ``` ```javascript const newContent = rebuildMemory(dedupedSections); ``` ```javascript fs.writeFileSync(memoryPath, newContent); ``` ### Technical Analysis The parser recognizes only lines beginning with `###` as section boundaries. All content before the first such heading is silently omitted. Other Markdown heading levels are not represented structurally and can be absorbed into a preceding section. Blank lines and the original document layout are also discarded. The duplicate-removal logic creates a separate data-loss condition. When two section titles have similarity greater than `0.8`, the later section is marked for removal without merging its content into the retained section. Identical headings with different bodies therefore cause all facts unique to the later section to be deleted. The reconstructed document is written ...[truncated 1340 chars]- Remediation
View remediation
