Skip to content

feat: Circuit breaker + retry logic for agent-to-agent calls (RELIABILITY-001) #304

Closed

Description

@vybe

Summary

Agent-to-agent HTTP calls in agent_client.py currently have zero retries and no circuit breaking. When an agent is unhealthy or overloaded, callers wait up to 15 minutes before failing, causing cascading timeouts across the fleet. This is the single biggest reliability issue at scale.

Solution

Drop-in two well-established libraries:

  • pybreaker — Per-agent circuit breakers. After N failures in M seconds, short-circuit all calls to that agent (immediate CircuitBreakerError instead of 15-min timeout). Self-heals after cooldown period.
  • tenacity — Exponential backoff retries for transient failures (connection errors, timeouts). Combines with circuit breaker: retry transient issues, stop retrying when agent is truly down.

Scope

  • Add pybreaker and tenacity to backend dependencies
  • Create per-agent circuit breaker registry in agent_client.py
  • Wrap _request() method with tenacity retry decorator (3 attempts, exponential backoff)
  • Wrap agent HTTP calls with circuit breaker
  • Expose circuit breaker state in fleet health endpoint (/api/monitoring/health)
  • Log circuit state transitions (closed→open→half-open) via structured logging

Acceptance Criteria

  • Agent calls retry up to 3x with exponential backoff on transient errors
  • After 3 consecutive failures to an agent, circuit opens — subsequent calls fail immediately
  • Circuit auto-resets after 30s cooldown (half-open → test → close or re-open)
  • Circuit breaker state visible in fleet health API response
  • No behavior change for healthy agents (transparent when things work)
  • ~70 lines changed, no architectural changes

Key Files

  • src/backend/services/agent_client.py — primary target
  • src/backend/services/monitoring_service.py — expose breaker state
  • src/backend/routers/monitoring.py — health endpoint enrichment

Dependencies

None — standalone improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-p1type-feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions