Self-hosted v0.0.3: encrypted snapshot OOMs (RangeError in node:crypto) past ~150 MB DB, orphaning docs into a permanent retry-cron loop (plus lossy deletion and a runaway memory agent)
Summary
On the self-hosted binary (server-v0.0.3, macOS arm64), once the local DB (~/.supermemory/data/data) reaches about 150 MB, the periodic encrypted snapshot fails every time with RangeError: Out of memory thrown inside node:crypto. The process throws at under 2 GB RSS on a machine with plenty of free RAM, so this is not RAM exhaustion. The snapshot serializes the entire DB into a single base64 JS string that exceeds the engine's maximum string length (about 512 MB, 0x1fffffe8). From there it cascades into a permanent CPU loop, and the only cleanup available is lossy.
Related (not a duplicate)
- Distinct from #1093 (embedding-worker WASM-heap OOM, fixed). That OOM is in the embedding pool (
ort-webWASM heap). This one is in the storage snapshot path (node:crypto), which base64-encodes and encrypts the whole DB as one blob. Different subsystem, different stack trace. - The ~4 h runaway memory agent (Observed #4) is separate from the existing memory-agent-failure reports (Ollama
item_reference,reasoning_content). The request here is specifically a timeout or iteration cap. - The docs (
self-hosting/local-vs-enterprise) say "local is bounded by one machine," but this is a hard failure at ~150 MB on a single machine, not a throughput or scaling limit, and no DB-size limit or snapshot setting is documented.
Environment
server-v0.0.3(bun build --compilebinary), macOS arm64- Local embeddings (
Xenova/bge-base-en-v1.5), default config - DB about 156 MB when the failures begin
Observed
- Snapshot OOM (136 times in one log):
[storage] Snapshot failed
RangeError: Out of memory
at AR (/$bunfs/root/supermemory-server:42:2067)
at update3 (node:crypto:278:35)
data/data is a single SMD1-prefixed encrypted blob (the whole DB). Strings in the binary show the snapshot path uses BToA/base64 plus JSON.stringify, and the binary carries the constant 536870888 (0x1FFFFFE8, V8's String::kMaxLength) next to ERR_STRING_TOO_LONG and "Cannot create a string longer than…". So it builds one giant string of the whole DB and hits the max-string ceiling.
- Orphan retry loop (consequence):
[Cron] Found N stuck/failed documents
[Cron] Marked <id> as failed: Permanently failed (no retry params key)
[Cron] Marked <id> as terminally failed: No retry params on disk (pre-existing doc or store cleared)
When the snapshot fails, per-doc retry-params don't persist, so docs stay at status=failed. The retry cron re-finds and re-marks the same ids every cycle, indefinitely (one id appeared 243 times in a single log), alongside constant [NODE-CRON] missed execution … high CPU warnings. The retry counter (maxRetries/retryCount, capped at 3) appears to live only in the on-disk retry-params file, so once that file is gone the give-up check never fires and the doc is never excluded from the scan.
-
Deletion is lossy (consequence): deleting 4
faileddocs withDELETE /v3/documents/{id}dropped the store's unique extracted-memory count by exactly the sum of those docs'.memories(196). So deleting a document also deletes its memories.DELETEalso rejects in-flight docs ({"error":"Document is still processing"}), so a stuckqueueddoc cannot be removed at all. -
Runaway memory agent (separate):
[Workflow] Document <id> memory agent failed (14644306ms)
WARN [Workflow] Self-hosted memory agent failed for document, skipping memory generation
About 4 hours of CPU on a single document before it gave up.
Likely root cause
The snapshot is monolithic: it serializes and base64-encodes the whole DB into one JS string before encrypting, so peak allocation grows with total DB size and eventually exceeds the engine's maximum single-string length. This is a hard ceiling, independent of free RAM, so it cannot be tuned around and recurs deterministically once the DB is large enough.
Suggested fixes
- Stream or chunk the snapshot (encrypt in chunks, or use incremental persistence) so it never builds one giant string. This is the core fix.
- Persist
retryCountin the DB row, not only in the on-disk file, so the give-up check survives a lost file. Also exclude "no retry params" and terminally-failed docs from the stuck/failed scan so they cannot loop forever. - Add a timeout or iteration cap to the memory agent so a single doc cannot run for hours.
- Deletion safety: document that
DELETEremoves the doc's memories, and consider akeepMemories/detach option. Allow deleting stuckqueueddocs.
Workarounds (for other self-hosters)
- Back up through the API (
POST /v3/documents/list, thenGET /v3/documents/{id}per doc). The internal snapshot is unreliable once the DB is large. - Don't purge
faileddocs to stop the loop, because it deletes their memories. - A restart sheds the CPU and RAM creep, but the snapshot keeps failing once the DB is large.
Confirmed that the encrypted local-storage snapshot problem is still present in the official server-v0.0.5 Linux x64 release.
Environment / artifact:
- Ubuntu Linux x86_64
- official
server-v0.0.5release binary - SHA-256:
b2fccca3ff2b5607ce41028c759f375c4ecf5461adc9f3306f41c2757edaf375 - populated v0.0.3 store copied to tmpfs on the same machine
Observed on the unmodified v0.0.5 binary:
[storage] Snapshot: 99392.4 KB in 6117ms
The snapshot repeats on the fixed 10-second interval even while no ingestion is active. At this store size, that is approximately:
- 97.1 MiB rewritten per snapshot
- 9.7 MiB/s average write rate
- 819 GiB/day theoretical write volume
Binary inspection shows the interval is still hard-coded as:
Li2=1e4
I could not find any SUPERMEMORY_SNAPSHOT_* or persistence interval environment variable in the v0.0.5 binary. The same code path still performs full dumpDataDir("gzip") → encrypt → atomic rewrite; graceful shutdown also flushes a snapshot.
So v0.0.5 does not yet address the underlying monolithic snapshot problem described here, and it adds severe idle CPU/I/O amplification well before the ~150 MB single-string OOM ceiling is reached. On an 8 GB self-hosted machine this kept a core busy, drove reclaim/swap, and generated continuous NVMe writes with an otherwise idle queue.
A practical fix would be one or more of:
- dirty-aware snapshots (skip the interval write when no DB mutation occurred),
- a documented
SUPERMEMORY_SNAPSHOT_INTERVAL_MSsetting, - incremental/chunked persistence instead of a full encrypted blob rewrite,
- retaining the forced snapshot on graceful SIGTERM/SIGINT.
This was reproduced against a copied data dir; no production data was modified.
The failure cascade suggests the snapshot, retry state, and deletion paths need one recovery contract rather than separate patches.
For snapshots, I would use chunked encrypted generations plus an atomic manifest swap:
generation_id
chunk digests/sizes
encryption metadata
source DB revision
created_at
complete marker
Write and verify all chunks first, then atomically publish the manifest. An interrupted generation remains unreferenced and collectible; restore uses only a complete manifest. This avoids a single base64/string authority boundary.
Retry state should live in the durable database with a terminal tombstone, so missing sidecar params cannot reset the same document into an infinite retry population.
For deletion, a source document and extracted memories need explicit ownership/cardinality. Deleting one document should remove only memories uniquely owned by it; deduplicated or accepted durable memories should lose the source edge, not disappear. A preview should report cascade counts before apply.
That source-versus-durable-memory distinction is part of this continuity model: https://github.com/hegu-1/personal-ai-os/blob/main/docs/continuity-snapshot-trace.md
I lost data twice because of this, once system crashes, the data can no longer be decrypted.
Same code path, but it burns CPU long before it OOMs
We're self-hosting 0.0.5 and hit this from the other direction. Our database is 136 MB (142,340,432 bytes) — under the ~150 MB cliff described here, so no OOM yet. But the snapshot is already costing us 60% of a CPU core, continuously, forever.
I think that's worth adding to this issue, because it reframes the problem: the OOM isn't an edge case that appears at 150 MB. The snapshot is expensive at every size — the OOM is just the point where it finally falls over. Anyone below the cliff is quietly paying for this and probably blaming something else.
What's happening
Every ~21 seconds the server serialises the entire PGlite database, encrypts it, and rewrites ~/.supermemory/data. That takes about 12 seconds of CPU. Then it idles ~8 seconds and does it again. 12 / 21 ≈ 60%, which matches the process lifetime average exactly.
Per-second sampling of the server PID against the mtime of the data file — the burst ends precisely when the file lands, every cycle:
17:03:53 cpu=100% data_mtime=17:03:42
17:03:54 cpu=110% data_mtime=17:03:42
17:03:55 cpu=100% data_mtime=17:03:42
17:03:56 cpu=90% data_mtime=17:03:42
17:03:57 cpu=100% data_mtime=17:03:42
17:03:59 cpu=90.9% data_mtime=17:03:42
17:04:00 cpu=100% data_mtime=17:03:42
17:04:01 cpu=81.8% data_mtime=17:03:42
17:04:02 cpu=100% data_mtime=17:03:42
17:04:04 cpu=0.0% data_mtime=17:04:03 <-- file rewritten, burst ends
17:04:05 cpu=0.0% data_mtime=17:04:03
17:04:06 cpu=0.0% data_mtime=17:04:03
17:04:07 cpu=0.0% data_mtime=17:04:03
17:04:08 cpu=0.0% data_mtime=17:04:03
17:04:10 cpu=0.0% data_mtime=17:04:03
17:04:11 cpu=0.0% data_mtime=17:04:03
17:04:12 cpu=90.9% data_mtime=17:04:03 <-- next cycle
17:04:13 cpu=100% data_mtime=17:04:03
17:04:15 cpu=110% data_mtime=17:04:03
Across that window the file changed by roughly 240 bytes. So it's rewriting 136 MB to persist a couple of hundred bytes of actual change — O(n) work for O(1) delta, on a fixed timer, whether anything happened or not.
This is genuinely idle time
No ingestion is running. It's not embeddings, dreaming, or the workflow engine:
- Ingest queue is empty. 764 documents: 760
done, 4failed, zero inqueued/extracting/chunking/embedding/indexing. NewestupdatedAtpredates the current process start. - Embedding workers are idle. Per-thread sampling puts both
Bun Poolthreads at 0.0% during the burst. All the CPU is on the main thread. Their higher lifetime average is just the documented startup prewarm. - Dreaming finds nothing. The retry crons fire on schedule and log
Found 0 stuck queued documents,0 stale processing dreaming batches,0 stuck/failed documents.retry-params/is empty, so the retry-loop pathology described in this issue is not what we're seeing. - rivet-engine is at 1.1% CPU. Not it either.
That leaves the snapshot, and the mtime correlation above pins it directly.
No way to turn it down
We dumped every SUPERMEMORY_* symbol out of the binary — 40 variables covering embeddings, ingest concurrency, telemetry, port, data dir, rivet passthroughs. There's nothing for snapshot interval, flush cadence, or persistence mode. So self-hosters can't mitigate this without a code change, and pruning the database just to keep CPU down isn't a reasonable ask at 764 documents.
What would fix it
In rough order of how much we'd like it:
- Incremental persistence. PGlite is Postgres — WAL and dirty-page flushing already exist. Persisting only what changed makes cost proportional to the change, not the database.
- Adaptive interval. If nothing's been written, don't snapshot. A dirty flag would remove nearly all of this for idle instances.
- Make the interval configurable.
SUPERMEMORY_SNAPSHOT_INTERVAL_MSor similar. Not a fix, but it would let people trade durability for CPU today. - Stream the encryption. Would help the OOM in the original report specifically — the base64-string-of-the-whole-DB step is what breaks past ~150 MB.
Extrapolating the O(n) cost: at ~1 GB a cycle would take roughly 85 seconds, which is longer than the interval itself. So this doesn't degrade gracefully, it hits a wall — and per the original report, an OOM one.
Environment
- supermemory self-hosted
0.0.5, local embeddings (Xenova/bge-base-en-v1.5, 768 dims), external LLM provider - DigitalOcean droplet, 2 vCPU / 8 GB, Ubuntu 24.04, kernel 6.8.0-137
- Database 136 MB, 764 documents
- Process RSS ~2.1 GB, lifetime CPU 59.8% over 54 minutes uptime
Happy to run further measurements or test a patch — this is easy for us to reproduce on demand.
Unrelated and much smaller, but noticed while digging: [better-auth/magic-link] allowedAttempts is ignored... is logged every 5 seconds, on the rivet-engine callback. better-auth emits that at plugin init, so it suggests a fresh betterAuth instance is constructed per inbound request. Cosmetic next to the above, and not the CPU cause — happy to open it separately if useful.