Skip to content

Gateway memory leak: 389MB → 14.7GB over 4 days with session accumulation #54155

@the-lobsternaut

Description

@the-lobsternaut

Description

The openclaw-gateway process leaks memory steadily over multi-day uptime, growing from ~389MB at startup to 14.7GB (58% of 24GB RAM on Mac Mini) after approximately 4 days of continuous operation.

Environment

  • OpenClaw: 2026.3.13 → 2026.3.23-2 (observed on both)
  • OS: macOS 15.7.4 (arm64), Mac Mini M-series, 24GB RAM
  • Node: v25.6.1
  • Primary model: Local GLM-4.7 via llama.cpp (openai-completions API on LAN)
  • Fallback model: Anthropic Claude Opus 4.6
  • Memory search: Local embeddings via node-llama-cpp (Qwen3-Embedding-4B)
  • Channels: Signal (single DM peer)
  • Cron jobs: 1 active (SDN submodule sync, every 6h)
  • Tools profile: coding

Observed behavior

  1. Gateway starts at ~389MB RSS
  2. Over 4 days, RSS grows to 14.7GB without returning memory
  3. Session JSONL files grow to 1.5–6.5MB each on disk
  4. compaction.mode: "safeguard" with maxHistoryShare: 0.5 and 131K context window means sessions can accumulate ~65K tokens before compaction triggers
  5. Context pruning (cache-ttl, TTL 6h) does not appear to reclaim in-process memory after pruning
  6. After the process is killed and restarted, memory returns to ~389MB immediately

Likely contributing factors

Steps to reproduce

  1. Configure gateway with a local model (131K context), Signal channel, and 1+ cron jobs
  2. Let it run for 3-4 days with periodic Signal messages and cron execution
  3. Monitor RSS: ps aux | grep openclaw-gateway | awk '{print $6/1024 "MB"}'
  4. Observe steady growth without plateau

Workaround

We implemented a daily maintenance LaunchAgent that:

  • Kills the gateway at 4 AM (auto-restarts via LaunchAgent service)
  • Resets any session JSONL files > 500KB
  • Deletes old .reset.* files > 3 days
  • Tightened compaction: maxHistoryShare: 0.3, pruning TTL 2h, keepLastAssistants: 2

This keeps memory under control but doesn't fix the underlying leak.

Expected behavior

Gateway RSS should plateau or return memory after session compaction/pruning, not grow unboundedly. Completed subagent sessions should be evicted from memory.

Metadata

Metadata

Assignees

Labels

P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions