本文へ移動
cccskills
無料GitHub で公開日本語紹介

openclaw-test-heap-leaks

OpenClawのテスト中に起きるメモリ増加や不足を調べます。測定結果やメモリ内の記録を比較し、実際の解放漏れとテスト実行側の保持を見分け、修正を検証します。

原文Investigate OpenClaw pnpm test memory growth, Vitest OOMs, RSS spikes, and heap snapshot deltas.

インストール方法を見る

こんなときに便利

  • Vitestのメモリ不足を調べたいとき
  • 同一プロセスのメモリ記録を比較したいとき
  • 解放漏れとモジュール保持を見分けたいとき
  • 実行時の解放漏れ修正を検証したいとき

日本語での紹介

できること

OpenClawのテストで起きるメモリ増加や、Vitestのメモリ不足による失敗を調査します。実際の実行条件を再現し、使用量の測定、メモリ割り当ての記録、ヒープスナップショットというメモリ内のオブジェクトの記録を比較します。アプリの解放漏れか、テスト実行プロセスに読み込んだモジュールが残っているのかを整理し、原因に合う修正と再検証につなげます。

こんなときに便利

テストを続けるとメモリが増える場合や、特定の構成・並列実行数で失敗する場合に向いています。長時間動く処理の修正についても、専用の検証プログラムで、関数が保持した状態が解放されるか確認します。

使い方の例

  • 「このテストのメモリ不足を同じ実行条件で再現して、原因を調べて」
  • 「同じプロセスの前後のスナップショットを比較して」
  • 「修正後に保持されるオブジェクトが減ったか検証して」

注意点

OpenClawのpnpmコマンド、付属スクリプト、Vitest構成を前提とし、関連するopenclaw-test-performanceの資料も参照します。記録の詳細確認にはDevToolsを使います。プロセス全体の使用量やオブジェクト名の増加だけでは、メモリリークと断定しません。

この紹介文は、公開されている SKILL.md をもとに AI(Claude Haiku)が作成しました。正確な仕様は下の原文を確認してください。

含まれるファイル(3)

  • SKILL.md7.3 KB
  • agents/openai.yaml237 B
  • scripts/heapsnapshot-delta.mjs13.9 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

OpenClaw Test Heap Leaks

Use this skill for test-memory investigations. Do not guess from RSS alone when heap snapshots are available. Treat snapshot-name deltas as triage evidence, not proof, until retainers or dominators support the call.

Read ../openclaw-test-performance/SKILL.md first for the current test-performance commands and proof routing.

For runtime fixes (e.g., closure leaks in long-running services like the gateway), see Validating runtime fixes below — that uses a dedicated harness rather than the unit-test profiling workflow.

Workflow

  1. Reproduce the failing shape first.

    • Match the real entrypoint and worker budget. For a broad unit-fast baseline with per-config max RSS and top-file timing, start with:

      pnpm test:perf:groups \
        --config test/vitest/vitest.unit-fast.config.ts \
        --allow-failures \
        --output .artifacts/test-perf/unit-fast-memory.json
      
    • For a suspected file, rerun that file with one worker and collect wall/RSS evidence: /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose.

    • Current pnpm test execution is planned by scripts/test-projects.mts. Record the printed Vitest config or shard and preserve that shape when the report is configuration- or worker-budget-specific.

  2. Collect the strongest available heap evidence.

    • Run pnpm test:perf:profile:runner -- --output-dir .artifacts/test-perf/vitest-runner-profile -- <file> for a CPU profile plus a sampling heap profile of the unit runner. Open the heap profile in DevTools and inspect the largest allocation families.
    • Sampling .heapprofile output is not a .heapsnapshot; do not pass it to the snapshot delta helper.
    • When a dedicated harness or another known producer emits repeated .heapsnapshot files, compare snapshots from the same PID with .agents/skills/openclaw-test-heap-leaks/scripts/heapsnapshot-delta.mjs.
    • If no snapshot or heap profile is available, RSS growth is useful triage evidence, but keep the leak classification inconclusive.
  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 likely 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.
    • If the names are ambiguous, stop short of a confident label and inspect retainers/dominators in DevTools for the top deltas.
  4. Fix the right layer.

    • For likely retained transformed-module growth in shared workers:
    • Inspect the owning Vitest config and the process chunking in scripts/test-projects.test-support.mjs. Fix process lifetime or project ownership there only when the same-shape evidence shows that shared-worker retention is the cause.
    • test/vitest/vitest.unit-fast-isolated.config.ts is for audited stateful tests that need a fresh module graph. Do not use it as a generic memory-hotspot list.
    • For real leaks:
    • Patch the implicated test or runtime cleanup path.
    • Look for missing afterEach/afterAll, module-reset gaps, retained global state, unreleased DB handles, or listeners/timers that survive the file.
  5. Verify with the most direct proof.

    • Re-run the same grouped or scoped command and confirm the max-RSS trend or OOM is reduced.
    • When a dedicated producer emits heap profiles or snapshots, repeat the same producer and compare equivalent artifacts.
    • For routing or config changes, verify the expected Vitest config or shard starts and the affected tests complete.

