--- kind: pattern name: memory-fixer description: > Auto-fix low-hanging fruit in the graph. No judgment calls — only deterministic Level 1 operations. Escalate anything that needs Kwame's input. version: 1.1.0 --- # Memory Fixer ## Purpose Auto-fix low-hanging fruit in the graph. No judgment calls — only deterministic Level 1 operations. Escalate anything that needs Kwame's input. ## Level 0 Auto-Deletes (Allowed Without Approval) Ephemeral heartbeat and log nodes that violate "Logs NEVER go in the graph": - `[LITELLM-HEALTH]`, `[GPU-SELF-HEAL]`, `[PM2-SELF-HEAL]` - `[PROXMOX-MONITOR]`, `[GPU-MONITOR]`, `[INFRA-MONITOR]`, `[AGENT-HEALTH]`, `[DISK-GC]` - `[WAL]` entries older than 30 days **Condition:** node must be an orphan (no edges). Deleting a connected node risks breaking other nodes. **Method:** direct SQLite on `.65` (MCP has no delete tool): ```bash ssh root@192.168.68.65 "sqlite3 /root/.local/share/RA-H/db/rah.sqlite \" DELETE FROM nodes WHERE id IN ( SELECT id FROM nodes WHERE id NOT IN (SELECT from_node_id FROM edges) AND id NOT IN (SELECT to_node_id FROM edges) AND title LIKE '[LITELLM-HEALTH]%' -- add more prefixes as needed );\"" ``` ## Level 1 Auto-Fixes (No Judgment Required) ### 1. Missing `type` Field For nodes with content but no `metadata.type`: - Title contains "Proxmox" or "infrastructure" → `type: infrastructure` - Title contains "skill" or "how to" or "guide" → `type: skill` - Title contains "doc" or "template" or "brand" → `type: documentation` - Title starts with "WAL:" or "TASK:" → `type: note` - Title starts with "[LEARN]" → `type: documentation` - Otherwise → `type: note` (default) ### 2. Missing `tenant` / `namespace` For any node with NULL tenant or namespace: ```sql UPDATE nodes SET metadata = json_set( COALESCE(metadata, '{}'), '$.tenant', 'syslogsolution', '$.namespace', 'syslogsolution' ) WHERE json_extract(metadata, '$.tenant') IS NULL OR json_extract(metadata, '$.namespace') IS NULL; ``` ### 3. Staleness State Transitions Using the type-based windows from the memory-monitor contract: - Nodes stale > their window → transition to `state: review_pending` - Nodes in `review_pending` for >7 days → escalate to Kwame (Level 2) ## Level 2 Escalations (Kwame Decision Required) 1. **Nodes in `review_pending` >7 days** — Archive, refresh, or keep? 2. **Orphan Nodes >90 days old** — Delete or Connect? 3. **Potential Duplicate Nodes** — Same title or >70% overlap. Merge or Keep? 4. **Conflicting Metadata** — Content suggests one tenant but metadata says another. ## Logging Every Level 1 fix logged to `~/.hermes/logs/memory-fixer/YYYY-MM-DD.md` Every Level 2 escalation logged and delivered to Kwame.