Skip to content

feat(upstream): support request-scoped custom HTTP retry statuses - #120

Merged
spacewander merged 9 commits into
masterfrom
ai-proxy-advanced-fallback-401
Sep 24, 2026
Merged

spacewander merged 9 commits into
masterfrom
ai-proxy-advanced-fallback-401

Conversation

@oowl

@oowl oowl commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Allow resty.kong.upstream.set_next_upstream() to accept custom HTTP error statuses from http_400 through http_599, without adding a C constant for each new status. This enables the opt-in 400/401/402 failover in Kong/kong-ee#19297, targeting AIGW 2.2.

Custom statuses are copied into a 25-byte bitmap owned by the request context. Later setter calls replace both the mask and bitmap, failed validation preserves the previous criteria, and off overrides all retry criteria. Existing native status masks retain their behavior. The old C setter remains available and clears any custom statuses.

The matching nginx patch queries the bitmap and uses one generic custom-status flag. Custom 4xx statuses advance without marking the peer failed; custom 5xx statuses mark it failed. Real response status codes and nginx's retry limits, timeout, non-idempotent and body-buffering checks are preserved.

Dependency

Requires nginx-1.27.1_26-upstream-next-dynamic-status.patch from Kong/kong-ee#19297. The patch and module must be built together. No per-status HTTP_400/401/402 constants are required.

Validation

  • Compiled with Kong's OpenResty 1.27.1.2 and companion nginx patch.
  • Dynamic retry suite: 186 passing assertions covering 400/401/402 and arbitrary 418/529/599, isolation, replacement, input validation, off, exhaustion, native 429 accounting, retry counts/timeouts, POST body replay and streamed bodies.
  • Existing upstream and worker-connection suites: 38 passing assertions.
  • Consumer's full AI failover suite: 62 passing tests across PostgreSQL and DB-less modes.
  • Lua lint passed.

oowl and others added 2 commits June 16, 2026 16:43
Expose next_upstream masks for HTTP 400, 401 and 402 so that
set_next_upstream() accepts these status codes, enabling failover on
them (e.g. ai-proxy-advanced failover_criteria). Requires the matching
nginx core flags NGX_HTTP_UPSTREAM_FT_HTTP_400/401/402.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@oowl oowl changed the title feat(upstream): support http_400/http_401/http_402 in set_next_upstream feat(upstream): support request-scoped custom HTTP retry statuses Sep 20, 2026
@oowl
oowl force-pushed the ai-proxy-advanced-fallback-401 branch from 53267ff to fb4fadc Compare September 21, 2026 07:58
Comment thread src/ngx_http_lua_kong_common.h Outdated
ngx_str_t grpc_authority;
ngx_http_log_handler_pt orig_log_handler;
ngx_uint_t next_upstream;
u_char next_upstream_statuses[25]; /* HTTP 400..599 */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems static memory footprint debt even for people that not using it (API GW for example), can we improve it?

Copilot AI lite review requested due to automatic review settings September 24, 2026 04:10

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.

@spacewander
spacewander merged commit aab5953 into master Sep 24, 2026
10 of 12 checks passed
@spacewander
spacewander deleted the ai-proxy-advanced-fallback-401 branch September 24, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants