Circuit Breakers¶
Circuit breakers prevent cascade failures by stopping traffic to unhealthy workers. They're essential for maintaining system stability when workers fail.
Overview¶
Automatic Isolation¶
Automatically isolate unhealthy workers to prevent cascade failures across your inference fleet.
Fail Fast¶
Detect failing workers and stop sending traffic immediately—no wasted requests or timeout waits.
Self-Healing¶
Automatically test recovery and restore traffic when workers become healthy again.
Observable¶
Prometheus metrics for breaker state, state transitions, and recorded outcomes.
Why Circuit Breakers?¶
Without circuit breakers, a failing worker can cause:
- Wasted requests: Requests sent to failing workers timeout
- Increased latency: Clients wait for timeouts before retry
- Resource exhaustion: Connections pile up to dead workers
- Cascade failures: Retry storms overwhelm remaining workers
Circuit breakers fail fast—they detect failing workers and stop sending traffic immediately.
How It Works¶
Each worker has its own circuit breaker with three states:
✓ Closed State¶
Normal operation - requests flow through.
- Each failed request increments a consecutive-failure counter
- A success resets the counter to zero
- Opens when the counter reaches
--cb-failure-threshold
✗ Open State¶
Circuit tripped - the worker is out of routing.
- No new requests are sent to the worker
- With no other worker available, requests get 503
no_available_workers - Moves to half-open after
--cb-timeout-duration-secs, or at once when the worker is promoted back toReady
Half-Open State¶
Testing recovery - the worker takes traffic again.
- Traffic to the worker is not throttled
--cb-success-thresholdconsecutive successes close the circuit- Any failure reopens it
State Transitions¶
Closed → Open¶
The circuit opens when:
consecutive_failures >= failure_thresholdconsecutive_failures counts failed requests, not attempts: however many of a request's retries fail on the same worker, that worker's breaker is charged one failure, so the threshold's meaning does not shift with --retry-max-retries. Per-request counting applies to HTTP workers in regular mode and to gRPC and ZMQ workers (regular, PD, and EPD dispatch). For HTTP workers in PD mode and for external provider workers, every failed attempt still counts individually.
Per-request counting applies since v1.13.0. In v1.12.0 and earlier, every failed attempt increments the counter on every path: with the default five attempts per request, two failed requests on one worker can produce the ten failures the default threshold needs.
A batched /v1/embeddings request on a gRPC worker also counts as one request to the breaker, even though the gateway dispatches it as one engine call per input: the breaker judges the whole batch once, on the worst answer among the calls. A worker failure outranks capacity pushback, which outranks a status that is the request's own fault (such as the rejection of one input), which outranks success — so a worker failure on any input reaches the breaker no matter where it sits in the batch. An answer that says nothing about the worker, such as a failed fetch of an input's media, is left out of the comparison. The worst answer is then classified as usual (see What Counts as a Failure), so a batch whose worst answer is capacity pushback still records nothing.
A single successful request resets consecutive_failures to zero. --cb-window-duration-secs is accepted and validated but is not consumed by the state machine — failures are tracked with a running consecutive-failure counter rather than a sliding window.
A streamed response can record two samples. A successful head (the 2xx status and the response headers) records one success as soon as it arrives, before the body is relayed, and is not sampled again when the stream ends. If the worker then ends the body with an error before its natural end, that cut records one failure on the same worker's breaker — on the HTTP relays, 504 when a timeout cut the body mid-stream and 502 for any other cut (the connection reset or closed, a malformed transfer). The head's earlier success does not offset the cut: it resets consecutive_failures when the head arrives, and the cut then counts as one fresh failure.
After a failed head, the head's status is the breaker sample, and a cut of the body that follows records nothing more. A cut is sampled outside the per-request counting above: if a request's attempt fails at the head and its retry on the same worker gets a successful head whose body is then cut, that worker is charged both for the failed head and for the cut.
This cut accounting applies on three paths: the regular HTTP relay; the disaggregated (PD) HTTP router's decode relay, where the cut is the decode worker's failure; and gRPC and ZMQ streams, where it charges the worker whose stream ended with the error. On gRPC and ZMQ streams an engine failure mid-stream samples the status it maps to, exactly as a failed dispatch of the same status does (see What Counts as a Failure): a connection the engine's server cut maps to 502 and a deadline to 504, both failures. Capacity pushback mid-stream still records nothing, and a mid-stream rejection of the request, mapped to 400, is still a success for the breaker.
A regular (non-PD) dispatch to a gRPC or ZMQ worker records its breaker success at the stream's first response, not when the worker accepts the call: these streams have no response head, and a call the worker took but never answered is no success. With a request deadline armed, every unanswered call ends with the deadline's 504 and no success before it, so a worker that accepts every call and answers nothing opens its circuit after --cb-failure-threshold requests in a row. On ZMQ workers the deadline is armed by default: their links carry --request-timeout-secs (default 1800) or the worker's own timeout_secs. On gRPC workers it is opt-in: --grpc-request-timeout-secs defaults to 0, which arms no deadline, and without one the gateway waits on a silent worker as long as the client does — a stream the client gives up on records nothing on the breaker.
On the PD HTTP router an attempt runs on two workers, a prefill and a decode. A failure one side causes by itself — its worker's own error status, a transport failure on the call to it, or its body cut after a successful head — is recorded on that side's worker alone; the healthy partner is not charged a failure for that attempt. A request timeout is the request's end rather than either side's own failure: on sequential dispatch (decode contacted only after the prefill answers) and under the opt-in concurrent MoRI-IO WRITE dispatch, its 504 is recorded on the side the timeout cut; a timeout that cuts the parallel dispatch (both sides sent at once) names no side, so its 504 is recorded on both workers. The exception to the double charge is a prefill whose body is already draining in the background (a streamed request without logprobs whose prefill returned a successful head): its worker's outcome is whatever the drain records — nothing, when the request's end cancels it mid-drain — so the 504 reaches only the decode worker. See PD Disaggregation.
External provider workers never charge the breaker for a body cut: on the OpenAI-compatible endpoints their breaker records the head's status when the provider answers and nothing more for the stream, and the native Messages API passthrough for Anthropic-type providers records no breaker sample for a streamed response at all.
Open → Half-Open¶
Once the circuit has been open for --cb-timeout-duration-secs, the next check of the worker's state (for example, during worker selection) moves it to half-open.
A promotion back to Ready is a second trigger: when a demoted worker's health checks pass again and promote it — or any other path returns it to Ready — its open circuit moves to half-open at once, so the worker takes traffic as soon as its health returns instead of waiting out the timeout. The trial is the same one the timeout starts: --cb-success-threshold consecutive successes close the circuit, and any failure reopens it for a full timeout.
A promotion also resets the consecutive-failure count of a circuit the outage left closed, so the first failure after the worker's return does not open the circuit on the outage's account. Each promotion starts at most one trial: passing probes on a worker that is already Ready are not a promotion, so a circuit that reopens during the trial waits for its open timeout or for the worker's next demotion and promotion.
Promotion readmission exists since v1.13.0. In v1.12.0 and earlier, a worker promoted by its health probes stayed unroutable until the open timeout passed.
Half-Open → Closed¶
If --cb-success-threshold consecutive requests succeed, the circuit closes and normal operation resumes.
Half-Open → Open¶
If any request fails during half-open, the circuit reopens immediately and the open timeout starts over.
What Counts as a Failure¶
The breaker classifies outcomes by the status of the response a worker sends back. Since v1.10, capacity pushback is not a failure:
| Worker outcome | Recorded as |
|---|---|
2xx, or any status not listed below (for example 400 or 404) |
Success |
408, 500, 502, 503, 504 |
Failure |
| No response (connection error or timeout), recorded as the 5xx the gateway returns for it | Failure |
The worker cuts a streamed body: on the HTTP relays (after a successful head), recorded as 504 (timeout) or 502 (any other cut); on gRPC and ZMQ streams, recorded as the status the cut maps to, whether or not a response has arrived yet; see State Transitions |
Failure |
429 (capacity pushback) |
Nothing: neither a failure nor a success |
- Why 429 is excluded. A busy engine answers 429 to say "not now". Counting that as a failure would open the breakers of the busiest workers during a load spike and push their traffic onto the rest. The gateway still retries a 429 when retries are enabled, but the response records no breaker sample in either direction, so it cannot close a half-open breaker either.
- gRPC workers. gRPC status codes are mapped to HTTP statuses first:
RESOURCE_EXHAUSTEDbecomes 429 (pushback),UNAVAILABLEbecomes 503 andDEADLINE_EXCEEDEDbecomes 504 (failures), andINVALID_ARGUMENTbecomes 400 (a success for the breaker). - Gateway sheds never count. Responses the gateway produces without a worker answering, such as admission sheds, overload protection sheds (
worker_overload_protection_shed), andno_available_workers, record nothing on any breaker. - 503 is still a failure by default, because a 503 cannot be told apart from an outage. If a backend uses 503 for backpressure, add it to that worker's capacity codes.
Per-Worker Overrides¶
The resilience block of a worker spec (for example, in a POST /workers request body; see the Admin API) overrides the breaker settings for that worker:
{
"url": "http://gpu1:8000",
"resilience": {
"capacity_status_codes": [429, 503],
"cb_failure_threshold": 5,
"cb_timeout_secs": 30
}
}| Field | Default | Description |
|---|---|---|
capacity_status_codes |
[429] |
Statuses treated as capacity pushback, which record no breaker sample |
retryable_status_codes |
[408, 429, 500, 502, 503, 504] |
Statuses that count as breaker failures (codes also listed in capacity_status_codes are skipped). Despite the name, it does not change which responses the gateway retries |
cb_failure_threshold |
--cb-failure-threshold |
Consecutive failed requests that open the circuit |
cb_success_threshold |
--cb-success-threshold |
Consecutive half-open successes that close the circuit |
cb_timeout_secs |
--cb-timeout-duration-secs |
Seconds the circuit stays open before it moves to half-open |
A status list you set replaces the default instead of adding to it, so keep 429 in capacity_status_codes if you still want it treated as pushback.
Configuration¶
smg launch \
--worker-urls http://w1:8000 http://w2:8000 \
--cb-failure-threshold 5 \
--cb-success-threshold 2 \
--cb-timeout-duration-secs 30Parameters¶
| Parameter | Default | Description |
|---|---|---|
--cb-failure-threshold |
10 |
Consecutive failed requests before the circuit opens |
--cb-success-threshold |
3 |
Consecutive successes in half-open state to close circuit |
--cb-timeout-duration-secs |
60 |
Seconds before open circuit transitions to half-open |
--cb-window-duration-secs |
120 |
Accepted and validated (must be > 0) but not consumed by the state machine; see Closed → Open |
--disable-circuit-breaker |
false |
Breakers never open: the failure threshold is raised to its maximum. Outcomes are still counted in the metrics |
The thresholds must be at least 1, and the durations must be greater than 0.
--cb-failure-threshold counts failed requests (since v1.13.0; earlier releases count failed attempts); see State Transitions.
Configuration Examples¶
Fast Circuit Opening¶
Sensitive to failures—isolate workers quickly.
smg launch \
--cb-failure-threshold 3 \
--cb-timeout-duration-secs 30Use when: Critical availability, latency-sensitive applications
Tolerant Configuration¶
Allow occasional failures before tripping.
smg launch \
--cb-failure-threshold 20 \
--cb-success-threshold 5 \
--cb-timeout-duration-secs 120Use when: Flaky workers, network instability, batch processing
Tuning Guidelines¶
| Scenario | Recommendation |
|---|---|
| Flaky workers | Higher failure_threshold, shorter timeout |
| Critical availability | Lower failure_threshold, longer timeout |
| Fast recovery workers | Lower timeout, lower success_threshold |
| Slow recovery workers | Higher timeout, higher success_threshold |
| Backends that answer 503 when busy | Add 503 to the worker's capacity_status_codes |
Example Scenarios¶
Normal Operation¶
Worker Fails¶
Once every worker for the model has an open circuit, requests get 503 no_available_workers. For external provider workers the code is service_unavailable.
Recovery¶
Monitoring¶
Metrics¶
| Metric | Type | Labels | Description |
|---|---|---|---|
smg_worker_cb_state |
Gauge | worker |
Current state: 0 closed, 1 open, 2 half-open. A removed worker's series is dropped from the scrape |
smg_worker_cb_transitions_total |
Counter | worker, from, to |
State transitions; from and to are closed, open, or half_open |
smg_worker_cb_outcomes_total |
Counter | worker, outcome |
Recorded outcomes, success or failure. Capacity pushback records nothing |
smg_worker_cb_consecutive_failures |
Gauge | worker |
Current consecutive-failure count |
smg_worker_cb_consecutive_successes |
Gauge | worker |
Current consecutive-success count |
smg_worker_cb_health_readmissions_total |
Counter | worker |
Open circuits moved to half-open by a promotion back to Ready instead of by the open timeout. Published at zero for each worker |
The worker label is the worker URL.
smg_worker_cb_health_readmissions_total exists since v1.13.0; see State Transitions.
Useful PromQL Queries¶
Current States¶
# Current circuit breaker states
smg_worker_cb_state
# Workers with open circuits
count(smg_worker_cb_state == 1)Transitions and Outcomes¶
# State transitions rate
rate(smg_worker_cb_transitions_total[5m])
# Failure share per worker
sum by (worker) (rate(smg_worker_cb_outcomes_total{outcome="failure"}[5m]))
/ sum by (worker) (rate(smg_worker_cb_outcomes_total[5m]))What to Watch¶
| Signal | Meaning | Action |
|---|---|---|
smg_worker_cb_state == 1 for a worker |
The worker is out of routing | Check the worker's logs and health |
Every live worker at 1 |
No worker can take traffic; requests get 503 no_available_workers |
Treat it as an outage |
Repeated open → half_open → open transitions |
The worker fails as soon as traffic returns (flapping) | Investigate the worker before it rejoins |
smg_worker_cb_consecutive_failures near the threshold |
The worker is failing right now | Check it before the circuit opens |
Alerting Example¶
groups:
- name: smg-circuit-breakers
rules:
- alert: CircuitBreakerOpen
expr: smg_worker_cb_state == 1
for: 1m
labels:
severity: warning
annotations:
summary: "Circuit breaker open for {{ $labels.worker }}"
- alert: AllCircuitsOpen
# Removed workers drop out of the scrape, so every series is a registered worker.
expr: count(smg_worker_cb_state == 1) == count(smg_worker_cb_state)
for: 30s
labels:
severity: critical
annotations:
summary: "All worker circuit breakers are open"Interaction with Other Features¶
Retries¶
- For local workers, each retry attempt runs worker selection again, so a worker whose circuit is open is skipped.
- A request's retries on the same worker charge its breaker once; a cut of a streamed body is one more sample on top (on the HTTP relays, only after a successful head). See State Transitions for the paths this covers and the v1.12.0 behavior.
- If every worker is unavailable, the attempt gets 503
no_available_workers. - A half-open worker is selected like any other; its outcomes decide whether the circuit closes or reopens.
- A 429 from a worker is retried when retries are enabled, but leaves that worker's breaker untouched.
Health Checks¶
Circuit breakers and health checks are independent gates: health checks probe workers in the background, while circuit breakers react to real request outcomes. A worker receives traffic only when both allow it, and when overload protection, if enabled, has not vetoed it:
| Health Check | Circuit Breaker | Receives traffic? |
|---|---|---|
| Passing | Closed or half-open | Yes |
| Passing | Open | No, until the circuit moves to half-open — at the open timeout, or at once when a promotion back to Ready readmits it |
| Failing | Any | No |
The gates exclude a worker independently, but recovery is coupled: a promotion back to Ready puts the worker's open circuit on trial immediately, while an open circuit on a worker that is already Ready waits out --cb-timeout-duration-secs. See State Transitions for the trial rules and the v1.12.0 behavior.
Disabling Circuit Breakers¶
In some cases, you may want to disable circuit breakers:
smg launch --worker-urls http://w1:8000 --disable-circuit-breakerThe breakers keep recording outcomes, so the metrics still move, but no circuit opens unless a worker sets its own cb_failure_threshold in its resilience block.
What's Next?¶
Rate Limiting¶
Cap how many requests the gateway runs at once, with a bounded queue.