Heuristics

  • Do not call everything a leak. Growth in a non-isolated shared Vitest project can be a worker-lifetime problem rather than an application object leak.
  • scripts/test-projects.mts, scripts/test-group-report.mts, and scripts/run-vitest-profile.mts are the current execution, grouped-RSS, and profile entrypoints.
  • The [test] starting ... lines identify the Vitest config or shard to reproduce.
  • .artifacts/vitest-shard-timings.json stores config/shard durations for scheduling. It is not a file-level memory-hotspot or behavior manifest.
  • When the same retained object families grow across multiple intervals in the same worker PID, trust the snapshots over intuition, then confirm ambiguous calls with retainer evidence.

Snapshot Comparison

  • Direct comparison:
    • node .agents/skills/openclaw-test-heap-leaks/scripts/heapsnapshot-delta.mjs before.heapsnapshot after.heapsnapshot
  • Auto-select earliest/latest snapshots per PID within one lane:
    • node .agents/skills/openclaw-test-heap-leaks/scripts/heapsnapshot-delta.mjs --lane-dir <snapshot-directory>
  • Useful flags:
    • --top 40
    • --min-kb 32
    • --pid 16133

Read the top positive deltas first. Large positive growth in module-transform artifacts points to shared-process lifetime or project ownership; large positive growth in runtime objects suggests a real leak. If the names alone do not settle it, open the same snapshot pair in DevTools and inspect retainers/dominators for the top rows before declaring root cause.

Validating runtime fixes (not test-memory)

The workflow above is for diagnosing Vitest worker memory growth. For validating that a runtime/closure fix actually releases captured state, use the dedicated harness:

  • pnpm leak:embedded-run — runs scripts/embedded-run-abort-leak.ts. Loops N aborted runs in a function-shaped scope mimicking runEmbeddedAttempt, writes heap snapshots, and reports a PASS/FAIL verdict on retention growth using FinalizationRegistry for tracked-instance counting plus RSS delta.

Modes:

  • closure-extracted (default) — production fix shape (helper at module scope).
  • closure-inline — pre-fix shape (closure inside the runner scope). Use as a sensitivity check: if it passes you've broken the harness, not fixed a bug.
  • synthetic-leak — deliberately retains via a module-level bucket. Use to confirm the harness can detect leaks before trusting a PASS on a real fix.

Snapshots land in .tmp/embedded-run-abort-leak/. Diff with the same script as above:

node .agents/skills/openclaw-test-heap-leaks/scripts/heapsnapshot-delta.mjs \
  .tmp/embedded-run-abort-leak/baseline-*.heapsnapshot \
  .tmp/embedded-run-abort-leak/batch-N-*.heapsnapshot --top 30

When fixing a different runtime leak, add a new harness alongside this one rather than retrofitting it. The fixture function should mimic the lexical scope of the function where the leak lives, not be a generic abort-loop.

Output Expectations

When using this skill, report:

  • The exact reproduce command.
  • Which Vitest config or target was reproduced, and which PID was compared when snapshots were available.
  • The dominant retained object families from the heap profile or snapshot delta, when available.
  • Whether the issue is a likely real leak or likely shared-worker retained module growth, plus whether retainers/dominators confirmed it.
  • The concrete fix or impact-reduction patch.
  • What you verified, and what snapshot overhead prevented you from verifying.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

1password

無料日本語概要

1Password CLIの導入と認証を確認し、保存したパスワードやAPIキーをコマンドや設定へ渡します。デスクトップ連携やサービスアカウントにも対応します。

  • 1Password CLIを導入したいとき
  • APIキーをコマンドに渡したいとき
  • CIでサービスアカウント認証を使う
openclaw/openclaw39.2万2026年10月10日 更新

acp-router

無料日本語概要

OpenClawへの自然な言葉の依頼をClaude Codeなどの外部コーディングエージェントへ振り分け、作業の開始や継続、スレッド内の会話をつなぐスキルです。

  • Claude Codeをスレッドで開始
  • 外部エージェントの作業を続けたいとき
  • acpxから直接指示を渡したいとき
openclaw/openclaw39.2万2026年10月10日 更新

Add and live-prove a model provider with non-interactive config one-liners, without exposing credentials.

日本語の概要は準備中です。原文の説明を表示しています。

openclaw/openclaw39.2万2026年10月10日 更新

Requested GitHub PR/issue agent transcripts: redact, trim, preview, and insert safely.

日本語の概要は準備中です。原文の説明を表示しています。

openclaw/openclaw39.2万2026年10月10日 更新

apple-notes

無料日本語概要

macOSのApple Notesをエージェントから作成・検索・編集・削除し、フォルダ間の移動やHTML・Markdownへの書き出しを行うスキル。

  • タイトルを付けてメモを作りたいとき
  • フォルダ指定やあいまい検索でメモ探し
  • メモの編集とフォルダ整理
openclaw/openclaw39.2万2026年10月10日 更新

apple-reminders

無料日本語概要

Apple Remindersの予定付きToDoをMacから確認・追加・編集するスキル。リストの管理や完了・削除にも対応し、iPhoneやiPadで見るタスクを整理できます。

  • 今日のタスクや期限超過を確認したいとき
  • 期限付きの個人ToDoを追加したいとき
  • iPhoneやiPadのタスクを整理
openclaw/openclaw39.2万2026年10月10日 更新

openclaw のスキルをすべて見る

このスキルの問題を報告する