Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use this skill when designing resilient code, systems, or AI agents that recover from failure automatically. Also use for proactive resilience thinking — pre-mortems, failure mode analysis, chaos engineering, circuit breakers, retry logic, fallback strategies, and the developer self-improvement loop. Trigger on keywords: self-healing, resilience, fault tolerance, circuit breaker, retry, fallback, graceful degradation, chaos engineering, pre-mortem, failure mode, recovery, resilient design.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-12 | ✗→✓ | ▲ Improved | 37% | 0% |
| case-22 | ✓→✗ | ▼ Worse | 172% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 50% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 43% | 0% |
| case-06 | ✓→✓ | = Same ✓ | 38% | 0% |
> "Everything will eventually fail over time." — Werner Vogels, Amazon CTO
Self-healing is not a feature you add — it's a design philosophy you start with. The question is never "will this fail?" but "when this fails, what happens next?"
The shift: From reactive firefighting → proactive resilience engineering.
The same mindset applies at every level: code, systems, AI agents, and your own development practice.
Every self-healing system follows this pattern:
textDETECT → Monitor signals (health checks, error rates, latency, business KPIs) DECIDE → Select recovery strategy (retry, fallback, scale, restart, degrade) ACT → Execute recovery (automatically or with human confirmation) VERIFY → Confirm recovery succeeded LEARN → Update the healing logic based on what worked
This loop runs continuously. Design every system component with this loop in mind.
For transient failures (network timeouts, rate limits):
typescriptasync function withRetry<T>( fn: () => Promise<T>, maxAttempts = 3, baseDelayMs = 1000 ): Promise<T> { for (let attempt = 1; attempt <= maxAttempts; attempt++) { try { return await fn() } catch (error) { if (attempt === maxAttempts) throw error const delay = baseDelayMs * Math.pow(2, attempt - 1) await sleep(delay + Math.random() * 100) // jitter } } throw new Error('Max retries exceeded') }
Prevents cascading failures when a dependency is down:
textCLOSED (normal) → failures exceed threshold → OPEN (blocking calls) OPEN → after timeout → HALF-OPEN (test one call) HALF-OPEN → success → CLOSED | failure → OPEN
Use: Resilience4j (Java), Polly (.NET), opossum (Node.js), tenacity (Python)
Isolate failures to prevent them spreading:
When a feature fails, serve a reduced but functional experience:
textFull service: personalized recommendations Degraded: cached popular items Minimal: static placeholder with "recommendations unavailable"
Never show a crash when you can show reduced functionality.
Define explicit fallback for every external dependency:
typescriptasync function getRecommendations(userId: string) { try { return await recommendationService.get(userId) } catch { // Fallback: return cached popular items instead of crashing return await cache.get('popular-items') ?? DEFAULT_ITEMS } }
Every external call needs a timeout. No exceptions.
typescriptconst response = await fetch(url, { signal: AbortSignal.timeout(5000) // 5 second max })
yamllivenessProbe: # Restart container if health check fails readinessProbe: # Remove from load balancer if not ready resources: limits: # Prevent one pod consuming all resources
Every service needs:
/health — Is the service alive? (liveness)/ready — Is the service ready to accept traffic? (readiness)/metrics — Prometheus-compatible metricsMonitor these for every service:
Agents need resilience too:
textGenerate output → Validate output → If invalid: feedback + regenerate Max iterations: 3 (circuit breaker to prevent infinite loops)
textPLAN: Generate plan, validate feasibility before acting EXECUTE: Take action OBSERVE: Check if action succeeded REPLAN: If observation shows failure, adjust plan and retry
textPrimary approach fails → Try alternative approach Alternative fails → Request human clarification Clarification unavailable → Safe default action or graceful stop
text1. Run tests/lint on generated code 2. Check output format matches requirements 3. Verify no forbidden patterns (hardcoded secrets, deprecated APIs) 4. Use a separate "validator" agent to check the "generator" agent's work
Before building anything significant, ask:
textImagine it's 6 months from now and this has completely failed. What went wrong? Work backwards from the failure.
Then design to prevent the top 3 failure modes you identified.
For each component, answer: | Component | How can it fail? | Impact? | Likelihood? | Prevention? | Recovery? | |---|---|---|---|---|---| | DB connection | Timeout, crash | High | Medium | Connection pooling, retry | Fallback to read replica | | External API | Down, slow, rate-limited | Medium | High | Circuit breaker, cache | Return cached data | | Auth service | Unreachable | Critical | Low | Token caching | Grace period for existing tokens |
Deliberately introduce failures to test your healing logic:
Rule: If your system can't survive Chaos Engineering in staging, it will surprise you in production.
The same resilience philosophy applies to your own development practice:
text1. ROOT CAUSE: What was the actual cause? (not just the symptom) 2. PREVENTION: What would have caught this earlier? 3. DETECTION: How do I make this class of error visible faster? 4. SYSTEM FIX: Add a rule, test, or lint check to prevent recurrence
Keep a running log of your own recurring mistakes and the rules you created to prevent them. Review it at the start of each sprint or project.
markdown## Mistake: Forgot to handle null from API response Root cause: Assumed API always returns data Prevention: Always check API contract, add null guards by default System fix: Added ESLint rule for nullable return types
textHEALTHY → (error rate spike) → DEGRADED DEGRADED → (partial recovery) → RECOVERING DEGRADED → (escalation) → FAILING FAILING → (intervention) → RECOVERING RECOVERING → (verification passes) → HEALTHY
Design every system to:
Before shipping any service or feature:
Other measured skills in the registry, with their headline benchmark lift.