The September 10 investigation reproduced expensive processing in the KNX event path: a single sensor update repeatedly cloned and normalized the entire home memory and semantic registry. Observation correlation also repeatedly parsed timestamps while scanning older groups.
Live updates now replace only the affected collection and state/entity records. Imported memory and user edits still receive full validation. Correlation stops once older groups cannot fall within its time window. Event retention, state freshness, observation evidence, habit learning, autonomous policy and device permissions are preserved.
The synthetic benchmark runs the actual Cerebrum node with 300 KNX sensors, 300 initial observations and two batches of 600 events. It includes filesystem archiving, world-model ticks and memory checkpoints. It uses a temporary storage directory and simulated integration responses, with no device or model calls. It verifies raw-event counts and observation evidence references.
Measured locally on Node.js 24.13.0, with the Node CPU profiler enabled for both runs:
| Traffic | Before: CPU ms/event | After: CPU ms/event | Reduction |
|---|---|---|---|
| Repeated values | 7.738 | 2.509 | 68% |
| Changing values | 19.430 | 5.817 | 70% |
These are process CPU measurements for synthetic traffic, not the CPU percentage of the deployed Proxmox VM. Disk synchronization still contributes to elapsed time. Actual utilization depends on event rate, catalog size, storage and the other work running in Node-RED. The later SSH investigation below measures the deployed process separately.
Run from the repository with dependencies installed:
node scripts/benchmark-ingestion.js 300 600
To collect a CPU profile as well:
node --cpu-prof --cpu-prof-dir=/tmp scripts/benchmark-ingestion.js 300 600
Arguments are entity count (1–600) and events per batch (at least the entity count). Reported CPU includes user and system time; elapsed time also includes disk waits. Run comparisons on the same host without competing benchmarks.
Background memory growth with the dashboard closed
The follow-up investigation reproduced growth in the live KNX correlation cache. Its 500-edge limit ran only when a dashboard summary was requested. With no dashboard reads, correlations between addresses accumulated without that limit. The rate-series cache had the same issue with its 300-series limit. Anomaly summaries were limited to 120 only in the returned view.
The ingestion path now keeps the most recently touched technical entries within those limits. The existing state tick also expires stale graph samples, rate samples and recent history when traffic stops. These caches are disposable dashboard projections; raw events, semantic observations, episodes and learned habits keep their existing archive and retention behavior. Autonomy snapshots normalize only the states, habits and episodes that the world-model tick consumes.
Measured locally on Node.js 24.13.0, comparing commit a40f263 with this change using the same instrumented script, 600 sensors, 600 warm-up events and two batches of 1,200 events, with no dashboard reads:
| Measurement | Before | After |
|---|---|---|
| Retained graph correlations | 132,000 | 500 |
| Retained rate series | 601 | 300 |
| Sampled peak JavaScript heap | 240.0 MiB | 104.1 MiB |
| Retained JavaScript heap after GC | 167.8 MiB | 25.2 MiB |
| Sampled peak process RSS | 427.9 MiB | 291.8 MiB |
The benchmark verified all 3,000 raw telegrams, 1,800 observations and their evidence references. Heap retention fell about 85%; sampled peak RSS fell about 32%. The script samples memory every 50 telegrams and after verification, so the reported peaks are sampled maxima. --expose-gc permits one final collection in the benchmark to distinguish retained objects from temporary allocations; production code does not force garbage collection. Process RSS and JavaScript heap are different from Proxmox’s total VM memory reading; see the separate deployed measurements below.
node --expose-gc --max-old-space-size=512 scripts/benchmark-ingestion.js 600 1200
Relaxed background timers
| Work | Previous cadence | Current cadence |
|---|---|---|
| Derived home-memory Markdown checkpoint during traffic | 1.5 seconds, then 10 seconds in 0.3.6 | 60 seconds |
| Local state/world-model check and periodic-review eligibility | 15 seconds | 30 seconds |
| AI Education file polling | 10 seconds | 30 seconds |
| KNX connection fallback polling | 1 second | 5 seconds, with a configured gateway |
| Home-automation registry fallback refresh | 30 seconds | 60 seconds |
| Suspended legacy semantic scheduler and proactive LLM checks | 15 and 30 seconds | No timer |
Checkpoints retain the first scheduled deadline during continuous traffic and flush at shutdown; raw event/observation archiving remains immediate. Registry notifications and Education saves/chat/review checks still run directly. JavaScript automations use their existing deadline timer. The local observation and review eligibility cadence can add up to 30 seconds of detection delay; the configured LLM invocation policy, device permissions and automation deadlines are preserved.
Snapshot-request memory spikes
A camera request also prepares conversational history. The previous KNX and adapter query loaders read each entire daily archive into a string and split it into an array of every line, even when the prompt included only a few recent records. This created a temporary allocation spike independently of JPEG size. The sidebar HTTP response also serialized a Buffer as an array of individual byte numbers.
Queries now scan 64 KiB chunks with a maximum 1 MiB record, preserving UTF-8 boundaries, legacy JSONL, final lines without a newline and complete aggregate counts. File descriptors close on errors and early termination. Top-count selection keeps a small sorted result instead of copying and sorting the entire counter table. The same reader serves operation-history files. Raw files and their retention policy are unchanged; exact aggregate counters still scale with the number of distinct event categories/values.
At POST /cerebrumUltimate/sidebar/ask, metadata.image.data is now a Base64 string with metadata.image.encoding: "base64", plus the existing media type and filename. HTTP consumers should decode that encoding instead of expecting {type:"Buffer",data:[...]}. Internal sidebarAsk() and Node-RED/Telegram output retain the original binary image; no resizing or recompression is applied and JPEG bytes stay out of the memory archive.
The local event-snapshot benchmark exercises the real chat, prompt-history, provider and HTTP response paths, with a simulated model/provider and temporary files. It first queries recorded events and then retrieves the exact event image, preparing history in both model passes. Node.js 24.13.0, 192.8 MiB of history (231,000 events), one 4 MiB image, comparing a40f263 with the fixes:
| Measurement | Before | After |
|---|---|---|
| Whole-file history reads | 2 | 0 |
| Sampled peak JavaScript heap | 411.0 MiB | 28.7 MiB |
| Sampled peak process RSS | 958.5 MiB | 138.9 MiB |
| JavaScript heap after final GC | 12.3 MiB | 12.4 MiB |
| HTTP response size | 16.0 MiB | 5.3 MiB |
The observed RSS peak falls about 86%. Similar final heap usage identifies temporary allocation pressure in this reproduction, rather than a retained JPEG leak. These are local process measurements, not a measurement of the user’s VM. The benchmark checks exact image bytes, full history counts in both model passes, one event query, one exact event-image retrieval, no substitution with a current image and cleanup of pending requests. Regression coverage additionally checks full KNX/adapter counts in the snapshot prompt and prevents bulk history reads.
node --expose-gc --max-old-space-size=768 scripts/benchmark-snapshot.js 192 4 event
Arguments are approximate history size in MiB (up to 512), image size in MiB (up to 6), and event (default) or current. Sampling occurs at file-read, model/provider and JSON-serialization boundaries. With --expose-gc, the benchmark collects before and after the request; production code does not force GC. No real cameras, model APIs or user storage are accessed.
Diagnosing a rising Proxmox memory percentage
On September 10, live checks of the affected 2 GiB VM between 10:07 and 10:10 CEST found available memory at approximately 1,244 → 1,215 → 1,292 MiB and file cache at 1,203 → 1,205 → 1,207 MiB, despite Proxmox memory readings near 87–89%. Cumulative swap-in and swap-out counters stayed unchanged at 20 KiB each. These are guest-wide measurements, not Node-RED process RSS. They establish that the VM had substantial available memory at those times; they do not identify which process populated the cache or rule out a separate process leak at another time. Two Proxmox CPU readings were 8.50% and 9.65% of one vCPU; attributing that utilization requires process-level measurements.
Linux distinguishes completely free memory from MemAvailable, which estimates how much can be used by applications without swapping and includes reclaimable memory. File reads can fill page cache without retaining the file in the JavaScript heap. See the Linux /proc/meminfo documentation and QEMU guest memory statistics. Do not clear caches, force GC or change the VM’s allocation merely to lower the displayed percentage.
In unpatched 0.3.6, the shared-archive retention check starts 60 seconds after Cerebrum initialization and scans the archive even when no records have expired. A local scan of a synthetic 384 MiB shared archive took 68.5 seconds, with sampled process RSS at 124–128 MiB and no forced GC. A separate six-minute run with 600 synthetic KNX sensors and about eight events/second settled at roughly 235–240 MiB RSS after warm-up. Both used Node.js 24.13.0 with a 512 MiB old-space limit; neither substitutes for measuring the deployed Node-RED process and its actual integrations.
For process-level diagnosis, copy the standalone scripts/diagnose-memory.js file to the Linux VM (or use a repository checkout there) and run it as the Node-RED process owner:
node scripts/diagnose-memory.js auto 360 > /tmp/cerebrum-memory.jsonl
It samples /proc every 20 seconds for six minutes and exits. It reports process RSS, anonymous/file-backed memory, swap, cumulative I/O, and guest available memory/cache. It does not read flow or archive contents, call a model, request a camera snapshot, force collection, or restart the service. If automatic process detection finds zero or multiple candidates, replace auto with the Node-RED PID. Run it while the reported growth is occurring. The script has no dependencies and is a repository diagnostic, not an automatically running Cerebrum timer.
When guest login is unavailable but Proxmox already receives balloon statistics, its VM Monitor can provide a read-only guest-wide check:
info qom-tree /machine/peripheral
qom-get /machine/peripheral/balloon0 guest-stats
Use the balloon device path actually listed by the first command. Check that last-update advances; compare stat-available-memory, stat-disk-caches and swap counters across samples. Memory values are bytes; unsupported counters may appear as -1 or an unsigned all-ones value. This does not require installing or enabling the QEMU guest agent, but existing balloon statistics support is required.
SSH investigation and retention checkpoint
The September 10 SSH investigation found Node.js 22.23.2 running Cerebrum 0.3.6, with the preceding ingestion and snapshot fixes already installed. The common JSONL archive occupied 3.67 GB, while the derived home-memory Markdown was about 1.36 MB. The configured history retention was 20 days. No chat or snapshot requests were needed for the measurements.
Bounded samples at 25 positions across the archive predominantly contained older context records, including home.observations, state projections and world-model projections from September 7–9. In a separate 2 MiB sample spanning 109.5 seconds on September 8, 3,061 context:home.observations records included 2,978 exact repetitions of already sampled data objects. This confirms substantial duplication in that historical window; it is not an exact whole-file breakdown. The latest 8 MiB spanned approximately 44 minutes on September 10 and contained no context:home.observations records. Current code already excludes reconstructible projections and fixes observation snapshot identities. Those fixes prevent repeated writes going forward; they do not retroactively remove old archive records or change their evidence IDs.
During the six-minute baseline at 10:48–10:54 CEST, Node-RED RSS ranged from 516.9 to 538.9 MiB, guest available memory from 1,204.2 to 1,236.6 MiB, and process swap remained zero. Node-RED wrote 80.3 MiB to storage while the common archive grew by 1.11 MiB and the daily KNX archive by 0.13 MiB. CPU averaged 4.67% of one CPU in the final three minutes, after profiling had stopped. These measure the complete Node-RED process with live integrations, not Cerebrum in isolation. A separate two-minute main-thread profile identified repeated synchronous persistence and derived-memory normalization; its wall time includes disk waits and is not a CPU-utilization percentage.
The follow-up patch spaces derived home-memory checkpoints to 60 seconds. Explicit edits, habit-learning checkpoints and shutdown persistence keep their existing behavior; raw event and observation appends still flush synchronously. This reduces repeated normalization and full Markdown writes during continuous traffic without postponing the raw archive.
Retention now keeps the oldest valid timestamp alongside an exact archive fingerprint (device, inode, size, modification and change times). The advisory sidecar, cerebrum-memory.jsonl.retention-state.json, is plain JSON. Appends update the timestamp bound in memory; completed scans and clean shutdown save it atomically. If the bound proves no record has expired, retention skips reading the archive. A missing, malformed or stale checkpoint, external changes, unsaved writes after a crash, or expired timestamps fall back to the existing validating scan and configured retention. The first scan of an existing archive is still required. Unknown timestamps are retained, and a backdated tail appended during scanning is included before publishing the checkpoint. Failure to save this optional file does not reject archived events.
A local 384 MiB archive probe with the patch took 74.4 seconds for its first scan, then 6 milliseconds and zero archive bytes read for retention on a newly opened instance. This uses the same 64 KiB streaming reader and 10 ms cooperative backoff; the optimization removes unnecessary repeat scans rather than making a required full scan faster. Regression tests cover restart reuse, aging, shorter retention, backdated appends, concurrent tails, external edits and optional-checkpoint failures. The complete suite passed 330 tests, runtime loading and lint checks.
On the VM, the first required scan completed at 11:16:22 CEST. While scanning, Node-RED read approximately 110 MiB every 20 seconds and the guest kept more than 1.1 GiB available. A clean restart at 11:17:28 saved and reused the checkpoint. The retention check at 11:18:33 completed without another full scan: cumulative Node-RED reads remained near 68 MiB for startup and reached only 71.4 MiB by the end of the six-minute observation window. Those totals include all Node-RED file reads, not just Cerebrum. The existing Linux page cache was left intact.
| Live measurement | Before this follow-up patch | After patch and clean restart |
|---|---|---|
| Six-minute observation window, CEST | 10:48–10:54 | 11:17:48–11:23:48 |
| CPU mean in final three minutes, one CPU | 4.67% | 4.39% |
| CPU range in final three minutes | 3.00–5.90% | 2.95–5.59% |
| Process RSS, MiB | 516.9–538.9 | 420.7–476.3 |
| Guest available memory, MiB | 1,204.2–1,236.6 | 1,293.4–1,364.1 |
| Process swap, MiB | 0 | 0 |
| Process disk writes, MiB | 80.3 | 42.6 |
| KNX records appended to daily history | 894 | 921 |
Disk writes fell 47% with comparable live KNX traffic. Steady-state CPU changed only slightly; the larger CPU/I/O benefit is avoiding unnecessary startup and daily scans (the configured timer runs every 24 hours). RSS after a fresh restart is not an hour-long steady-state heap comparison. The observed windows show substantial available guest memory and no process swapping; they do not establish a 24-hour maximum. Events, observations and configured retention remain active. Node-RED is running with the two patched JavaScript files; original copies are preserved on the VM in /home/pi/cerebrum-code-backup-20260910. Temporary profiling and measurement processes were stopped, and the loopback Node inspector was closed.