AgentSkillsCN

Error Recovery Patterns Skill

当事物出现故障时,该如何应对?

SKILL.md
--- frontmatter
name: "Error Recovery Patterns Skill"
description: "What to do when things break."
applyTo: "**/*error*,**/*exception*,**/*retry*,**/*fallback*,**/*recovery*"

Error Recovery Patterns Skill

What to do when things break.

Recovery Hierarchy

Prevent → Detect → Contain → Recover → Learn

Retry Rules

RetryDon't Retry
Network timeoutsValidation errors (400)
Rate limits (429)Auth failures (401, 403)
Server errors (5xx)Not found (404)
Connection refusedBusiness logic errors

Retry with Backoff

typescript
const delay = baseDelay * Math.pow(2, attempt - 1);
const jitter = Math.random() * 0.3 * delay;
await sleep(delay + jitter);

Circuit Breaker States

CLOSED → (failures > threshold) → OPEN → (timeout) → HALF-OPEN → (success) → CLOSED

Fallback Patterns

PatternUse Case
Default valueConfig loading
Cached valueData fetch failure
Degraded serviceNon-critical features
typescript
const result = await primary().catch(() => fallback());

Rollback Patterns

PatternUse Case
DB transactionAtomic operations
Saga (compensate)Distributed transactions
Feature flagInstant rollback

Error Boundaries

Contain failures to prevent cascade. Catch at component boundaries, log, show fallback UI.

Synapses

See synapses.json for connections.