Skip to content

Conversation

@dannykopping
Copy link
Collaborator

Closes #135

Introduces a new header (X-AI-Bridge-Actor-Id) which will optionally be sent along with upstream requests with the actor's identity as the value.

Any metadata includes in the context.Actor struct will also be added to the headers in the format X-AI-Bridge-Actor-{Key}={Value}.

When enabled in coder/coder, two new headers will be added:

X-Ai-Bridge-Actor-Id: f2b8590e-693a-4cf7-9e30-36ccd8af3a60
X-Ai-Bridge-Actor-Metadata-Username: admin

Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping marked this pull request as ready for review January 23, 2026 09:37
Copy link
Contributor

@ssncferreira ssncferreira left a comment

Choose a reason for hiding this comment

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

Overall LGTM 👍 just some nits around header key/value sanitization. I know most of this is validated on the coder side, but since this is a library might be worth sanitizing or rejecting bad input.

}

func ActorMetadataHeader(name string) string {
return fmt.Sprintf("%s-Metadata-%s", prefix, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: shouldn't we check if name != ""?
Otherwise, we could end with headers like X-AI-Bridge-Actor-Metadata-


var opts []option.RequestOption
opts = append(opts, option.WithRequestTimeout(time.Second*600))
if actor := aibcontext.ActorFromContext(r.Context()); actor != nil && i.cfg.SendActorHeaders {
Copy link
Contributor

Choose a reason for hiding this comment

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

minor nit: should we maybe check the cfg first, as in most cases this will be false?

headers := make(map[string]string, len(actor.Metadata)+1)

// Add actor ID.
headers[ActorIDHeader()] = actor.ID
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can actor.ID be ""? Probably not, but be worth the check


// Add headers for provided metadata.
for k, v := range actor.Metadata {
headers[ActorMetadataHeader(k)] = fmt.Sprintf("%v", v)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we should probably be sanitizing the headers/vallues to make sure they don't have whitespaces or invalid characters

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.

Send initiator identity and other configured metadata with upstream requests

2 participants