Bug Report: Gateway Memory Leak Causing Silent OOM Crashes
Summary
The OpenClaw gateway (v2026.4.2) exhibits a persistent memory leak where RSS grows from ~560MB at startup to 3-4GB within 1-2 hours, eventually crashing silently. The process disappears without logging any error, SIGTERM, or heap-related message. launchd relaunches it automatically, but active agent runs are killed with process_lost.
Environment
- Platform: macOS arm64, Mac Mini, 16GB RAM
- Node: v22.22.1 with
--max-old-space-size=6144
- OpenClaw: v2026.4.2 (d74a122)
- Config: 12 agents, 19 enabled cron jobs, Discord + iMessage channels, maxConcurrent=2
- Session files: Pruned to 10-20 per agent, sessions.json ~10MB total
Observed Behavior
Gateway restarts observed today (April 7): 6 restarts in 12 hours
Memory growth pattern:
- Startup: ~560MB RSS (3.5% of 16GB)
- After 20 min: ~3.6GB (22%)
- After 1-2 hours: ~4.5GB → silent crash
- No SIGTERM, no heap error, no log entry before crash
This pattern persists even after:
- Pruning session files to 10 per agent
- Cleaning sessions.json indexes (10.5MB total)
- Removing stale .deleted/.tmp files
- Setting
--max-old-space-size=6144
Root Cause Analysis
The memory leak appears to be in the gateway's runtime state accumulation, not in session file loading. With only 10-20 session files per agent (~270MB total on disk, ~30MB in sessions.json indexes), the gateway still grows to 3-4GB RSS. This suggests:
- Agent run state (embedded runs, tool call history) is not being released after runs complete
- The cron scheduler accumulates job state across runs
- WebSocket connection state may not be properly GC'd after connections close
Impact
- Active agent runs killed with
process_lost every 1-2 hours
- Tasks must be retried, wasting LLM tokens and time
- The Paperclip integration sees repeated failures for long-running tasks (>15 min runs impossible if gateway crashes every 60-90 min)
Workarounds Applied
--max-old-space-size=6144 in launchd plist (delays crash but doesn't prevent it)
- Automated session pruning every 2 hours (reduces startup memory, doesn't fix runtime leak)
ThrottleInterval=10 in launchd (prevents restart loops)
Suggested Investigation
- Profile heap growth using
--inspect flag during a 30-minute run
- Check if
WeakRef or finalizers are used for run/session state
- Check if the embedded agent runner holds references to completed runs
- Check cron job scheduler state accumulation
Bug Report: Gateway Memory Leak Causing Silent OOM Crashes
Summary
The OpenClaw gateway (v2026.4.2) exhibits a persistent memory leak where RSS grows from ~560MB at startup to 3-4GB within 1-2 hours, eventually crashing silently. The process disappears without logging any error, SIGTERM, or heap-related message. launchd relaunches it automatically, but active agent runs are killed with
process_lost.Environment
--max-old-space-size=6144Observed Behavior
Gateway restarts observed today (April 7): 6 restarts in 12 hours
Memory growth pattern:
This pattern persists even after:
--max-old-space-size=6144Root Cause Analysis
The memory leak appears to be in the gateway's runtime state accumulation, not in session file loading. With only 10-20 session files per agent (~270MB total on disk, ~30MB in sessions.json indexes), the gateway still grows to 3-4GB RSS. This suggests:
Impact
process_lostevery 1-2 hoursWorkarounds Applied
--max-old-space-size=6144in launchd plist (delays crash but doesn't prevent it)ThrottleInterval=10in launchd (prevents restart loops)Suggested Investigation
--inspectflag during a 30-minute runWeakRefor finalizers are used for run/session state