Skip to content

Commit 7139695

Browse files
ArchieIndianclaude
andauthored
Add memory-integrity-checker skill (#39)
Validates memory summary DAGs with 8 structural checks: orphan nodes, circular references, token inflation, broken lineage, stale active, empty nodes, duplicate edges, depth mismatch. Auto-fixes safe issues. Cron Sundays 3am. Inspired by lossless-claw's DAG integrity checking system. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d454136 commit 7139695

4 files changed

Lines changed: 686 additions & 0 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
name: memory-integrity-checker
3+
version: "1.0"
4+
category: openclaw-native
5+
description: Validates memory summary DAGs for structural integrity — detects orphan nodes, circular references, token inflation, broken lineage, and stale summaries that corrupt the agent's memory.
6+
stateful: true
7+
cron: "0 3 * * 0"
8+
---
9+
10+
# Memory Integrity Checker
11+
12+
## What it does
13+
14+
As memory DAGs grow through compaction, they can develop structural problems: orphan nodes with no parent, circular reference loops, summaries that inflated instead of compressing, broken lineage chains, and stale nodes that should have been dissolved. These problems silently corrupt the agent's memory.
15+
16+
Memory Integrity Checker runs 8 structural checks on the DAG, generates a repair plan, and optionally auto-fixes safe issues.
17+
18+
Inspired by [lossless-claw](https://github.com/Martian-Engineering/lossless-claw)'s DAG integrity checking system, which detects and repairs corrupted summaries.
19+
20+
## When to invoke
21+
22+
- Automatically Sundays at 3am (cron) — weekly structural audit
23+
- After a crash or unexpected shutdown — check for corruption
24+
- When the agent's memory seems inconsistent — diagnose structural issues
25+
- Before a major compaction or prune operation — ensure clean starting state
26+
27+
## Integrity checks (8 total)
28+
29+
| Check | What it detects | Severity |
30+
|---|---|---|
31+
| ORPHAN_NODE | Node with no parent and not a root | HIGH |
32+
| CIRCULAR_REF | Circular parent-child loops in the DAG | CRITICAL |
33+
| TOKEN_INFLATION | Summary has more tokens than its combined children | HIGH |
34+
| BROKEN_LINEAGE | Edge references a node ID that doesn't exist | CRITICAL |
35+
| STALE_ACTIVE | Active node older than 30 days with no children | MEDIUM |
36+
| EMPTY_NODE | Node with empty or whitespace-only content | HIGH |
37+
| DUPLICATE_EDGE | Same parent-child edge appears multiple times | LOW |
38+
| DEPTH_MISMATCH | Node's depth doesn't match its position in the DAG | MEDIUM |
39+
40+
## How to use
41+
42+
```bash
43+
python3 integrity.py --check # Run all 8 integrity checks
44+
python3 integrity.py --check --fix # Auto-fix safe issues
45+
python3 integrity.py --check --only ORPHAN_NODE # Run a specific check
46+
python3 integrity.py --repair-plan # Generate repair plan without fixing
47+
python3 integrity.py --status # Last check summary
48+
python3 integrity.py --format json # Machine-readable output
49+
```
50+
51+
## Procedure
52+
53+
**Step 1 — Run integrity checks**
54+
55+
```bash
56+
python3 integrity.py --check
57+
```
58+
59+
Runs all 8 checks and reports findings by severity.
60+
61+
**Step 2 — Review repair plan**
62+
63+
```bash
64+
python3 integrity.py --repair-plan
65+
```
66+
67+
For each finding, shows what the auto-fix would do:
68+
- ORPHAN_NODE → reattach to nearest active root or deactivate
69+
- DUPLICATE_EDGE → remove duplicates
70+
- EMPTY_NODE → deactivate
71+
- STALE_ACTIVE → deactivate
72+
73+
**Step 3 — Apply safe fixes**
74+
75+
```bash
76+
python3 integrity.py --check --fix
77+
```
78+
79+
Auto-fixes LOW and MEDIUM severity issues. HIGH and CRITICAL require manual review.
80+
81+
## State
82+
83+
Check results, finding history, and repair actions stored in `~/.openclaw/skill-state/memory-integrity-checker/state.yaml`.
84+
85+
Fields: `last_check_at`, `findings`, `check_history`, `repairs_applied`.
86+
87+
## Notes
88+
89+
- Reads from memory-dag-compactor's state file — does not maintain its own DAG
90+
- Auto-fix only applies to LOW and MEDIUM severity issues
91+
- CRITICAL issues (circular refs, broken lineage) require manual intervention
92+
- Circular reference detection uses DFS with visited-set tracking
93+
- Token inflation check compares parent tokens vs. sum of children tokens
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: "1.0"
2+
description: DAG integrity check results, findings, and repair history.
3+
fields:
4+
last_check_at:
5+
type: datetime
6+
findings:
7+
type: list
8+
description: Integrity issues found in the most recent check
9+
items:
10+
check: { type: string, description: "Check name (e.g. ORPHAN_NODE)" }
11+
severity: { type: enum, values: [CRITICAL, HIGH, MEDIUM, LOW] }
12+
node_id: { type: string }
13+
detail: { type: string }
14+
auto_fixable: { type: boolean }
15+
check_history:
16+
type: list
17+
description: Rolling log of past checks (last 20)
18+
items:
19+
checked_at: { type: datetime }
20+
nodes_checked: { type: integer }
21+
findings: { type: integer }
22+
critical: { type: integer }
23+
high: { type: integer }
24+
medium: { type: integer }
25+
low: { type: integer }
26+
repairs_applied:
27+
type: list
28+
description: History of auto-fix actions taken
29+
items:
30+
repaired_at: { type: datetime }
31+
check: { type: string }
32+
node_id: { type: string }
33+
action: { type: string }
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Example runtime state for memory-integrity-checker
2+
last_check_at: "2026-03-16T03:00:12.000000"
3+
findings:
4+
- check: ORPHAN_NODE
5+
severity: HIGH
6+
node_id: s-d1-003
7+
detail: "Depth 1 node has no parent — should be connected to a d0 parent"
8+
auto_fixable: true
9+
- check: STALE_ACTIVE
10+
severity: MEDIUM
11+
node_id: s-d0-002
12+
detail: "Active node is 45 days old with no children"
13+
auto_fixable: true
14+
- check: DUPLICATE_EDGE
15+
severity: LOW
16+
node_id: "s-d2-001->s-d1-000"
17+
detail: "Duplicate edge in DAG"
18+
auto_fixable: true
19+
check_history:
20+
- checked_at: "2026-03-16T03:00:12.000000"
21+
nodes_checked: 24
22+
findings: 3
23+
critical: 0
24+
high: 1
25+
medium: 1
26+
low: 1
27+
- checked_at: "2026-03-09T03:00:10.000000"
28+
nodes_checked: 18
29+
findings: 0
30+
critical: 0
31+
high: 0
32+
medium: 0
33+
low: 0
34+
repairs_applied:
35+
- repaired_at: "2026-03-16T03:00:12.000000"
36+
check: DUPLICATE_EDGE
37+
node_id: "s-d2-001->s-d1-000"
38+
action: "Removed duplicate edges"
39+
- repaired_at: "2026-03-16T03:00:12.000000"
40+
check: STALE_ACTIVE
41+
node_id: s-d0-002
42+
action: "Deactivated stale node s-d0-002"
43+
# ── Walkthrough ──────────────────────────────────────────────────────────────
44+
# Cron runs Sundays at 3am: python3 integrity.py --check --fix
45+
#
46+
# Memory Integrity Check — 2026-03-16 03:00
47+
# ───────────────────────────────────────────────────────
48+
# Nodes checked: 24 | Edges: 18
49+
# Findings: 3 (0 critical, 1 high, 1 medium, 1 low)
50+
#
51+
# ! [ HIGH] ORPHAN_NODE: s-d1-003
52+
# Depth 1 node has no parent [auto-fixable]
53+
# ~ [ MEDIUM] STALE_ACTIVE: s-d0-002
54+
# Active node is 45 days old with no children [auto-fixable]
55+
# . [ LOW] DUPLICATE_EDGE: s-d2-001->s-d1-000
56+
# Duplicate edge in DAG [auto-fixable]
57+
#
58+
# Repairs applied: 2
59+
# + Removed duplicate edges
60+
# + Deactivated stale node s-d0-002
61+
#
62+
# Status: DEGRADED
63+
#
64+
# python3 integrity.py --repair-plan
65+
#
66+
# Repair Plan — 3 findings
67+
# ───────────────────────────────────────────────────────
68+
# Auto-fixable (3):
69+
# ORPHAN_NODE on s-d1-003: Depth 1 node has no parent
70+
# STALE_ACTIVE on s-d0-002: Active node is 45 days old
71+
# DUPLICATE_EDGE on s-d2-001->s-d1-000: Duplicate edge

0 commit comments

Comments
 (0)