---
name: store_memory protection before RAG re-bootstrap (unified at-risk rule + promote-to-disk twin)
description: Before AI_INFRA runs replace-mode bootstrap.py (wipes collection + re-index from corpus files), inventory store_memory chunks and verify each survives. Cross-project (NAMGROUP lost 2 chunks; SE applied rule S41).
type: lesson
originSessionId: solution-erp-s41
revision: S41 (2026-05-29)
---

# store_memory protection before RAG re-bootstrap (S41 SOLUTION_ERP)

**Context:** AI_INFRA re-bootstrap uses `auto_reindex_mode=replace` → WIPES the whole Qdrant collection, then re-indexes ONLY from `corpus_paths`/`extra_corpus` files on disk. Any `store_memory` chunk whose content does NOT live in a corpus file is LOST. NAMGROUP lost 2 chunks this way (.tsx content outside corpus glob).

## ⭐ UNIFIED AT-RISK RULE (apply cross-project)
A `store_memory` chunk is AT-RISK ⟺ its content is NOT reproducible from a file that is:
{exists} ∧ {matches a `corpus_paths` glob} ∧ {NOT excluded by `exclude_paths`}.

- "File exists" is NOT enough — must also match corpus glob (NAMGROUP `.tsx` existed but was outside `docs/**/*.md` → lost).
- Twin INSIDE corpus glob (+ not excluded) = SAFE (replace-mode re-creates it from the file).
- A `source_path` with a `#anchor` is a VIRTUAL label set at store-time — it does NOT guarantee the content is a real section in that file. Verify the actual file content, not the anchor.

## Inventory method
- True `store_memory` chunks surface with `heading_path = "(manual)"` (file-indexed chunks carry a real heading hierarchy). AI_INFRA tool is marker-based (more reliable than self-count — SE counted 3, tool found 5).
- For each: pull the chunk content via `search_memory`, then check against disk.

## Fix for at-risk chunks: PROMOTE-TO-DISK
Write the chunk content VERBATIM into a real corpus file (e.g. `docs/changelog/sessions/*.md`) with a header noting it's the on-disk twin of chunk `<id>`. After re-bootstrap it returns as FILE-INDEXED (real `heading_path`, not `(manual)`) = proof of zero-loss.

## Related: exclude_paths must be `**/`-anchored (gotcha #10)
Root-anchored `node_modules/**` / `docs/_archive/**` do NOT match nested paths (e.g. `docs/_user-guide/node_modules/`) → junk hides inside corpus while count looks clean. Use `**/node_modules/**`, `**/_archive/**`. AI_INFRA paired a `find_files` dir-aware fix host-side (eb9634e). SE S41 corpus: 3080→2406 (−674 junk).

## Ownership (charter v2)
SE owns its corpus DECLARATION (corpus_paths/exclude_paths) + content + this verification. AI_INFRA owns the MECHANISM (bootstrap.py / chunk_size / path-resolution / running the re-index). SE does NOT run bootstrap.py.
