debugging-strategies
Systematic debugging: stack trace analysis, log-based diagnosis, bisecting regressions, memory leak detection, and profiling.
What this skill does
# Debugging Strategies
Systematic approaches to finding and fixing bugs.
## Stack Trace Analysis
### Read the trace bottom-up
The bottom of a stack trace is the most recent call — start there.
```bash
# Node.js — get full stack traces
NODE_OPTIONS="--stack-trace-limit=50" node app.js
# Python — verbose traceback
python3 -u -X tracemalloc app.py
```
### Common patterns
- **TypeError: Cannot read property of undefined** → Check the object one level up in the chain
- **ECONNREFUSED** → Service isn't running or wrong port
- **ENOMEM** → Memory exhaustion, check for leaks
- **Segfault** → Native addon or buffer overflow
## Log-Based Debugging
```bash
# Tail logs with filtering
tail -f app.log | grep -E "ERROR|WARN"
# Search recent logs for pattern
grep -n "error" app.log | tail -20
# Correlate by request ID
grep "req-abc123" app.log
# Docker container logs
docker logs --since 5m --follow myapp 2>&1 | grep -i error
# Kubernetes pod logs
kubectl logs -l app=myapp --since=10m | grep -i "exception\|error\|fatal"
# Multiple pods
kubectl logs -l app=myapp --all-containers --prefix --since=5m
```
## Git Bisect (Find the Breaking Commit)
```bash
# Start bisect
git bisect start
# Mark current as bad
git bisect bad
# Mark known good commit
git bisect good v1.0.0
# Test each commit git checks out, then mark:
git bisect good # or
git bisect bad
# Automate with a test script
git bisect run npm test
# When done
git bisect reset
# View bisect log
git bisect log
```
## Memory Leak Detection
### Node.js
```bash
# Heap snapshot
node --inspect app.js
# Open chrome://inspect → Take heap snapshot → Compare snapshots
# Track memory over time
node -e "
setInterval(() => {
const mem = process.memoryUsage();
console.log(JSON.stringify({
rss: (mem.rss / 1024 / 1024).toFixed(1) + 'MB',
heap: (mem.heapUsed / 1024 / 1024).toFixed(1) + 'MB',
external: (mem.external / 1024 / 1024).toFixed(1) + 'MB'
}));
}, 5000);
require('./app.js');
"
# Generate heap dump on OOM
node --max-old-space-size=512 --heap-prof app.js
```
### Python
```bash
# Track object counts
python3 -c "
import tracemalloc
tracemalloc.start()
# ... run code ...
snapshot = tracemalloc.take_snapshot()
for stat in snapshot.statistics('lineno')[:10]:
print(stat)
"
# objgraph for reference cycles
python3 -c "
import objgraph
objgraph.show_most_common_types(limit=10)
"
```
## Network Debugging
```bash
# DNS resolution
dig example.com +short
nslookup example.com
# Port check
nc -zv localhost 3000
# HTTP timing
curl -s -o /dev/null -w "DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" https://example.com
# Watch connections
lsof -i :3000
netstat -an | grep 3000
```
## Reproduce and Isolate
```bash
# Minimal reproduction
# 1. Create minimal test case
# 2. Remove code until bug disappears
# 3. Last removal is the culprit
# Environment comparison
node --version && npm --version && echo "OS: $(uname -s)"
env | grep -iE "node|npm|path|home" | sort
# Check for race conditions — run multiple times
for i in $(seq 1 10); do
npm test 2>&1 | tail -1
done
```
## Notes
- Reproduce first, fix second. If you can't reproduce it, you can't verify the fix.
- `git bisect run` is underused — it automates finding the exact commit that broke something.
- Memory leaks show as gradually increasing RSS over time. Take snapshots at intervals and compare.
- When stuck, explain the bug to someone (or write it down). Rubber duck debugging works.
- Check the obvious first: is the service running? Are env vars set? Is the config correct?
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.