Ns advanced memory leak hunter
Skill nodesource/nsolid-plugin/skills/ns-advanced-memory-leak-hunter
Performs an advanced N|Solid memory leak hunt comparing baseline vs peak heap evidence to isolate retained constructors, closures, and retainer paths. Use when the user reports recurring/staircase memory growth, elusive leaks, retained objects, closures holding references, or a standard heap sample/snapshot analysis was inconclusive. Prefer supplied baseline/peak assets; capture new samples only when needed.From its SKILL.md
npx -y skills add nodesource/nsolid-plugin --skill ns-advanced-memory-leak-hunterAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 12 stars12 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
6.0 KB, as published. Nobody here has run it
Phase 0: Reuse Evidence and Resolve Target
- If the user already supplied both baseline and peak evidence, skip straight to Phase 4.
- If no agent
idis supplied, callinformation-dashboard(q: "app=<appName>",start: "5m"when app is known) to resolve the required agentid; preserve the exactappNamefor downloads. Stop if no matching agent is connected.
Phase 1: Establish the Baseline
- Take an initial low-overhead heap sample using
heap-sampling(id: <agentId>,duration: 30). - Run the wait script using the absolute path of the directory where you read this SKILL.md:
node "<skill-dir>/wait.cjs" 30 - Call
asset-summaryon the returned baseline asset ID. If not ready, runnode "<skill-dir>/wait.cjs" 10and retry; useassets-in-progressonly as a secondary queue clue. Cap retries at 12; if still not ready, report the baseline asset ID and its pending state instead of continuing indefinitely. - From the baseline summary, note the top allocating constructors (e.g.,
Object,Array,system / Map). - Check
.nsolid/assets/index.jsonand.nsolid/assets/for the same baseline asset ID. If it is already present locally, skip the download. - If the baseline asset is not present, save it locally:
node "<skill-dir>/fetch-asset.cjs" <baselineAssetId> heapprofile <appName>
Phase 2: Monitor RSS and Heap Growth
- Call
metrics-historicwithfield: ["rss", "heapUsed", "heapTotal", "loopEstimatedLag"],q: "app=<appName>"orq: "id=<id>", andstart: "1h". - Search for the "Sawtooth Pattern" (normal garbage collection) vs "Staircase Pattern" (unreleased memory).
- Identify the moment where
heapUsedstops dropping to its original baseline.
Phase 3: Capture the Peak / Leak State
- Once you confirm memory has substantially grown from the baseline, trigger a second analysis.
- Use advanced
track-heap-objectsonly for closure/retainer suspicion; otherwise useheap-samplingfor 60 seconds. Both require the resolved agentid. - Wait for the operation to complete:
Then callnode "<skill-dir>/wait.cjs" 60asset-summaryon the peak asset ID. If not ready, runnode "<skill-dir>/wait.cjs" 10and retry; useassets-in-progressonly as a secondary queue clue. Cap retries at 12; if still not ready, report the peak asset ID and its pending state instead of continuing indefinitely. - Analyze the
asset-summary. - Check
.nsolid/assets/index.jsonand.nsolid/assets/for the same peak asset ID. If it is already present locally, skip the download. - If the peak asset is not present, save it locally:
node "<skill-dir>/fetch-asset.cjs" <peakAssetId> heapprofile <appName>
Phase 4: Delta Analysis
- Compare the top allocators from the Peak profile (Phase 3) against the Baseline profile (Phase 1).
- Report the delta — which constructors or functions experienced the most massive growth between the two profiles.
- Propose exact code optimizations or point the user to the exact function causing the retained bytes.
Phase 5: Runtime Code Extraction & Optimization
- If the summary provides a
location(containingscriptId,line,column) and a knownurl(file path) for the leaking function, extract its source. - Call
runtime-codepassing the agentid,threadId,scriptId, andpath.- Extraction will fail if
scriptIdis0. - If the process runs in Docker, try tweaking the path up to two times. If it still fails, ask the user to provide the source code.
- Extraction will fail if
- Human in the loop: Present the problematic code and root cause to the user. Ask: "I've isolated the cause of the memory leak in this function. Would you like me to propose a fix?"
- Only after user approval, propose an optimized rewrite and use the
ns-validate-optimizationskill to verify the fix.
Phase 6: Write a Report
- Compose the full report as markdown using this structure:
# Memory Leak Hunt Report — <appName> **Date**: <ISO date> **Agent ID**: <id> ## Summary <Brief description of the leak — leaking constructor, growth rate, root cause> ## Baseline (Phase 1) **Asset ID**: <baselineAssetId> | Constructor | Self Size | Count | |-------------|-----------|-------| | <name> | <size> | <count> | ## Peak (Phase 3) **Asset ID**: <peakAssetId> | Constructor | Self Size | Count | |-------------|-----------|-------| | <name> | <size> | <count> | ## Delta Analysis | Constructor | Baseline Size | Peak Size | Growth | |-------------|--------------|-----------|--------| | <name> | <size> | <size> | +<delta> | ## Root Cause <Explanation of the leaking constructor/closure> ## Recommendation <Proposed fix> ## Assets - Baseline heap profile: `.nsolid/assets/heapprofile-<appName>-<baselineAssetIdPrefix>.heapprofile` - Peak heap profile: `.nsolid/assets/heapprofile-<appName>-<peakAssetIdPrefix>.heapprofile`
7. Write the Report to Disk
- Ask the user if they want to save the report to disk.
- If the user confirms, write the final report as a markdown file (
.md) under.nsolid/assets/— for example.nsolid/assets/memory-analysis-<appName>.md.
Guardrails
- No early assumptions: Never declare a memory leak from a single snapshot. Always compare baseline to peak.
- Reuse what exists: Do not capture a new baseline or peak sample if the user already supplied the needed assets.
- Wait times: Memory tools block the thread. Do not spam endpoints while an asset is in progress.