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
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
Requirements
CLOSED: normal operation; failure count resets on successOPEN: reject all calls immediately afterfailureThresholdconsecutive failures; start cooldown timerHALF_OPEN: after cooldown, allow a limited probe ofprobeCountrequests; success closes, failure reopensfailureThreshold(default 3),cooldownMs(default 60_000),probeCount(default 1){ state, failures, successes, lastFailureAt, lastSuccessAt }opened,closed,half_opened)Acceptance Criteria
failureThresholdconsecutive failures, circuit opens (calls rejected immediately)CircuitOpenError(not a Venice 5xx)cooldownMs, circuit entersHALF_OPENHALF_OPEN, a single successful probe closes the circuit (closed state)HALF_OPEN, a single failed probe reopens the circuitCLOSEDreset the failure countgetCircuitState()