agentleFS
dbtinoy-dbtinoy-/lexigram-framework-skills/resilience-patterns/SKILL.md

resilience-patterns

Skill1 starsChanged 3 months agoMITView on GitHub

Use when adding retry logic, circuit breakers, rate limiting, or fault-tolerance patterns in the Lexigram framework

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All decorators take config objects, not raw keyword arguments.

    line 14
  2. Distinctive:

    No jitter on retry delay — thundering herd on recovery

    line 92

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Resilience Patterns

Overview

Lexigram provides composable fault-tolerance primitives: retry, circuit breaker, bulkhead, rate limiter, and timeout. Patterns compose into a ResiliencePipeline.

Decorators

All decorators take config objects, not raw keyword arguments. Decorators apply bottom-up — write the stack so the closest decorator to the function runs first:

from lexigram.resilience import retry, circuit_breaker, bulkhead, with_timeout
from lexigram.resilience import RetryConfig, CircuitBreakerConfig, BulkheadConfig, TimeoutConfig, CircuitBreakerRegistry

@with_timeout(TimeoutConfig(timeout=30.0))                                              # 4th: outermost deadline
@retry(RetryConfig(max_attempts=3, base_delay=1.0, backoff_factor=2.0))                 # 3rd: retry inside CB
@circuit_breaker("external-api", registry=CircuitBreakerRegistry(), config=CircuitBreakerConfig(failure_threshold=5, recovery_timeout=30))  # 2nd: fail fast
@bulkhead(BulkheadConfig(max_concurrent=10, queue_size=20))                             # 1st: limit concurrency
async def call_external_api(payload: dict) -> Result[Response, DomainError]:
    return await self.client.post(payload)

Programmatic API

from lexigram.resilience import (
    RetryConfig, CircuitBreaker, RetryPolicy,
    CircuitBreakerConfig, CircuitBreakerRegistry,
    ResiliencePipeline, TimeoutConfig,
)

# Retry
config = RetryConfig(max_attempts=3, base_delay=1.0, backoff_factor=2.0, jitter=True)
policy = RetryPolicy(config)
result = await policy.execute(lambda: fetch_data())

# Circuit breaker — use protect() as context manager
cb = CircuitBreaker(CircuitBreakerConfig(failure_threshold=5, recovery_timeout=30.0))
async with cb.protect():
    result = await call_service()

# Resilience pipeline
from lexigram.resilience import ResiliencePipeline

pipeline = ResiliencePipeline(
    retry_config=RetryConfig(max_attempts=3),
    circuit_config=CircuitBreakerConfig(failure_threshold=5, recovery_timeout=30),
    timeout_config=TimeoutConfig(timeout=15.0),
)
result = await pipeline.execute(fetch_data)

Composition Order

Request → Bulkhead → Circuit Breaker → Retry → Timeout → Service

Quick Reference

PatternDecoratorWhen to Use
Retry@retry(config)Transient failures (network, 503)
Circuit Breaker@circuit_breaker(name, ...)Downstream is down — fail fast
Bulkhead@bulkhead(config)Limit concurrent calls
Rate LimiterRateLimiterThrottle request rate
Timeout@with_timeout(config)Hard deadline for slow calls

Config

resilience:
  retry:
    max_attempts: 3
    base_delay: 1.0
    backoff_factor: 2.0
    jitter: true
  circuit_breaker:
    failure_threshold: 5
    recovery_timeout: 30.0

Common Mistakes

  • Retrying non-idempotent operations — can cause duplicate charges/actions
  • Placing retry outside circuit breaker — retries keep hammering a dead service
  • No jitter on retry delay — thundering herd on recovery
  • Sync functions: use circuit_breaker_sync — the other decorators auto-detect sync/async
  • Missing fallback — user gets 500 instead of a degraded response

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.