Skip to content

feat(llm-gateway): forward priority#277

Open
along-2017 wants to merge 4 commits into
mainfrom
feat/llm-gateway-forward-x-priority
Open

feat(llm-gateway): forward priority#277
along-2017 wants to merge 4 commits into
mainfrom
feat/llm-gateway-forward-x-priority

Conversation

@along-2017

@along-2017 along-2017 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

TL;DR

The gateway now forwards the caller priority that NVCF API resolves during invocation auth to Stargate, as the X-Priority header on all three LLM paths (chat/completions, responses, embeddings/generic proxy). The header is gateway-owned: client-supplied values are stripped on the proxied paths, an explicit 0 (highest priority) is forwarded, and an unset priority omits the header so Stargate applies its own default.

Additional Details

  • Priority arrives on the auth response as proto3 optional uint32 and stays nullable end to end, so "no priority configured" is never conflated with priority 0.
  • Emission mirrors the existing trusted optional headers (x-routing-method, x-cache-affinity-key): set only when resolved, never defaulted.
  • Rejecting client-supplied X-Priority with an explicit 400 will be tracked in a separate PR; the strip here makes forwarding safe regardless of merge order.

For the Reviewer

  • Proxy in provider/stargate.go is the subtle site: it clones inbound client headers, so X-Priority is deleted right after the clone and set only from the resolved value.
  • The .pb.go files are regenerated from the proto change; review llm_gateway.proto instead.

For QA

  • go build ./... and go test ./... are green in the gateway module. New tests cover resolved, explicit-zero, unset, and client-supplied-header cases on every path, at the middleware, client-mapping, and header-emission layers; the two highest-risk regressions (unset mapped to 0, proxy emitting 0 unconditionally) were verified by mutation.

Issues

Closes #186.

Checklist

  • I am familiar with the Contributing Guidelines.
  • I have signed off my commits for Developer Certificate of Origin (DCO) compliance.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@along-2017 along-2017 self-assigned this Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The gateway maps optional priority from NVCF authorization into RequestContext and forwards it as a gateway-controlled X-Priority header to response proxy and Stargate requests. Tests cover resolved, zero-valued, absent, and client-supplied priority cases.

Changes

Resolved priority forwarding

Layer / File(s) Summary
Priority contract and authorization propagation
src/invocation-plane-services/llm-api-gateway/nvcf/..., src/invocation-plane-services/llm-api-gateway/requestctx/requestctx.go, src/invocation-plane-services/llm-api-gateway/api/auth_middleware...
Optional priority is mapped from the proto response, copied into RequestContext, and tested for present and absent values.
Responses proxy header ownership
src/invocation-plane-services/llm-api-gateway/api/responses_handler...
The responses proxy removes client-provided X-Priority and emits only the resolved context priority.
Stargate priority forwarding
src/invocation-plane-services/llm-api-gateway/provider/stargate...
Stargate forwards resolved priority, preserves explicit zero, and strips or omits client-supplied priority when unset.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant LLM API Gateway
  participant NVCF Authorization
  participant Stargate
  Client->>LLM API Gateway: Invocation request
  LLM API Gateway->>NVCF Authorization: AuthorizeInvocation
  NVCF Authorization-->>LLM API Gateway: Optional resolved Priority
  LLM API Gateway->>LLM API Gateway: Store Priority in RequestContext
  LLM API Gateway->>Stargate: Proxy with controlled X-Priority
  Stargate-->>LLM API Gateway: Upstream response
  LLM API Gateway-->>Client: Proxied response
Loading

Suggested reviewers: max-nv

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR forwards resolved priority as X-Priority, omits it when unset, and adds tests covering both behaviors as required by #186.
Out of Scope Changes check ✅ Passed The changes stay focused on propagating and stripping priority headers, with no clear unrelated modifications.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: forwarding priority through the LLM gateway.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/llm-gateway-forward-x-priority

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

🛡️ CodeQL Analysis

🚨 Found 2 issue(s)

Severity Breakdown:

  • 🔴 Errors: 0
  • 🟡 Warnings: 0
  • 🔵 Notes: 0
📋 Top Issues

🔗 View full details in Security tab

🕐 Last updated: 2026-07-20 23:06:59 UTC | Commit: 6dddab2

@along-2017
along-2017 force-pushed the feat/llm-gateway-forward-x-priority branch from 6dddab2 to ed82f7f Compare July 20, 2026 23:44
@kristinapathak

Copy link
Copy Markdown
Contributor

Please provide a github issue instead of an internal JIRA.

@along-2017
along-2017 force-pushed the feat/llm-gateway-forward-x-priority branch from a9fd75d to 3108a91 Compare July 21, 2026 16:36
@along-2017
along-2017 marked this pull request as ready for review July 21, 2026 17:26
@along-2017
along-2017 requested a review from a team as a code owner July 21, 2026 17:26
Comment thread src/invocation-plane-services/llm-api-gateway/api/auth_middleware_test.go Outdated
NVCF API now resolves a caller priority at auth time and returns it on
AuthLlmInvokeResponse. Carry that value through the gateway and forward it
to Stargate as the X-Priority header so Stargate can apply per-priority
routing and queue estimation.

- Add optional uint32 priority to the AuthLlmInvokeResponse proto and
  regenerate the generated Go.
- Carry the nullable priority on InvocationAuthResponse and copy it onto
  RequestContext in the invocation auth middleware.
- Emit X-Priority on all three LLM paths (chat/completions, responses, and
  the embeddings/generic proxy) only when a value is resolved. An explicit 0
  (highest priority) is forwarded; an unset value omits the header so
  Stargate applies its own default, matching how the gateway already omits
  x-routing-method and x-cache-affinity-key.

The clone-based proxy path still forwards a client-supplied X-Priority when
the gateway resolves none. Rejecting client-supplied X-Priority is handled
separately; that change should land with or before this one.

Signed-off-by: along <along@nvidia.com>
Close two review gaps, both mutation-verified: a client mapping that turns
an unset proto priority into 0 and a proxy that unconditionally emits
X-Priority 0 previously passed the whole suite.

- Assert AuthorizeInvocation maps an unset proto priority to nil, and add a
  round-trip case for explicit 0 and the uint32 max as set values.
- Assert Proxy omits X-Priority when no priority is resolved, and that a
  resolved value replaces a client-supplied header from the clone with
  exactly one value rather than appending.

Signed-off-by: along <along@nvidia.com>
Address review feedback: the middleware priority tests exercised only
/v1/chat/completions. The auth middleware is registered globally and the
routing key comes from the request body model field, so propagation is
path-independent; make the resolved and unset cases table-driven over
/v1/chat/completions, /v1/responses, and /v1/embeddings to pin that for
every entry that forwards X-Priority.

Signed-off-by: along <along@nvidia.com>
@along-2017
along-2017 force-pushed the feat/llm-gateway-forward-x-priority branch from 75150e7 to 70321cd Compare July 21, 2026 21:36
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.

Forward resolved priority to the LLM backend

3 participants