iai-personal-memory-engine icon indicating copy to clipboard operation
iai-personal-memory-engine copied to clipboard

Daemon OOMs in a boot loop on a migrated native (lilli) store; legacy store is fine - 3.2.1

Open aphroditecircus opened this issue 2 months ago • 4 comments

Summary

After migrate-to-lilli --swap (which reports verify: GREEN -- all dimensions match), the daemon cannot complete a single boot on the resulting native store: RSS climbs to ~3 GB within 40 s, the kernel OOM-kills it, systemd restarts it, and the loop repeats every ~90 s. The same store content on the legacy SQLite format boots and runs.

Rolling the pre-migration directory back restores normal operation immediately. I have reproduced this three times, including once on a deliberately shrunk store, and rolled back each time.

Environment

  • iai-pme 3.2.1 (installed with uv pip install; the venv has no pip, so iai-mcp self-update cannot run — it exits with No module named pip and then reports daemon NOT restarted)
  • Python 3.12.13, Linux x86_64, systemd --user unit
  • 6 vCPU / 12.5 GB RAM VM
  • Embedder: multilingual-e5-small, languages en+de+it
  • cgroup limits on the unit: MemoryHigh=MemoryMax=3000M, MemorySwapMax=3G

Store shape

Roughly constant record count, but the edge count doubles about every 24 h:

records edges events store size
day 1 ~41 700 391 628 746 695 1.2 GB
day 2, 09:35 42 894 584 900 790 939 1.3 GB
day 2, 23:12 42 894 901 439 187 738 (pruned) 913 MB legacy / 691 MB native

The store is 17 days old. The events are the daemon's own telemetry, ~44 000 rows/day, dominated by pattern_separation_pass and schema_induction_run.

Reproduction

# daemon stopped, all other readers (watchers, brain dashboard, external CLIs) stopped
iai-mcp migrate-to-lilli --src <store>/hippo/brain.sqlite3 --swap --apply --yes
#   verify:      GREEN -- all dimensions match
#   rows copied: 1132081 (records=42894, edges=901439, events=187738, ...)
#   swapped -- the live store now runs on the native engine
systemctl --user start iai-mcp-daemon

Observed, sampled every 20 s:

  pid=936194 rss=2196M up=00:20
  pid=936194 rss=2863M up=00:40
  pid=936194 rss=2966M up=01:00
  pid=936194 rss=2872M up=01:20
  pid=0      gone                  <- oom-kill
  pid=959958 rss=1202M up=00:15    <- restart, same curve
  pid=959958 rss=3024M up=00:35
  pid=0      gone

systemd records Failed with result 'oom-kill' for each. The exit-code failures in between are the next start hitting the dying process's Hippo lock (HippoLockHeldError: Hippo storage at <store>/hippo is already opened by another process).

Where it is spending the memory

kill -USR2 at ~2.5 GB, five threads in the same stack (paths shortened):

Thread 0x… (most recent call first):
  File "<site-packages>/iai_mcp/lillibrain/connection.py", line 1536 in execute
  File "<site-packages>/iai_mcp/hippo/_ro_pool.py",        line  252 in execute
  File "<site-packages>/iai_mcp/store/_store.py",          line 1691 in active_records_count
  File "<site-packages>/iai_mcp/runtime_graph_cache.py",   line  697 in _cache_key
  File "<site-packages>/iai_mcp/runtime_graph_cache.py",   line 1205 in try_load_…
  File "<site-packages>/iai_mcp/retrieve.py",              line  975 in _runtime_graph_rebuild…
  File "<site-packages>/iai_mcp/retrieve.py",              line 1173 in build_runtime_graph
  File "<python3.12>/concurrent/futures/thread.py", …

So the boot-time build_runtime_graph runs on several pool threads at once, and each one reaches active_records_count through the read-only connection pool on the lilli connection. Given the edge count is the only figure that grew while this got worse, the runtime-graph rebuild over ~900 k edges looks like the driver — not the store size, which actually shrank to 691 MB.

What I ruled out

  • Telemetry volume. events deleted from 824 584 → 187 738 (store 1.5 GB → 913 MB, native 691 MB) before migrating. Identical failure, same curve. Boot memory does not scale with telemetry.
  • The read-only pool. IAI_MCP_RO_POOL_OFF=1 made no difference.
  • Simply needing more room. With MemoryHigh=MemoryMax=5G and MemorySwapMax=6G it died at ~50 s having taken >11 GB. It is unbounded growth, not a ceiling that is slightly too low.
  • A bad conversion. The tool's own verification is GREEN, and the row counts match exactly.

A note on the legacy format

doctor warns that the legacy format "orphans the write-ahead-log sidecars under a running daemon" when an external process opens it read-only, and recommends migrating. That matches what I see: the WAL grows back to over 1 GB within a day, because several components legitimately read the store externally. So the recommended fix is exactly the path that does not boot here, which leaves the legacy format plus its WAL growth as the only working option.

Current workaround

Stay on the legacy store and cap the unit. Note that MemoryHigh below MemoryMax is the wrong choice here: in the band between the two the kernel throttles instead of killing, and the daemon sits there answering no MCP call at all while still looking alive (memory pressure ~50 %, worker threads parked in mem_cgroup_handle_over_high for 7–15 minutes). Setting both to the same value turns that into an honest kill-and-restart.

Happy to run any instrumented build or supply more dumps.

Related

--prune-telemetry-before is silently ignored — filed separately, because it is what forced me to prune by hand before the run above.

aphroditecircus avatar Sep 11 '26 21:09 aphroditecircus

#174

aphroditecircus avatar Sep 11 '26 21:09 aphroditecircus

Fixed in v3.2.2 (live on PyPI as iai-pme 3.2.2). Developed/tested on macOS; Linux/Windows paths welcome from contributors.

CodeAbra avatar Sep 14 '26 01:09 CodeAbra

Re-tested on Linux with 3.2.3 (from PyPI) and the fix does not hold here. Same store, same box as the original report.

Setup

  • Debian 13, kernel 6.12, Python 3.12.13, iai-pme 3.2.3 installed with uv into a venv
  • daemon runs as a systemd --user unit with MemoryHigh=MemoryMax=3000M, MemorySwapMax=3G (so ~6 GB ceiling)
  • store: 46 883 records, 790 104 edges, 351 555 events after --prune-telemetry-before (3-day cutoff)
  • migrate-to-lilli --swap --prune-telemetry-before <ISO> --apply --yes: verify GREEN on the first attempt, 443 s, 1 188 552 rows, native store 819 MB. #174 is fixed for us, thanks.

Daemon boot on the migrated store (systemctl --user start, sampled every 10 s, RSS / swap of the main pid):

t+10s   839M /    0M
t+20s  2142M /    0M
t+30s  3024M /  458M   (cgroup at memory.max from here on)
t+40s  3013M / 1477M
t+60s  2987M / 2007M
t+81s  2850M / 2673M
t+91s  2897M / 2910M
t+96s  OOM kill (memory.max + memory.swap.max exhausted)

systemd restarts it after 30 s and the second instance draws the identical curve (404M → 1991M → 2949M+549M swap → 2936M+2752M swap at t+110s of its own life). No MCP client, no CLI call, nothing else touching the store during the boot; no iai watch running. Journal shows only slow RO execute … SELECT COUNT(*) FROM records WHERE tombstoned_at IS NULL … (1.2 s, then 10.6 s on the second boot) before the kill.

Same shape as with 3.2.1 (2.2 GB at 20 s, 3.0 GB at 40 s). On the legacy stdlib store the same daemon boots and then gets OOM-killed roughly every 30–40 min instead, so we rolled the swap back again.

If it helps I can run a build with extra logging or a USR2 dump at 2.5 GB; the earlier dump (3.2.1) had five threads in store/_store.py active_records_count → hippo/_ro_pool.py and runtime_graph_cache._cache_key. Happy to test a patch on this store.

aphroditecircus avatar Sep 16 '26 00:09 aphroditecircus

Thanks for the careful re-test, and sorry — we closed this too early. You're right that it doesn't hold on a store this size, so I'm reopening it. The boot-time RSS climb through active_records_count → the RO pool → runtime_graph_cache._cache_key matches what your dump showed. Yes please: a USR2 dump around 2.5 GB would help a lot, and we'll get you a patch to try on this store. We develop on macOS, so your Linux repro and dumps are exactly what we need here.

CodeAbra avatar Sep 16 '26 03:09 CodeAbra