Skip to content

Implement Venice client circuit breaker with half-open state and automatic recovery #495

Description

@devJaja

Summary

The Venice client has a circuit breaker, but it needs full three-state implementation (closed → open → half-open → closed) with automatic recovery, configurable thresholds, and metrics. Currently a Venice outage may cause immediate failures rather than gracefully shedding load.

Priority

P1 — A single Venice outage currently degrades the whole network.

Files to work on

backend/src/services/venice/circuitBreaker.ts
backend/src/services/venice/client.ts
backend/src/services/venice/circuitBreaker.test.ts

Requirements

  • Implement full circuit breaker state machine:
    • CLOSED: normal operation; failure count resets on success
    • OPEN: reject all calls immediately after failureThreshold consecutive failures; start cooldown timer
    • HALF_OPEN: after cooldown, allow a limited probe of probeCount requests; success closes, failure reopens
  • Configurable: failureThreshold (default 3), cooldownMs (default 60_000), probeCount (default 1)
  • Expose metrics: { state, failures, successes, lastFailureAt, lastSuccessAt }
  • Emit events on state transitions (opened, closed, half_opened)
  • Add unit tests for all state transitions including timing with mocked timers

Acceptance Criteria

  • After failureThreshold consecutive failures, circuit opens (calls rejected immediately)
  • Rejected calls throw CircuitOpenError (not a Venice 5xx)
  • After cooldownMs, circuit enters HALF_OPEN
  • In HALF_OPEN, a single successful probe closes the circuit (closed state)
  • In HALF_OPEN, a single failed probe reopens the circuit
  • Successful calls in CLOSED reset the failure count
  • Circuit state is observable via getCircuitState()

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions