Skip to content

refactor(aibridge/intercept): inject actor headers in middleware - #29839

Merged
johnstcn merged 2 commits into
mainfrom
refactor/ai-gateway-actor-header-middleware
Sep 24, 2026
Merged

johnstcn merged 2 commits into
mainfrom
refactor/ai-gateway-actor-header-middleware

Conversation

@johnstcn

@johnstcn johnstcn commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Move actor-header injection into the shared upstream-header middleware for Messages, Chat Completions, and Responses. Read the authenticated actor from the request context and remove the duplicated SDK-option injection from blocking and streaming paths, completing the TODO from @ssncferreira.

Preserve the existing header names and forwarding toggle. This is the first PR in the actor-header stack: #29839 → #29840 (email forwarding) → #29812 (configurable names).

Refs https://linear.app/codercom/issue/AIGOV-601

🤖 Generated by AI with human input.

@linear-code

linear-code Bot commented Sep 24, 2026

Copy link
Copy Markdown

AIGOV-601

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

if i.clientHeaders != nil {
opts = append(opts, option.WithMiddleware(func(req *http.Request, next option.MiddlewareNext) (*http.Response, error) {
req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.cred.AuthHeader())
req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.cred.AuthHeader(), i.cfg, aibcontext.ActorFromContext(req.Context()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for this 🙏 completely forgot about the TODO 🙇‍♀️

}
}

if cfg.SendActorHeaders {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not necessarly, for this PR, but AFAIK we are not stripping the X-AI-Bridge-Actor-*, meaning that if a user does make a request with these headers, they will still be sent upstream. We should probably strip them

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can't find any mention in our current documentation regarding what headers we strip. Stripping additional headers would be a behavioural change that I'd rather keep out of scope of this PR. It's worth a follow-up issue though.

Comment thread aibridge/intercept/client_headers.go Outdated
// Preserve actor headers injected by aibridge as per-request SDK options.
// Preserve actor headers injected by other SDK options.
for name, values := range sdkHeader {
if IsActorHeader(name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IIUC, with SDK-option injection removed, the actors headers are no longer injected in sdkHeader. So we can probably just delete this? 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍 Good catch

@johnstcn
johnstcn merged commit 9a4cb3a into main Sep 24, 2026
27 of 28 checks passed
@johnstcn
johnstcn deleted the refactor/ai-gateway-actor-header-middleware branch September 24, 2026 16:20
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants