Agent skill
error-recovery
(ePost) Use when operations fail transiently — timeouts, network errors, retries, circuit breakers, graceful degradation
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/error-recovery-klara-copilot-epost-agent-kit
Metadata
Additional technical details for this skill
- keywords
-
error retry fallback circuit-breaker backoff resilience failure exponential degradation
- triggers
-
[ "error", "exception", "timeout", "retry", "fallback" ] - platforms
-
[ "all" ] - connections
-
{ "enhances": [ "debug" ] } - agent affinity
-
[ "epost-fullstack-developer", "epost-debugger", "epost-tester" ]
SKILL.md
Error Recovery Skill
Standardized patterns for robust error handling in agent execution.
Overview
This skill provides battle-tested strategies for handling failures gracefully: retry with exponential backoff, circuit breaker patterns, and fallback strategies. Use when operations may fail transiently (network, timeouts) or when you need graceful degradation.
When to Use
- Network requests that may timeout or fail
- External API calls with intermittent issues
- File operations on unreliable storage
- Multi-step workflows where individual steps can fail
- Agent delegation with potential cascade failures
Core Patterns
1. Retry with Exponential Backoff
When: Transient errors (network timeout, rate limiting, temporary unavailability)
Pattern:
async function retryWithBackoff(operation, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return await operation();
} catch (error) {
if (!isRetriable(error) || attempt === maxRetries - 1) {
throw error;
}
const delay = Math.pow(2, attempt) * 1000; // 1s, 2s, 4s
await sleep(delay);
}
}
}
function isRetriable(error) {
const retriableCodes = ['ETIMEDOUT', 'ECONNRESET', 'ENOTFOUND'];
return retriableCodes.includes(error.code) ||
(error.status >= 500 && error.status < 600);
}
2. Circuit Breaker
When: Cascading failures (agent A fails → agent B fails → agent C fails)
Pattern:
class CircuitBreaker {
constructor(threshold = 3, timeout = 60000) {
this.failureCount = 0;
this.threshold = threshold;
this.timeout = timeout;
this.state = 'CLOSED'; // CLOSED, OPEN, HALF_OPEN
this.nextAttempt = Date.now();
}
async execute(operation) {
if (this.state === 'OPEN') {
if (Date.now() < this.nextAttempt) {
throw new Error('Circuit breaker OPEN');
}
this.state = 'HALF_OPEN';
}
try {
const result = await operation();
this.onSuccess();
return result;
} catch (error) {
this.onFailure();
throw error;
}
}
onSuccess() {
this.failureCount = 0;
this.state = 'CLOSED';
}
onFailure() {
this.failureCount++;
if (this.failureCount >= this.threshold) {
this.state = 'OPEN';
this.nextAttempt = Date.now() + this.timeout;
}
}
}
3. Fallback Strategy
When: Primary approach fails, acceptable alternative exists
Pattern:
async function withFallback(primary, fallback, condition) {
try {
return await primary();
} catch (error) {
if (condition(error)) {
console.warn('Primary failed, using fallback:', error.message);
return await fallback();
}
throw error;
}
}
// Example usage
const result = await withFallback(
() => complexAIAnalysis(code),
() => simplePatternMatching(code),
(err) => err.code === 'TIMEOUT' || err.code === 'RATE_LIMIT'
);
Decision Matrix
| Scenario | Strategy | Max Retries | Backoff |
|---|---|---|---|
| Network request | Retry | 3 | Exponential (1s, 2s, 4s) |
| External API | Retry + Circuit Breaker | 3 | Exponential |
| File read/write | Retry | 2 | Linear (500ms, 1s) |
| Agent delegation | Circuit Breaker + Fallback | 1 | None |
| User input validation | Fail Fast | 0 | None |
| Missing dependency | Fail Fast | 0 | None |
When to Fail Fast
Do NOT retry for:
- Invalid input (schema validation failures)
- Missing required dependencies
- Authentication/authorization errors
- Logical errors in code
- Data corruption
Pattern:
if (!isValid(input)) {
throw new Error('Invalid input - fix and retry');
}
if (!fs.existsSync(requiredFile)) {
throw new Error('Missing required file');
}
Agent-Specific Guidelines
For Implementer Agents
- Retry file operations (transient disk issues)
- Fail fast on syntax errors
- Fallback: simpler implementation if complex approach fails
For Tester Agents
- Retry flaky tests (once only)
- Fail fast on compilation errors
- Fallback: skip optional tests if infrastructure unavailable
For Git Manager
- Retry push (network issues)
- Fail fast on merge conflicts
- Fallback: none (git operations must succeed)
For Researcher Agents
- Retry API calls (rate limiting, timeouts)
- Circuit breaker for unreliable sources
- Fallback: use cached results if available
Best Practices
- Log retries clearly: Help debugging
- Set reasonable limits: Avoid infinite loops
- Preserve original error: Include in final throw
- Document why retrying: Comment the reasoning
- Monitor failure rates: Track circuit breaker trips
Example Integration
// In subagent execution
const circuitBreaker = new CircuitBreaker(3, 60000);
try {
const result = await circuitBreaker.execute(async () => {
return await retryWithBackoff(
() => implementFeature(spec),
3
);
});
return result;
} catch (error) {
// Fallback to simpler implementation
console.warn('Complex implementation failed, using simpler approach');
return await simpleImplementation(spec);
}
References
Related Skills
debug— Systematic debugging methodologyproblem-solving— Root cause analysis techniquesknowledge-capture— Persist error patterns and recovery strategies
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?