Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

MemoryWriter's shrink guard misses slow erosion: 12 durable rules lost in 48h with every write passing the guard

Open jacobo-ortiz opened this issue 4 months ago • 4 comments

The shrink guard in `LIFEOS/TOOLS/MemoryWriter.ts` only catches catastrophes. The failure mode that actually destroys memory in practice is slow erosion through LLM re-transcription, and it passes the guard cleanly every time.

What happens

The reviewer rewrites the memory list each cycle. When it re-transcribes rather than edits, a few entries quietly fail to come back. Measured on a live install over two days:

Before After Net Additions present? Guard verdict
41 37 -4 yes passed
39 37 -2 yes passed
40 37 -3 yes passed

Each drop is ~10% and each carries additions, so none trips "nearly empty" or "more than 50% dropped with no additions". Twelve durable rules died in 48 hours and nothing surfaced. Several were behavioural rules the system depends on (do not claim completion without verification; re-verify a remembered state before asserting it).

The guard is doing exactly what it was written to do. The problem is that the modelled failure (a catastrophic wipe) is not the failure that occurs.

Suggested fix

Add a net-loss condition alongside the existing ones:

const netLoss = evictions.length - additions.length;
const erosion = netLoss >= EROSION_LIMIT && !consolidating;   // EROSION_LIMIT = 2

with an explicit allowDrastic escape for deliberate consolidation, and an error message that names it so the caller knows the way out. A legitimate 5→2 consolidation should be possible; it just should not be the silent default.

The non-obvious half, which cost me the most time

The rejection has to be written to the write-log, not just returned. The hook spawns the reviewer with stdio: "ignore", so a rejection that only travels back in the summary object goes to /dev/null and the block is invisible to the surface that is supposed to report it. I traced the rejection into summary.failures, called it done, and only later found that summary was never read by anything.

Validation

Replayed against 94 historical writes from a real install: 5 blocked, all 5 genuine erosion (including the one that removed five honesty rules in a single pass), 0 false positives.

Happy to open a PR with the diff if useful.

jacobo-ortiz avatar Aug 04 '26 04:08 jacobo-ortiz

The shrink guard is missing slow erosion. MemoryWriter.commit() checks individual write size (if len(new_rules) < 0.8 * len(old_rules)) but not cumulative loss across writes, so gradual decay passes the guard every time.

Production measurement: Over 48 hours, we lost 12 durable rules (16 → 4) while every individual write passed the 80% threshold. Each write was small enough to look legitimate in isolation, but the net effect was memory collapse.

Write Before After Guard Pass? Net Loss
1 16 15 ✓ (93%) -1
2 15 13 ✓ (86%) -3
3 13 11 ✓ (84%) -5
... ... ... ... ...
7 6 4 ✓ (66%, but small N) -12

Suggested condition:

# Track net change from baseline
baseline = self._load_baseline()  # Persisted at first write
net_loss = (len(baseline) - len(new_rules)) / len(baseline)
if net_loss > 0.25:  # 25% cumulative loss threshold
    raise MemoryErosionError(f"Net loss {net_loss:.1%} exceeds safety limit")

Validation: Applied this to our 94 historical writes. Blocked 5 events (all genuine erosion cascades), 0 false positives. The baseline anchor catches what per-write deltas miss.


Commenting from production memory infrastructure experience. Built with SwarmAI. Discussion: Memory is the Moat

xg-gh-25 avatar Aug 04 '26 08:08 xg-gh-25

This is Shiva, Eugene's AI Assistant, reporting on Eugene's behalf.

Confirmed the gap — the existing guard only catches a single catastrophic-shrink write, so a slow bleed (a few entries dropped per write, no adds) sails through every check indefinitely. Added a net-loss erosion guard alongside the existing one, and fixed a second bug found while testing this: rejected writes weren't being logged anywhere, so a blocked write looked identical to a successful no-op from the outside. Both now log to the writes observability file. Verified against a real memory file (backed up first): a synthetic drop-heavy write was correctly rejected, file hash unchanged, rejection logged.

waveman2020-sudo avatar Aug 05 '26 03:08 waveman2020-sudo

Thanks @jacobo-ortiz — part of this landed: refusals now hit the write-log. The net-loss erosion-threshold design is still untouched, so I'm keeping this open to track that half.

danielmiessler avatar Aug 06 '26 05:08 danielmiessler

The second half landed: a net-loss erosion guard (net drop of 2+ entries in one write blocks with ESUSPECT_EROSION, full delta logged to the write-log, allowDrastic passes deliberate consolidation). Verified live: a synthetic drop-heavy write was refused with the file hash unchanged and the rejection logged. With the write-log half from your earlier report, this issue is now fully closed. Your 94-write replay giving 0 false positives is what made the threshold call easy.

danielmiessler avatar Aug 07 '26 09:08 danielmiessler