Repository navigation
Conversation
…es once
A provider that is down used to cost every request a full attempt: on
18-19 Oct our Qwen server answered 502 to every request for about a day.
A circuit breaker per provider and upstream model now opens after five
provider failures in a row and keeps requests away for 30 s (doubling up
to 5 min after failed probes). While it is open, requests go straight to
the model's fallback provider, or fail at once with 503 and Retry-After.
One request probes the provider to close it again. Without a fallback, a
connection error or a quick 502/503 before any output is retried once; a
request reaches at most two provider attempts.
Rejected requests, rate limits and canceled clients never count as
failures. New metrics: nexus_gateway_circuit_open and
nexus_gateway_circuit_transitions_total; retries are counted in
nexus_gateway_provider_retries_total{reason="transient_retry"}.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
From 18 Oct 15:33 UTC our Qwen 3.8 27B server answered every request with a 502 in about 0.25 s, for about a day: 193 failed requests, 0 successful, 3 accounts. Every request still paid for a full provider attempt, and the gateway had no way to step around a provider it already knew was down. Models that do have a fallback provider (DeepSeek → Doubleword, MiniMax → Novita) only switched after each request had failed on the primary first.
This is the gateway part of the self-healing work for the Nexus Gateway error-rate goal.
What changes
Circuit breaker, per provider and upstream model (
services/breaker.go):503 provider_unavailable,cause=circuit_openand aRetry-Afterheader.provider_configuration_error(our key or account at the provider). Rejected requests, 4xx answers, rate limits and canceled clients never count.One retry for quick failures:
Observability:
nexus_gateway_circuit_open{provider,provider_model}(1 while open) andnexus_gateway_circuit_transitions_total{provider,provider_model,state}.nexus_gateway_provider_retries_total{reason="transient_retry"}.provider circuit opened/provider circuit closed/retrying provider after a quick failure.Configuration (
apps/gateway/selfhealing.go; defaults in parentheses):PROVIDER_BREAKER_FAILURES(5; 0 turns the breaker off)PROVIDER_BREAKER_OPEN_SECONDS(30)PROVIDER_BREAKER_MAX_OPEN_SECONDS(300)PROVIDER_RETRY_FAST_FAILURES(true)Behaviour changes to note
Retry-Afterinstead of the provider's 502. Clients that honourRetry-Afterback off by themselves.Not in this PR
/v1/models, so apps can switch models themselves.Testing
go vet ./apps/gateway/...,go test ./..., andgo test -raceon services and pkg.Retry-Afterwithout reaching it;TestSystemOnerepeats provider failures on purpose to check status passthrough, so it turns the breaker off.🤖 Generated with Claude Code