Repository navigation
feat(gateway): add an opt-in circuit breaker for the anonymous free-tier lane - #140
Merged
Merged
Conversation
A flagged free-tier exit keeps answering 403 (IP-level abuse detection) and retrying only extends the penalty. Add an optional lane-level circuit breaker, configured with models.anonymous_backoff: - threshold consecutive failed anonymous attempts, or one 403/429, pause the whole lane for base_hours, doubling on every further trip up to max_hours; - while paused, no proxy is drawn and no upstream request is made, so routing falls straight through to the authenticated tiers; - a successful attempt closes the breaker and restores the free lane; - absent config leaves behavior unchanged; - availability probes honour the breaker instead of refreshing the block.
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.
Summary
When the anonymous free tier is blocked for the deployment's egress IP (the
403"abusive traffic"
FreeTierError), the lane currently keeps probing:anonymousNodes.MarkFailurecools one exit for at most 8xperformance.failure_cooldown_seconds(default 120s), then the cursor draws thenext exit, so every client request repeats the whole 403 walk. The upstream
message explicitly warns that retrying extends the penalty. Related to #131.
This PR adds an optional lane-level circuit breaker, next to the existing
per-exit cooldown:
thresholdconsecutive failed anonymous attempts, or a single403/429(an explicit block signal), pause the whole anonymous lane for
base_hours;max_hours;straight to the authenticated tiers, and availability probes honour the state
instead of refreshing the block;
default and every existing configuration keeps working.
Usage
Enable it by adding the block to the configuration file:
{ "models": { "anonymous_backoff": { "threshold": 6, "base_hours": 1, "max_hours": 24 } } }nothing changes.
(
6,1,24), so"anonymous_backoff": {}is the same as the exampleabove.
1h -> 2h -> 4h -> ...and stop atmax_hours; anyanonymous success resets the strikes, so the free lane recovers by itself
once the block lifts.
the authenticated tiers in
preferorder. Free models that are onlyavailable anonymously return the keyed-tier error until the window expires.
WARNlog eventanonymous_breaker_openreports the upstreamstatusandthe
paused_forwindow, so the state is visible in the logs.This is the configuration used in the live test below:
Relationship to #131
#131 proposes a per-exit TTL plus
503 free_tier_ip_blockedwhen every exit isblocked. This PR is complementary but deliberately differs in one respect:
when a Go key is configured, keyed requests to
/zen/goare authenticated andare not subject to the free-tier IP block (verified
200from the same blockedIP), so falling through to the keyed tiers can keep serving instead of returning
503. A Zen key shares the free gateway and will still 403. If maintainersprefer the
503semantics, that is a small change on top of this PR.Testing
go build ./...andgo vet ./internal/...pass;gofmtclean.anonymous_breaker_open,status=403,paused_for=1h0m0s), and the next request reached the Go tierin about 1.5s with no anonymous attempt.
AI disclosure
This change was generated by an AI coding agent (DeepSeek) working with the
human submitter, then built, vetted, and validated in a live deployment as
described above. The human submitter has reviewed the diff and can answer
follow-up questions.