Skip to content

EAI-7043: fix UUID-based AIM routing via Lua filter#764

Merged
johnl-amd merged 5 commits into
mainfrom
EAI-7043-fix-ai-gateway-backend-route-specificity
Jun 25, 2026
Merged

EAI-7043: fix UUID-based AIM routing via Lua filter#764
johnl-amd merged 5 commits into
mainfrom
EAI-7043-fix-ai-gateway-backend-route-specificity

Conversation

@johnl-amd

Copy link
Copy Markdown
Contributor

Summary

  • Lua filter (set-model-header-from-body) now skips setting x-ai-eg-model when a backend UUID is present in the request body or headers, so model-name fallback rules in other HTTPRoutes cannot match. The UUID rule (Host + x-ai-eg-backend) wins by specificity over catch-all rules regardless of HTTPRoute creation order.
  • Introduces x-ai-eg-model-log header, always set from the body's model field, so the access log retains model attribution for both UUID-routed and model-name-routed requests.
  • Access log format updated to read x-ai-eg-model-log instead of x-ai-eg-model.

Root cause

Envoy Gateway merges HTTPRoute rules maintaining per-route creation-timestamp ordering, not global specificity. Two rules with equal header-match counts from different HTTPRoutes — the older route always wins. When two AIMs serve the same model, the first-created route's model-name rule would always win, routing to the wrong AIM regardless of the x-ai-eg-backend header.

Test plan

  • Deploy to app-dev and send a request with "backend": "<uuid>" in the body; verify backendCluster in access log shows the correct AIM's HTTPRoute rule
  • Verify model field in access log is still populated for UUID requests
  • Verify model-name routing (no backend field) still works for standard OpenAI clients

…is present

When x-ai-eg-backend is set (from body or as a direct header), x-ai-eg-model
is intentionally skipped. This prevents model-name fallback rules in other
HTTPRoutes from matching — Envoy Gateway maintains per-HTTPRoute ordering so
an older route's model-name rule fires before a newer route's UUID rule when
both have equal specificity. Without x-ai-eg-model, only the UUID rule and
catch-all rules remain; the UUID rule (2 conditions) beats catch-all (0
conditions) by specificity regardless of creation order.
@johnl-amd johnl-amd requested a review from a team as a code owner June 24, 2026 11:39

@blankdots blankdots left a comment

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.

lgtm

@johnl-amd johnl-amd merged commit 73b3ca4 into main Jun 25, 2026
7 checks passed
@johnl-amd johnl-amd deleted the EAI-7043-fix-ai-gateway-backend-route-specificity branch June 25, 2026 09:41
oskarasbrink added a commit that referenced this pull request Jun 25, 2026
merge main to get #764 into RC branch
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.

2 participants