Circuit Breaker
A Circuit Breaker is a safety mechanism in SpecWeave that prevents cascading failures when hooks or sync operations repeatedly fail. After 3 consecutive failures, the circuit "trips" and stops further attempts until manually reset.
How It Works
| State | Behavior |
|---|---|
| Closed | Normal operation, all requests pass through |
| Open | Blocked, requests fail fast without trying |
| Half-Open | Testing if service recovered |
When It Trips
The circuit breaker trips when:
- Hook failures: Same hook fails 3 times in a row
- Sync failures: GitHub/JIRA/ADO sync fails repeatedly
- API errors: External service returns errors consistently
Benefits
- Prevents crash loops: Stops repeated failing operations
- Protects resources: Stops hammering failing services
- Enables recovery: Gives systems time to recover
- Fail fast: Returns errors quickly instead of timing out
Checking Status
# Check if circuit breaker is tripped
cat .specweave/state/.hook-circuit-breaker 2>/dev/null
# If output shows "open", the circuit is tripped
Resetting
When you've fixed the underlying issue:
# Reset circuit breaker
rm -f .specweave/state/.hook-circuit-breaker*
# Or reset all hook state
rm -f .specweave/state/.hook-*
Configuration
Circuit breaker thresholds can be configured:
// .specweave/config.json
{
"circuitBreaker": {
"failureThreshold": 3,
"resetTimeout": 60000
}
}
Related Terms
- Hooks - Protected by circuit breakers
- Split-Source Sync - Uses circuit breakers for external APIs
- Context Explosion - Different failure mode