Skip to content

feat(ai-proxy-multi): let configured HTTP statuses trigger a fallback - #13852

Merged
nic-6443 merged 1 commit into
apache:masterfrom
nic-6443:feat/ai-proxy-multi-fallback-http-statuses
Aug 20, 2026
Merged

feat(ai-proxy-multi): let configured HTTP statuses trigger a fallback#13852
nic-6443 merged 1 commit into
apache:masterfrom
nic-6443:feat/ai-proxy-multi-fallback-http-statuses

Conversation

@nic-6443

Copy link
Copy Markdown
Member

Request-level fallback in ai-proxy-multi only covers 429 and 5xx. A provider that answers 401 for an expired API key, or 402 for a drained quota, returns that response straight to the client even when other instances with working keys are configured. Active health checks can eventually take the bad instance out of rotation, but they cannot rescue the request that is already in flight — which is exactly the multi-key setup people use this plugin for.

This adds fallback_http_statuses, an explicit list of upstream statuses that join the http_429 / http_5xx entries of fallback_strategy in triggering a fallback:

{
  "fallback_http_statuses": [401, 402],
  "instances": [ ... ]
}

It is opt-in per status rather than a blanket "retry 4xx": most 4xx responses are caused by the request itself, and retrying those on another instance only burns quota on a request that will fail everywhere.

The decision lives in two places that have to agree. ai-proxy/base.lua diverts only 429/5xx to the error path, where the response body is read and handed to the retry callback; every other status is parsed and streamed to the client and never reaches retry_on_error at all. So relaxing only the retry condition would have had no effect — both now consult the same helper. max_retries and retry_on_failure_within_ms bound these retries like any other fallback, and with no matching status the behaviour is unchanged.

Tests cover the fallback on 401/402, the max_retries interaction, the unchanged pass-through when the status is not configured, and the schema range check.

Only 429 and 5xx could fall back to another instance. A provider that
answers 401 for an expired API key or 402 for a drained quota therefore
returned that response straight to the client even when other instances
with working keys were configured: active health checks can eventually
take the instance out of rotation, but they cannot rescue the request
that is in flight.

Add fallback_http_statuses, an explicit list of upstream statuses that
join http_429 / http_5xx in triggering the fallback. It has to be opt-in
per status: most 4xx responses are caused by the request itself, and
retrying those on another instance would only burn quota on a request
that fails everywhere.

The decision lives in two places that must agree. base.lua diverts only
429/5xx to the error path, where the body is read and handed to the
retry callback; every other status is streamed to the client and never
reaches ai-proxy-multi's retry_on_error at all. Both now consult the
same helper, so a configured status is diverted and then retried, and
max_retries / retry_on_failure_within_ms bound it like any other
fallback.
Copilot AI lite review requested due to automatic review settings August 19, 2026 14:03
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dosubot dosubot Bot added the enhancement New feature or request label Aug 19, 2026

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nic-6443
nic-6443 merged commit aa4472c into apache:master Aug 20, 2026
26 of 35 checks passed
@nic-6443
nic-6443 deleted the feat/ai-proxy-multi-fallback-http-statuses branch August 20, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants