# Openclaw Test Heap Leaks

Investigate `pnpm test` memory growth, Vitest worker OOMs, and suspicious RSS increases...

- Repository: https://github.com/SafeAI-Lab-X/ClawKeeper (1020 stars)
- Category: Testing
- License: see repository
- Last updated: 2026-08-17
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add SafeAI-Lab-X/ClawKeeper --skill openclaw-test-heap-leaks -g -a claude-code -y`
Codex: `npx skills add SafeAI-Lab-X/ClawKeeper --skill openclaw-test-heap-leaks -g -a codex -y`
Cursor: `npx skills add SafeAI-Lab-X/ClawKeeper --skill openclaw-test-heap-leaks -g -a cursor -y`
Gemini CLI: `npx skills add SafeAI-Lab-X/ClawKeeper --skill openclaw-test-heap-leaks -g -a gemini-cli -y`

## Description

Investigate `pnpm test` memory growth, Vitest worker OOMs, and suspicious RSS increases in OpenClaw using the `scripts/test-parallel.mjs` heap snapshot tooling. Use when Codex needs to reproduce test-lane memory growth, collect repeated `.heapsnapshot` files, compare snapshots from the same worker PID, distinguish transformed-module retention from real data leaks, and fix or reduce the impact by patching cleanup logic or isolating hotspot tests.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# OpenClaw Test Heap Leaks

Use this skill for test-memory investigations. Do not guess from RSS alone when heap snapshots are available.

## Workflow

1. Reproduce the failing shape first.
   - Match the real entrypoint if possible. For Linux CI-style unit failures, start with:
   - `pnpm canvas:a2ui:bundle && OPENCLAW_TEST_MEMORY_TRACE=1 OPENCLAW_TEST_HEAPSNAPSHOT_INTERVAL_MS=60000 OPENCLAW_TEST_HEAPSNAPSHOT_DIR=.tmp/heapsnap OPENCLAW_TEST_WORKERS=2 OPENCLAW_TEST_MAX_OLD_SPACE_SIZE_MB=6144 pnpm test`
   - Keep `OPENCLAW_TEST_MEMORY_TRACE=1` enabled so the wrapper prints per-file RSS summaries alongside the snapshots.
   - If the report is about a specific shard or worker budget, preserve that shape.

2. Wait for repeated snapshots before concluding anything.
   - Take at least two intervals from the same lane.
   - Compare snapshots from the same PID inside one lane directory such as `.tmp/heapsnap/unit-fast/`.
   - Use `scripts/heapsnapshot-delta.mjs` to compare either two files directly or the earliest/latest pair per PID in one lane directory.

3. Classify the growth before choosing a fix.
   - If growth is dominated by Vite/Vitest transformed source strings, `Module`, `system / Context`, bytecode, descriptor arrays, or property maps, treat it as retained module graph growth in long-lived workers.
   - If growth is dominated by app objects, caches, buffers, server handles, timers, mock state, sqlite state, or similar runtime objects, treat it as a likely cleanup or lifecycle leak.

The rest: https://github.com/SafeAI-Lab-X/ClawKeeper/blob/HEAD/legacy/clawkeeper-watcher/.agents/skills/openclaw-test-heap-leaks/SKILL.md
