| name | clay-advanced-troubleshooting |
| description | Apply Clay advanced debugging techniques for hard-to-diagnose issues.
Use when standard troubleshooting fails, investigating complex race conditions,
or preparing evidence bundles for Clay support escalation.
Trigger with phrases like "clay hard bug", "clay mystery error",
"clay impossible to debug", "difficult clay issue", "clay deep debug".
|
| allowed-tools | Read, Grep, Bash(kubectl:*), Bash(curl:*), Bash(tcpdump:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Clay Advanced Troubleshooting
Overview
Deep debugging techniques for complex Clay issues that resist standard troubleshooting.
Prerequisites
- Access to production logs and metrics
- kubectl access to clusters
- Network capture tools available
- Understanding of distributed tracing
Evidence Collection Framework
Comprehensive Debug Bundle
#!/bin/bash
BUNDLE="clay-advanced-debug-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$BUNDLE"/{logs,metrics,network,config,traces}
kubectl logs -l app=clay-integration --since=1h > "$BUNDLE/logs/pods.log"
journalctl -u clay-service --since "1 hour ago" > "$BUNDLE/logs/system.log"
curl -s localhost:9090/api/v1/query?query=clay_requests_total > "$BUNDLE/metrics/requests.json"
curl -s localhost:9090/api/v1/query?query=clay_errors_total > "$BUNDLE/metrics/errors.json"
timeout 30 tcpdump -i any port 443 -w "$BUNDLE/network/capture.pcap" &
curl -s localhost:16686/api/traces?service=clay > "$BUNDLE/traces/jaeger.json"
kubectl get cm clay-config -o yaml > "$BUNDLE/config/configmap.yaml"
kubectl get secret clay-secrets -o yaml > "$BUNDLE/config/secrets-redacted.yaml"
tar -czf "$BUNDLE.tar.gz" "$BUNDLE"
echo "Advanced debug bundle: $BUNDLE.tar.gz"
Systematic Isolation
Layer-by-Layer Testing
async function diagnoseClayIssue(): Promise<DiagnosisReport> {
const results: DiagnosisResult[] = [];
results.push(await testNetworkConnectivity());
results.push(await testDNSResolution('api.clay.com'));
results.push(await testTLSHandshake('api.clay.com'));
results.push(await testAuthentication());
results.push(await testAPIResponse());
results.push(await testResponseParsing());
return { results, firstFailure: results.find(r => !r.success) };
}
Minimal Reproduction
async function minimalRepro(): Promise<void> {
const client = new ClayClient({
apiKey: process.env.CLAY_API_KEY!,
});
try {
const result = await client.ping();
console.log('Ping successful:', result);
} catch (error) {
console.error('Ping failed:', {
message: error.message,
code: error.code,
stack: error.stack,
});
}
}
Timing Analysis
class TimingAnalyzer {
private timings: Map<string, number[]> = new Map();
async measure<T>(label: string, fn: () => Promise<T>): Promise<T> {
const start = performance.now();
try {
return await fn();
} finally {
const duration = performance.now() - start;
const existing = this.timings.get(label) || [];
existing.push(duration);
this.timings.set(label, existing);
}
}
report(): TimingReport {
const report: TimingReport = {};
for (const [label, times] of this.timings) {
report[label] = {
count: times.length,
min: Math.min(...times),
max: Math.(...times),
: times.( a + b, ) / times.,
: .(times, ),
};
}
report;
}
}
Memory and Resource Analysis
const heapUsed: number[] = [];
setInterval(() => {
const usage = process.memoryUsage();
heapUsed.push(usage.heapUsed);
if (heapUsed.length > 60) {
const trend = heapUsed[59] - heapUsed[0];
if (trend > 100 * 1024 * 1024) {
console.warn('Potential memory leak in clay integration');
}
}
}, 60000);
Race Condition Detection
class ClayConcurrencyChecker {
private inProgress: Set<string> = new Set();
async execute<T>(key: string, fn: () => Promise<T>): Promise<T> {
if (this.inProgress.has(key)) {
console.warn(`Concurrent access detected for ${key}`);
}
this.inProgress.add(key);
try {
return await fn();
} finally {
this.inProgress.delete(key);
}
}
}
Support Escalation Template
## Clay Support Escalation
**Severity:** P[1-4]
**Request ID:** [from error response]
**Timestamp:** [ISO 8601]
### Issue Summary
[One paragraph description]
### Steps to Reproduce
1. [Step 1]
2. [Step 2]
### Expected vs Actual
- Expected: [behavior]
- Actual: [behavior]
### Evidence Attached
- [ ] Debug bundle (clay-advanced-debug-*.tar.gz)
- [ ] Minimal reproduction code
- [ ] Timing analysis
- [ ] Network capture (if relevant)
### Workarounds Attempted
1. [Workaround 1] - Result: [outcome]
2. [Workaround 2] - Result: [outcome]
Instructions
Step 1: Collect Evidence Bundle
Run the comprehensive debug script to gather all relevant data.
Step 2: Systematic Isolation
Test each layer independently to identify the failure point.
Step 3: Create Minimal Reproduction
Strip down to the simplest failing case.
Step 4: Escalate with Evidence
Use the support template with all collected evidence.
Output
- Comprehensive debug bundle collected
- Failure layer identified
- Minimal reproduction created
- Support escalation submitted
Error Handling
| Issue | Cause | Solution |
|---|
| Can't reproduce | Race condition | Add timing analysis |
| Intermittent failure | Timing-dependent | Increase sample size |
| No useful logs | Missing instrumentation | Add debug logging |
| Memory growth | Resource leak | Use heap profiling |
Examples
Quick Layer Test
curl -v https://api.clay.com/health 2>&1 | grep -E "(Connected|TLS|HTTP)"
Resources
Next Steps
For load testing, see clay-load-scale.